-
Notifications
You must be signed in to change notification settings - Fork 498
Refactor button widgets; add widgets.RadioButton
#5781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
bcc0d46
Create graphic_button.lua
Bumber64 6367685
Update help_button.lua - Derive from GraphicButton widget
Bumber64 8badbf4
Update configure_button.lua - Derive from GraphicButton widget
Bumber64 f7debea
Create toggle_button.lua
Bumber64 d7fb882
Update widgets.lua - Add ToggleButton widget
Bumber64 84c33aa
Merge branch 'develop' into button-widgets
Bumber64 0fdc3b7
ConfigureButton replaces GraphicButton; rename ToggleButton; docs
Bumber64 3fb5af1
Use postinit
Bumber64 d25d438
Update changelog.txt
Bumber64 ac925d2
Merge branch 'develop' into button-widgets
ab9rf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,53 +1,35 @@ | ||
| -- A 3x1 tile button with a question mark on it. Clicking on it will show help text for a command | ||
|
|
||
| local textures = require('gui.textures') | ||
| local Panel = require('gui.widgets.containers.panel') | ||
| local Label = require('gui.widgets.labels.label') | ||
| local ConfigureButton = require('gui.widgets.buttons.configure_button') | ||
|
|
||
| local to_pen = dfhack.pen.parse | ||
| local help_pen_center = dfhack.pen.parse{ | ||
| tile=curry(textures.tp_control_panel, 9) or nil, ch=string.byte('?')} | ||
|
|
||
| ---------------- | ||
| -- HelpButton -- | ||
| ---------------- | ||
|
|
||
| ---@class widgets.HelpButton.attrs: widgets.Panel.attrs | ||
| ---@class widgets.HelpButton.attrs: widgets.ConfigureButton.attrs | ||
| ---@field command? string | ||
|
|
||
| ---@class widgets.HelpButton.attrs.partial: widgets.HelpButton.attrs | ||
|
|
||
| ---@class widgets.HelpButton: widgets.Panel, widgets.HelpButton.attrs | ||
| ---@field super widgets.Panel | ||
| ---@class widgets.HelpButton: widgets.ConfigureButton, widgets.HelpButton.attrs | ||
| ---@field super widgets.ConfigureButton | ||
| ---@field ATTRS widgets.HelpButton.attrs|fun(attributes: widgets.HelpButton.attrs.partial) | ||
| ---@overload fun(init_table: widgets.HelpButton.attrs.partial): self | ||
| HelpButton = defclass(HelpButton, Panel) | ||
| HelpButton = defclass(HelpButton, ConfigureButton) | ||
|
Bumber64 marked this conversation as resolved.
|
||
|
|
||
| HelpButton.ATTRS{ | ||
| frame={t=0, r=1, w=3, h=1}, | ||
| command=DEFAULT_NIL, | ||
| pen_center=help_pen_center, | ||
|
Bumber64 marked this conversation as resolved.
|
||
| } | ||
|
|
||
| local button_pen_left = to_pen{fg=COLOR_CYAN, | ||
| tile=curry(textures.tp_control_panel, 7) or nil, ch=string.byte('[')} | ||
| local button_pen_right = to_pen{fg=COLOR_CYAN, | ||
| tile=curry(textures.tp_control_panel, 8) or nil, ch=string.byte(']')} | ||
| local help_pen_center = to_pen{ | ||
| tile=curry(textures.tp_control_panel, 9) or nil, ch=string.byte('?')} | ||
|
|
||
| function HelpButton:init() | ||
| self.frame.w = self.frame.w or 3 | ||
| self.frame.h = self.frame.h or 1 | ||
|
|
||
| local command = self.command .. ' ' | ||
|
|
||
| self:addviews{ | ||
| Label{ | ||
| frame={t=0, l=0, w=3, h=1}, | ||
| text={ | ||
| {tile=button_pen_left}, | ||
| {tile=help_pen_center}, | ||
| {tile=button_pen_right}, | ||
| }, | ||
| on_click=function() dfhack.run_command('gui/launcher', command) end, | ||
| }, | ||
| } | ||
| self.on_click = function() dfhack.run_command('gui/launcher', command) end | ||
|
Bumber64 marked this conversation as resolved.
|
||
| end | ||
|
|
||
| return HelpButton | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| -- A 3x1 tile button that toggles state when clicked | ||
|
|
||
| local textures = require('gui.textures') | ||
| local ConfigureButton = require('gui.widgets.buttons.configure_button') | ||
|
|
||
| local to_pen = dfhack.pen.parse | ||
|
|
||
| local enabled_pen_left = to_pen{fg=COLOR_CYAN, | ||
| tile=curry(textures.tp_control_panel, 1), ch=string.byte('[')} | ||
|
Bumber64 marked this conversation as resolved.
|
||
| local enabled_pen_center = to_pen{fg=COLOR_LIGHTGREEN, | ||
| tile=curry(textures.tp_control_panel, 2) or nil, ch=251} -- check | ||
| local enabled_pen_right = to_pen{fg=COLOR_CYAN, | ||
| tile=curry(textures.tp_control_panel, 3) or nil, ch=string.byte(']')} | ||
| local disabled_pen_left = to_pen{fg=COLOR_CYAN, | ||
| tile=curry(textures.tp_control_panel, 4) or nil, ch=string.byte('[')} | ||
| local disabled_pen_center = to_pen{fg=COLOR_RED, | ||
| tile=curry(textures.tp_control_panel, 5) or nil, ch=string.byte('x')} | ||
| local disabled_pen_right = to_pen{fg=COLOR_CYAN, | ||
| tile=curry(textures.tp_control_panel, 6) or nil, ch=string.byte(']')} | ||
|
|
||
| ----------------- | ||
| -- RadioButton -- | ||
| ----------------- | ||
|
|
||
| ---@class widgets.RadioButton.attrs: widgets.ConfigureButton.attrs | ||
| ---@field initial_state boolean | ||
|
|
||
| ---@class widgets.RadioButton.attrs.partial: widgets.RadioButton.attrs | ||
|
|
||
| ---@class widgets.RadioButton: widgets.ConfigureButton, widgets.RadioButton.attrs | ||
| ---@field super widgets.ConfigureButton | ||
| ---@field ATTRS widgets.RadioButton.attrs|fun(attributes: widgets.RadioButton.attrs.partial) | ||
| ---@overload fun(init_table: widgets.RadioButton.attrs.partial): self | ||
| RadioButton = defclass(RadioButton, ConfigureButton) | ||
|
|
||
| RadioButton.ATTRS{ | ||
| initial_state=true, | ||
| } | ||
|
|
||
| function RadioButton:init() | ||
| self.toggle_state = self.initial_state | ||
|
|
||
| self.on_click = function() self.toggle_state = not self.toggle_state end | ||
| self.pen_left = function() return self.toggle_state and enabled_pen_left or disabled_pen_left end | ||
| self.pen_center = function() return self.toggle_state and enabled_pen_center or disabled_pen_center end | ||
| self.pen_right = function() return self.toggle_state and enabled_pen_right or disabled_pen_right end | ||
| end | ||
|
|
||
|
SilasD marked this conversation as resolved.
|
||
| return RadioButton | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.