Button: fix enableDisable when multilines

Also add support for a enabled_func() property, and
ensure its enable/disable state on each repaint.
reviewable/pr10228/r4
poire-z 1 year ago
parent e3156c7b25
commit 02d6097dca

@ -252,6 +252,9 @@ function Button:enable()
if not self.enabled then
if self.text then
self.label_widget.fgcolor = Blitbuffer.COLOR_BLACK
if self.label_widget.update then -- using a TextBoxWidget
self.label_widget:update() -- needed to redraw with the new color
end
else
self.label_widget.dim = false
end
@ -263,6 +266,9 @@ function Button:disable()
if self.enabled then
if self.text then
self.label_widget.fgcolor = Blitbuffer.COLOR_DARK_GRAY
if self.label_widget.update then
self.label_widget:update()
end
else
self.label_widget.dim = true
end
@ -289,6 +295,14 @@ function Button:enableDisable(enable)
end
end
function Button:paintTo(bb, x, y)
if self.enabled_func then
-- state may change because of outside factors, so check it on each painting
self:enableDisable(self.enabled_func())
end
InputContainer.paintTo(self, bb, x, y)
end
function Button:hide()
if self.icon and not self.hidden then
self.frame.orig_background = self.frame.background

@ -53,6 +53,7 @@ function ButtonTable:init()
icon_height = btn_entry.icon_height,
align = btn_entry.align,
enabled = btn_entry.enabled,
enabled_func = btn_entry.enabled_func,
callback = function()
if self.show_parent and self.show_parent.movable then
self.show_parent.movable:resetEventState()

Loading…
Cancel
Save