mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Menu widget: cleanup (#10241)
This commit is contained in:
@@ -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(),
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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{
|
||||
|
||||
Reference in New Issue
Block a user