diff --git a/frontend/ui/widget/button.lua b/frontend/ui/widget/button.lua index 5e08c5813..2ba9321e8 100644 --- a/frontend/ui/widget/button.lua +++ b/frontend/ui/widget/button.lua @@ -7,6 +7,7 @@ Button = InputContainer:new{ text = nil, -- mandatory preselect = false, callback = nil, + enabled = true, margin = 0, bordersize = 3, background = 0, @@ -18,11 +19,13 @@ Button = InputContainer:new{ } function Button:init() - local text_widget = TextWidget:new{ + self.text_widget = TextWidget:new{ text = self.text, + bgcolor = 0.0, + fgcolor = self.enabled and 1.0 or 0.5, face = Font:getFace(self.text_font_face, self.text_font_size) } - local text_size = text_widget:getSize() + local text_size = self.text_widget:getSize() if self.width == nil then self.width = text_size.w end @@ -35,7 +38,7 @@ function Button:init() padding = self.padding, HorizontalGroup:new{ HorizontalSpan:new{ width = (self.width - text_size.w)/2 }, - text_widget, + self.text_widget, HorizontalSpan:new{ width = (self.width - text_size.w)/2 }, } } @@ -68,7 +71,19 @@ function Button:onUnfocus() return true end +function Button:enable() + self.enabled = true + self.text_widget.fgcolor = 1.0 +end + +function Button:disable() + self.enabled = false + self.text_widget.fgcolor = 0.5 +end + function Button:onTapSelect() - self.callback() + if self.enabled then + self.callback() + end return true end diff --git a/frontend/ui/widget/buttontable.lua b/frontend/ui/widget/buttontable.lua index 842e16564..bbf905ab1 100644 --- a/frontend/ui/widget/buttontable.lua +++ b/frontend/ui/widget/buttontable.lua @@ -4,8 +4,8 @@ require "ui/widget/line" ButtonTable = InputContainer:new{ buttons = { { - {text="OK", callback=nil}, - {text="Cancel", callback=nil}, + {text="OK", enabled=true, callback=nil}, + {text="Cancel", enabled=false, callback=nil}, }, }, tap_close_callback = nil, @@ -43,6 +43,7 @@ function ButtonTable:init() for j = 1, #line do local button = Button:new{ text = line[j].text, + enabled = line[j].enabled, callback = line[j].callback, width = Screen:getWidth()*0.9/#line, bordersize = 0,