2016-02-14 21:47:36 +00:00
|
|
|
--[[--
|
|
|
|
Widget that presents a multi-page to show key value pairs.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
local Foo = KeyValuePage:new{
|
|
|
|
title = "Statistics",
|
|
|
|
kv_pairs = {
|
|
|
|
{"Current period", "00:00:00"},
|
|
|
|
-- single or more "-" will generate a solid line
|
|
|
|
"----------------------------",
|
|
|
|
{"Page to read", "5"},
|
|
|
|
{"Time to read", "00:01:00"},
|
|
|
|
{"Press me", "will invoke the callback",
|
|
|
|
callback = function() print("hello") end },
|
|
|
|
},
|
|
|
|
}
|
|
|
|
UIManager:show(Foo)
|
|
|
|
|
|
|
|
]]
|
|
|
|
|
2019-12-06 21:55:39 +00:00
|
|
|
local BD = require("ui/bidi")
|
2016-02-14 21:47:36 +00:00
|
|
|
local Blitbuffer = require("ffi/blitbuffer")
|
2017-08-02 17:17:56 +00:00
|
|
|
local BottomContainer = require("ui/widget/container/bottomcontainer")
|
|
|
|
local Button = require("ui/widget/button")
|
2016-02-14 21:47:36 +00:00
|
|
|
local CloseButton = require("ui/widget/closebutton")
|
2017-04-25 16:49:39 +00:00
|
|
|
local Device = require("device")
|
|
|
|
local Font = require("ui/font")
|
|
|
|
local FrameContainer = require("ui/widget/container/framecontainer")
|
|
|
|
local Geom = require("ui/geometry")
|
2016-02-14 21:47:36 +00:00
|
|
|
local GestureRange = require("ui/gesturerange")
|
2017-04-25 16:49:39 +00:00
|
|
|
local HorizontalGroup = require("ui/widget/horizontalgroup")
|
2017-08-02 17:17:56 +00:00
|
|
|
local HorizontalSpan = require("ui/widget/horizontalspan")
|
2017-04-25 16:49:39 +00:00
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
|
|
|
local LeftContainer = require("ui/widget/container/leftcontainer")
|
|
|
|
local LineWidget = require("ui/widget/linewidget")
|
|
|
|
local OverlapGroup = require("ui/widget/overlapgroup")
|
2017-09-13 14:56:20 +00:00
|
|
|
local Size = require("ui/size")
|
2017-07-01 09:30:30 +00:00
|
|
|
local TextViewer = require("ui/widget/textviewer")
|
2017-04-25 16:49:39 +00:00
|
|
|
local TextWidget = require("ui/widget/textwidget")
|
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
local VerticalGroup = require("ui/widget/verticalgroup")
|
|
|
|
local VerticalSpan = require("ui/widget/verticalspan")
|
2018-01-11 11:45:00 +00:00
|
|
|
local Input = Device.input
|
2016-02-14 21:47:36 +00:00
|
|
|
local Screen = Device.screen
|
2017-08-02 17:17:56 +00:00
|
|
|
local T = require("ffi/util").template
|
|
|
|
local _ = require("gettext")
|
2016-02-14 21:47:36 +00:00
|
|
|
|
|
|
|
local KeyValueTitle = VerticalGroup:new{
|
|
|
|
kv_page = nil,
|
|
|
|
title = "",
|
2016-02-16 01:56:13 +00:00
|
|
|
tface = Font:getFace("tfont"),
|
2016-02-14 21:47:36 +00:00
|
|
|
align = "left",
|
2017-10-16 15:51:56 +00:00
|
|
|
use_top_page_count = false,
|
2016-02-14 21:47:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function KeyValueTitle:init()
|
|
|
|
self.close_button = CloseButton:new{ window = self }
|
2016-02-16 01:56:13 +00:00
|
|
|
local btn_width = self.close_button:getSize().w
|
2016-03-07 06:41:17 +00:00
|
|
|
-- title and close button
|
2016-02-14 21:47:36 +00:00
|
|
|
table.insert(self, OverlapGroup:new{
|
|
|
|
dimen = { w = self.width },
|
|
|
|
TextWidget:new{
|
2019-10-21 13:20:40 +00:00
|
|
|
text = self.title,
|
|
|
|
max_width = self.width - btn_width,
|
2016-02-16 01:56:13 +00:00
|
|
|
face = self.tface,
|
2016-02-14 21:47:36 +00:00
|
|
|
},
|
|
|
|
self.close_button,
|
|
|
|
})
|
2016-03-07 06:41:17 +00:00
|
|
|
-- page count and separation line
|
2016-02-14 21:47:36 +00:00
|
|
|
self.title_bottom = OverlapGroup:new{
|
2017-09-13 14:56:20 +00:00
|
|
|
dimen = { w = self.width, h = Size.line.thick },
|
2016-02-14 21:47:36 +00:00
|
|
|
LineWidget:new{
|
2017-09-13 14:56:20 +00:00
|
|
|
dimen = Geom:new{ w = self.width, h = Size.line.thick },
|
2019-03-14 19:58:45 +00:00
|
|
|
background = Blitbuffer.COLOR_DARK_GRAY,
|
2016-02-14 21:47:36 +00:00
|
|
|
style = "solid",
|
|
|
|
},
|
|
|
|
}
|
2017-10-16 15:51:56 +00:00
|
|
|
if self.use_top_page_count then
|
|
|
|
self.page_cnt = FrameContainer:new{
|
|
|
|
padding = Size.padding.default,
|
|
|
|
margin = 0,
|
|
|
|
bordersize = 0,
|
|
|
|
background = Blitbuffer.COLOR_WHITE,
|
|
|
|
-- overlap offset x will be updated in setPageCount method
|
|
|
|
overlap_offset = {0, -15},
|
|
|
|
TextWidget:new{
|
|
|
|
text = "", -- page count
|
2019-03-14 19:58:45 +00:00
|
|
|
fgcolor = Blitbuffer.COLOR_DARK_GRAY,
|
2017-10-16 15:51:56 +00:00
|
|
|
face = Font:getFace("smallffont"),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
table.insert(self.title_bottom, self.page_cnt)
|
|
|
|
end
|
2016-02-14 21:47:36 +00:00
|
|
|
table.insert(self, self.title_bottom)
|
2017-09-13 14:56:20 +00:00
|
|
|
table.insert(self, VerticalSpan:new{ width = Size.span.vertical_large })
|
2016-02-14 21:47:36 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function KeyValueTitle:setPageCount(curr, total)
|
|
|
|
if total == 1 then
|
|
|
|
-- remove page count if there is only one page
|
|
|
|
table.remove(self.title_bottom, 2)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
self.page_cnt[1]:setText(curr .. "/" .. total)
|
2016-03-07 06:41:17 +00:00
|
|
|
self.page_cnt.overlap_offset[1] = (self.width - self.page_cnt:getSize().w - 10)
|
2016-02-14 21:47:36 +00:00
|
|
|
self.title_bottom[2] = self.page_cnt
|
|
|
|
end
|
|
|
|
|
|
|
|
function KeyValueTitle:onClose()
|
|
|
|
self.kv_page:onClose()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local KeyValueItem = InputContainer:new{
|
|
|
|
key = nil,
|
|
|
|
value = nil,
|
2020-01-23 16:35:57 +00:00
|
|
|
value_lang = nil,
|
2017-04-29 08:38:09 +00:00
|
|
|
cface = Font:getFace("smallinfofont"),
|
|
|
|
tface = Font:getFace("smallinfofontbold"),
|
2016-02-14 21:47:36 +00:00
|
|
|
width = nil,
|
|
|
|
height = nil,
|
2017-07-01 09:30:30 +00:00
|
|
|
textviewer_width = nil,
|
|
|
|
textviewer_height = nil,
|
2017-10-23 19:30:06 +00:00
|
|
|
value_overflow_align = "left",
|
2016-02-14 21:47:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function KeyValueItem:init()
|
|
|
|
self.dimen = Geom:new{w = self.width, h = self.height}
|
|
|
|
|
|
|
|
if self.callback and Device:isTouchDevice() then
|
|
|
|
self.ges_events.Tap = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "tap",
|
|
|
|
range = self.dimen,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-01-21 21:33:40 +00:00
|
|
|
-- self.value may contain some control characters (\n \t...) that would
|
|
|
|
-- be rendered as a square. Replace them with a shorter and nicer '|'.
|
|
|
|
-- (Let self.value untouched, as with Hold, the original value can be
|
|
|
|
-- displayed correctly in TextViewer.)
|
|
|
|
local tvalue = tostring(self.value)
|
|
|
|
tvalue = tvalue:gsub("[\n\t]", "|")
|
|
|
|
|
2017-09-13 14:56:20 +00:00
|
|
|
local frame_padding = Size.padding.default
|
2017-04-26 12:55:35 +00:00
|
|
|
local frame_internal_width = self.width - frame_padding * 2
|
2019-12-06 21:55:28 +00:00
|
|
|
local middle_padding = Size.padding.default -- min enforced padding between key and value
|
|
|
|
local available_width = frame_internal_width - middle_padding
|
|
|
|
|
2019-10-21 13:20:40 +00:00
|
|
|
-- Default widths (and position of value widget) if each text fits in 1/2 screen width
|
2019-12-06 21:55:28 +00:00
|
|
|
local key_w = frame_internal_width / 2 - middle_padding
|
2017-04-26 12:55:35 +00:00
|
|
|
local value_w = frame_internal_width / 2
|
2019-10-21 13:20:40 +00:00
|
|
|
|
|
|
|
local key_widget = TextWidget:new{
|
|
|
|
text = self.key,
|
2019-12-06 21:55:28 +00:00
|
|
|
max_width = available_width,
|
2019-10-21 13:20:40 +00:00
|
|
|
face = self.tface,
|
|
|
|
}
|
|
|
|
local value_widget = TextWidget:new{
|
|
|
|
text = tvalue,
|
2019-12-06 21:55:28 +00:00
|
|
|
max_width = available_width,
|
2019-10-21 13:20:40 +00:00
|
|
|
face = self.cface,
|
2020-01-23 16:35:57 +00:00
|
|
|
lang = self.value_lang,
|
2019-10-21 13:20:40 +00:00
|
|
|
}
|
|
|
|
local key_w_rendered = key_widget:getWidth()
|
|
|
|
local value_w_rendered = value_widget:getWidth()
|
|
|
|
|
|
|
|
-- As both key_widget and value_width will be in a HorizontalGroup,
|
|
|
|
-- and key is always left aligned, we can just tweak the key width
|
|
|
|
-- to position the value_widget
|
|
|
|
local value_align_right = false
|
|
|
|
local fit_right_align = true -- by default, really right align
|
|
|
|
|
2017-04-25 16:49:39 +00:00
|
|
|
if key_w_rendered > key_w or value_w_rendered > value_w then
|
2019-10-21 13:20:40 +00:00
|
|
|
-- One (or both) does not fit in 1/2 width
|
2019-12-06 21:55:28 +00:00
|
|
|
if key_w_rendered + value_w_rendered > available_width then
|
2019-10-21 13:20:40 +00:00
|
|
|
-- Both do not fit: one has to be truncated so they fit
|
2017-04-25 16:49:39 +00:00
|
|
|
if key_w_rendered >= value_w_rendered then
|
2019-10-21 13:20:40 +00:00
|
|
|
-- Rare case: key larger than value.
|
|
|
|
-- We should have kept our keys small, smaller than 1/2 width.
|
|
|
|
-- If it is larger than value, it's that value is kinda small,
|
|
|
|
-- so keep the whole value, and truncate the key
|
2019-12-06 21:55:28 +00:00
|
|
|
key_w = available_width - value_w_rendered
|
2017-04-25 16:49:39 +00:00
|
|
|
else
|
2019-10-21 13:20:40 +00:00
|
|
|
-- Usual case: value larger than key.
|
2019-12-06 21:55:28 +00:00
|
|
|
-- Keep our small key, fit the value in the remaining width.
|
2019-10-21 13:20:40 +00:00
|
|
|
key_w = key_w_rendered
|
2017-04-25 16:49:39 +00:00
|
|
|
end
|
2019-10-21 13:20:40 +00:00
|
|
|
value_align_right = true -- so the ellipsis touches the screen right border
|
|
|
|
if self.value_overflow_align ~= "right" and self.value_align ~= "right" then
|
|
|
|
-- Don't adjust the ellipsis to the screen right border,
|
|
|
|
-- so the left of text is aligned with other truncated texts
|
|
|
|
fit_right_align = false
|
|
|
|
end
|
|
|
|
-- Allow for displaying the non-truncated texts with Hold
|
2017-07-01 09:30:30 +00:00
|
|
|
if Device:isTouchDevice() then
|
|
|
|
self.ges_events.Hold = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "hold",
|
|
|
|
range = self.dimen,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
2016-02-16 01:56:13 +00:00
|
|
|
else
|
2019-10-21 13:20:40 +00:00
|
|
|
-- Both can fit: break the 1/2 widths
|
2017-12-17 21:08:13 +00:00
|
|
|
if self.value_overflow_align == "right" or self.value_align == "right" then
|
2019-12-06 21:55:28 +00:00
|
|
|
key_w = available_width - value_w_rendered
|
2019-10-21 13:20:40 +00:00
|
|
|
value_align_right = true
|
2017-10-23 19:30:06 +00:00
|
|
|
else
|
2019-10-21 13:20:40 +00:00
|
|
|
key_w = key_w_rendered
|
2017-10-23 19:30:06 +00:00
|
|
|
end
|
2016-02-16 01:56:13 +00:00
|
|
|
end
|
2019-10-21 13:20:40 +00:00
|
|
|
-- In all the above case, we set the right key_w to include any
|
2019-12-06 21:55:28 +00:00
|
|
|
-- needed additional in-between padding: value_w is what's left.
|
|
|
|
value_w = available_width - key_w
|
2016-02-16 01:56:13 +00:00
|
|
|
else
|
2017-12-17 21:08:13 +00:00
|
|
|
if self.value_align == "right" then
|
2019-12-06 21:55:28 +00:00
|
|
|
key_w = available_width - value_w_rendered
|
2019-10-21 13:20:40 +00:00
|
|
|
value_w = value_w_rendered
|
|
|
|
value_align_right = true
|
2017-12-17 21:08:13 +00:00
|
|
|
end
|
2016-02-16 01:56:13 +00:00
|
|
|
end
|
|
|
|
|
2019-12-06 21:55:28 +00:00
|
|
|
-- Adjust widgets' max widths if needed
|
2019-10-21 13:20:40 +00:00
|
|
|
value_widget:setMaxWidth(value_w)
|
|
|
|
if fit_right_align and value_align_right and value_widget:getWidth() < value_w then
|
|
|
|
-- Because of truncation at glyph boundaries, value_widget
|
|
|
|
-- may be a tad smaller than the specified value_w:
|
|
|
|
-- add some padding to key_w so value is pushed to the screen right border
|
|
|
|
key_w = key_w + ( value_w - value_widget:getWidth() )
|
|
|
|
end
|
|
|
|
key_widget:setMaxWidth(key_w)
|
|
|
|
|
|
|
|
-- For debugging positioning:
|
|
|
|
-- value_widget = FrameContainer:new{ padding=0, margin=0, bordersize=1, value_widget }
|
|
|
|
|
2016-02-16 01:56:13 +00:00
|
|
|
self[1] = FrameContainer:new{
|
2017-04-26 12:55:35 +00:00
|
|
|
padding = frame_padding,
|
2016-02-16 01:56:13 +00:00
|
|
|
bordersize = 0,
|
2017-04-25 16:49:39 +00:00
|
|
|
HorizontalGroup:new{
|
2016-02-14 21:47:36 +00:00
|
|
|
dimen = self.dimen:copy(),
|
2016-02-16 01:56:13 +00:00
|
|
|
LeftContainer:new{
|
2017-04-25 16:49:39 +00:00
|
|
|
dimen = {
|
|
|
|
w = key_w,
|
|
|
|
h = self.height
|
|
|
|
},
|
2019-10-21 13:20:40 +00:00
|
|
|
key_widget,
|
2016-02-16 01:56:13 +00:00
|
|
|
},
|
2019-12-06 21:55:28 +00:00
|
|
|
HorizontalSpan:new{
|
|
|
|
width = middle_padding,
|
|
|
|
},
|
2017-04-25 16:49:39 +00:00
|
|
|
LeftContainer:new{
|
|
|
|
dimen = {
|
|
|
|
w = value_w,
|
|
|
|
h = self.height
|
|
|
|
},
|
2019-10-21 13:20:40 +00:00
|
|
|
value_widget,
|
2016-02-14 21:47:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
function KeyValueItem:onTap()
|
2017-10-08 18:51:24 +00:00
|
|
|
if self.callback then
|
2017-10-10 21:50:45 +00:00
|
|
|
if G_reader_settings:isFalse("flash_ui") then
|
2017-10-08 18:51:24 +00:00
|
|
|
self.callback()
|
2017-10-10 21:50:45 +00:00
|
|
|
else
|
|
|
|
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)
|
|
|
|
UIManager:setDirty(nil, function()
|
2018-06-02 16:10:55 +00:00
|
|
|
return "fast", self[1].dimen
|
2017-10-08 18:51:24 +00:00
|
|
|
end)
|
2018-06-02 16:10:55 +00:00
|
|
|
UIManager:tickAfterNext(function()
|
2017-10-10 21:50:45 +00:00
|
|
|
self.callback()
|
|
|
|
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)
|
|
|
|
UIManager:setDirty(nil, function()
|
2017-10-10 21:50:45 +00:00
|
|
|
return "ui", self[1].dimen
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end
|
2017-10-08 18:51:24 +00:00
|
|
|
end
|
2016-02-14 21:47:36 +00:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2017-07-01 09:30:30 +00:00
|
|
|
function KeyValueItem:onHold()
|
|
|
|
local textviewer = TextViewer:new{
|
|
|
|
title = self.key,
|
|
|
|
text = self.value,
|
2020-01-23 16:35:57 +00:00
|
|
|
lang = self.value_lang,
|
2017-07-01 09:30:30 +00:00
|
|
|
width = self.textviewer_width,
|
|
|
|
height = self.textviewer_height,
|
|
|
|
}
|
|
|
|
UIManager:show(textviewer)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2016-02-14 21:47:36 +00:00
|
|
|
|
|
|
|
local KeyValuePage = InputContainer:new{
|
|
|
|
title = "",
|
|
|
|
width = nil,
|
|
|
|
height = nil,
|
2020-01-23 16:35:57 +00:00
|
|
|
values_lang = nil,
|
2016-02-14 21:47:36 +00:00
|
|
|
-- index for the first item to show
|
|
|
|
show_page = 1,
|
2017-10-16 15:51:56 +00:00
|
|
|
use_top_page_count = false,
|
2017-10-23 19:30:06 +00:00
|
|
|
-- aligment of value when key or value overflows its reserved width (for
|
|
|
|
-- now: 50%): "left" (stick to key), "right" (stick to scren right border)
|
|
|
|
value_overflow_align = "left",
|
2016-02-14 21:47:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function KeyValuePage:init()
|
|
|
|
self.dimen = Geom:new{
|
|
|
|
w = self.width or Screen:getWidth(),
|
|
|
|
h = self.height or Screen:getHeight(),
|
|
|
|
}
|
2018-03-17 22:02:32 +00:00
|
|
|
if self.dimen.w == Screen:getWidth() and self.dimen.h == Screen:getHeight() then
|
|
|
|
self.covers_fullscreen = true -- hint for UIManager:_repaint()
|
|
|
|
end
|
2016-02-14 21:47:36 +00:00
|
|
|
|
2017-07-01 09:30:30 +00:00
|
|
|
if Device:hasKeys() then
|
|
|
|
self.key_events = {
|
|
|
|
Close = { {"Back"}, doc = "close page" },
|
2018-01-11 11:45:00 +00:00
|
|
|
NextPage = {{Input.group.PgFwd}, doc = "next page"},
|
|
|
|
PrevPage = {{Input.group.PgBack}, doc = "prev page"},
|
2017-07-01 09:30:30 +00:00
|
|
|
}
|
|
|
|
end
|
2016-02-14 21:47:36 +00:00
|
|
|
if Device:isTouchDevice() then
|
|
|
|
self.ges_events.Swipe = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "swipe",
|
|
|
|
range = self.dimen,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2017-09-28 13:35:25 +00:00
|
|
|
-- return button
|
2019-12-06 21:55:39 +00:00
|
|
|
--- @todo: alternative icon if BD.mirroredUILayout()
|
2017-09-28 13:35:25 +00:00
|
|
|
self.page_return_arrow = Button:new{
|
|
|
|
icon = "resources/icons/appbar.arrow.left.up.png",
|
|
|
|
callback = function() self:onReturn() end,
|
|
|
|
bordersize = 0,
|
|
|
|
show_parent = self,
|
|
|
|
}
|
2017-08-02 17:17:56 +00:00
|
|
|
-- group for page info
|
2019-12-06 21:55:39 +00:00
|
|
|
local chevron_left = "resources/icons/appbar.chevron.left.png"
|
|
|
|
local chevron_right = "resources/icons/appbar.chevron.right.png"
|
|
|
|
local chevron_first = "resources/icons/appbar.chevron.first.png"
|
|
|
|
local chevron_last = "resources/icons/appbar.chevron.last.png"
|
|
|
|
if BD.mirroredUILayout() then
|
|
|
|
chevron_left, chevron_right = chevron_right, chevron_left
|
|
|
|
chevron_first, chevron_last = chevron_last, chevron_first
|
|
|
|
end
|
2017-08-02 17:17:56 +00:00
|
|
|
self.page_info_left_chev = Button:new{
|
2019-12-06 21:55:39 +00:00
|
|
|
icon = chevron_left,
|
2017-08-02 17:17:56 +00:00
|
|
|
callback = function() self:prevPage() end,
|
|
|
|
bordersize = 0,
|
|
|
|
show_parent = self,
|
|
|
|
}
|
|
|
|
self.page_info_right_chev = Button:new{
|
2019-12-06 21:55:39 +00:00
|
|
|
icon = chevron_right,
|
2017-08-02 17:17:56 +00:00
|
|
|
callback = function() self:nextPage() end,
|
|
|
|
bordersize = 0,
|
|
|
|
show_parent = self,
|
|
|
|
}
|
|
|
|
self.page_info_first_chev = Button:new{
|
2019-12-06 21:55:39 +00:00
|
|
|
icon = chevron_first,
|
2017-08-02 17:17:56 +00:00
|
|
|
callback = function() self:goToPage(1) end,
|
|
|
|
bordersize = 0,
|
|
|
|
show_parent = self,
|
|
|
|
}
|
|
|
|
self.page_info_last_chev = Button:new{
|
2019-12-06 21:55:39 +00:00
|
|
|
icon = chevron_last,
|
2017-08-02 17:17:56 +00:00
|
|
|
callback = function() self:goToPage(self.pages) end,
|
|
|
|
bordersize = 0,
|
|
|
|
show_parent = self,
|
|
|
|
}
|
|
|
|
self.page_info_spacer = HorizontalSpan:new{
|
|
|
|
width = Screen:scaleBySize(32),
|
|
|
|
}
|
2017-09-28 13:35:25 +00:00
|
|
|
self.page_return_spacer = HorizontalSpan:new{
|
|
|
|
width = self.page_return_arrow:getSize().w
|
|
|
|
}
|
|
|
|
|
|
|
|
if self.callback_return == nil and self.return_button == nil then
|
|
|
|
self.page_return_arrow:hide()
|
|
|
|
elseif self.callback_return == nil then
|
|
|
|
self.page_return_arrow:disable()
|
|
|
|
end
|
|
|
|
|
2017-08-02 17:17:56 +00:00
|
|
|
self.page_info_left_chev:hide()
|
|
|
|
self.page_info_right_chev:hide()
|
|
|
|
self.page_info_first_chev:hide()
|
|
|
|
self.page_info_last_chev:hide()
|
|
|
|
|
|
|
|
self.page_info_text = Button:new{
|
|
|
|
text = "",
|
|
|
|
hold_input = {
|
2019-03-01 11:59:39 +00:00
|
|
|
title = _("Enter page number"),
|
2017-08-02 17:17:56 +00:00
|
|
|
type = "number",
|
|
|
|
hint_func = function()
|
|
|
|
return "(" .. "1 - " .. self.pages .. ")"
|
|
|
|
end,
|
|
|
|
callback = function(input)
|
|
|
|
local page = tonumber(input)
|
2017-08-06 09:57:20 +00:00
|
|
|
if page and page >= 1 and page <= self.pages then
|
2017-08-02 17:17:56 +00:00
|
|
|
self:goToPage(page)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
bordersize = 0,
|
|
|
|
margin = Screen:scaleBySize(20),
|
|
|
|
text_font_face = "pgfont",
|
|
|
|
text_font_bold = false,
|
|
|
|
}
|
|
|
|
self.page_info = HorizontalGroup:new{
|
2017-09-28 13:35:25 +00:00
|
|
|
self.page_return_arrow,
|
2017-08-02 17:17:56 +00:00
|
|
|
self.page_info_first_chev,
|
|
|
|
self.page_info_spacer,
|
|
|
|
self.page_info_left_chev,
|
|
|
|
self.page_info_text,
|
|
|
|
self.page_info_right_chev,
|
|
|
|
self.page_info_spacer,
|
|
|
|
self.page_info_last_chev,
|
2017-09-28 13:35:25 +00:00
|
|
|
self.page_return_spacer,
|
2017-08-02 17:17:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
local footer = BottomContainer:new{
|
|
|
|
dimen = self.dimen:copy(),
|
|
|
|
self.page_info,
|
|
|
|
}
|
|
|
|
|
2017-09-13 14:56:20 +00:00
|
|
|
local padding = Size.padding.large
|
2016-02-14 21:47:36 +00:00
|
|
|
self.item_width = self.dimen.w - 2 * padding
|
2017-09-13 14:56:20 +00:00
|
|
|
self.item_height = Size.item.height_default
|
2016-02-14 21:47:36 +00:00
|
|
|
-- setup title bar
|
|
|
|
self.title_bar = KeyValueTitle:new{
|
|
|
|
title = self.title,
|
|
|
|
width = self.item_width,
|
|
|
|
height = self.item_height,
|
2017-10-16 15:51:56 +00:00
|
|
|
use_top_page_count = self.use_top_page_count,
|
2016-02-14 21:47:36 +00:00
|
|
|
kv_page = self,
|
|
|
|
}
|
|
|
|
-- setup main content
|
2016-02-16 01:56:13 +00:00
|
|
|
self.item_margin = self.item_height / 4
|
|
|
|
local line_height = self.item_height + 2 * self.item_margin
|
2017-08-02 17:17:56 +00:00
|
|
|
local content_height = self.dimen.h - self.title_bar:getSize().h - self.page_info:getSize().h
|
2016-02-14 21:47:36 +00:00
|
|
|
self.items_per_page = math.floor(content_height / line_height)
|
|
|
|
self.pages = math.ceil(#self.kv_pairs / self.items_per_page)
|
|
|
|
self.main_content = VerticalGroup:new{}
|
2017-07-01 09:30:30 +00:00
|
|
|
|
|
|
|
-- set textviewer height to let our title fully visible
|
|
|
|
self.textviewer_width = self.item_width
|
|
|
|
self.textviewer_height = self.dimen.h - 2*self.title_bar:getSize().h
|
|
|
|
|
2016-02-14 21:47:36 +00:00
|
|
|
self:_populateItems()
|
2017-08-02 17:17:56 +00:00
|
|
|
|
|
|
|
local content = OverlapGroup:new{
|
|
|
|
dimen = self.dimen:copy(),
|
2019-12-06 21:55:39 +00:00
|
|
|
allow_mirroring = false,
|
2017-08-02 17:17:56 +00:00
|
|
|
VerticalGroup:new{
|
|
|
|
align = "left",
|
|
|
|
self.title_bar,
|
|
|
|
self.main_content,
|
|
|
|
},
|
|
|
|
footer,
|
|
|
|
}
|
2016-02-14 21:47:36 +00:00
|
|
|
-- assemble page
|
|
|
|
self[1] = FrameContainer:new{
|
|
|
|
height = self.dimen.h,
|
|
|
|
padding = padding,
|
|
|
|
bordersize = 0,
|
|
|
|
background = Blitbuffer.COLOR_WHITE,
|
2017-08-02 17:17:56 +00:00
|
|
|
content
|
2016-02-14 21:47:36 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
function KeyValuePage:nextPage()
|
|
|
|
local new_page = math.min(self.show_page+1, self.pages)
|
|
|
|
if new_page > self.show_page then
|
|
|
|
self.show_page = new_page
|
|
|
|
self:_populateItems()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function KeyValuePage:prevPage()
|
|
|
|
local new_page = math.max(self.show_page-1, 1)
|
|
|
|
if new_page < self.show_page then
|
|
|
|
self.show_page = new_page
|
|
|
|
self:_populateItems()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-02 17:17:56 +00:00
|
|
|
function KeyValuePage:goToPage(page)
|
|
|
|
self.show_page = page
|
|
|
|
self:_populateItems()
|
|
|
|
end
|
|
|
|
|
2016-02-16 01:56:13 +00:00
|
|
|
-- make sure self.item_margin and self.item_height are set before calling this
|
2016-02-14 21:47:36 +00:00
|
|
|
function KeyValuePage:_populateItems()
|
2017-08-02 17:17:56 +00:00
|
|
|
self.page_info:resetLayout()
|
2016-02-14 21:47:36 +00:00
|
|
|
self.main_content:clear()
|
|
|
|
local idx_offset = (self.show_page - 1) * self.items_per_page
|
|
|
|
for idx = 1, self.items_per_page do
|
|
|
|
local entry = self.kv_pairs[idx_offset + idx]
|
|
|
|
if entry == nil then break end
|
|
|
|
|
|
|
|
table.insert(self.main_content,
|
2016-02-16 01:56:13 +00:00
|
|
|
VerticalSpan:new{ width = self.item_margin })
|
2016-02-14 21:47:36 +00:00
|
|
|
if type(entry) == "table" then
|
|
|
|
table.insert(
|
|
|
|
self.main_content,
|
|
|
|
KeyValueItem:new{
|
|
|
|
height = self.item_height,
|
|
|
|
width = self.item_width,
|
|
|
|
key = entry[1],
|
|
|
|
value = entry[2],
|
2020-01-23 16:35:57 +00:00
|
|
|
value_lang = self.values_lang,
|
2016-02-14 21:47:36 +00:00
|
|
|
callback = entry.callback,
|
2017-09-28 13:35:25 +00:00
|
|
|
callback_back = entry.callback_back,
|
2017-07-01 09:30:30 +00:00
|
|
|
textviewer_width = self.textviewer_width,
|
|
|
|
textviewer_height = self.textviewer_height,
|
2017-10-23 19:30:06 +00:00
|
|
|
value_overflow_align = self.value_overflow_align,
|
2017-12-17 21:08:13 +00:00
|
|
|
value_align = self.value_align,
|
2017-10-08 18:51:24 +00:00
|
|
|
show_parent = self,
|
2016-02-14 21:47:36 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
elseif type(entry) == "string" then
|
|
|
|
local c = string.sub(entry, 1, 1)
|
|
|
|
if c == "-" then
|
2017-07-01 09:30:30 +00:00
|
|
|
table.insert(self.main_content,
|
|
|
|
VerticalSpan:new{ width = self.item_margin })
|
2016-02-14 21:47:36 +00:00
|
|
|
table.insert(self.main_content, LineWidget:new{
|
2019-03-14 19:58:45 +00:00
|
|
|
background = Blitbuffer.COLOR_LIGHT_GRAY,
|
2016-02-14 21:47:36 +00:00
|
|
|
dimen = Geom:new{
|
|
|
|
w = self.item_width,
|
2017-09-13 14:56:20 +00:00
|
|
|
h = Size.line.thick
|
2016-02-14 21:47:36 +00:00
|
|
|
},
|
|
|
|
style = "solid",
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
table.insert(self.main_content,
|
2016-02-16 01:56:13 +00:00
|
|
|
VerticalSpan:new{ width = self.item_margin })
|
2016-02-14 21:47:36 +00:00
|
|
|
end
|
2019-10-21 12:24:29 +00:00
|
|
|
self.page_info_text:setText(T(_("Page %1 of %2"), self.show_page, self.pages))
|
2017-08-02 17:17:56 +00:00
|
|
|
self.page_info_left_chev:showHide(self.pages > 1)
|
|
|
|
self.page_info_right_chev:showHide(self.pages > 1)
|
|
|
|
self.page_info_first_chev:showHide(self.pages > 2)
|
|
|
|
self.page_info_last_chev:showHide(self.pages > 2)
|
|
|
|
|
|
|
|
self.page_info_left_chev:enableDisable(self.show_page > 1)
|
|
|
|
self.page_info_right_chev:enableDisable(self.show_page < self.pages)
|
|
|
|
self.page_info_first_chev:enableDisable(self.show_page > 1)
|
|
|
|
self.page_info_last_chev:enableDisable(self.show_page < self.pages)
|
|
|
|
|
2016-02-14 21:47:36 +00:00
|
|
|
UIManager:setDirty(self, function()
|
|
|
|
return "ui", self.dimen
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2018-01-11 11:45:00 +00:00
|
|
|
function KeyValuePage:onNextPage()
|
|
|
|
self:nextPage()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function KeyValuePage:onPrevPage()
|
|
|
|
self:prevPage()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2016-02-14 21:47:36 +00:00
|
|
|
function KeyValuePage:onSwipe(arg, ges_ev)
|
2019-12-06 21:55:39 +00:00
|
|
|
local direction = BD.flipDirectionIfMirroredUILayout(ges_ev.direction)
|
|
|
|
if direction == "west" then
|
2016-02-14 21:47:36 +00:00
|
|
|
self:nextPage()
|
|
|
|
return true
|
2019-12-06 21:55:39 +00:00
|
|
|
elseif direction == "east" then
|
2016-02-14 21:47:36 +00:00
|
|
|
self:prevPage()
|
|
|
|
return true
|
2019-12-06 21:55:39 +00:00
|
|
|
elseif direction == "south" then
|
2018-09-21 13:48:40 +00:00
|
|
|
-- Allow easier closing with swipe down
|
|
|
|
self:onClose()
|
2019-12-06 21:55:39 +00:00
|
|
|
elseif direction == "north" then
|
2018-09-21 13:48:40 +00:00
|
|
|
-- no use for now
|
|
|
|
do end -- luacheck: ignore 541
|
|
|
|
else -- diagonal swipe
|
2017-07-01 09:30:30 +00:00
|
|
|
-- trigger full refresh
|
|
|
|
UIManager:setDirty(nil, "full")
|
|
|
|
-- a long diagonal swipe may also be used for taking a screenshot,
|
|
|
|
-- so let it propagate
|
|
|
|
return false
|
2016-02-14 21:47:36 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function KeyValuePage:onClose()
|
|
|
|
UIManager:close(self)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2017-09-28 13:35:25 +00:00
|
|
|
function KeyValuePage:onReturn()
|
|
|
|
if self.callback_return then
|
|
|
|
self:callback_return()
|
|
|
|
UIManager:close(self)
|
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, "ui")
|
2017-09-28 13:35:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-14 21:47:36 +00:00
|
|
|
return KeyValuePage
|