Show TitleBar left and right buttons on non-touch devices (#9041)

Titlebar button navigation in menu, including ListMenu and MosaicMenu in FileManager, History, Favourites and Shortcuts.
Hide show password checkbox in non-touch devices
reviewable/pr9072/r1
Philip Chan 2 years ago committed by GitHub
parent 9b9cfe29a4
commit d6ff983243
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -146,6 +146,8 @@ function FileManager:setupLayout()
return_arrow_propagation = true,
-- allow Menu widget to delegate handling of some gestures to GestureManager
filemanager = self,
-- let Menu widget merge our title_bar into its own TitleBar's FocusManager layout
outer_title_bar = self.title_bar,
}
self.file_chooser = file_chooser
self.focused_file = nil -- use it only once

@ -359,6 +359,7 @@ end
function FileChooser:updateItems(select_number)
Menu.updateItems(self, select_number) -- call parent's updateItems()
self:mergeTitleBarIntoLayout()
self.path_items[self.path] = (self.page - 1) * self.perpage + (select_number or 1)
end

@ -208,6 +208,7 @@ function FocusManager:onFocusMove(args)
end
if not self.layout[self.selected.y] or not self.layout[self.selected.y][self.selected.x] then
logger.dbg("FocusManager: no currently selected widget found")
return true
end
local current_item = self.layout[self.selected.y][self.selected.x]
@ -269,7 +270,7 @@ function FocusManager:moveFocusTo(x, y, focus_flags)
target_item = self.layout[y][x]
end
if target_item then
logger.dbg("FocusManager: Move focus position to:", y, ",", x)
logger.dbg("FocusManager: Move focus position to:", x, ",", y)
self.selected.x = x
self.selected.y = y
-- widget create new layout on update, previous may be removed from new layout.

@ -337,9 +337,16 @@ function InputText:isTextEdited()
end
function InputText:init()
if self.text_type == "password" then
-- text_type changes from "password" to "text" when we toggle password
self.is_password_type = true
if Device:isTouchDevice() then
if self.text_type == "password" then
-- text_type changes from "password" to "text" when we toggle password
self.is_password_type = true
end
else
-- focus move does not work with textbox and show password checkbox
-- force show password for non-touch device
self.text_type = "text"
self.is_password_type = false
end
-- Beware other cases where implicit conversion to text may be done
-- at some point, but checkTextEditability() would say "not editable".

@ -1098,6 +1098,7 @@ function Menu:updateItems(select_number)
if self.show_path then
self.title_bar:setSubTitle(BD.directory(filemanagerutil.abbreviate(self.path)))
end
self:mergeTitleBarIntoLayout()
UIManager:setDirty(self.show_parent, function()
local refresh_dimen =
@ -1107,6 +1108,26 @@ function Menu:updateItems(select_number)
end)
end
-- merge TitleBar layout into self FocusManager layout
function Menu:mergeTitleBarIntoLayout()
local menu_item_layout_start_row = 1
local titlebars = {self.title_bar, self.outer_title_bar}
for _, v in ipairs(titlebars) do
-- Menu uses the right key to trigger the context menu: we can't use it to move focus in horizontal directions.
-- So, add title bar buttons to FocusManager's layout in a vertical-only layout
local title_bar_layout = v:generateVerticalLayout()
for _, row in ipairs(title_bar_layout) do
table.insert(self.layout, menu_item_layout_start_row, row)
menu_item_layout_start_row = menu_item_layout_start_row + 1
end
end
if menu_item_layout_start_row > #self.layout then -- no menu items
menu_item_layout_start_row = #self.layout -- avoid index overflow
end
self:moveFocusTo(1, menu_item_layout_start_row) -- move focus to first menu item if any, keep original behavior
end
--[[
the itemnumber paramter determines menu page number after switching item table
1. itemnumber >= 0
@ -1147,6 +1168,9 @@ function Menu:switchItemTable(new_title, new_item_table, itemnumber, itemmatch)
if self.page > max_pages then
self.page = max_pages
end
if self.page <= 0 then
self.page = 1
end
self.item_table = new_item_table
self:updateItems()

@ -101,15 +101,13 @@ function TitleBar:init()
-- No button on non-touch device
local left_icon_reserved_width = 0
local right_icon_reserved_width = 0
if Device:isTouchDevice() then
if self.left_icon then
self.has_left_icon = true
left_icon_reserved_width = left_icon_size + self.button_padding
end
if self.right_icon then
self.has_right_icon = true
right_icon_reserved_width = right_icon_size + self.button_padding
end
if self.left_icon then
self.has_left_icon = true
left_icon_reserved_width = left_icon_size + self.button_padding
end
if self.right_icon then
self.has_right_icon = true
right_icon_reserved_width = right_icon_size + self.button_padding
end
if self.align == "center" then
@ -457,4 +455,31 @@ function TitleBar:setRightIcon(icon)
UIManager:setDirty(self.show_parent, "ui", self.dimen)
end
end
-- layout for FocusManager
function TitleBar:generateHorizontalLayout()
local row = {}
if self.left_button then
table.insert(row, self.left_button)
end
if self.right_button then
table.insert(row, self.right_button)
end
local layout = {}
if #row > 0 then
table.insert(layout, row)
end
return layout
end
function TitleBar:generateVerticalLayout()
local layout = {}
if self.left_button then
table.insert(layout, {self.left_button})
end
if self.right_button then
table.insert(layout, {self.right_button})
end
return layout
end
return TitleBar

@ -409,6 +409,7 @@ function CoverMenu:updateItems(select_number)
self.onFileHold_ours = self.onFileHold
end)
end
Menu.mergeTitleBarIntoLayout(self)
end
-- Similar to onFileHold setup just above, but for History,

@ -385,24 +385,22 @@ function MosaicMenuItem:init()
self.percent_finished = nil
-- we need this table per-instance, so we declare it here
if Device:isTouchDevice() then
self.ges_events = {
TapSelect = {
GestureRange:new{
ges = "tap",
range = self.dimen,
},
doc = "Select Menu Item",
self.ges_events = {
TapSelect = {
GestureRange:new{
ges = "tap",
range = self.dimen,
},
HoldSelect = {
GestureRange:new{
ges = "hold",
range = self.dimen,
},
doc = "Hold Menu Item",
doc = "Select Menu Item",
},
HoldSelect = {
GestureRange:new{
ges = "hold",
range = self.dimen,
},
}
end
doc = "Hold Menu Item",
},
}
-- We now build the minimal widget container that won't change after udpate()

Loading…
Cancel
Save