2017-09-10 21:07:29 +00:00
|
|
|
--[[--
|
2017-09-11 08:32:39 +00:00
|
|
|
A button widget that shows text or an icon and handles callback when tapped.
|
|
|
|
|
|
|
|
@usage
|
|
|
|
local Button = require("ui/widget/button")
|
|
|
|
local button = Button:new{
|
|
|
|
text = _("Press me!"),
|
|
|
|
enabled = false, -- defaults to true
|
|
|
|
callback = some_callback_function,
|
|
|
|
width = Screen:scaleBySize(50),
|
|
|
|
max_width = Screen:scaleBySize(100),
|
|
|
|
bordersize = Screen:scaleBySize(3),
|
|
|
|
margin = 0,
|
|
|
|
padding = Screen:scaleBySize(2),
|
|
|
|
}
|
2017-09-10 21:07:29 +00:00
|
|
|
--]]
|
|
|
|
|
|
|
|
local Blitbuffer = require("ffi/blitbuffer")
|
2015-04-13 06:45:02 +00:00
|
|
|
local CenterContainer = require("ui/widget/container/centercontainer")
|
2017-09-10 21:07:29 +00:00
|
|
|
local Device = require("device")
|
|
|
|
local Font = require("ui/font")
|
2015-04-13 06:45:02 +00:00
|
|
|
local FrameContainer = require("ui/widget/container/framecontainer")
|
2017-09-10 21:07:29 +00:00
|
|
|
local Geom = require("ui/geometry")
|
|
|
|
local GestureRange = require("ui/gesturerange")
|
2013-10-18 20:38:07 +00:00
|
|
|
local ImageWidget = require("ui/widget/imagewidget")
|
2017-09-10 21:07:29 +00:00
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
2017-09-13 14:56:20 +00:00
|
|
|
local Size = require("ui/size")
|
2015-04-13 06:45:02 +00:00
|
|
|
local TextWidget = require("ui/widget/textwidget")
|
2014-05-01 10:37:12 +00:00
|
|
|
local UIManager = require("ui/uimanager")
|
2013-10-18 20:38:07 +00:00
|
|
|
local _ = require("gettext")
|
2012-06-10 15:52:09 +00:00
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
local Button = InputContainer:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
text = nil, -- mandatory
|
2019-06-28 02:46:16 +00:00
|
|
|
text_func = nil,
|
2014-03-13 13:52:43 +00:00
|
|
|
icon = nil,
|
2019-12-06 21:55:39 +00:00
|
|
|
icon_rotation_angle = 0,
|
2014-03-13 13:52:43 +00:00
|
|
|
preselect = false,
|
|
|
|
callback = nil,
|
|
|
|
enabled = true,
|
2020-05-07 18:24:12 +00:00
|
|
|
allow_hold_when_disabled = false,
|
2014-03-13 13:52:43 +00:00
|
|
|
margin = 0,
|
2017-09-13 14:56:20 +00:00
|
|
|
bordersize = Size.border.button,
|
2014-10-22 13:34:11 +00:00
|
|
|
background = Blitbuffer.COLOR_WHITE,
|
2017-09-13 14:56:20 +00:00
|
|
|
radius = Size.radius.button,
|
|
|
|
padding = Size.padding.button,
|
2019-11-01 00:52:05 +00:00
|
|
|
padding_h = nil,
|
|
|
|
padding_v = nil,
|
2014-03-13 13:52:43 +00:00
|
|
|
width = nil,
|
2017-08-19 10:48:51 +00:00
|
|
|
max_width = nil,
|
2014-03-13 13:52:43 +00:00
|
|
|
text_font_face = "cfont",
|
|
|
|
text_font_size = 20,
|
2015-04-13 06:45:02 +00:00
|
|
|
text_font_bold = true,
|
2012-06-10 15:52:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function Button:init()
|
2019-06-28 02:46:16 +00:00
|
|
|
-- Prefer an optional text_func over text
|
|
|
|
if self.text_func and type(self.text_func) == "function" then
|
|
|
|
self.text = self.text_func()
|
|
|
|
end
|
|
|
|
|
2019-11-01 00:52:05 +00:00
|
|
|
if not self.padding_h then
|
|
|
|
self.padding_h = self.padding
|
|
|
|
end
|
|
|
|
if not self.padding_v then
|
|
|
|
self.padding_v = self.padding
|
|
|
|
end
|
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.text then
|
|
|
|
self.label_widget = TextWidget:new{
|
|
|
|
text = self.text,
|
2019-11-01 00:52:05 +00:00
|
|
|
max_width = self.max_width and self.max_width - 2*self.padding_h - 2*self.margin - 2*self.bordersize or nil,
|
2019-03-14 19:58:45 +00:00
|
|
|
fgcolor = self.enabled and Blitbuffer.COLOR_BLACK or Blitbuffer.COLOR_DARK_GRAY,
|
2015-04-13 06:45:02 +00:00
|
|
|
bold = self.text_font_bold,
|
2014-03-13 13:52:43 +00:00
|
|
|
face = Font:getFace(self.text_font_face, self.text_font_size)
|
|
|
|
}
|
|
|
|
else
|
|
|
|
self.label_widget = ImageWidget:new{
|
|
|
|
file = self.icon,
|
2019-12-06 21:55:39 +00:00
|
|
|
rotation_angle = self.icon_rotation_angle,
|
2014-10-14 13:34:09 +00:00
|
|
|
dim = not self.enabled,
|
2017-09-10 21:07:29 +00:00
|
|
|
scale_for_dpi = true,
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
local widget_size = self.label_widget:getSize()
|
|
|
|
if self.width == nil then
|
|
|
|
self.width = widget_size.w
|
|
|
|
end
|
|
|
|
-- set FrameContainer content
|
2014-09-14 03:42:12 +00:00
|
|
|
self.frame = FrameContainer:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
margin = self.margin,
|
|
|
|
bordersize = self.bordersize,
|
|
|
|
background = self.background,
|
|
|
|
radius = self.radius,
|
2019-11-01 00:52:05 +00:00
|
|
|
padding_top = self.padding_v,
|
|
|
|
padding_bottom = self.padding_v,
|
|
|
|
padding_left = self.padding_h,
|
|
|
|
padding_right = self.padding_h,
|
2014-03-13 13:52:43 +00:00
|
|
|
CenterContainer:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = self.width,
|
|
|
|
h = widget_size.h
|
|
|
|
},
|
|
|
|
self.label_widget,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if self.preselect then
|
2018-09-13 11:49:23 +00:00
|
|
|
self.frame.invert = true
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2014-09-14 03:42:12 +00:00
|
|
|
self.dimen = self.frame:getSize()
|
|
|
|
self[1] = self.frame
|
2014-03-13 13:52:43 +00:00
|
|
|
if Device:isTouchDevice() then
|
|
|
|
self.ges_events = {
|
2014-10-20 14:19:31 +00:00
|
|
|
TapSelectButton = {
|
2014-03-13 13:52:43 +00:00
|
|
|
GestureRange:new{
|
|
|
|
ges = "tap",
|
|
|
|
range = self.dimen,
|
|
|
|
},
|
2014-06-05 06:58:53 +00:00
|
|
|
doc = "Tap Button",
|
2014-03-13 13:52:43 +00:00
|
|
|
},
|
2014-10-20 14:19:31 +00:00
|
|
|
HoldSelectButton = {
|
2014-08-17 16:32:09 +00:00
|
|
|
GestureRange:new{
|
|
|
|
ges = "hold",
|
|
|
|
range = self.dimen,
|
|
|
|
},
|
|
|
|
doc = "Hold Button",
|
2019-02-15 23:42:27 +00:00
|
|
|
},
|
|
|
|
-- Safe-guard for when used inside a MovableContainer
|
|
|
|
HoldReleaseSelectButton = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "hold_release",
|
|
|
|
range = self.dimen,
|
|
|
|
},
|
2014-08-17 16:32:09 +00:00
|
|
|
}
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
|
|
|
end
|
2012-06-10 15:52:09 +00:00
|
|
|
end
|
|
|
|
|
2017-10-22 11:09:49 +00:00
|
|
|
function Button:setText(text, width)
|
2015-04-13 06:45:02 +00:00
|
|
|
self.text = text
|
2017-10-22 11:09:49 +00:00
|
|
|
self.width = width
|
2015-04-13 06:45:02 +00:00
|
|
|
self:init()
|
|
|
|
end
|
|
|
|
|
|
|
|
function Button:setIcon(icon)
|
|
|
|
self.icon = icon
|
|
|
|
self.width = nil
|
|
|
|
self:init()
|
|
|
|
end
|
|
|
|
|
2012-06-10 15:52:09 +00:00
|
|
|
function Button:onFocus()
|
2018-09-13 11:49:23 +00:00
|
|
|
if self.no_focus then return end
|
2015-09-13 08:09:00 +00:00
|
|
|
self.frame.invert = true
|
2014-03-13 13:52:43 +00:00
|
|
|
return true
|
2012-06-10 15:52:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Button:onUnfocus()
|
2018-09-13 11:49:23 +00:00
|
|
|
if self.no_focus then return end
|
2015-09-13 08:09:00 +00:00
|
|
|
self.frame.invert = false
|
2014-03-13 13:52:43 +00:00
|
|
|
return true
|
2012-06-10 15:52:09 +00:00
|
|
|
end
|
|
|
|
|
2013-06-16 03:13:54 +00:00
|
|
|
function Button:enable()
|
2014-03-13 13:52:43 +00:00
|
|
|
self.enabled = true
|
|
|
|
if self.text then
|
2016-06-09 05:26:30 +00:00
|
|
|
if self.enabled then
|
|
|
|
self.label_widget.fgcolor = Blitbuffer.COLOR_BLACK
|
|
|
|
else
|
2019-03-14 19:58:45 +00:00
|
|
|
self.label_widget.fgcolor = Blitbuffer.COLOR_DARK_GRAY
|
2016-06-09 05:26:30 +00:00
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
else
|
|
|
|
self.label_widget.dim = not self.enabled
|
|
|
|
end
|
2013-06-16 03:13:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Button:disable()
|
2014-03-13 13:52:43 +00:00
|
|
|
self.enabled = false
|
|
|
|
if self.text then
|
2016-06-09 05:26:30 +00:00
|
|
|
if self.enabled then
|
|
|
|
self.label_widget.fgcolor = Blitbuffer.COLOR_BLACK
|
|
|
|
else
|
2019-03-14 19:58:45 +00:00
|
|
|
self.label_widget.fgcolor = Blitbuffer.COLOR_DARK_GRAY
|
2016-06-09 05:26:30 +00:00
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
else
|
|
|
|
self.label_widget.dim = not self.enabled
|
|
|
|
end
|
2013-08-02 14:41:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Button:enableDisable(enable)
|
2014-03-13 13:52:43 +00:00
|
|
|
if enable then
|
|
|
|
self:enable()
|
|
|
|
else
|
|
|
|
self:disable()
|
|
|
|
end
|
2013-08-02 14:41:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Button:hide()
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.icon then
|
2014-09-14 03:42:12 +00:00
|
|
|
self.frame.orig_background = self[1].background
|
|
|
|
self.frame.background = nil
|
2014-03-13 13:52:43 +00:00
|
|
|
self.label_widget.hide = true
|
|
|
|
end
|
2013-08-02 14:41:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Button:show()
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.icon then
|
|
|
|
self.label_widget.hide = false
|
2014-09-14 03:42:12 +00:00
|
|
|
self.frame.background = self[1].old_background
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2013-08-02 14:41:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Button:showHide(show)
|
2014-03-13 13:52:43 +00:00
|
|
|
if show then
|
|
|
|
self:show()
|
|
|
|
else
|
|
|
|
self:hide()
|
|
|
|
end
|
2013-06-16 03:13:54 +00:00
|
|
|
end
|
|
|
|
|
2014-10-20 14:19:31 +00:00
|
|
|
function Button:onTapSelectButton()
|
2014-08-20 06:45:11 +00:00
|
|
|
if self.enabled and self.callback then
|
2017-10-10 21:50:45 +00:00
|
|
|
if G_reader_settings:isFalse("flash_ui") then
|
2014-05-01 10:37:12 +00:00
|
|
|
self.callback()
|
2017-10-10 21:50:45 +00:00
|
|
|
else
|
Enable HW dithering in a few key places (#4541)
* Enable HW dithering on supported devices (Clara HD, Forma; Oasis 2, PW4)
* FileManager and co. (where appropriate, i.e., when covers are shown)
* Book Status
* Reader, where appropriate:
* CRe: on pages whith image content (for over 7.5% of the screen area, should hopefully leave stuff like bullet points or small scene breaks alone).
* Other engines: on user-request (in the gear tab of the bottom menu), via the new "Dithering" knob (will only appear on supported devices).
* ScreenSaver
* ImageViewer
* Minimize repaints when flash_ui is enabled (by, almost everywhere, only repainting the flashing element, and not the toplevel window which hosts it).
(The first pass of this involved fixing a few Button instances whose show_parent was wrong, in particular, chevrons in the FM & TopMenu).
* Hunted down a few redundant repaints (unneeded setDirty("all") calls),
either by switching the widget to nil when only a refresh was needed, and not a repaint,
or by passing the appropritate widget to setDirty.
(Note to self: Enable *verbose* debugging to catch broken setDirty calls via its post guard).
There were also a few instances of 'em right behind a widget close.
* Don't repaint the underlying widget when initially showing TopMenu & ConfigDialog.
We unfortunately do need to do it when switching tabs, because of their variable heights.
* On Kobo, disabled the extra and completely useless full refresh before suspend/reboot/poweroff, as well as on resume. No more double refreshes!
* Fix another debug guard in Kobo sysfs_light
* Switch ImageWidget & ImageViewer mostly to "ui" updates, which will be better suited to image content pretty much everywhere, REAGL or not.
PS: (Almost :100: commits! :D)
2019-02-07 00:14:37 +00:00
|
|
|
-- For most of our buttons, we can't avoid that initial repaint...
|
A few graphics fixes after #4541 (#4554)
* Various FocusManager related tweaks to limit its usage to devices with a DPad, and prevent initial button highlights in Dialogs on devices where it makes no sense (i.e., those without a DPad. And even on DPad devices, I'm not even sure how we'd go about making one of those pop up anyway, because no Touch ;)!).
* One mysterious fix to text-only Buttons so that the flash_ui highlight always works, and always honors `FrameContainer`'s pill shape. (Before that, an unhighlight on a text button with a callback that didn't repaint anything [say, the find first/find last buttons in the Reader's search bar when you're already on the first/last match] would do a square black highlight, and a white pill-shaped unhighlight (leaving the black corners visible)).
The workaround makes *absolutely* no sense to me (as `self[1] -> self.frame`, AFAICT), but it works, and ensures all highlights/unhighlights are pill-shaped, so at least we're not doing maths for rounded corners for nothing ;).
2019-02-07 23:56:32 +00:00
|
|
|
self[1].invert = true
|
Enable HW dithering in a few key places (#4541)
* Enable HW dithering on supported devices (Clara HD, Forma; Oasis 2, PW4)
* FileManager and co. (where appropriate, i.e., when covers are shown)
* Book Status
* Reader, where appropriate:
* CRe: on pages whith image content (for over 7.5% of the screen area, should hopefully leave stuff like bullet points or small scene breaks alone).
* Other engines: on user-request (in the gear tab of the bottom menu), via the new "Dithering" knob (will only appear on supported devices).
* ScreenSaver
* ImageViewer
* Minimize repaints when flash_ui is enabled (by, almost everywhere, only repainting the flashing element, and not the toplevel window which hosts it).
(The first pass of this involved fixing a few Button instances whose show_parent was wrong, in particular, chevrons in the FM & TopMenu).
* Hunted down a few redundant repaints (unneeded setDirty("all") calls),
either by switching the widget to nil when only a refresh was needed, and not a repaint,
or by passing the appropritate widget to setDirty.
(Note to self: Enable *verbose* debugging to catch broken setDirty calls via its post guard).
There were also a few instances of 'em right behind a widget close.
* Don't repaint the underlying widget when initially showing TopMenu & ConfigDialog.
We unfortunately do need to do it when switching tabs, because of their variable heights.
* On Kobo, disabled the extra and completely useless full refresh before suspend/reboot/poweroff, as well as on resume. No more double refreshes!
* Fix another debug guard in Kobo sysfs_light
* Switch ImageWidget & ImageViewer mostly to "ui" updates, which will be better suited to image content pretty much everywhere, REAGL or not.
PS: (Almost :100: commits! :D)
2019-02-07 00:14:37 +00:00
|
|
|
UIManager:widgetRepaint(self[1], self[1].dimen.x, self[1].dimen.y)
|
A few graphics fixes after #4541 (#4554)
* Various FocusManager related tweaks to limit its usage to devices with a DPad, and prevent initial button highlights in Dialogs on devices where it makes no sense (i.e., those without a DPad. And even on DPad devices, I'm not even sure how we'd go about making one of those pop up anyway, because no Touch ;)!).
* One mysterious fix to text-only Buttons so that the flash_ui highlight always works, and always honors `FrameContainer`'s pill shape. (Before that, an unhighlight on a text button with a callback that didn't repaint anything [say, the find first/find last buttons in the Reader's search bar when you're already on the first/last match] would do a square black highlight, and a white pill-shaped unhighlight (leaving the black corners visible)).
The workaround makes *absolutely* no sense to me (as `self[1] -> self.frame`, AFAICT), but it works, and ensures all highlights/unhighlights are pill-shaped, so at least we're not doing maths for rounded corners for nothing ;).
2019-02-07 23:56:32 +00:00
|
|
|
-- NOTE: This completely insane double repaint is needed to avoid cosmetic issues with FrameContainer's rounded corners on Text buttons...
|
|
|
|
-- On the upside, we now actually get to *see* those rounded corners (as the highlight), where it was a simple square before.
|
|
|
|
-- c.f., #4554 & #4541
|
|
|
|
-- NOTE: self[1] -> self.frame, if you're confused about what this does vs. onFocus/onUnfocus ;).
|
|
|
|
if self.text then
|
|
|
|
UIManager:widgetRepaint(self[1], self[1].dimen.x, self[1].dimen.y)
|
|
|
|
end
|
Enable HW dithering in a few key places (#4541)
* Enable HW dithering on supported devices (Clara HD, Forma; Oasis 2, PW4)
* FileManager and co. (where appropriate, i.e., when covers are shown)
* Book Status
* Reader, where appropriate:
* CRe: on pages whith image content (for over 7.5% of the screen area, should hopefully leave stuff like bullet points or small scene breaks alone).
* Other engines: on user-request (in the gear tab of the bottom menu), via the new "Dithering" knob (will only appear on supported devices).
* ScreenSaver
* ImageViewer
* Minimize repaints when flash_ui is enabled (by, almost everywhere, only repainting the flashing element, and not the toplevel window which hosts it).
(The first pass of this involved fixing a few Button instances whose show_parent was wrong, in particular, chevrons in the FM & TopMenu).
* Hunted down a few redundant repaints (unneeded setDirty("all") calls),
either by switching the widget to nil when only a refresh was needed, and not a repaint,
or by passing the appropritate widget to setDirty.
(Note to self: Enable *verbose* debugging to catch broken setDirty calls via its post guard).
There were also a few instances of 'em right behind a widget close.
* Don't repaint the underlying widget when initially showing TopMenu & ConfigDialog.
We unfortunately do need to do it when switching tabs, because of their variable heights.
* On Kobo, disabled the extra and completely useless full refresh before suspend/reboot/poweroff, as well as on resume. No more double refreshes!
* Fix another debug guard in Kobo sysfs_light
* Switch ImageWidget & ImageViewer mostly to "ui" updates, which will be better suited to image content pretty much everywhere, REAGL or not.
PS: (Almost :100: commits! :D)
2019-02-07 00:14:37 +00:00
|
|
|
UIManager:setDirty(nil, function()
|
2018-06-02 16:10:55 +00:00
|
|
|
return "fast", self[1].dimen
|
2014-11-30 00:12:00 +00:00
|
|
|
end)
|
Enable HW dithering in a few key places (#4541)
* Enable HW dithering on supported devices (Clara HD, Forma; Oasis 2, PW4)
* FileManager and co. (where appropriate, i.e., when covers are shown)
* Book Status
* Reader, where appropriate:
* CRe: on pages whith image content (for over 7.5% of the screen area, should hopefully leave stuff like bullet points or small scene breaks alone).
* Other engines: on user-request (in the gear tab of the bottom menu), via the new "Dithering" knob (will only appear on supported devices).
* ScreenSaver
* ImageViewer
* Minimize repaints when flash_ui is enabled (by, almost everywhere, only repainting the flashing element, and not the toplevel window which hosts it).
(The first pass of this involved fixing a few Button instances whose show_parent was wrong, in particular, chevrons in the FM & TopMenu).
* Hunted down a few redundant repaints (unneeded setDirty("all") calls),
either by switching the widget to nil when only a refresh was needed, and not a repaint,
or by passing the appropritate widget to setDirty.
(Note to self: Enable *verbose* debugging to catch broken setDirty calls via its post guard).
There were also a few instances of 'em right behind a widget close.
* Don't repaint the underlying widget when initially showing TopMenu & ConfigDialog.
We unfortunately do need to do it when switching tabs, because of their variable heights.
* On Kobo, disabled the extra and completely useless full refresh before suspend/reboot/poweroff, as well as on resume. No more double refreshes!
* Fix another debug guard in Kobo sysfs_light
* Switch ImageWidget & ImageViewer mostly to "ui" updates, which will be better suited to image content pretty much everywhere, REAGL or not.
PS: (Almost :100: commits! :D)
2019-02-07 00:14:37 +00:00
|
|
|
-- And we also often have to delay the callback to both see the flash and/or avoid tearing artefacts w/ fast refreshes...
|
2018-06-02 16:10:55 +00:00
|
|
|
UIManager:tickAfterNext(function()
|
2017-10-10 21:50:45 +00:00
|
|
|
self.callback()
|
2019-09-17 12:50:03 +00:00
|
|
|
if not self[1] or not self[1].invert or not self[1].dimen then
|
|
|
|
-- widget no more there (destroyed, re-init'ed by setText(), or not inverted: nothing to invert back
|
|
|
|
return
|
|
|
|
end
|
2017-10-10 21:50:45 +00:00
|
|
|
self[1].invert = false
|
Enable HW dithering in a few key places (#4541)
* Enable HW dithering on supported devices (Clara HD, Forma; Oasis 2, PW4)
* FileManager and co. (where appropriate, i.e., when covers are shown)
* Book Status
* Reader, where appropriate:
* CRe: on pages whith image content (for over 7.5% of the screen area, should hopefully leave stuff like bullet points or small scene breaks alone).
* Other engines: on user-request (in the gear tab of the bottom menu), via the new "Dithering" knob (will only appear on supported devices).
* ScreenSaver
* ImageViewer
* Minimize repaints when flash_ui is enabled (by, almost everywhere, only repainting the flashing element, and not the toplevel window which hosts it).
(The first pass of this involved fixing a few Button instances whose show_parent was wrong, in particular, chevrons in the FM & TopMenu).
* Hunted down a few redundant repaints (unneeded setDirty("all") calls),
either by switching the widget to nil when only a refresh was needed, and not a repaint,
or by passing the appropritate widget to setDirty.
(Note to self: Enable *verbose* debugging to catch broken setDirty calls via its post guard).
There were also a few instances of 'em right behind a widget close.
* Don't repaint the underlying widget when initially showing TopMenu & ConfigDialog.
We unfortunately do need to do it when switching tabs, because of their variable heights.
* On Kobo, disabled the extra and completely useless full refresh before suspend/reboot/poweroff, as well as on resume. No more double refreshes!
* Fix another debug guard in Kobo sysfs_light
* Switch ImageWidget & ImageViewer mostly to "ui" updates, which will be better suited to image content pretty much everywhere, REAGL or not.
PS: (Almost :100: commits! :D)
2019-02-07 00:14:37 +00:00
|
|
|
UIManager:widgetRepaint(self[1], self[1].dimen.x, self[1].dimen.y)
|
A few graphics fixes after #4541 (#4554)
* Various FocusManager related tweaks to limit its usage to devices with a DPad, and prevent initial button highlights in Dialogs on devices where it makes no sense (i.e., those without a DPad. And even on DPad devices, I'm not even sure how we'd go about making one of those pop up anyway, because no Touch ;)!).
* One mysterious fix to text-only Buttons so that the flash_ui highlight always works, and always honors `FrameContainer`'s pill shape. (Before that, an unhighlight on a text button with a callback that didn't repaint anything [say, the find first/find last buttons in the Reader's search bar when you're already on the first/last match] would do a square black highlight, and a white pill-shaped unhighlight (leaving the black corners visible)).
The workaround makes *absolutely* no sense to me (as `self[1] -> self.frame`, AFAICT), but it works, and ensures all highlights/unhighlights are pill-shaped, so at least we're not doing maths for rounded corners for nothing ;).
2019-02-07 23:56:32 +00:00
|
|
|
if self.text then
|
|
|
|
UIManager:widgetRepaint(self[1], self[1].dimen.x, self[1].dimen.y)
|
|
|
|
end
|
Enable HW dithering in a few key places (#4541)
* Enable HW dithering on supported devices (Clara HD, Forma; Oasis 2, PW4)
* FileManager and co. (where appropriate, i.e., when covers are shown)
* Book Status
* Reader, where appropriate:
* CRe: on pages whith image content (for over 7.5% of the screen area, should hopefully leave stuff like bullet points or small scene breaks alone).
* Other engines: on user-request (in the gear tab of the bottom menu), via the new "Dithering" knob (will only appear on supported devices).
* ScreenSaver
* ImageViewer
* Minimize repaints when flash_ui is enabled (by, almost everywhere, only repainting the flashing element, and not the toplevel window which hosts it).
(The first pass of this involved fixing a few Button instances whose show_parent was wrong, in particular, chevrons in the FM & TopMenu).
* Hunted down a few redundant repaints (unneeded setDirty("all") calls),
either by switching the widget to nil when only a refresh was needed, and not a repaint,
or by passing the appropritate widget to setDirty.
(Note to self: Enable *verbose* debugging to catch broken setDirty calls via its post guard).
There were also a few instances of 'em right behind a widget close.
* Don't repaint the underlying widget when initially showing TopMenu & ConfigDialog.
We unfortunately do need to do it when switching tabs, because of their variable heights.
* On Kobo, disabled the extra and completely useless full refresh before suspend/reboot/poweroff, as well as on resume. No more double refreshes!
* Fix another debug guard in Kobo sysfs_light
* Switch ImageWidget & ImageViewer mostly to "ui" updates, which will be better suited to image content pretty much everywhere, REAGL or not.
PS: (Almost :100: commits! :D)
2019-02-07 00:14:37 +00:00
|
|
|
UIManager:setDirty(nil, function()
|
2018-06-02 16:10:55 +00:00
|
|
|
return "fast", self[1].dimen
|
2017-10-10 21:50:45 +00:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end
|
2015-04-13 06:45:02 +00:00
|
|
|
elseif self.tap_input then
|
|
|
|
self:onInput(self.tap_input)
|
2017-03-28 22:47:18 +00:00
|
|
|
elseif type(self.tap_input_func) == "function" then
|
|
|
|
self:onInput(self.tap_input_func())
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2017-12-17 17:27:24 +00:00
|
|
|
if self.readonly ~= true then
|
|
|
|
return true
|
|
|
|
end
|
2013-02-21 14:29:54 +00:00
|
|
|
end
|
2013-10-18 20:38:07 +00:00
|
|
|
|
2014-10-20 14:19:31 +00:00
|
|
|
function Button:onHoldSelectButton()
|
2020-05-07 18:24:12 +00:00
|
|
|
if self.hold_callback and (self.enabled or self.allow_hold_when_disabled) then
|
2014-08-17 16:32:09 +00:00
|
|
|
self.hold_callback()
|
2015-04-13 06:45:02 +00:00
|
|
|
elseif self.hold_input then
|
2019-05-08 08:13:44 +00:00
|
|
|
self:onInput(self.hold_input, true)
|
2017-03-28 22:47:18 +00:00
|
|
|
elseif type(self.hold_input_func) == "function" then
|
2019-05-08 08:13:44 +00:00
|
|
|
self:onInput(self.hold_input_func(), true)
|
2014-08-17 16:32:09 +00:00
|
|
|
end
|
2019-08-03 18:35:48 +00:00
|
|
|
if self.readonly ~= true then
|
|
|
|
return true
|
|
|
|
end
|
2014-08-17 16:32:09 +00:00
|
|
|
end
|
|
|
|
|
2019-02-15 23:42:27 +00:00
|
|
|
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
|
2020-05-07 18:24:12 +00:00
|
|
|
if self.hold_callback and (self.enabled or self.allow_hold_when_disabled) then
|
2019-02-15 23:42:27 +00:00
|
|
|
return true
|
|
|
|
elseif self.hold_input or type(self.hold_input_func) == "function" then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
return Button
|