From 6132e8c904c9e019bfd08e6b534306a9decd416d Mon Sep 17 00:00:00 2001 From: poire-z Date: Tue, 16 Feb 2021 15:56:55 +0100 Subject: [PATCH] Button: don't handle long-press when not enabled It was only not handled when hold_callback. Do that also when hold_input/hold_input_func. Also fix the handling of HoldRelease (as the Hold may change the state of 'enabled', so we can't rely on it to guess the Hold is being handled by Button). Menu: prevent long-press on "No choice available", as there's then no page to navigate to. --- frontend/ui/widget/button.lua | 29 +++++++++++++++++------------ frontend/ui/widget/menu.lua | 2 ++ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/frontend/ui/widget/button.lua b/frontend/ui/widget/button.lua index 26b82a02c..ed03628c6 100644 --- a/frontend/ui/widget/button.lua +++ b/frontend/ui/widget/button.lua @@ -401,12 +401,21 @@ function Button:refresh() end function Button:onHoldSelectButton() - if self.hold_callback and (self.enabled or self.allow_hold_when_disabled) then - self.hold_callback() - elseif self.hold_input then - self:onInput(self.hold_input, true) - elseif type(self.hold_input_func) == "function" then - self:onInput(self.hold_input_func(), true) + -- If we're going to process this hold, we must make + -- sure to also handle its hold_release below, so it's + -- not propagated up to a MovableContainer + self._hold_handled = nil + if self.enabled or self.allow_hold_when_disabled then + if self.hold_callback then + self.hold_callback() + self._hold_handled = true + elseif self.hold_input then + self:onInput(self.hold_input, true) + self._hold_handled = true + elseif type(self.hold_input_func) == "function" then + self:onInput(self.hold_input_func(), true) + self._hold_handled = true + end end if self.readonly ~= true then return true @@ -414,12 +423,8 @@ function Button:onHoldSelectButton() end function Button:onHoldReleaseSelectButton() - -- Safe-guard for when used inside a MovableContainer, - -- which would handle HoldRelease and process it like - -- a Hold if we wouldn't return true here - if self.hold_callback and (self.enabled or self.allow_hold_when_disabled) then - return true - elseif self.hold_input or type(self.hold_input_func) == "function" then + if self._hold_handled then + self._hold_handled = nil return true end return false diff --git a/frontend/ui/widget/menu.lua b/frontend/ui/widget/menu.lua index ce1e84904..7d9a4faa3 100644 --- a/frontend/ui/widget/menu.lua +++ b/frontend/ui/widget/menu.lua @@ -1024,6 +1024,7 @@ function Menu:updatePageInfo(select_number) -- update page information if self.page_num > 1 then self.page_info_text:setText(FFIUtil.template(_("Page %1 of %2"), self.page, self.page_num)) + self.page_info_text.enabled = true else self.page_info_text:setText(""); end @@ -1040,6 +1041,7 @@ function Menu:updatePageInfo(select_number) self.page_return_arrow:enableDisable(#self.paths > 0) else self.page_info_text:setText(_("No choices available")) + self.page_info_text.enabled = false end end