From aedb713f82c268abc4edd933f5e0e1408ddc00cf Mon Sep 17 00:00:00 2001 From: hius07 <62179190+hius07@users.noreply.github.com> Date: Sat, 25 Mar 2023 09:48:30 +0200 Subject: [PATCH] Menu widget: cleanup (#10241) --- .../apps/filemanager/filemanagershortcuts.lua | 3 - frontend/ui/widget/closebutton.lua | 84 ------------------- frontend/ui/widget/menu.lua | 46 ++++------ plugins/coverbrowser.koplugin/covermenu.lua | 1 - plugins/opds.koplugin/opdscatalog.lua | 1 - 5 files changed, 17 insertions(+), 118 deletions(-) delete mode 100644 frontend/ui/widget/closebutton.lua diff --git a/frontend/apps/filemanager/filemanagershortcuts.lua b/frontend/apps/filemanager/filemanagershortcuts.lua index f8057f9b7..83f6dc3bc 100644 --- a/frontend/apps/filemanager/filemanagershortcuts.lua +++ b/frontend/apps/filemanager/filemanagershortcuts.lua @@ -225,11 +225,8 @@ function FileManagerShortcuts:onShowFolderShortcutsDialog(select_callback) self.fm_bookmark = Menu:new{ title = _("Folder shortcuts"), show_parent = self.ui, - width = Screen:getWidth(), - height = Screen:getHeight(), no_title = false, parent = nil, - has_close_button = true, is_popout = false, is_borderless = true, curr_path = self.ui.file_chooser and self.ui.file_chooser.path or self.ui:getLastDirFile(), diff --git a/frontend/ui/widget/closebutton.lua b/frontend/ui/widget/closebutton.lua deleted file mode 100644 index c57aaebb9..000000000 --- a/frontend/ui/widget/closebutton.lua +++ /dev/null @@ -1,84 +0,0 @@ ---[[-- -Button widget that shows an "×" and handles closing window when tapped - -Example: - - local CloseButton = require("ui/widget/closebutton") - local parent_widget = OverlapGroup:new{} - table.insert(parent_widget, CloseButton:new{ - window = parent_widget, - }) - UIManager:show(parent_widget) - -]] - -local Font = require("ui/font") -local FrameContainer = require("ui/widget/container/framecontainer") -local GestureRange = require("ui/gesturerange") -local InputContainer = require("ui/widget/container/inputcontainer") -local TextWidget = require("ui/widget/textwidget") -local Screen = require("device").screen - -local CloseButton = InputContainer:extend{ - overlap_align = "right", - window = nil, - padding_left = Screen:scaleBySize(14), -- for larger touch area - padding_right = 0, - padding_top = 0, - padding_bottom = 0, -} - -function CloseButton:init() - local text_widget = TextWidget:new{ - text = "×", - face = Font:getFace("cfont", 30), - } - - -- The text box height is greater than its width, and we want this × to be - -- diagonally aligned with the top right corner (assuming padding_right=0, - -- or padding_right = padding_top so the diagonal aligment is preserved). - local text_size = text_widget:getSize() - local text_width_pad = (text_size.h - text_size.w) / 2 - - self[1] = FrameContainer:new{ - bordersize = 0, - padding = 0, - padding_top = self.padding_top, - padding_bottom = self.padding_bottom, - padding_left = self.padding_left, - padding_right = self.padding_right + text_width_pad, - text_widget, - } - - self.ges_events.Close = { - GestureRange:new{ - ges = "tap", - -- x and y coordinates for the widget is only known after the it is - -- drawn. so use callback to get range at runtime. - range = function() return self.dimen end, - }, - } - - self.ges_events.HoldClose = { - GestureRange:new{ - ges = "hold_release", - range = function() return self.dimen end, - }, - } -end - -function CloseButton:onClose() - if self.window.onClose then - self.window:onClose() - end - return true -end - -function CloseButton:onHoldClose() - if self.window.onHoldClose then - self.window:onHoldClose() - end - return true -end - -return CloseButton diff --git a/frontend/ui/widget/menu.lua b/frontend/ui/widget/menu.lua index ffef40ac5..417fbe5e9 100644 --- a/frontend/ui/widget/menu.lua +++ b/frontend/ui/widget/menu.lua @@ -490,11 +490,7 @@ function MenuItem:onTapSelect(arg, ges) local pos = self:getGesPosition(ges) if G_reader_settings:isFalse("flash_ui") then - logger.dbg("creating coroutine for menu select") - local co = coroutine.create(function() - self.menu:onMenuSelect(self.table, pos) - end) - coroutine.resume(co) + self.menu:onMenuSelect(self.table, pos) else -- c.f., ui/widget/iconbutton for the canonical documentation about the flash_ui code flow @@ -515,11 +511,7 @@ function MenuItem:onTapSelect(arg, ges) -- Callback -- - logger.dbg("creating coroutine for menu select") - local co = coroutine.create(function() - self.menu:onMenuSelect(self.table, pos) - end) - coroutine.resume(co) + self.menu:onMenuSelect(self.table, pos) UIManager:forceRePaint() end @@ -602,8 +594,6 @@ local Menu = FocusManager:extend{ is_popout = true, -- set icon to add title bar left button title_bar_left_icon = nil, - -- set this to true to add close button - has_close_button = true, -- close_callback is a function, which is executed when menu is closed -- it is usually set by the widget which creates the menu close_callback = nil, @@ -640,9 +630,12 @@ function Menu:init() self.show_parent = self.show_parent or self self.item_table = self.item_table or {} self.item_table_stack = {} - self.dimen = Geom:new{ x = 0, y = 0, w = self.width, h = self.height or Screen:getHeight() } - if self.dimen.h > Screen:getHeight() or self.dimen.h == nil then - self.dimen.h = Screen:getHeight() + + self.screen_w = Screen:getWidth() + self.screen_h = Screen:getHeight() + self.dimen = Geom:new{ x = 0, y = 0, w = self.width or self.screen_w, h = self.height or self.screen_h } + if self.dimen.h > self.screen_h then + self.dimen.h = self.screen_h end self.border_size = self.is_borderless and 0 or Size.border.window @@ -675,7 +668,7 @@ function Menu:init() left_icon = self.title_bar_left_icon, left_icon_tap_callback = function() self:onLeftButtonTap() end, left_icon_hold_callback = function() self:onLeftButtonHold() end, - close_callback = self.has_close_button and function() self:onClose() end, + close_callback = function() self:onClose() end, show_parent = self.show_parent or self, } @@ -844,7 +837,7 @@ function Menu:init() dimen = self.inner_dimen:copy(), WidgetContainer:new{ dimen = Geom:new{ - w = Screen:getWidth(), + w = self.screen_w, h = self.page_return_arrow:getSize().h, }, self.return_button, @@ -852,13 +845,9 @@ function Menu:init() } self:_recalculateDimen() - self.vertical_span = HorizontalGroup:new{ - VerticalSpan:new{ width = self.span_width } - } self.content_group = VerticalGroup:new{ align = "left", header, - self.vertical_span, body, } local content = OverlapGroup:new{ @@ -891,8 +880,8 @@ function Menu:init() ges = "tap", range = Geom:new{ x = 0, y = 0, - w = Screen:getWidth(), - h = Screen:getHeight(), + w = self.screen_w, + h = self.screen_h, } } } @@ -984,7 +973,7 @@ function Menu:updatePageInfo(select_number) self:moveFocusTo(1, select_number) end -- update page information - self.page_info_text:setText(FFIUtil.template(_("Page %1 of %2"), self.page, self.page_num)) + self.page_info_text:setText(T(_("Page %1 of %2"), self.page, self.page_num)) if self.page_num > 1 then self.page_info_text:enable() else @@ -1020,7 +1009,6 @@ function Menu:updateItems(select_number) self.item_group:clear() self.page_info:resetLayout() self.return_button:resetLayout() - self.vertical_span:clear() self.content_group:resetLayout() self:_recalculateDimen() @@ -1345,8 +1333,8 @@ function Menu:onSwipe(arg, ges_ev) elseif direction == "east" then self:onPrevPage() elseif direction == "south" then - if self.has_close_button and not self.no_title then - -- If there is a close button displayed (so, this Menu can be + if not self.no_title then + -- If there is a titlebar with a close button displayed (so, this Menu can be -- closed), allow easier closing with swipe south. self:onClose() end @@ -1365,8 +1353,8 @@ function Menu:onMultiSwipe(arg, ges_ev) -- For consistency with other fullscreen widgets where swipe south can't be -- used to close and where we then allow any multiswipe to close, allow any -- multiswipe to close this widget too. - if self.has_close_button and not self.no_title then - -- If there is a close button displayed (so, this Menu can be + if not self.no_title then + -- If there is a titlebar with a close button displayed (so, this Menu can be -- closed), allow easier closing with swipe south. self:onClose() end diff --git a/plugins/coverbrowser.koplugin/covermenu.lua b/plugins/coverbrowser.koplugin/covermenu.lua index 0dd454c5a..00bd14784 100644 --- a/plugins/coverbrowser.koplugin/covermenu.lua +++ b/plugins/coverbrowser.koplugin/covermenu.lua @@ -84,7 +84,6 @@ function CoverMenu:updateItems(select_number) self:_recalculateDimen() self.page_info:resetLayout() self.return_button:resetLayout() - self.vertical_span:clear() self.content_group:resetLayout() -- default to select the first item if not select_number then diff --git a/plugins/opds.koplugin/opdscatalog.lua b/plugins/opds.koplugin/opdscatalog.lua index 555ce5e34..07bdcb2a8 100644 --- a/plugins/opds.koplugin/opdscatalog.lua +++ b/plugins/opds.koplugin/opdscatalog.lua @@ -20,7 +20,6 @@ function OPDSCatalog:init() show_parent = self, is_popout = false, is_borderless = true, - has_close_button = true, close_callback = function() return self:onClose() end, file_downloaded_callback = function(downloaded_file) UIManager:show(ConfirmBox:new{