Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gesture spread pinch #5188

Merged
merged 3 commits into from Aug 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
67 changes: 23 additions & 44 deletions frontend/apps/reader/modules/readerfont.lua
Expand Up @@ -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
Expand Down Expand Up @@ -338,25 +311,31 @@ function ReaderFont:addToMainMenu(menu_items)
}
end

function ReaderFont:onAdjustSpread(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 = _("Increasing font size…")}
UIManager:show(info)
UIManager:forceRePaint()
self:onChangeSize("increase", delta_int)
UIManager:close(info)
return true
end

function ReaderFont:onAdjustPinch(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 = _("Decreasing font size…")}
UIManager:show(info)
UIManager:forceRePaint()
self:onChangeSize("decrease", delta_int)
UIManager:close(info)
if direction == 1 then
Copy link
Member

@Frenzie Frenzie Aug 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't that be >= or something?

Edit: pardon, direction, not distance.

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

Expand Down
32 changes: 31 additions & 1 deletion frontend/apps/reader/modules/readergesture.lua
Expand Up @@ -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"),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down