2016-12-05 00:41:01 +00:00
|
|
|
--[[--
|
2016-12-11 03:08:31 +00:00
|
|
|
WidgetContainer is a container for one or multiple Widgets. It is the base
|
|
|
|
class for all the container widgets.
|
2016-12-05 00:41:01 +00:00
|
|
|
|
2016-12-11 03:08:31 +00:00
|
|
|
Child widgets are stored in WidgetContainer as conventional array items:
|
|
|
|
|
|
|
|
WidgetContainer:new{
|
|
|
|
ChildWidgetFoo:new{},
|
|
|
|
ChildWidgetBar:new{},
|
|
|
|
...
|
|
|
|
}
|
|
|
|
|
|
|
|
It handles event propagation and painting (with different alignments) for its children.
|
2016-12-05 00:41:01 +00:00
|
|
|
]]
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
local Geom = require("ui/geometry")
|
|
|
|
local Widget = require("ui/widget/widget")
|
2019-02-18 16:07:27 +00:00
|
|
|
local Device = require("device")
|
2013-10-18 20:38:07 +00:00
|
|
|
|
2019-02-18 16:07:27 +00:00
|
|
|
if Device.should_restrict_JIT then
|
2020-12-26 19:23:51 +00:00
|
|
|
jit.off(true, true)
|
2016-04-07 15:28:52 +00:00
|
|
|
end
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
local WidgetContainer = Widget:new()
|
|
|
|
|
|
|
|
function WidgetContainer:init()
|
2015-09-13 08:06:22 +00:00
|
|
|
if self.dimen then
|
2016-02-14 21:47:36 +00:00
|
|
|
if self.initDimen then
|
|
|
|
self:initDimen()
|
|
|
|
else
|
|
|
|
if not self.dimen.w then
|
2016-06-05 23:37:58 +00:00
|
|
|
self.dimen.w = self[1]:getSize().w
|
2016-02-14 21:47:36 +00:00
|
|
|
end
|
|
|
|
if not self.dimen.h then
|
2016-06-05 23:37:58 +00:00
|
|
|
self.dimen.h = self[1]:getSize().h
|
2016-02-14 21:47:36 +00:00
|
|
|
end
|
2015-09-13 08:06:22 +00:00
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2013-10-18 20:38:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function WidgetContainer:getSize()
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.dimen then
|
|
|
|
-- fixed size
|
|
|
|
return self.dimen
|
|
|
|
elseif self[1] then
|
|
|
|
-- return size of first child widget
|
|
|
|
return self[1]:getSize()
|
|
|
|
else
|
|
|
|
return Geom:new{ w = 0, h = 0 }
|
|
|
|
end
|
2013-10-18 20:38:07 +00:00
|
|
|
end
|
|
|
|
|
2016-12-05 00:41:01 +00:00
|
|
|
--[[--
|
2017-11-15 08:02:33 +00:00
|
|
|
Deletes all child widgets.
|
2016-12-05 00:41:01 +00:00
|
|
|
]]
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
function WidgetContainer:clear(skip_free)
|
|
|
|
-- HorizontalGroup & VerticalGroup call us after already having called free,
|
|
|
|
-- so allow skipping this one ;).
|
|
|
|
if not skip_free then
|
|
|
|
-- Make sure we free 'em before orphaning them...
|
|
|
|
self:free()
|
|
|
|
end
|
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
while table.remove(self) do end
|
2013-10-18 20:38:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function WidgetContainer:paintTo(bb, x, y)
|
2014-03-13 13:52:43 +00:00
|
|
|
-- default to pass request to first child widget
|
|
|
|
if self[1] then
|
|
|
|
x = x + (self.dimen.x or 0)
|
|
|
|
y = y + (self.dimen.y or 0)
|
|
|
|
if self.align == "top" then
|
|
|
|
local contentSize = self[1]:getSize()
|
|
|
|
self[1]:paintTo(bb,
|
|
|
|
x + math.floor((self.dimen.w - contentSize.w)/2), y)
|
|
|
|
elseif self.align == "bottom" then
|
|
|
|
local contentSize = self[1]:getSize()
|
|
|
|
self[1]:paintTo(bb,
|
|
|
|
x + math.floor((self.dimen.w - contentSize.w)/2),
|
|
|
|
y + (self.dimen.h - contentSize.h))
|
2014-08-17 16:32:09 +00:00
|
|
|
elseif self.align == "center" then
|
|
|
|
local contentSize = self[1]:getSize()
|
|
|
|
self[1]:paintTo(bb,
|
|
|
|
x + math.floor((self.dimen.w - contentSize.w)/2),
|
|
|
|
y + math.floor((self.dimen.h - contentSize.h)/2))
|
2014-03-13 13:52:43 +00:00
|
|
|
else
|
|
|
|
return self[1]:paintTo(bb, x, y)
|
|
|
|
end
|
|
|
|
end
|
2013-10-18 20:38:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function WidgetContainer:propagateEvent(event)
|
2014-03-13 13:52:43 +00:00
|
|
|
-- propagate to children
|
|
|
|
for _, widget in ipairs(self) do
|
|
|
|
if widget:handleEvent(event) then
|
|
|
|
-- stop propagating when an event handler returns true
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return false
|
2013-10-18 20:38:07 +00:00
|
|
|
end
|
|
|
|
|
2016-12-05 00:41:01 +00:00
|
|
|
--[[--
|
|
|
|
WidgetContainer will pass event to its children by calling their handleEvent
|
2016-12-11 03:08:31 +00:00
|
|
|
methods. If no child consumes the event (by returning true), it will try
|
|
|
|
to react to the event by itself.
|
2016-12-05 00:41:01 +00:00
|
|
|
|
|
|
|
@tparam ui.event.Event event
|
2017-11-15 08:02:33 +00:00
|
|
|
@treturn bool true if event is consumed, otherwise false. A consumed event will
|
2016-12-05 00:41:01 +00:00
|
|
|
not be sent to other widgets.
|
|
|
|
]]
|
2013-10-18 20:38:07 +00:00
|
|
|
function WidgetContainer:handleEvent(event)
|
2014-03-13 13:52:43 +00:00
|
|
|
if not self:propagateEvent(event) then
|
|
|
|
-- call our own standard event handler
|
|
|
|
return Widget.handleEvent(self, event)
|
|
|
|
else
|
|
|
|
return true
|
|
|
|
end
|
2013-10-18 20:38:07 +00:00
|
|
|
end
|
|
|
|
|
2022-03-14 18:56:18 +00:00
|
|
|
-- Honor full for TextBoxWidget's benefit...
|
|
|
|
function WidgetContainer:free(full)
|
2014-03-13 13:52:43 +00:00
|
|
|
for _, widget in ipairs(self) do
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
if widget.free then
|
|
|
|
--print("WidgetContainer: Calling free for widget", debug.getinfo(widget.free, "S").short_src, widget, "from", debug.getinfo(self.free, "S").short_src, self)
|
2022-03-14 18:56:18 +00:00
|
|
|
widget:free(full)
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2013-10-18 20:38:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return WidgetContainer
|