Checkbutton widget optimization (#8522)

-checkmark toggling is separated from the callback
-default width added
reviewable/pr8528/r1
hius07 2 years ago committed by GitHub
parent 6ebcfd9e79
commit 19271c08c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -158,9 +158,7 @@ function FileSearcher:onShowFileSearch(search_string)
text = _("Case sensitive"),
checked = self.case_sensitive,
parent = self.search_dialog,
max_width = self.search_dialog._input_widget.width,
callback = function()
self.check_button_case:toggleCheck()
self.case_sensitive = self.check_button_case.checked
end,
}

@ -916,10 +916,6 @@ function ReaderBookmark:onSearchBookmark(bm_menu)
text = " " .. _("Case sensitive"),
checked = false,
parent = input_dialog,
max_width = input_dialog._input_widget.width,
callback = function()
check_button_case:toggleCheck()
end,
}
input_dialog:addWidget(check_button_case)
separator = CenterContainer:new{
@ -940,30 +936,18 @@ function ReaderBookmark:onSearchBookmark(bm_menu)
text = " " .. DISPLAY_PREFIX["highlight"] .. _("highlights"),
checked = true,
parent = input_dialog,
max_width = input_dialog._input_widget.width,
callback = function()
check_button_highlight:toggleCheck()
end,
}
input_dialog:addWidget(check_button_highlight)
check_button_note = CheckButton:new{
text = " " .. DISPLAY_PREFIX["note"] .. _("notes"),
checked = true,
parent = input_dialog,
max_width = input_dialog._input_widget.width,
callback = function()
check_button_note:toggleCheck()
end,
}
input_dialog:addWidget(check_button_note)
check_button_bookmark = CheckButton:new{
text = " " .. DISPLAY_PREFIX["bookmark"] .. _("page bookmarks"),
checked = true,
parent = input_dialog,
max_width = input_dialog._input_widget.width,
callback = function()
check_button_bookmark:toggleCheck()
end,
}
input_dialog:addWidget(check_button_bookmark)

@ -139,20 +139,12 @@ function ReaderSearch:onShowFulltextSearchInput()
text = _("Case sensitive"),
checked = not self.case_insensitive,
parent = self.input_dialog,
max_width = self.input_dialog._input_widget.width,
callback = function()
self.check_button_case:toggleCheck()
end,
}
self.input_dialog:addWidget(self.check_button_case)
self.check_button_regex = CheckButton:new{
text = _("Regular expression (long-press for help)"),
checked = self.use_regex,
parent = self.input_dialog,
max_width = self.input_dialog._input_widget.width,
callback = function()
self.check_button_regex:toggleCheck()
end,
hold_callback = function()
UIManager:show(InfoMessage:new{
text = help_text,

@ -118,30 +118,18 @@ local sub_item_table = {
text = _("in bold"),
checked = G_reader_settings:isTrue("keyboard_key_bold"),
parent = input_dialog,
max_width = input_dialog._input_widget.width,
callback = function()
check_button_bold:toggleCheck()
end,
}
input_dialog:addWidget(check_button_bold)
check_button_border = CheckButton:new{
text = _("with border"),
checked = G_reader_settings:nilOrTrue("keyboard_key_border"),
parent = input_dialog,
max_width = input_dialog._input_widget.width,
callback = function()
check_button_border:toggleCheck()
end,
}
input_dialog:addWidget(check_button_border)
check_button_compact = CheckButton:new{
text = _("compact"),
checked = G_reader_settings:isTrue("keyboard_key_compact"),
parent = input_dialog,
max_width = input_dialog._input_widget.width,
callback = function()
check_button_compact:toggleCheck()
end,
}
input_dialog:addWidget(check_button_compact)

@ -35,7 +35,9 @@ local CheckButton = InputContainer:new{
face = Font:getFace("smallinfofont"),
background = Blitbuffer.COLOR_WHITE,
text = nil,
max_width = nil, -- must be set by the caller
parent = nil, -- parent widget, must be set by the caller
width = nil, -- default value: parent widget's input widget width
-- If the parent widget has no input widget, the width must be set by the caller.
}
function CheckButton:init()
@ -54,7 +56,7 @@ function CheckButton:initCheckButton(checked)
self._textwidget = TextBoxWidget:new{
text = self.text,
face = self.face,
width = self.max_width - self._checkmark.dimen.w,
width = (self.width or self.parent._input_widget.width) - self._checkmark.dimen.w,
fgcolor = self.enabled and Blitbuffer.COLOR_BLACK or Blitbuffer.COLOR_DARK_GRAY,
}
local textbox_shift = math.max(0, self._checkmark.baseline - self._textwidget:getBaseline())
@ -109,9 +111,17 @@ function CheckButton:initCheckButton(checked)
end
function CheckButton:onTapCheckButton()
if self.enabled and self.callback then
if not self.enabled then return true end
if self.tap_input then
self:onInput(self.tap_input)
elseif type(self.tap_input_func) == "function" then
self:onInput(self.tap_input_func())
else
if G_reader_settings:isFalse("flash_ui") then
self.callback()
self:toggleCheck()
if self.callback then
self.callback()
end
else
-- c.f., ui/widget/iconbutton for the canonical documentation about the flash_ui code flow
@ -134,14 +144,13 @@ function CheckButton:onTapCheckButton()
-- Callback
--
self.callback()
self:toggleCheck()
if self.callback then
self.callback()
end
UIManager:forceRePaint()
end
elseif self.tap_input then
self:onInput(self.tap_input)
elseif type(self.tap_input_func) == "function" then
self:onInput(self.tap_input_func())
end
return true
end

@ -867,9 +867,7 @@ function InputDialog:_addScrollButtons(nav_bar)
text = _("Case sensitive"),
checked = self.case_sensitive,
parent = input_dialog,
max_width = input_dialog._input_widget.width,
callback = function()
self.check_button_case:toggleCheck()
self.case_sensitive = self.check_button_case.checked
end,
}

@ -393,9 +393,8 @@ function InputText:initTextBox(text, char_added)
self._check_button = self._check_button or CheckButton:new{
text = _("Show password"),
parent = self,
max_width = self.width,
width = self.width,
callback = function()
self._check_button:toggleCheck()
self.text_type = self._check_button.checked and "text" or "password"
self:setText(self:getText(), true)
end,

@ -63,13 +63,8 @@ function OpenWithDialog:init()
self._check_file_button = self._check_file_button or CheckButton:new{
text = _("Always use this engine for this file"),
callback = function()
self._check_file_button:toggleCheck()
end,
max_width = self.element_width,
width = self.element_width,
face = self.face,
parent = self,
}
self._always_file_toggle = LeftContainer:new{
@ -83,13 +78,8 @@ function OpenWithDialog:init()
self._check_global_button = self._check_global_button or CheckButton:new{
text = _("Always use this engine for file type"),
callback = function()
self._check_global_button:toggleCheck()
end,
max_width = self.element_width,
width = self.element_width,
face = self.face,
parent = self,
}
self._always_global_toggle = LeftContainer:new{

Loading…
Cancel
Save