From bcc0d46dda602cdfbe9054aad3f185e3b2036bdd Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Tue, 31 Mar 2026 04:10:46 -0700 Subject: [PATCH 1/8] Create graphic_button.lua --- .../gui/widgets/buttons/graphic_button.lua | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 library/lua/gui/widgets/buttons/graphic_button.lua diff --git a/library/lua/gui/widgets/buttons/graphic_button.lua b/library/lua/gui/widgets/buttons/graphic_button.lua new file mode 100644 index 0000000000..f2ffa36be8 --- /dev/null +++ b/library/lua/gui/widgets/buttons/graphic_button.lua @@ -0,0 +1,68 @@ +local textures = require('gui.textures') +local Panel = require('gui.widgets.containers.panel') +local Label = require('gui.widgets.labels.label') + +local to_pen = dfhack.pen.parse + +local button_pen_left = to_pen{fg=COLOR_CYAN, + tile=curry(textures.tp_control_panel, 7) or nil, ch=string.byte('[')} +local button_pen_center = to_pen{fg=COLOR_CYAN, + tile=curry(textures.tp_control_panel, 10) 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(']')} + +------------------- +-- GraphicButton -- +------------------- + +---@class widgets.GraphicButton.attrs: widgets.Panel.attrs +---@field on_click? function +---@field pen_left dfhack.pen|fun(): dfhack.pen +---@field pen_center dfhack.pen|fun(): dfhack.pen +---@field pen_right dfhack.pen|fun(): dfhack.pen + +---@class widgets.GraphicButton.attrs.partial: widgets.GraphicButton.attrs + +---@class widgets.GraphicButton: widgets.Panel, widgets.GraphicButton.attrs +---@field super widgets.Panel +---@field ATTRS widgets.GraphicButton.attrs|fun(attributes: widgets.GraphicButton.attrs.partial) +---@overload fun(init_table: widgets.GraphicButton.attrs.partial): self +GraphicButton = defclass(GraphicButton, Panel) + +GraphicButton.ATTRS{ + on_click=DEFAULT_NIL, + pen_left=button_pen_left, + pen_center=button_pen_center, + pen_right=button_pen_right, +} + +function GraphicButton:init() + self.frame.w = self.frame.w or 3 + self.frame.h = self.frame.h or 1 + + self:addviews{ + Label{ + view_id='label', + frame={t=0, l=0, w=3, h=1}, + text={ + {tile=self.pen_left}, + {tile=self.pen_center}, + {tile=self.pen_right}, + }, + on_click=self.on_click, + }, + } +end + +function GraphicButton:refresh() + local l = self.subviews.label + + l.on_click = self.on_click + l.pen_left = self.pen_left + l.pen_center = self.pen_center + l.pen_right = self.pen_right + + l:setText({{tile=self.pen_left}, {tile=self.pen_center}, {tile=self.pen_right}}) +end + +return GraphicButton From 6367685819cd0cf37e5fb48bb99555f0457e413b Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Tue, 31 Mar 2026 04:13:14 -0700 Subject: [PATCH 2/8] Update help_button.lua - Derive from GraphicButton widget --- .../lua/gui/widgets/buttons/help_button.lua | 38 +++++-------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/library/lua/gui/widgets/buttons/help_button.lua b/library/lua/gui/widgets/buttons/help_button.lua index 9f9b7dc989..99aa15e7fb 100644 --- a/library/lua/gui/widgets/buttons/help_button.lua +++ b/library/lua/gui/widgets/buttons/help_button.lua @@ -1,53 +1,35 @@ local textures = require('gui.textures') -local Panel = require('gui.widgets.containers.panel') -local Label = require('gui.widgets.labels.label') +local GraphicButton = require('gui.widgets.buttons.graphic_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.GraphicButton.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.GraphicButton, widgets.HelpButton.attrs +---@field super widgets.GraphicButton ---@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, GraphicButton) HelpButton.ATTRS{ frame={t=0, r=1, w=3, h=1}, command=DEFAULT_NIL, + pen_center=help_pen_center, } -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 + self:refresh() end return HelpButton From 8badbf43952be756953c249e725fadfcf78d6106 Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Tue, 31 Mar 2026 04:14:05 -0700 Subject: [PATCH 3/8] Update configure_button.lua - Derive from GraphicButton widget --- .../gui/widgets/buttons/configure_button.lua | 46 +++---------------- 1 file changed, 6 insertions(+), 40 deletions(-) diff --git a/library/lua/gui/widgets/buttons/configure_button.lua b/library/lua/gui/widgets/buttons/configure_button.lua index b93b1e18b2..bfca49eeb5 100644 --- a/library/lua/gui/widgets/buttons/configure_button.lua +++ b/library/lua/gui/widgets/buttons/configure_button.lua @@ -1,53 +1,19 @@ local textures = require('gui.textures') -local Panel = require('gui.widgets.containers.panel') -local Label = require('gui.widgets.labels.label') +local GraphicButton = require('gui.widgets.buttons.graphic_button') -local to_pen = dfhack.pen.parse - -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 configure_pen_center = to_pen{ +local configure_pen_center = dfhack.pen.parse{ tile=curry(textures.tp_control_panel, 10) or nil, ch=15} -- gear/masterwork symbol --------------------- -- ConfigureButton -- --------------------- ----@class widgets.ConfigureButton.attrs: widgets.Panel.attrs ----@field on_click? function - ----@class widgets.ConfigureButton.attrs.partial: widgets.ConfigureButton.attrs - ----@class widgets.ConfigureButton: widgets.Panel, widgets.ConfigureButton.attrs ----@field super widgets.Panel ----@field ATTRS widgets.ConfigureButton.attrs|fun(attributes: widgets.ConfigureButton.attrs.partial) ----@overload fun(init_table: widgets.ConfigureButton.attrs.partial): self -ConfigureButton = defclass(ConfigureButton, Panel) +---@class widgets.ConfigureButton.attrs: widgets.GraphicButton.attrs +---@field super widgets.GraphicButton +ConfigureButton = defclass(ConfigureButton, GraphicButton) ConfigureButton.ATTRS{ - on_click=DEFAULT_NIL, + pen_center=configure_pen_center, } -function ConfigureButton:preinit(init_table) - init_table.frame = init_table.frame or {} - init_table.frame.h = init_table.frame.h or 1 - init_table.frame.w = init_table.frame.w or 3 -end - -function ConfigureButton:init() - self:addviews{ - Label{ - frame={t=0, l=0, w=3, h=1}, - text={ - {tile=button_pen_left}, - {tile=configure_pen_center}, - {tile=button_pen_right}, - }, - on_click=self.on_click, - }, - } -end - return ConfigureButton From f7debea7a39562fc56370baa56b39dca69c8f313 Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Tue, 31 Mar 2026 04:14:56 -0700 Subject: [PATCH 4/8] Create toggle_button.lua --- .../lua/gui/widgets/buttons/toggle_button.lua | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 library/lua/gui/widgets/buttons/toggle_button.lua diff --git a/library/lua/gui/widgets/buttons/toggle_button.lua b/library/lua/gui/widgets/buttons/toggle_button.lua new file mode 100644 index 0000000000..21c2122476 --- /dev/null +++ b/library/lua/gui/widgets/buttons/toggle_button.lua @@ -0,0 +1,49 @@ +local textures = require('gui.textures') +local GraphicButton = require('gui.widgets.buttons.graphic_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('[')} +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(']')} + +------------------ +-- ToggleButton -- +------------------ + +---@class widgets.ToggleButton.attrs: widgets.GraphicButton.attrs +---@field initial_state boolean + +---@class widgets.ToggleButton.attrs.partial: widgets.ToggleButton.attrs + +---@class widgets.ToggleButton: widgets.GraphicButton, widgets.ToggleButton.attrs +---@field super widgets.GraphicButton +---@field ATTRS widgets.ToggleButton.attrs|fun(attributes: widgets.ToggleButton.attrs.partial) +---@overload fun(init_table: widgets.ToggleButton.attrs.partial): self +ToggleButton = defclass(ToggleButton, GraphicButton) + +ToggleButton.ATTRS{ + initial_state=true, +} + +function ToggleButton: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 + + self:refresh() +end + +return ToggleButton From d7fb882a520d2d586fdebaf328a5a63698af3f01 Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Tue, 31 Mar 2026 04:16:04 -0700 Subject: [PATCH 5/8] Update widgets.lua - Add ToggleButton widget --- library/lua/gui/widgets.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/library/lua/gui/widgets.lua b/library/lua/gui/widgets.lua index e7870f88e8..744827d9bb 100644 --- a/library/lua/gui/widgets.lua +++ b/library/lua/gui/widgets.lua @@ -18,6 +18,7 @@ WrappedLabel = require('gui.widgets.labels.wrapped_label') TooltipLabel = require('gui.widgets.labels.tooltip_label') HelpButton = require('gui.widgets.buttons.help_button') ConfigureButton = require('gui.widgets.buttons.configure_button') +ToggleButton = require('gui.widgets.buttons.toggle_button') BannerPanel = require('gui.widgets.containers.banner_panel') TextButton = require('gui.widgets.buttons.text_button') CycleHotkeyLabel = require('gui.widgets.labels.cycle_hotkey_label') From 0fdc3b748d8c277c618b17a426fe20a2c4f13eaa Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Sat, 4 Jul 2026 22:35:46 -0700 Subject: [PATCH 6/8] ConfigureButton replaces GraphicButton; rename ToggleButton; docs * Update widgets.lua - RadioButton * Update and rename toggle_button.lua to radio_button.lua * Update help_button.lua * Update configure_button.lua - Replace GraphicButton * Delete library/lua/gui/widgets/buttons/graphic_button.lua * Update Lua API.rst - Add RadioButton; HelpButton now subclass --- docs/dev/Lua API.rst | 33 ++++++--- library/lua/gui/widgets.lua | 4 +- .../gui/widgets/buttons/configure_button.lua | 64 +++++++++++++++-- .../gui/widgets/buttons/graphic_button.lua | 68 ------------------- .../lua/gui/widgets/buttons/help_button.lua | 12 ++-- .../{toggle_button.lua => radio_button.lua} | 30 ++++---- 6 files changed, 108 insertions(+), 103 deletions(-) delete mode 100644 library/lua/gui/widgets/buttons/graphic_button.lua rename library/lua/gui/widgets/buttons/{toggle_button.lua => radio_button.lua} (64%) diff --git a/docs/dev/Lua API.rst b/docs/dev/Lua API.rst index 0fbcb41971..9071a1db6b 100644 --- a/docs/dev/Lua API.rst +++ b/docs/dev/Lua API.rst @@ -6346,12 +6346,27 @@ This is a specialized subclass of CycleHotkeyLabel that has two options: ``On`` (with a value of ``true``) and ``Off`` (with a value of ``false``). The ``On`` option is rendered in green. +ConfigureButton class +--------------------- + +A 3x1 tile button with a gear symbol on it, intended to represent a configure +icon. Clicking on the icon will run the given callback. The graphics can also +be overridden to create custom buttons. + +It has the following attributes: + +:on_click: The function to run when the icon is clicked. +:pen_left: Pen or function returning a pen to overwrite the left tile of the button. +:pen_center: As above, but for the center tile (gear symbol). +:pen_right: As above, but for the right tile. + HelpButton class ---------------- -A 3x1 tile button with a question mark on it, intended to represent a help -icon. Clicking on the icon will launch `gui/launcher` with a given command -string, showing the help text for that command. +Subclass of ConfigureButton; a 3x1 tile button with a question mark on it, +intended to represent a help icon. Clicking on the icon will launch +`gui/launcher` with a given command string, showing the help text for that +command. It has the following attributes: @@ -6361,15 +6376,17 @@ It also sets the ``frame`` attribute so the button appears in the upper right corner of the parent, but you can override this to your liking if you want a different position. -ConfigureButton class ---------------------- +RadioButton class +----------------- -A 3x1 tile button with a gear mark on it, intended to represent a configure -icon. Clicking on the icon will run the given callback. +Subclass of ConfigureButton; a 3x1 tile button that resembles a radio button +(or check box in ASCII mode), identical to the ones found in +`gui/control-panel`. Clicking on the button will toggle its enabled state. +This state is represented by the boolean value ``toggle_state``. It has the following attributes: -:on_click: The function on run when the icon is clicked. +:initial_state: Start in the ``true`` or ``false`` state. Defaults to ``true``. BannerPanel class ----------------- diff --git a/library/lua/gui/widgets.lua b/library/lua/gui/widgets.lua index 744827d9bb..726b52003a 100644 --- a/library/lua/gui/widgets.lua +++ b/library/lua/gui/widgets.lua @@ -16,9 +16,9 @@ Label = require('gui.widgets.labels.label') Scrollbar = require('gui.widgets.scrollbar') WrappedLabel = require('gui.widgets.labels.wrapped_label') TooltipLabel = require('gui.widgets.labels.tooltip_label') -HelpButton = require('gui.widgets.buttons.help_button') ConfigureButton = require('gui.widgets.buttons.configure_button') -ToggleButton = require('gui.widgets.buttons.toggle_button') +HelpButton = require('gui.widgets.buttons.help_button') +RadioButton = require('gui.widgets.buttons.radio_button') BannerPanel = require('gui.widgets.containers.banner_panel') TextButton = require('gui.widgets.buttons.text_button') CycleHotkeyLabel = require('gui.widgets.labels.cycle_hotkey_label') diff --git a/library/lua/gui/widgets/buttons/configure_button.lua b/library/lua/gui/widgets/buttons/configure_button.lua index bfca49eeb5..f3199618ca 100644 --- a/library/lua/gui/widgets/buttons/configure_button.lua +++ b/library/lua/gui/widgets/buttons/configure_button.lua @@ -1,19 +1,71 @@ +-- A 3x1 tile button with a gear symbol on it. Clicking on it will run a callback + local textures = require('gui.textures') -local GraphicButton = require('gui.widgets.buttons.graphic_button') +local Panel = require('gui.widgets.containers.panel') +local Label = require('gui.widgets.labels.label') + +local to_pen = dfhack.pen.parse -local configure_pen_center = dfhack.pen.parse{ +local button_pen_left = to_pen{fg=COLOR_CYAN, + tile=curry(textures.tp_control_panel, 7) or nil, ch=string.byte('[')} +local button_pen_center = to_pen{ tile=curry(textures.tp_control_panel, 10) or nil, ch=15} -- gear/masterwork symbol +local button_pen_right = to_pen{fg=COLOR_CYAN, + tile=curry(textures.tp_control_panel, 8) or nil, ch=string.byte(']')} --------------------- -- ConfigureButton -- --------------------- ----@class widgets.ConfigureButton.attrs: widgets.GraphicButton.attrs ----@field super widgets.GraphicButton -ConfigureButton = defclass(ConfigureButton, GraphicButton) +---@class widgets.ConfigureButton.attrs: widgets.Panel.attrs +---@field on_click? function +---@field pen_left dfhack.pen|fun(): dfhack.pen +---@field pen_center dfhack.pen|fun(): dfhack.pen +---@field pen_right dfhack.pen|fun(): dfhack.pen + +---@class widgets.ConfigureButton.attrs.partial: widgets.ConfigureButton.attrs + +---@class widgets.ConfigureButton: widgets.Panel, widgets.ConfigureButton.attrs +---@field super widgets.Panel +---@field ATTRS widgets.ConfigureButton.attrs|fun(attributes: widgets.ConfigureButton.attrs.partial) +---@overload fun(init_table: widgets.ConfigureButton.attrs.partial): self +ConfigureButton = defclass(ConfigureButton, Panel) ConfigureButton.ATTRS{ - pen_center=configure_pen_center, + frame={t=0, l=0, w=3, h=1}, + on_click=DEFAULT_NIL, + pen_left=button_pen_left, + pen_center=button_pen_center, + pen_right=button_pen_right, } +function ConfigureButton:init() + self.frame.h = self.frame.h or 1 + self.frame.w = self.frame.w or 3 + + self:addviews{ + Label{ + view_id='label', + frame={t=0, l=0, w=3, h=1}, + text={ + {tile=self.pen_left}, + {tile=self.pen_center}, + {tile=self.pen_right}, + }, + on_click=self.on_click, + }, + } +end + +function ConfigureButton:refresh() + local l = self.subviews.label + + l.on_click = self.on_click + l.pen_left = self.pen_left + l.pen_center = self.pen_center + l.pen_right = self.pen_right + + l:setText({{tile=self.pen_left}, {tile=self.pen_center}, {tile=self.pen_right}}) +end + return ConfigureButton diff --git a/library/lua/gui/widgets/buttons/graphic_button.lua b/library/lua/gui/widgets/buttons/graphic_button.lua deleted file mode 100644 index f2ffa36be8..0000000000 --- a/library/lua/gui/widgets/buttons/graphic_button.lua +++ /dev/null @@ -1,68 +0,0 @@ -local textures = require('gui.textures') -local Panel = require('gui.widgets.containers.panel') -local Label = require('gui.widgets.labels.label') - -local to_pen = dfhack.pen.parse - -local button_pen_left = to_pen{fg=COLOR_CYAN, - tile=curry(textures.tp_control_panel, 7) or nil, ch=string.byte('[')} -local button_pen_center = to_pen{fg=COLOR_CYAN, - tile=curry(textures.tp_control_panel, 10) 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(']')} - -------------------- --- GraphicButton -- -------------------- - ----@class widgets.GraphicButton.attrs: widgets.Panel.attrs ----@field on_click? function ----@field pen_left dfhack.pen|fun(): dfhack.pen ----@field pen_center dfhack.pen|fun(): dfhack.pen ----@field pen_right dfhack.pen|fun(): dfhack.pen - ----@class widgets.GraphicButton.attrs.partial: widgets.GraphicButton.attrs - ----@class widgets.GraphicButton: widgets.Panel, widgets.GraphicButton.attrs ----@field super widgets.Panel ----@field ATTRS widgets.GraphicButton.attrs|fun(attributes: widgets.GraphicButton.attrs.partial) ----@overload fun(init_table: widgets.GraphicButton.attrs.partial): self -GraphicButton = defclass(GraphicButton, Panel) - -GraphicButton.ATTRS{ - on_click=DEFAULT_NIL, - pen_left=button_pen_left, - pen_center=button_pen_center, - pen_right=button_pen_right, -} - -function GraphicButton:init() - self.frame.w = self.frame.w or 3 - self.frame.h = self.frame.h or 1 - - self:addviews{ - Label{ - view_id='label', - frame={t=0, l=0, w=3, h=1}, - text={ - {tile=self.pen_left}, - {tile=self.pen_center}, - {tile=self.pen_right}, - }, - on_click=self.on_click, - }, - } -end - -function GraphicButton:refresh() - local l = self.subviews.label - - l.on_click = self.on_click - l.pen_left = self.pen_left - l.pen_center = self.pen_center - l.pen_right = self.pen_right - - l:setText({{tile=self.pen_left}, {tile=self.pen_center}, {tile=self.pen_right}}) -end - -return GraphicButton diff --git a/library/lua/gui/widgets/buttons/help_button.lua b/library/lua/gui/widgets/buttons/help_button.lua index 99aa15e7fb..61e9e16239 100644 --- a/library/lua/gui/widgets/buttons/help_button.lua +++ b/library/lua/gui/widgets/buttons/help_button.lua @@ -1,5 +1,7 @@ +-- 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 GraphicButton = require('gui.widgets.buttons.graphic_button') +local ConfigureButton = require('gui.widgets.buttons.configure_button') local help_pen_center = dfhack.pen.parse{ tile=curry(textures.tp_control_panel, 9) or nil, ch=string.byte('?')} @@ -8,16 +10,16 @@ local help_pen_center = dfhack.pen.parse{ -- HelpButton -- ---------------- ----@class widgets.HelpButton.attrs: widgets.GraphicButton.attrs +---@class widgets.HelpButton.attrs: widgets.ConfigureButton.attrs ---@field command? string ---@class widgets.HelpButton.attrs.partial: widgets.HelpButton.attrs ----@class widgets.HelpButton: widgets.GraphicButton, widgets.HelpButton.attrs ----@field super widgets.GraphicButton +---@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, GraphicButton) +HelpButton = defclass(HelpButton, ConfigureButton) HelpButton.ATTRS{ frame={t=0, r=1, w=3, h=1}, diff --git a/library/lua/gui/widgets/buttons/toggle_button.lua b/library/lua/gui/widgets/buttons/radio_button.lua similarity index 64% rename from library/lua/gui/widgets/buttons/toggle_button.lua rename to library/lua/gui/widgets/buttons/radio_button.lua index 21c2122476..df0dcb82ec 100644 --- a/library/lua/gui/widgets/buttons/toggle_button.lua +++ b/library/lua/gui/widgets/buttons/radio_button.lua @@ -1,5 +1,7 @@ +-- A 3x1 tile button that toggles state when clicked + local textures = require('gui.textures') -local GraphicButton = require('gui.widgets.buttons.graphic_button') +local ConfigureButton = require('gui.widgets.buttons.configure_button') local to_pen = dfhack.pen.parse @@ -16,26 +18,26 @@ local disabled_pen_center = to_pen{fg=COLOR_RED, local disabled_pen_right = to_pen{fg=COLOR_CYAN, tile=curry(textures.tp_control_panel, 6) or nil, ch=string.byte(']')} ------------------- --- ToggleButton -- ------------------- +----------------- +-- RadioButton -- +----------------- ----@class widgets.ToggleButton.attrs: widgets.GraphicButton.attrs +---@class widgets.RadioButton.attrs: widgets.ConfigureButton.attrs ---@field initial_state boolean ----@class widgets.ToggleButton.attrs.partial: widgets.ToggleButton.attrs +---@class widgets.RadioButton.attrs.partial: widgets.RadioButton.attrs ----@class widgets.ToggleButton: widgets.GraphicButton, widgets.ToggleButton.attrs ----@field super widgets.GraphicButton ----@field ATTRS widgets.ToggleButton.attrs|fun(attributes: widgets.ToggleButton.attrs.partial) ----@overload fun(init_table: widgets.ToggleButton.attrs.partial): self -ToggleButton = defclass(ToggleButton, GraphicButton) +---@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) -ToggleButton.ATTRS{ +RadioButton.ATTRS{ initial_state=true, } -function ToggleButton:init() +function RadioButton:init() self.toggle_state = self.initial_state self.on_click = function() self.toggle_state = not self.toggle_state end @@ -46,4 +48,4 @@ function ToggleButton:init() self:refresh() end -return ToggleButton +return RadioButton From 3fb5af13e70edd559fe4e09ad27b0b078ec927ff Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Sun, 5 Jul 2026 20:41:07 -0700 Subject: [PATCH 7/8] Use postinit * Update radio_button.lua * Update configure_button.lua * Update help_button.lua --- library/lua/gui/widgets/buttons/configure_button.lua | 2 +- library/lua/gui/widgets/buttons/help_button.lua | 2 -- library/lua/gui/widgets/buttons/radio_button.lua | 2 -- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/library/lua/gui/widgets/buttons/configure_button.lua b/library/lua/gui/widgets/buttons/configure_button.lua index f3199618ca..7d865b27ad 100644 --- a/library/lua/gui/widgets/buttons/configure_button.lua +++ b/library/lua/gui/widgets/buttons/configure_button.lua @@ -57,7 +57,7 @@ function ConfigureButton:init() } end -function ConfigureButton:refresh() +function ConfigureButton:postinit() local l = self.subviews.label l.on_click = self.on_click diff --git a/library/lua/gui/widgets/buttons/help_button.lua b/library/lua/gui/widgets/buttons/help_button.lua index 61e9e16239..9fa45f7a70 100644 --- a/library/lua/gui/widgets/buttons/help_button.lua +++ b/library/lua/gui/widgets/buttons/help_button.lua @@ -29,9 +29,7 @@ HelpButton.ATTRS{ function HelpButton:init() local command = self.command .. ' ' - self.on_click = function() dfhack.run_command('gui/launcher', command) end - self:refresh() end return HelpButton diff --git a/library/lua/gui/widgets/buttons/radio_button.lua b/library/lua/gui/widgets/buttons/radio_button.lua index df0dcb82ec..04d45732cb 100644 --- a/library/lua/gui/widgets/buttons/radio_button.lua +++ b/library/lua/gui/widgets/buttons/radio_button.lua @@ -44,8 +44,6 @@ function RadioButton:init() 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 - - self:refresh() end return RadioButton From d25d4383223393f4c07725bbdb5da4d229750b14 Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Sun, 5 Jul 2026 20:46:53 -0700 Subject: [PATCH 8/8] Update changelog.txt --- docs/changelog.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/changelog.txt b/docs/changelog.txt index 8e299189e7..e3c42fec28 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -61,10 +61,12 @@ Template for new versions: ## Fixes ## Misc Improvements +- ``widgets.HelpButton``: Now derives from ``widgets.ConfigureButton`` instead of using redundant code ## Documentation ## API +- ``widgets.RadioButton``: New button widget resembling those used in ``gui/control-panel`` ## Lua