mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Button: fix enableDisable when multilines
Also add support for a enabled_func() property, and ensure its enable/disable state on each repaint.
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user