From c65d12803234f149f6e072136a1758312789172a Mon Sep 17 00:00:00 2001 From: poire-z Date: Sat, 9 Mar 2024 09:11:23 +0100 Subject: [PATCH] Menu, DictQuickLookup, TextViewer: allow mousewheel scrolling (#11525) We also need to catch it in TrapWidget so we can interrupt Wikipedia articles images loading. --- frontend/ui/widget/dictquicklookup.lua | 13 +++++++++++++ frontend/ui/widget/menu.lua | 17 +++++++++++++++++ frontend/ui/widget/textviewer.lua | 9 +++++++++ frontend/ui/widget/trapwidget.lua | 7 +++++++ 4 files changed, 46 insertions(+) diff --git a/frontend/ui/widget/dictquicklookup.lua b/frontend/ui/widget/dictquicklookup.lua index 809f8652c..45722e40c 100644 --- a/frontend/ui/widget/dictquicklookup.lua +++ b/frontend/ui/widget/dictquicklookup.lua @@ -1239,6 +1239,19 @@ function DictQuickLookup:onForwardingPan(arg, ges) end function DictQuickLookup:onForwardingPanRelease(arg, ges) + -- Allow scrolling with the mousewheel + if ges.from_mousewheel and ges.relative and ges.relative.y then + if ges.relative.y < 0 then + if not self.definition_widget[1]:onScrollDown() then + self:onReadNextResult() + end + elseif ges.relative.y > 0 then + if not self.definition_widget[1]:onScrollUp() then + self:onReadPrevResult() + end + end + return true + end -- We can forward onMovablePanRelease() does enough checks return self.movable:onMovablePanRelease(arg, ges) end diff --git a/frontend/ui/widget/menu.lua b/frontend/ui/widget/menu.lua index ffc27a429..368898bbf 100644 --- a/frontend/ui/widget/menu.lua +++ b/frontend/ui/widget/menu.lua @@ -931,6 +931,12 @@ function Menu:init() } } end + self.ges_events.Pan = { -- (for mousewheel scrolling support) + GestureRange:new{ + ges = "pan", + range = self.dimen, + } + } self.ges_events.Close = self.on_close_ges if not Device:hasKeyboard() then @@ -1386,6 +1392,17 @@ function Menu:onSwipe(arg, ges_ev) end end +function Menu:onPan(arg, ges_ev) + if ges_ev.mousewheel_direction then + if ges_ev.direction == "north" then + self:onNextPage() + elseif ges_ev.direction == "south" then + self:onPrevPage() + end + end + return true +end + 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 diff --git a/frontend/ui/widget/textviewer.lua b/frontend/ui/widget/textviewer.lua index 6a2a91851..cae3ce8e2 100644 --- a/frontend/ui/widget/textviewer.lua +++ b/frontend/ui/widget/textviewer.lua @@ -444,6 +444,15 @@ function TextViewer:onForwardingPan(arg, ges) end function TextViewer:onForwardingPanRelease(arg, ges) + -- Allow scrolling with the mousewheel + if ges.from_mousewheel and ges.relative and ges.relative.y then + if ges.relative.y < 0 then + self.scroll_text_w:scrollText(1) + elseif ges.relative.y > 0 then + self.scroll_text_w:scrollText(-1) + end + return true + end -- We can forward onMovablePanRelease() does enough checks return self.movable:onMovablePanRelease(arg, ges) end diff --git a/frontend/ui/widget/trapwidget.lua b/frontend/ui/widget/trapwidget.lua index bfc708f07..c4b324290 100644 --- a/frontend/ui/widget/trapwidget.lua +++ b/frontend/ui/widget/trapwidget.lua @@ -54,6 +54,9 @@ function TrapWidget:init() SwipeDismiss = { GestureRange:new{ ges = "swipe", range = full_screen, } }, + PanReleaseDismiss = { -- emitted on mousewheel event + GestureRange:new{ ges = "pan_release", range = full_screen, } + }, } end if self.text then @@ -139,6 +142,10 @@ function TrapWidget:onSwipeDismiss(_, ev) return self:_dismissAndResend("Gesture", ev) end +function TrapWidget:onPanReleaseDismiss(_, ev) + return self:_dismissAndResend("Gesture", ev) +end + function TrapWidget:onShow() if self.frame then UIManager:setDirty(self, function()