QuickMenu: anchor to gesture position 3 (#10646)

reviewable/pr10662/r1
hius07 10 months ago committed by GitHub
parent 4b475bee04
commit 86f4b3c18d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -35,6 +35,7 @@ local Event = require("ui/event")
local Notification = require("ui/widget/notification")
local ReaderHighlight = require("apps/reader/modules/readerhighlight")
local ReaderZooming = require("apps/reader/modules/readerzooming")
local Screen = Device.screen
local UIManager = require("ui/uimanager")
local util = require("util")
local _ = require("gettext")
@ -673,7 +674,7 @@ function Dispatcher:_sortActions(caller, location, settings, touchmenu_instance)
location[settings].settings.order[i] = v.key
end
end
if touchmenu_instance then touchmenu_instance:updateItems() end
if touchmenu_instance then touchmenu_instance:updateItems() end
caller.updated = true
end
}
@ -929,75 +930,50 @@ function Dispatcher:addSubMenu(caller, menu, location, settings)
end
menu[#menu].separator = true
table.insert(menu, {
text = _("Show as QuickMenu"),
text = _("Sort"),
checked_func = function()
return location[settings] ~= nil
and location[settings].settings ~= nil
and location[settings].settings.show_as_quickmenu
and location[settings].settings.order ~= nil
end,
callback = function()
if location[settings] then
if location[settings].settings then
if location[settings].settings.show_as_quickmenu then
location[settings].settings.show_as_quickmenu = nil
if next(location[settings].settings) == nil then
location[settings].settings = nil
end
else
location[settings].settings.show_as_quickmenu = true
end
else
location[settings].settings = {["show_as_quickmenu"] = true}
end
callback = function(touchmenu_instance)
Dispatcher:_sortActions(caller, location, settings, touchmenu_instance)
end,
hold_callback = function(touchmenu_instance)
if location[settings]
and location[settings].settings
and location[settings].settings.order then
Dispatcher:_removeFromOrder(location, settings)
caller.updated = true
if touchmenu_instance then touchmenu_instance:updateItems() end
end
end,
})
table.insert(menu, {
text = _("Always active"),
text = _("Show as QuickMenu"),
checked_func = function()
return location[settings] ~= nil
and location[settings].settings ~= nil
and location[settings].settings.always_active
and location[settings].settings.show_as_quickmenu
end,
callback = function()
if location[settings] then
if location[settings].settings then
if location[settings].settings.always_active then
location[settings].settings.always_active = nil
if location[settings].settings.show_as_quickmenu then
location[settings].settings.show_as_quickmenu = nil
if next(location[settings].settings) == nil then
location[settings].settings = nil
end
else
location[settings].settings.always_active = true
location[settings].settings.show_as_quickmenu = true
end
else
location[settings].settings = {["always_active"] = true}
location[settings].settings = {["show_as_quickmenu"] = true}
end
caller.updated = true
end
end,
})
table.insert(menu, {
text = _("Sort"),
checked_func = function()
return location[settings] ~= nil
and location[settings].settings ~= nil
and location[settings].settings.order ~= nil
end,
callback = function(touchmenu_instance)
Dispatcher:_sortActions(caller, location, settings, touchmenu_instance)
end,
hold_callback = function(touchmenu_instance)
if location[settings]
and location[settings].settings
and location[settings].settings.order then
Dispatcher:_removeFromOrder(location, settings)
caller.updated = true
if touchmenu_instance then touchmenu_instance:updateItems() end
end
end,
})
end
function Dispatcher:isActionEnabled(action)
@ -1038,10 +1014,11 @@ function Dispatcher:_showAsMenu(settings, gesture)
quickmenu = ButtonDialog:new{
title = settings.settings.name or _("QuickMenu"),
title_align = "center",
width_factor = 0.8,
shrink_unneeded_width = true,
shrink_min_width = math.floor(0.6 * Screen:getWidth()),
use_info_style = false,
buttons = buttons,
anchor = function() return gesture and gesture.pos end,
anchor = (gesture and gesture.anchor_quickmenu) and (gesture.end_pos or gesture.pos),
}
UIManager:show(quickmenu)
end
@ -1078,7 +1055,7 @@ function Dispatcher:execute(settings, gesture)
end
if settingsList[k].category == "none" then
if settingsList[k].arg ~= nil then
UIManager:sendEvent(Event:new(settingsList[k].event, settingsList[k].arg))
UIManager:sendEvent(Event:new(settingsList[k].event, settingsList[k].arg, gesture))
else
UIManager:sendEvent(Event:new(settingsList[k].event))
end

@ -108,7 +108,14 @@ function ButtonDialog:init()
end
end
local content_width = self.width - 2*Size.border.window - 2*Size.padding.button
self.buttontable = ButtonTable:new{
buttons = self.buttons,
width = self.width - 2*Size.border.window - 2*Size.padding.button,
shrink_unneeded_width = self.shrink_unneeded_width,
shrink_min_width = self.shrink_min_width,
show_parent = self,
}
local buttontable_width = self.buttontable:getSize().w -- may be shrinked
local title_widget, title_widget_height
if self.title then
@ -128,7 +135,7 @@ function ButtonDialog:init()
bordersize = 0,
TextBoxWidget:new{
text = self.title,
width = content_width - 2 * (title_padding + title_margin),
width = buttontable_width - 2 * (title_padding + title_margin),
face = title_face,
alignment = self.title_align,
},
@ -139,13 +146,6 @@ function ButtonDialog:init()
title_widget_height = 0
end
self.buttontable = ButtonTable:new{
buttons = self.buttons,
width = content_width,
shrink_unneeded_width = self.shrink_unneeded_width,
shrink_min_width = self.shrink_min_width,
show_parent = self,
}
-- If the ButtonTable ends up being taller than the screen, wrap it inside a ScrollableContainer.
-- Ensure some small top and bottom padding, so the scrollbar stand out, and some outer margin
-- so the this dialog does not take the full height and stand as a popup.
@ -181,7 +181,7 @@ function ButtonDialog:init()
dimen = Geom:new{
-- We'll be exceeding the provided width in this case (let's not bother
-- ensuring it, we'd need to re-setup the ButtonTable...)
w = self.buttontable:getSize().w + scrollbar_width,
w = buttontable_width + scrollbar_width,
h = max_height,
},
show_parent = self,
@ -199,7 +199,7 @@ function ButtonDialog:init()
separator = LineWidget:new{
background = Blitbuffer.COLOR_GRAY,
dimen = Geom:new{
w = content_width + (scrollbar_width or 0),
w = buttontable_width + (scrollbar_width or 0),
h = Size.line.medium,
},
}

@ -244,6 +244,56 @@ function Gestures:genMenu(ges)
end,
})
Dispatcher:addSubMenu(self, sub_items, self.gestures, ges)
table.insert(sub_items, {
text = _("Anchor QuickMenu to gesture position"),
checked_func = function()
return self.gestures[ges] ~= nil
and self.gestures[ges].settings ~= nil
and self.gestures[ges].settings.anchor_quickmenu
end,
callback = function()
if self.gestures[ges] then
if self.gestures[ges].settings then
if self.gestures[ges].settings.anchor_quickmenu then
self.gestures[ges].settings.anchor_quickmenu = nil
if next(self.gestures[ges].settings) == nil then
self.gestures[ges].settings = nil
end
else
self.gestures[ges].settings.anchor_quickmenu = true
end
else
self.gestures[ges].settings = {["anchor_quickmenu"] = true}
end
self.updated = true
end
end,
})
table.insert(sub_items, {
text = _("Always active"),
checked_func = function()
return self.gestures[ges] ~= nil
and self.gestures[ges].settings ~= nil
and self.gestures[ges].settings.always_active
end,
callback = function()
if self.gestures[ges] then
if self.gestures[ges].settings then
if self.gestures[ges].settings.always_active then
self.gestures[ges].settings.always_active = nil
if next(self.gestures[ges].settings) == nil then
self.gestures[ges].settings = nil
end
else
self.gestures[ges].settings.always_active = true
end
else
self.gestures[ges].settings = {["always_active"] = true}
end
self.updated = true
end
end,
})
return sub_items
end
@ -1103,6 +1153,7 @@ function Gestures:gestureAction(action, ges)
return
else
self.ui:handleEvent(Event:new("HandledAsSwipe"))
ges.anchor_quickmenu = action_list.settings and action_list.settings.anchor_quickmenu
Dispatcher:execute(action_list, ges)
end
return true

@ -259,8 +259,8 @@ function Profiles:getSubMenuItems()
return sub_item_table
end
function Profiles:onProfileExecute(name)
Dispatcher:execute(self.data[name])
function Profiles:onProfileExecute(name, gesture)
Dispatcher:execute(self.data[name], gesture)
end
function Profiles:editProfileName(editCallback, old_name)
@ -271,6 +271,7 @@ function Profiles:editProfileName(editCallback, old_name)
buttons = {{
{
text = _("Cancel"),
id = "close",
callback = function()
UIManager:close(name_input)
end,

Loading…
Cancel
Save