mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
[UX] Add spread/pinch & font increase/decrease to gesture manager (#5188)
* Add spread/pinch gesture to gesture manager ability to disable: https://www.mobileread.com/forums/showthread.php?t=321818 https://github.com/koreader/koreader/pull/4815#issuecomment-478462416 * Add increase/decrease font size action gesture https://github.com/koreader/koreader/issues/4727#issuecomment-475950484
This commit is contained in:
@@ -94,33 +94,6 @@ function ReaderFont:init()
|
||||
self.ui.menu:registerToMainMenu(self)
|
||||
end
|
||||
|
||||
function ReaderFont:onReaderReady()
|
||||
self:setupTouchZones()
|
||||
end
|
||||
|
||||
function ReaderFont:setupTouchZones()
|
||||
if Device:isTouchDevice() then
|
||||
self.ui:registerTouchZones({
|
||||
{
|
||||
id = "id_spread",
|
||||
ges = "spread",
|
||||
screen_zone = {
|
||||
ratio_x = 0, ratio_y = 0, ratio_w = 1, ratio_h = 1,
|
||||
},
|
||||
handler = function(ges) return self:onAdjustSpread(ges) end
|
||||
},
|
||||
{
|
||||
id = "id_pinch",
|
||||
ges = "pinch",
|
||||
screen_zone = {
|
||||
ratio_x = 0, ratio_y = 0, ratio_w = 1, ratio_h = 1,
|
||||
},
|
||||
handler = function(ges) return self:onAdjustPinch(ges) end
|
||||
},
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
function ReaderFont:onSetDimensions(dimen)
|
||||
self.dimen = dimen
|
||||
end
|
||||
@@ -338,25 +311,31 @@ function ReaderFont:addToMainMenu(menu_items)
|
||||
}
|
||||
end
|
||||
|
||||
function ReaderFont:onAdjustSpread(ges)
|
||||
-- direction +1 - increase font size
|
||||
-- direction -1 - decrease front size
|
||||
function ReaderFont:onAdjustFontSize(ges, direction)
|
||||
if ges.distance == nil then
|
||||
ges.distance = 1
|
||||
end
|
||||
if direction ~= -1 and direction ~= 1 then
|
||||
-- set default value (increase frontlight)
|
||||
direction = 1
|
||||
end
|
||||
local step = math.ceil(2 * #self.steps * ges.distance / self.gestureScale)
|
||||
local delta_int = self.steps[step] or self.steps[#self.steps]
|
||||
local info = Notification:new{text = _("Increasing font size…")}
|
||||
UIManager:show(info)
|
||||
UIManager:forceRePaint()
|
||||
self:onChangeSize("increase", delta_int)
|
||||
UIManager:close(info)
|
||||
return true
|
||||
end
|
||||
|
||||
function ReaderFont:onAdjustPinch(ges)
|
||||
local step = math.ceil(2 * #self.steps * ges.distance / self.gestureScale)
|
||||
local delta_int = self.steps[step] or self.steps[#self.steps]
|
||||
local info = Notification:new{text = _("Decreasing font size…")}
|
||||
UIManager:show(info)
|
||||
UIManager:forceRePaint()
|
||||
self:onChangeSize("decrease", delta_int)
|
||||
UIManager:close(info)
|
||||
if direction == 1 then
|
||||
local info = Notification:new{text = _("Increasing font size…")}
|
||||
UIManager:show(info)
|
||||
UIManager:forceRePaint()
|
||||
self:onChangeSize("increase", delta_int)
|
||||
UIManager:close(info)
|
||||
else
|
||||
local info = Notification:new{text = _("Decreasing font size…")}
|
||||
UIManager:show(info)
|
||||
UIManager:forceRePaint()
|
||||
self:onChangeSize("decrease", delta_int)
|
||||
UIManager:close(info)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
@@ -85,6 +85,9 @@ local action_strings = {
|
||||
zoom_content = _("Zoom to fit content"),
|
||||
zoom_page = _("Zoom to fit page"),
|
||||
|
||||
increase_font = _("Increase font size"),
|
||||
decrease_font = _("Decrease font size"),
|
||||
|
||||
folder_up = _("Folder up"),
|
||||
show_plus_menu = _("Show plus menu"),
|
||||
folder_shortcuts = _("Folder shortcuts"),
|
||||
@@ -209,6 +212,8 @@ function ReaderGesture:init()
|
||||
two_finger_swipe_northwest = "ignore",
|
||||
two_finger_swipe_southeast = "ignore",
|
||||
two_finger_swipe_southwest = "ignore",
|
||||
spread_gesture = self.ges_mode == "gesture_reader" and "increase_font" or "ignore",
|
||||
pinch_gesture = self.ges_mode == "gesture_reader" and "decrease_font" or "ignore",
|
||||
}
|
||||
local gm = G_reader_settings:readSetting(self.ges_mode)
|
||||
if gm == nil then G_reader_settings:saveSetting(self.ges_mode, {}) end
|
||||
@@ -617,6 +622,19 @@ Default value: %1]]), GestureDetector.SWIPE_INTERVAL/1000),
|
||||
},
|
||||
},
|
||||
})
|
||||
table.insert(menu_items.gesture_manager.sub_item_table, {
|
||||
text = _("Spread and pinch"),
|
||||
sub_item_table = {
|
||||
{
|
||||
text_func = function() return actionTextFunc("spread_gesture", _("Spread")) end,
|
||||
sub_item_table = self:buildMenu("spread_gesture", self.default_gesture["spread_gesture"]),
|
||||
},
|
||||
{
|
||||
text_func = function() return actionTextFunc("pinch_gesture", _("Pinch")) end,
|
||||
sub_item_table = self:buildMenu("pinch_gesture", self.default_gesture["pinch_gesture"]),
|
||||
},
|
||||
}
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
@@ -685,6 +703,9 @@ function ReaderGesture:buildMenu(ges, default)
|
||||
{"wifi_off", Device:hasWifiToggle()},
|
||||
{"toggle_wifi", Device:hasWifiToggle(), true},
|
||||
|
||||
{"increase_font", not self.is_docless},
|
||||
{"decrease_font", not self.is_docless, true},
|
||||
|
||||
{"toggle_bookmark", not self.is_docless, true},
|
||||
{"toggle_page_flipping", not self.is_docless, true},
|
||||
{"toggle_reflow", not self.is_docless, true},
|
||||
@@ -1101,7 +1122,12 @@ function ReaderGesture:setupGesture(ges, action)
|
||||
"paging_swipe",
|
||||
}
|
||||
end
|
||||
|
||||
elseif ges == "spread_gesture" then
|
||||
ges_type = "spread"
|
||||
zone = zone_fullscreen
|
||||
elseif ges == "pinch_gesture" then
|
||||
ges_type = "pinch"
|
||||
zone = zone_fullscreen
|
||||
else return
|
||||
end
|
||||
self:registerGesture(ges, action, ges_type, zone, overrides, direction, distance)
|
||||
@@ -1370,6 +1396,10 @@ function ReaderGesture:gestureAction(action, ges)
|
||||
timeout = 1,
|
||||
})
|
||||
end
|
||||
elseif action == "increase_font" then
|
||||
self.ui:handleEvent(Event:new("AdjustFontSize", ges, 1))
|
||||
elseif action == "decrease_font" then
|
||||
self.ui:handleEvent(Event:new("AdjustFontSize", ges, -1))
|
||||
elseif action == "suspend" then
|
||||
UIManager:suspend()
|
||||
elseif action == "exit" then
|
||||
|
||||
Reference in New Issue
Block a user