2017-10-28 19:28:41 +00:00
|
|
|
local Button = require("ui/widget/button")
|
2017-11-04 14:31:41 +00:00
|
|
|
local ButtonProgressWidget = require("ui/widget/buttonprogresswidget")
|
2017-04-07 13:20:57 +00:00
|
|
|
local Blitbuffer = require("ffi/blitbuffer")
|
|
|
|
local BottomContainer = require("ui/widget/container/bottomcontainer")
|
2013-10-18 20:38:07 +00:00
|
|
|
local CenterContainer = require("ui/widget/container/centercontainer")
|
2017-04-07 13:20:57 +00:00
|
|
|
local ConfirmBox = require("ui/widget/confirmbox")
|
|
|
|
local Device = require("device")
|
|
|
|
local Event = require("ui/event")
|
|
|
|
local FixedTextWidget = require("ui/widget/fixedtextwidget")
|
2018-03-22 20:01:38 +00:00
|
|
|
local FocusManager = require("ui/widget/focusmanager")
|
2017-04-07 13:20:57 +00:00
|
|
|
local Font = require("ui/font")
|
2013-10-18 20:38:07 +00:00
|
|
|
local FrameContainer = require("ui/widget/container/framecontainer")
|
2017-04-07 13:20:57 +00:00
|
|
|
local Geom = require("ui/geometry")
|
|
|
|
local GestureRange = require("ui/gesturerange")
|
2014-11-20 02:59:58 +00:00
|
|
|
local HorizontalGroup = require("ui/widget/horizontalgroup")
|
2017-04-07 13:20:57 +00:00
|
|
|
local HorizontalSpan = require("ui/widget/horizontalspan")
|
|
|
|
local IconButton = require("ui/widget/iconbutton")
|
2014-11-20 02:59:58 +00:00
|
|
|
local ImageWidget = require("ui/widget/imagewidget")
|
2017-04-07 13:20:57 +00:00
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
2017-09-11 18:54:27 +00:00
|
|
|
local LineWidget = require("ui/widget/linewidget")
|
2017-04-07 13:20:57 +00:00
|
|
|
local RightContainer = require("ui/widget/container/rightcontainer")
|
2017-09-13 14:56:20 +00:00
|
|
|
local Size = require("ui/size")
|
2014-11-20 02:59:58 +00:00
|
|
|
local TextWidget = require("ui/widget/textwidget")
|
2017-04-07 13:20:57 +00:00
|
|
|
local ToggleSwitch = require("ui/widget/toggleswitch")
|
2013-10-18 20:38:07 +00:00
|
|
|
local UIManager = require("ui/uimanager")
|
2017-04-07 13:20:57 +00:00
|
|
|
local UnderlineContainer = require("ui/widget/container/underlinecontainer")
|
|
|
|
local VerticalGroup = require("ui/widget/verticalgroup")
|
|
|
|
local VerticalSpan = require("ui/widget/verticalspan")
|
2019-03-01 11:55:55 +00:00
|
|
|
local dump = require("dump")
|
2016-12-29 08:10:38 +00:00
|
|
|
local logger = require("logger")
|
2013-10-18 20:38:07 +00:00
|
|
|
local _ = require("gettext")
|
2017-04-07 13:20:57 +00:00
|
|
|
local Screen = Device.screen
|
|
|
|
local T = require("ffi/util").template
|
2013-01-15 09:24:38 +00:00
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
local OptionTextItem = InputContainer:new{}
|
2019-01-15 19:39:33 +00:00
|
|
|
|
2012-12-23 23:54:44 +00:00
|
|
|
function OptionTextItem:init()
|
2014-03-13 13:52:43 +00:00
|
|
|
local text_widget = self[1]
|
2014-05-28 12:05:38 +00:00
|
|
|
|
2018-11-20 19:54:03 +00:00
|
|
|
self.underline_container = UnderlineContainer:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
text_widget,
|
2018-11-20 19:54:03 +00:00
|
|
|
padding = self.underline_padding, -- vertical padding between text and underline
|
2014-03-13 13:52:43 +00:00
|
|
|
color = self.color,
|
|
|
|
}
|
2018-11-20 19:54:03 +00:00
|
|
|
self[1] = FrameContainer:new{
|
|
|
|
padding = 0,
|
|
|
|
padding_left = self.padding_left,
|
|
|
|
padding_right = self.padding_right,
|
|
|
|
bordersize = 0,
|
|
|
|
self.underline_container,
|
|
|
|
}
|
2014-03-13 13:52:43 +00:00
|
|
|
self.dimen = self[1]:getSize()
|
|
|
|
-- we need this table per-instance, so we declare it here
|
|
|
|
if Device:isTouchDevice() then
|
|
|
|
self.ges_events = {
|
|
|
|
TapSelect = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "tap",
|
|
|
|
range = self.dimen,
|
|
|
|
},
|
2014-06-05 06:58:53 +00:00
|
|
|
doc = "Select Option Item",
|
2014-03-13 13:52:43 +00:00
|
|
|
},
|
2014-07-03 08:30:24 +00:00
|
|
|
HoldSelect = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "hold",
|
|
|
|
range = self.dimen,
|
|
|
|
},
|
|
|
|
doc = "Hold Option Item",
|
|
|
|
},
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
|
|
|
end
|
2012-12-23 23:54:44 +00:00
|
|
|
end
|
|
|
|
|
2018-03-22 20:01:38 +00:00
|
|
|
function OptionTextItem:onFocus()
|
2018-11-20 19:54:03 +00:00
|
|
|
self.underline_container.color = Blitbuffer.COLOR_BLACK
|
2018-03-22 20:01:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function OptionTextItem:onUnfocus()
|
2018-11-20 19:54:03 +00:00
|
|
|
self.underline_container.color = Blitbuffer.COLOR_WHITE
|
2018-03-22 20:01:38 +00:00
|
|
|
end
|
|
|
|
|
2012-12-23 23:54:44 +00:00
|
|
|
function OptionTextItem:onTapSelect()
|
2015-03-16 13:49:53 +00:00
|
|
|
if not self.enabled then return true end
|
2014-03-13 13:52:43 +00:00
|
|
|
for _, item in pairs(self.items) do
|
2018-11-20 19:54:03 +00:00
|
|
|
item.underline_container.color = Blitbuffer.COLOR_WHITE
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2018-11-20 19:54:03 +00:00
|
|
|
self.underline_container.color = Blitbuffer.COLOR_BLACK
|
2014-07-03 08:30:24 +00:00
|
|
|
self.config:onConfigChoose(self.values, self.name,
|
|
|
|
self.event, self.args,
|
|
|
|
self.events, self.current_item)
|
2014-11-30 00:12:00 +00:00
|
|
|
UIManager:setDirty(self.config, function()
|
2018-06-02 16:10:55 +00:00
|
|
|
return "fast", self[1].dimen
|
2014-11-30 00:12:00 +00:00
|
|
|
end)
|
2014-03-13 13:52:43 +00:00
|
|
|
return true
|
2012-12-23 23:54:44 +00:00
|
|
|
end
|
2012-12-14 10:20:04 +00:00
|
|
|
|
2014-07-03 08:30:24 +00:00
|
|
|
function OptionTextItem:onHoldSelect()
|
|
|
|
self.config:onMakeDefault(self.name, self.name_text,
|
|
|
|
self.values or self.args,
|
|
|
|
self.values or self.item_text,
|
|
|
|
self.current_item)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
local OptionIconItem = InputContainer:new{}
|
2019-01-15 19:39:33 +00:00
|
|
|
|
2013-02-03 03:26:14 +00:00
|
|
|
function OptionIconItem:init()
|
2018-11-20 19:54:03 +00:00
|
|
|
self.underline_container = UnderlineContainer:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
self.icon,
|
2018-11-20 19:54:03 +00:00
|
|
|
padding = self.underline_padding,
|
2014-03-13 13:52:43 +00:00
|
|
|
color = self.color,
|
|
|
|
}
|
2018-11-20 19:54:03 +00:00
|
|
|
self[1] = FrameContainer:new{
|
|
|
|
padding = 0,
|
|
|
|
padding_left = self.padding_left,
|
|
|
|
padding_right = self.padding_right,
|
|
|
|
bordersize = 0,
|
|
|
|
self.underline_container,
|
|
|
|
}
|
|
|
|
self.dimen = self[1]:getSize()
|
2014-03-13 13:52:43 +00:00
|
|
|
-- we need this table per-instance, so we declare it here
|
|
|
|
if Device:isTouchDevice() then
|
|
|
|
self.ges_events = {
|
|
|
|
TapSelect = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "tap",
|
|
|
|
range = self.dimen,
|
|
|
|
},
|
2014-06-05 06:58:53 +00:00
|
|
|
doc = "Select Option Item",
|
2014-03-13 13:52:43 +00:00
|
|
|
},
|
2014-07-03 08:30:24 +00:00
|
|
|
HoldSelect = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "hold",
|
|
|
|
range = self.dimen,
|
|
|
|
},
|
|
|
|
doc = "Hold Option Item",
|
|
|
|
},
|
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
|
|
|
end
|
2013-02-03 03:26:14 +00:00
|
|
|
end
|
|
|
|
|
2018-03-22 20:01:38 +00:00
|
|
|
function OptionIconItem:onFocus()
|
|
|
|
self.icon.invert = true
|
|
|
|
end
|
|
|
|
|
|
|
|
function OptionIconItem:onUnfocus()
|
|
|
|
self.icon.invert = false
|
|
|
|
end
|
|
|
|
|
2013-02-03 03:26:14 +00:00
|
|
|
function OptionIconItem:onTapSelect()
|
2015-03-16 13:49:53 +00:00
|
|
|
if not self.enabled then return true end
|
2014-03-13 13:52:43 +00:00
|
|
|
for _, item in pairs(self.items) do
|
|
|
|
--item[1][1].invert = false
|
2018-11-20 19:54:03 +00:00
|
|
|
item.underline_container.color = Blitbuffer.COLOR_WHITE
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
|
|
|
--self[1][1].invert = true
|
2018-11-20 19:54:03 +00:00
|
|
|
self.underline_container.color = Blitbuffer.COLOR_BLACK
|
2014-07-03 08:30:24 +00:00
|
|
|
self.config:onConfigChoose(self.values, self.name,
|
|
|
|
self.event, self.args,
|
|
|
|
self.events, self.current_item)
|
2014-11-30 00:12:00 +00:00
|
|
|
UIManager:setDirty(self.config, function()
|
2018-06-02 16:10:55 +00:00
|
|
|
return "fast", self[1].dimen
|
2014-11-30 00:12:00 +00:00
|
|
|
end)
|
2014-03-13 13:52:43 +00:00
|
|
|
return true
|
2013-02-03 03:26:14 +00:00
|
|
|
end
|
|
|
|
|
2014-07-03 08:30:24 +00:00
|
|
|
function OptionIconItem:onHoldSelect()
|
|
|
|
self.config:onMakeDefault(self.name, self.name_text,
|
|
|
|
self.values, self.values, self.current_item)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
local ConfigOption = CenterContainer:new{}
|
2019-01-15 19:39:33 +00:00
|
|
|
|
2012-12-19 15:45:51 +00:00
|
|
|
function ConfigOption:init()
|
2014-11-23 08:52:08 +00:00
|
|
|
-- make default styles
|
2014-03-13 13:52:43 +00:00
|
|
|
local default_name_font_size = 20
|
2019-01-15 19:39:33 +00:00
|
|
|
local default_item_font_size = 16 -- font size for letters, toggles and buttonprogress
|
|
|
|
local default_items_spacing = 40 -- spacing between letters (font sizes) and icons
|
|
|
|
local default_option_height = 50 -- height of each line
|
|
|
|
-- The next ones are already scaleBySize()'d:
|
|
|
|
local default_option_vpadding = Size.padding.large -- vertical padding at top and bottom
|
|
|
|
local default_option_hpadding = Size.padding.fullscreen
|
|
|
|
-- horizontal padding at left and right, and between name and option items
|
|
|
|
local padding_small = Size.padding.small -- internal padding for options names (left)
|
|
|
|
local padding_button = Size.padding.button -- padding for underline below letters and icons
|
|
|
|
|
2019-08-23 17:53:53 +00:00
|
|
|
--- @todo Restore setting when there are more advanced settings.
|
2019-01-15 19:39:33 +00:00
|
|
|
--local show_advanced = G_reader_settings:readSetting("show_advanced") or false
|
|
|
|
local show_advanced = true
|
|
|
|
|
|
|
|
-- Get the width needed by the longest option name shown on the left
|
2014-11-23 08:52:08 +00:00
|
|
|
local max_option_name_width = 0
|
|
|
|
for c = 1, #self.options do
|
2019-01-15 19:39:33 +00:00
|
|
|
-- Ignore names of options that won't be shown
|
|
|
|
local show_default = not self.options[c].advanced or show_advanced
|
2019-06-25 22:23:41 +00:00
|
|
|
local show = self.options[c].show
|
|
|
|
-- Prefer show_func over show if there's one
|
|
|
|
if self.options[c].show_func then
|
|
|
|
show = self.options[c].show_func()
|
|
|
|
end
|
|
|
|
if show ~= false and show_default then
|
2019-01-15 19:39:33 +00:00
|
|
|
local name_font_face = self.options[c].name_font_face and self.options[c].name_font_face or "cfont"
|
|
|
|
local name_font_size = self.options[c].name_font_size and self.options[c].name_font_size or default_name_font_size
|
|
|
|
local text = self.options[c].name_text
|
|
|
|
local face = Font:getFace(name_font_face, name_font_size)
|
|
|
|
local txt_width = 0
|
|
|
|
if text ~= nil then
|
2019-10-21 13:20:40 +00:00
|
|
|
local tmp = TextWidget:new{
|
|
|
|
text = text,
|
|
|
|
face = face,
|
|
|
|
}
|
|
|
|
txt_width = tmp:getWidth()
|
2019-01-15 19:39:33 +00:00
|
|
|
end
|
|
|
|
max_option_name_width = math.max(max_option_name_width, txt_width)
|
2017-10-28 19:28:41 +00:00
|
|
|
end
|
2014-11-23 08:52:08 +00:00
|
|
|
end
|
2019-01-15 19:39:33 +00:00
|
|
|
-- Have option names take min 25% and max 50% of screen width
|
|
|
|
-- They will carry the left default_option_hpadding, but the in-between
|
|
|
|
-- one (and the right one) will be carried by the option items.
|
|
|
|
-- (Both these variables are between 0 and 1 and represent a % of screen width)
|
2020-06-16 20:14:14 +00:00
|
|
|
local default_name_align_right = (max_option_name_width + default_option_hpadding + 2*padding_small) / Screen:getWidth()
|
2019-01-15 19:39:33 +00:00
|
|
|
default_name_align_right = math.max(default_name_align_right, 0.25)
|
2017-10-28 19:28:41 +00:00
|
|
|
default_name_align_right = math.min(default_name_align_right, 0.5)
|
2014-11-23 08:52:08 +00:00
|
|
|
local default_item_align_center = 1 - default_name_align_right
|
|
|
|
|
|
|
|
-- fill vertical group of config tab
|
2014-03-13 13:52:43 +00:00
|
|
|
local vertical_group = VerticalGroup:new{}
|
|
|
|
table.insert(vertical_group, VerticalSpan:new{
|
2019-01-15 19:39:33 +00:00
|
|
|
width = default_option_vpadding,
|
2014-03-13 13:52:43 +00:00
|
|
|
})
|
2019-01-15 19:39:33 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
for c = 1, #self.options do
|
2014-07-17 14:31:01 +00:00
|
|
|
local show_default = not self.options[c].advanced or show_advanced
|
2019-06-25 22:23:41 +00:00
|
|
|
local show = self.options[c].show
|
|
|
|
-- Prefer show_func over show if there's one
|
|
|
|
if self.options[c].show_func then
|
|
|
|
show = self.options[c].show_func()
|
|
|
|
end
|
|
|
|
if show ~= false and show_default then
|
2014-11-23 08:52:08 +00:00
|
|
|
local name_align = self.options[c].name_align_right and self.options[c].name_align_right or default_name_align_right
|
|
|
|
local item_align = self.options[c].item_align_center and self.options[c].item_align_center or default_item_align_center
|
2014-03-13 13:52:43 +00:00
|
|
|
local name_font_face = self.options[c].name_font_face and self.options[c].name_font_face or "cfont"
|
|
|
|
local name_font_size = self.options[c].name_font_size and self.options[c].name_font_size or default_name_font_size
|
|
|
|
local item_font_face = self.options[c].item_font_face and self.options[c].item_font_face or "cfont"
|
|
|
|
local item_font_size = self.options[c].item_font_size and self.options[c].item_font_size or default_item_font_size
|
2017-10-31 20:42:13 +00:00
|
|
|
local option_height = Screen:scaleBySize(self.options[c].height and self.options[c].height or
|
|
|
|
default_option_height + (self.options[c].height or 30) * ((self.options[c].row_count or 1) -1))
|
2017-09-13 14:56:20 +00:00
|
|
|
local item_spacing_width = Screen:scaleBySize(self.options[c].spacing and self.options[c].spacing or default_items_spacing)
|
2015-03-16 13:49:53 +00:00
|
|
|
local enabled = true
|
2017-10-28 19:28:41 +00:00
|
|
|
if item_align == 1.0 then
|
|
|
|
name_align = 0
|
|
|
|
end
|
|
|
|
if name_align + item_align > 1 then
|
|
|
|
name_align = 0.5
|
|
|
|
item_align = 0.5
|
|
|
|
end
|
2015-03-16 13:49:53 +00:00
|
|
|
if self.options[c].enabled_func then
|
2019-08-30 11:47:51 +00:00
|
|
|
enabled = self.options[c].enabled_func(self.config.configurable, self.config.document)
|
2015-03-16 13:49:53 +00:00
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
local horizontal_group = HorizontalGroup:new{}
|
2019-01-15 19:39:33 +00:00
|
|
|
|
|
|
|
-- Deal with the name on the left
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.options[c].name_text then
|
2019-01-15 19:39:33 +00:00
|
|
|
-- the horizontal padding on the left will be ensured by the RightContainer
|
|
|
|
local name_widget_width = math.floor(name_align * Screen:getWidth())
|
2019-11-16 16:43:28 +00:00
|
|
|
-- We don't remove default_option_hpadding from name_text_max_width
|
|
|
|
-- to give more to text and avoid truncation: as it is right aligned,
|
|
|
|
-- the text can grow on the left, padding_small is enough.
|
|
|
|
local name_text_max_width = name_widget_width - 2*padding_small
|
2017-10-28 19:28:41 +00:00
|
|
|
local text = self.options[c].name_text
|
|
|
|
local face = Font:getFace(name_font_face, name_font_size)
|
2014-03-13 13:52:43 +00:00
|
|
|
local option_name_container = RightContainer:new{
|
2019-01-15 19:39:33 +00:00
|
|
|
dimen = Geom:new{ w = name_widget_width, h = option_height},
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
2017-10-28 19:28:41 +00:00
|
|
|
local option_name = Button:new{
|
|
|
|
text = text,
|
2019-10-21 13:20:40 +00:00
|
|
|
max_width = name_text_max_width,
|
2017-10-28 19:28:41 +00:00
|
|
|
bordersize = 0,
|
|
|
|
face = face,
|
|
|
|
enabled = enabled,
|
2020-05-07 18:24:12 +00:00
|
|
|
allow_hold_when_disabled = self.options[c].name_text_hold_callback ~= nil,
|
2017-10-28 19:28:41 +00:00
|
|
|
padding = padding_small,
|
|
|
|
text_font_face = name_font_face,
|
|
|
|
text_font_size = name_font_size,
|
|
|
|
text_font_bold = false,
|
2018-05-18 22:16:02 +00:00
|
|
|
hold_callback = function()
|
|
|
|
if self.options[c].name_text_hold_callback then
|
2018-05-26 17:45:37 +00:00
|
|
|
self.options[c].name_text_hold_callback(self.config.configurable, self.options[c],
|
|
|
|
self.config.config_options.prefix)
|
2018-05-18 22:16:02 +00:00
|
|
|
end
|
|
|
|
end,
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
|
|
|
table.insert(option_name_container, option_name)
|
|
|
|
table.insert(horizontal_group, option_name_container)
|
|
|
|
end
|
|
|
|
|
2019-01-15 19:39:33 +00:00
|
|
|
-- Deal with the option widget on the right
|
|
|
|
-- The horizontal padding between name and this option widget, and
|
|
|
|
-- the one on the right, are ensured by this CenterContainer
|
|
|
|
local option_widget_outer_width = math.floor(item_align * Screen:getWidth())
|
|
|
|
local option_widget_width = option_widget_outer_width - 2*default_option_hpadding
|
2014-03-13 13:52:43 +00:00
|
|
|
local option_items_container = CenterContainer:new{
|
2019-01-15 19:39:33 +00:00
|
|
|
dimen = Geom:new{
|
|
|
|
w = option_widget_outer_width,
|
|
|
|
h = option_height
|
|
|
|
}
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
|
|
|
local option_items_group = HorizontalGroup:new{}
|
|
|
|
local option_items_fixed = false
|
|
|
|
local option_items = {}
|
|
|
|
if type(self.options[c].item_font_size) == "table" then
|
|
|
|
option_items_group.align = "bottom"
|
|
|
|
option_items_fixed = true
|
|
|
|
end
|
2019-01-15 19:39:33 +00:00
|
|
|
|
2019-03-15 22:15:05 +00:00
|
|
|
-- Find out currently selected and default items indexes
|
2014-03-13 13:52:43 +00:00
|
|
|
local current_item = nil
|
2019-03-15 22:15:05 +00:00
|
|
|
local default_item = self.options[c].default_pos
|
2014-03-13 13:52:43 +00:00
|
|
|
local function value_diff(val1, val2, name)
|
|
|
|
if type(val1) ~= type(val2) then
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("different data types in option")
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
|
|
|
if type(val1) == "number" then
|
|
|
|
return math.abs(val1 - val2)
|
|
|
|
elseif type(val1) == "string" then
|
|
|
|
return val1 == val2 and 0 or 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if self.options[c].name then
|
|
|
|
if self.options[c].values then
|
|
|
|
-- check if current value is stored in configurable or calculated in runtime
|
|
|
|
local val = self.options[c].current_func and self.options[c].current_func()
|
|
|
|
or self.config.configurable[self.options[c].name]
|
2016-02-16 02:08:04 +00:00
|
|
|
local min_diff
|
2014-03-13 13:52:43 +00:00
|
|
|
if type(val) == "table" then
|
|
|
|
min_diff = value_diff(val[1], self.options[c].values[1][1])
|
|
|
|
else
|
|
|
|
min_diff = value_diff(val, self.options[c].values[1])
|
|
|
|
end
|
2014-05-28 12:05:38 +00:00
|
|
|
|
2016-02-16 02:08:04 +00:00
|
|
|
local diff
|
2014-03-13 13:52:43 +00:00
|
|
|
for index, val_ in pairs(self.options[c].values) do
|
|
|
|
if type(val) == "table" then
|
|
|
|
diff = value_diff(val[1], val_[1])
|
|
|
|
else
|
|
|
|
diff = value_diff(val, val_)
|
|
|
|
end
|
|
|
|
if val == val_ then
|
|
|
|
current_item = index
|
|
|
|
break
|
|
|
|
end
|
|
|
|
if diff <= min_diff then
|
|
|
|
min_diff = diff
|
|
|
|
current_item = index
|
|
|
|
end
|
|
|
|
end
|
2020-05-09 11:16:12 +00:00
|
|
|
-- If we want to have the ⋮ toggle selected when the value
|
|
|
|
-- is different from the predefined values:
|
|
|
|
-- if diff ~= 0 and self.options[c].alternate ~= false and self.options[c].more_options_param then
|
|
|
|
-- current_item = #self.options[c].values + 1
|
|
|
|
-- end
|
2014-03-13 13:52:43 +00:00
|
|
|
elseif self.options[c].args then
|
|
|
|
-- check if current arg is stored in configurable or calculated in runtime
|
|
|
|
local arg = self.options[c].current_func and self.options[c].current_func()
|
|
|
|
or self.config.configurable[self.options[c].name]
|
|
|
|
for idx, arg_ in pairs(self.options[c].args) do
|
|
|
|
if arg_ == arg then
|
|
|
|
current_item = idx
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-03-15 22:15:05 +00:00
|
|
|
local default_option_name = self.config.config_options.prefix.."_"..self.options[c].name
|
|
|
|
local default_value = G_reader_settings:readSetting(default_option_name)
|
2019-03-25 18:15:29 +00:00
|
|
|
if default_value and self.options[c].values then
|
2019-03-15 22:15:05 +00:00
|
|
|
local val = default_value
|
|
|
|
local min_diff
|
|
|
|
if type(val) == "table" then
|
|
|
|
min_diff = value_diff(val[1], self.options[c].values[1][1])
|
|
|
|
else
|
|
|
|
min_diff = value_diff(val, self.options[c].values[1])
|
|
|
|
end
|
|
|
|
|
|
|
|
local diff
|
|
|
|
for index, val_ in pairs(self.options[c].values) do
|
|
|
|
if type(val) == "table" then
|
|
|
|
diff = value_diff(val[1], val_[1])
|
|
|
|
else
|
|
|
|
diff = value_diff(val, val_)
|
|
|
|
end
|
|
|
|
if val == val_ then
|
|
|
|
default_item = index
|
|
|
|
break
|
|
|
|
end
|
|
|
|
if diff <= min_diff then
|
|
|
|
min_diff = diff
|
|
|
|
default_item = index
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2019-01-15 19:39:33 +00:00
|
|
|
|
|
|
|
-- Deal with the various kind of config widgets
|
|
|
|
|
|
|
|
-- Plain letters (ex: font sizes)
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.options[c].item_text then
|
2014-06-02 14:57:50 +00:00
|
|
|
local items_count = #self.options[c].item_text
|
2017-10-28 19:28:41 +00:00
|
|
|
local items_width = 0
|
|
|
|
for d = 1, #self.options[c].item_text do
|
|
|
|
local item = OptionTextItem:new{
|
|
|
|
TextWidget:new{
|
|
|
|
text = self.options[c].item_text[d],
|
|
|
|
face = Font:getFace(item_font_face,
|
|
|
|
option_items_fixed and item_font_size[d]
|
2014-06-02 14:57:50 +00:00
|
|
|
or item_font_size),
|
2017-10-28 19:28:41 +00:00
|
|
|
}
|
2014-06-02 14:57:50 +00:00
|
|
|
}
|
2017-10-28 19:28:41 +00:00
|
|
|
items_width = items_width + item:getSize().w
|
|
|
|
end
|
2019-01-15 19:39:33 +00:00
|
|
|
local max_item_spacing = (option_widget_width - items_width) / items_count
|
2017-10-28 19:28:41 +00:00
|
|
|
local width = math.min(max_item_spacing, item_spacing_width)
|
|
|
|
if max_item_spacing < item_spacing_width / 2 then
|
|
|
|
width = item_spacing_width / 2
|
|
|
|
end
|
2018-11-20 19:54:03 +00:00
|
|
|
local horizontal_half_padding = width / 2
|
2019-01-15 19:39:33 +00:00
|
|
|
local max_item_text_width = (option_widget_width - items_count * width) / items_count
|
2014-03-13 13:52:43 +00:00
|
|
|
for d = 1, #self.options[c].item_text do
|
2016-02-16 02:08:04 +00:00
|
|
|
local option_item
|
2014-03-13 13:52:43 +00:00
|
|
|
if option_items_fixed then
|
|
|
|
option_item = OptionTextItem:new{
|
|
|
|
FixedTextWidget:new{
|
|
|
|
text = self.options[c].item_text[d],
|
|
|
|
face = Font:getFace(item_font_face, item_font_size[d]),
|
2019-03-14 19:58:45 +00:00
|
|
|
fgcolor = enabled and Blitbuffer.COLOR_BLACK or Blitbuffer.COLOR_DARK_GRAY,
|
2014-03-13 13:52:43 +00:00
|
|
|
},
|
2018-11-20 19:54:03 +00:00
|
|
|
underline_padding = padding_button,
|
|
|
|
padding_left = d > 1 and horizontal_half_padding,
|
|
|
|
padding_right = d < #self.options[c].item_text and horizontal_half_padding,
|
2019-03-14 21:09:55 +00:00
|
|
|
color = d == current_item and (enabled and Blitbuffer.COLOR_BLACK or Blitbuffer.COLOR_DARK_GRAY) or Blitbuffer.COLOR_WHITE,
|
2015-03-16 13:49:53 +00:00
|
|
|
enabled = enabled,
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
|
|
|
else
|
2017-10-28 19:28:41 +00:00
|
|
|
local text = self.options[c].item_text[d]
|
|
|
|
local face = Font:getFace(item_font_face, item_font_size)
|
2014-03-13 13:52:43 +00:00
|
|
|
option_item = OptionTextItem:new{
|
|
|
|
TextWidget:new{
|
2017-10-28 19:28:41 +00:00
|
|
|
text = text,
|
2019-10-21 13:20:40 +00:00
|
|
|
max_width = max_item_text_width,
|
2017-10-28 19:28:41 +00:00
|
|
|
face = face,
|
2019-03-14 19:58:45 +00:00
|
|
|
fgcolor = enabled and Blitbuffer.COLOR_BLACK or Blitbuffer.COLOR_DARK_GRAY,
|
2014-03-13 13:52:43 +00:00
|
|
|
},
|
2018-11-20 19:54:03 +00:00
|
|
|
underline_padding = -padding_button,
|
|
|
|
padding_left = d > 1 and horizontal_half_padding,
|
|
|
|
padding_right = d < #self.options[c].item_text and horizontal_half_padding,
|
2019-03-14 21:09:55 +00:00
|
|
|
color = d == current_item and (enabled and Blitbuffer.COLOR_BLACK or Blitbuffer.COLOR_DARK_GRAY) or Blitbuffer.COLOR_WHITE,
|
2015-03-16 13:49:53 +00:00
|
|
|
enabled = enabled,
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
option_items[d] = option_item
|
|
|
|
option_item.items = option_items
|
|
|
|
option_item.name = self.options[c].name
|
2014-07-03 08:30:24 +00:00
|
|
|
option_item.name_text = self.options[c].name_text
|
|
|
|
option_item.item_text = self.options[c].item_text
|
2014-03-13 13:52:43 +00:00
|
|
|
option_item.values = self.options[c].values
|
|
|
|
option_item.args = self.options[c].args
|
|
|
|
option_item.event = self.options[c].event
|
|
|
|
option_item.current_item = d
|
|
|
|
option_item.config = self.config
|
2019-08-30 11:47:51 +00:00
|
|
|
option_item.document = self.document
|
2014-03-13 13:52:43 +00:00
|
|
|
table.insert(option_items_group, option_item)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-01-15 19:39:33 +00:00
|
|
|
-- Icons (ex: columns, text align, with PDF)
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.options[c].item_icons then
|
2014-06-02 14:57:50 +00:00
|
|
|
local items_count = #self.options[c].item_icons
|
|
|
|
local first_item = OptionIconItem:new{
|
|
|
|
icon = ImageWidget:new{
|
|
|
|
file = self.options[c].item_icons[1]
|
|
|
|
}
|
|
|
|
}
|
2019-01-15 19:39:33 +00:00
|
|
|
local max_item_spacing = (option_widget_width -
|
2014-06-02 14:57:50 +00:00
|
|
|
first_item:getSize().w * items_count) / items_count
|
2018-11-20 19:54:03 +00:00
|
|
|
local horizontal_half_padding = math.min(max_item_spacing, item_spacing_width) / 2
|
2014-03-13 13:52:43 +00:00
|
|
|
for d = 1, #self.options[c].item_icons do
|
|
|
|
local option_item = OptionIconItem:new{
|
|
|
|
icon = ImageWidget:new{
|
2015-03-16 13:49:53 +00:00
|
|
|
file = self.options[c].item_icons[d],
|
|
|
|
dim = not enabled,
|
2014-03-13 13:52:43 +00:00
|
|
|
},
|
2018-11-20 19:54:03 +00:00
|
|
|
underline_padding = -padding_button,
|
|
|
|
padding_left = d > 1 and horizontal_half_padding,
|
|
|
|
padding_right = d < #self.options[c].item_icons and horizontal_half_padding,
|
2019-03-14 21:09:55 +00:00
|
|
|
color = d == current_item and (enabled and Blitbuffer.COLOR_BLACK or Blitbuffer.COLOR_DARK_GRAY) or Blitbuffer.COLOR_WHITE,
|
2015-03-16 13:49:53 +00:00
|
|
|
enabled = enabled,
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
|
|
|
option_items[d] = option_item
|
|
|
|
option_item.items = option_items
|
|
|
|
option_item.name = self.options[c].name
|
2014-07-03 08:30:24 +00:00
|
|
|
option_item.name_text = self.options[c].name_text
|
2014-03-13 13:52:43 +00:00
|
|
|
option_item.values = self.options[c].values
|
|
|
|
option_item.args = self.options[c].args
|
|
|
|
option_item.event = self.options[c].event
|
|
|
|
option_item.current_item = d
|
|
|
|
option_item.config = self.config
|
|
|
|
table.insert(option_items_group, option_item)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-01-15 19:39:33 +00:00
|
|
|
-- Toggles (ex: mostly everything else)
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.options[c].toggle then
|
2019-01-15 19:39:33 +00:00
|
|
|
local max_toggle_width = option_widget_width
|
|
|
|
local toggle_width = self.options[c].width and Screen:scaleBySize(self.options[c].width)
|
|
|
|
or max_toggle_width
|
2016-04-26 02:45:55 +00:00
|
|
|
local row_count = self.options[c].row_count or 1
|
|
|
|
local toggle_height = Screen:scaleBySize(self.options[c].height
|
|
|
|
or 30 * row_count)
|
2019-09-27 10:58:40 +00:00
|
|
|
if self.options[c].more_options then
|
|
|
|
table.insert(self.options[c].toggle, "⋮")
|
|
|
|
table.insert(self.options[c].args, "⋮")
|
|
|
|
self.options[c].more_options = false
|
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
local switch = ToggleSwitch:new{
|
2014-06-02 14:57:50 +00:00
|
|
|
width = math.min(max_toggle_width, toggle_width),
|
2016-04-26 02:45:55 +00:00
|
|
|
height = toggle_height,
|
2014-11-23 08:52:08 +00:00
|
|
|
font_face = item_font_face,
|
|
|
|
font_size = item_font_size,
|
2014-03-13 13:52:43 +00:00
|
|
|
name = self.options[c].name,
|
2014-07-03 08:30:24 +00:00
|
|
|
name_text = self.options[c].name_text,
|
2014-03-13 13:52:43 +00:00
|
|
|
toggle = self.options[c].toggle,
|
|
|
|
alternate = self.options[c].alternate,
|
|
|
|
values = self.options[c].values,
|
|
|
|
args = self.options[c].args,
|
|
|
|
event = self.options[c].event,
|
|
|
|
events = self.options[c].events,
|
2019-05-05 08:15:13 +00:00
|
|
|
delay_repaint = self.options[c].delay_repaint,
|
2014-03-13 13:52:43 +00:00
|
|
|
config = self.config,
|
2015-03-16 13:49:53 +00:00
|
|
|
enabled = enabled,
|
2016-04-26 02:45:55 +00:00
|
|
|
row_count = row_count,
|
2019-09-27 10:58:40 +00:00
|
|
|
callback = function(arg)
|
2019-09-30 09:18:39 +00:00
|
|
|
if self.options[c].toggle[arg] == "⋮" then
|
2020-05-09 11:16:12 +00:00
|
|
|
if self.options[c].show_true_value_func and not self.options[c].more_options_param.show_true_value_func then
|
|
|
|
self.options[c].more_options_param.show_true_value_func = self.options[c].show_true_value_func
|
|
|
|
end
|
2019-09-27 10:58:40 +00:00
|
|
|
self.config:onConfigMoreChoose(self.options[c].values, self.options[c].name,
|
|
|
|
self.options[c].event, arg, self.options[c].name_text, self.options[c].delay_repaint, self.options[c].more_options_param)
|
|
|
|
end
|
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
|
|
|
local position = current_item
|
|
|
|
switch:setPosition(position)
|
|
|
|
table.insert(option_items_group, switch)
|
|
|
|
end
|
|
|
|
|
2019-01-15 19:39:33 +00:00
|
|
|
-- Progress bar (ex: contrast)
|
2017-11-04 14:31:41 +00:00
|
|
|
if self.options[c].buttonprogress then
|
2019-01-15 19:39:33 +00:00
|
|
|
local max_buttonprogress_width = option_widget_width
|
|
|
|
local buttonprogress_width = self.options[c].width and Screen:scaleBySize(self.options[c].width)
|
|
|
|
or max_buttonprogress_width
|
2019-03-14 21:23:17 +00:00
|
|
|
local switch
|
|
|
|
switch = ButtonProgressWidget:new{
|
2017-11-04 14:31:41 +00:00
|
|
|
width = math.min(max_buttonprogress_width, buttonprogress_width),
|
|
|
|
height = option_height,
|
2019-01-15 19:39:33 +00:00
|
|
|
padding = 0,
|
2019-03-02 11:24:15 +00:00
|
|
|
thin_grey_style = true,
|
2017-11-04 14:31:41 +00:00
|
|
|
font_face = item_font_face,
|
|
|
|
font_size = item_font_size,
|
2020-04-14 10:20:11 +00:00
|
|
|
name = self.options[c].name,
|
2017-11-04 14:31:41 +00:00
|
|
|
num_buttons = #self.options[c].values,
|
|
|
|
position = self.options[c].default_pos,
|
|
|
|
callback = function(arg)
|
2019-05-01 00:09:01 +00:00
|
|
|
if arg == "-" or arg == "+" then
|
|
|
|
self.config:onConfigFineTuneChoose(self.options[c].values, self.options[c].name,
|
2019-05-05 08:15:13 +00:00
|
|
|
self.options[c].event, self.options[c].args, self.options[c].events, arg, self.options[c].delay_repaint)
|
2019-09-14 14:30:25 +00:00
|
|
|
elseif arg == "⋮" then
|
|
|
|
self.config:onConfigMoreChoose(self.options[c].values, self.options[c].name,
|
|
|
|
self.options[c].event, arg, self.options[c].name_text, self.options[c].delay_repaint, self.options[c].more_options_param)
|
2019-05-01 00:09:01 +00:00
|
|
|
else
|
|
|
|
self.config:onConfigChoose(self.options[c].values, self.options[c].name,
|
2019-05-05 08:15:13 +00:00
|
|
|
self.options[c].event, self.options[c].args, self.options[c].events, arg, self.options[c].delay_repaint)
|
2019-05-01 00:09:01 +00:00
|
|
|
end
|
2019-03-14 21:23:17 +00:00
|
|
|
UIManager:setDirty(self.config, function()
|
|
|
|
return "fast", switch.dimen
|
2017-11-04 14:31:41 +00:00
|
|
|
end)
|
|
|
|
end,
|
|
|
|
hold_callback = function(arg)
|
2019-05-01 00:09:01 +00:00
|
|
|
if arg == "-" or arg == "+" then
|
|
|
|
self.config:onMakeFineTuneDefault(self.options[c].name, self.options[c].name_text, self.options[c].values,
|
|
|
|
self.options[c].labels or self.options[c].args, arg)
|
2019-09-23 22:24:45 +00:00
|
|
|
elseif arg ~= "⋮" then
|
2019-05-01 00:09:01 +00:00
|
|
|
self.config:onMakeDefault(self.options[c].name, self.options[c].name_text, self.options[c].values,
|
|
|
|
self.options[c].labels or self.options[c].args, arg)
|
|
|
|
end
|
2017-11-04 14:31:41 +00:00
|
|
|
end,
|
|
|
|
show_parrent = self.config,
|
|
|
|
enabled = enabled,
|
2019-05-01 00:09:01 +00:00
|
|
|
fine_tune = self.options[c].fine_tune,
|
2019-09-14 14:30:25 +00:00
|
|
|
more_options = self.options[c].more_options,
|
|
|
|
more_options_param = self.options[c].more_options_param,
|
2017-11-04 14:31:41 +00:00
|
|
|
}
|
2019-03-15 22:15:05 +00:00
|
|
|
switch:setPosition(current_item, default_item)
|
2017-11-04 14:31:41 +00:00
|
|
|
table.insert(option_items_group, switch)
|
|
|
|
end
|
2019-01-15 19:39:33 +00:00
|
|
|
|
|
|
|
-- Add it to our CenterContainer
|
2014-03-13 13:52:43 +00:00
|
|
|
table.insert(option_items_container, option_items_group)
|
2018-03-22 20:01:38 +00:00
|
|
|
--add line of item to the second last place in the focusmanager so the menubar stay at the bottom
|
|
|
|
table.insert(self.config.layout, #self.config.layout,self:_itemGroupToLayoutLine(option_items_group))
|
2014-03-13 13:52:43 +00:00
|
|
|
table.insert(horizontal_group, option_items_container)
|
|
|
|
table.insert(vertical_group, horizontal_group)
|
2019-06-25 22:23:41 +00:00
|
|
|
end -- if show ~= false
|
2019-01-15 19:39:33 +00:00
|
|
|
end -- for c = 1, #self.options
|
|
|
|
|
|
|
|
table.insert(vertical_group, VerticalSpan:new{ width = default_option_vpadding })
|
2014-03-13 13:52:43 +00:00
|
|
|
self[1] = vertical_group
|
|
|
|
self.dimen = vertical_group:getSize()
|
2012-12-19 15:45:51 +00:00
|
|
|
end
|
|
|
|
|
2018-03-22 20:01:38 +00:00
|
|
|
function ConfigOption:_itemGroupToLayoutLine(option_items_group)
|
|
|
|
local layout_line = {}
|
2020-04-14 10:20:11 +00:00
|
|
|
-- Insert items (skpping item_spacing without a .name attribute),
|
|
|
|
-- skipping indices at the beginning of the line in the layout
|
|
|
|
-- to align it with the current selected tab
|
|
|
|
local j = self.config.panel_index
|
|
|
|
for i, v in ipairs(option_items_group) do
|
|
|
|
if v.name then
|
|
|
|
layout_line[j] = v
|
|
|
|
j = j + 1
|
2018-03-22 20:01:38 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return layout_line
|
|
|
|
end
|
|
|
|
|
2019-01-15 19:39:33 +00:00
|
|
|
local ConfigPanel = FrameContainer:new{
|
|
|
|
background = Blitbuffer.COLOR_WHITE,
|
|
|
|
bordersize = 0,
|
|
|
|
}
|
|
|
|
|
2012-12-23 23:54:44 +00:00
|
|
|
function ConfigPanel:init()
|
2014-03-13 13:52:43 +00:00
|
|
|
local config_options = self.config_dialog.config_options
|
|
|
|
local default_option = config_options.default_options and config_options.default_options
|
|
|
|
or config_options[1].options
|
|
|
|
local panel = ConfigOption:new{
|
|
|
|
options = self.index and config_options[self.index].options or default_option,
|
|
|
|
config = self.config_dialog,
|
2019-08-30 11:47:51 +00:00
|
|
|
document = self.document,
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
|
|
|
self.dimen = panel:getSize()
|
|
|
|
table.insert(self, panel)
|
2013-01-15 09:24:38 +00:00
|
|
|
end
|
|
|
|
|
2017-09-11 18:54:27 +00:00
|
|
|
local MenuBar = FrameContainer:new{
|
|
|
|
bordersize = 0,
|
|
|
|
padding = 0,
|
|
|
|
background = Blitbuffer.COLOR_WHITE,
|
|
|
|
}
|
2013-01-15 09:24:38 +00:00
|
|
|
function MenuBar:init()
|
2017-09-13 14:56:20 +00:00
|
|
|
local icon_sep_width = Size.padding.button
|
|
|
|
local line_thickness = Size.line.thick
|
2014-03-13 13:52:43 +00:00
|
|
|
local config_options = self.config_dialog.config_options
|
|
|
|
local menu_items = {}
|
2017-09-24 13:22:06 +00:00
|
|
|
local icon_width = Screen:scaleBySize(40)
|
|
|
|
local icon_height = icon_width
|
|
|
|
local icons_width = (icon_width + 2*icon_sep_width) * #config_options
|
|
|
|
local icons_height = icon_height
|
2014-03-13 13:52:43 +00:00
|
|
|
for c = 1, #config_options do
|
2014-11-20 02:59:58 +00:00
|
|
|
local menu_icon = IconButton:new{
|
|
|
|
show_parent = self.config_dialog,
|
|
|
|
icon_file = config_options[c].icon,
|
2017-09-24 13:22:06 +00:00
|
|
|
width = icon_width,
|
|
|
|
height = icon_height,
|
|
|
|
scale_for_dpi = false,
|
2014-11-20 02:59:58 +00:00
|
|
|
callback = function()
|
|
|
|
self.config_dialog:handleEvent(Event:new("ShowConfigPanel", c))
|
|
|
|
end,
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
2014-11-20 02:59:58 +00:00
|
|
|
menu_items[c] = menu_icon
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2018-03-22 20:01:38 +00:00
|
|
|
table.insert(self.config_dialog.layout,menu_items) --for the focusmanager
|
2017-09-13 08:12:29 +00:00
|
|
|
local available_width = Screen:getWidth() - icons_width
|
|
|
|
-- local padding = math.floor(available_width / #menu_items / 2) -- all for padding
|
|
|
|
-- local padding = math.floor(available_width / #menu_items / 2 / 2) -- half padding, half spacing ?
|
|
|
|
local padding = math.min(math.floor(available_width / #menu_items / 2), Screen:scaleBySize(20)) -- as in TouchMenuBar
|
|
|
|
if padding > 0 then
|
|
|
|
for c = 1, #menu_items do
|
2017-09-27 16:15:11 +00:00
|
|
|
menu_items[c].padding_left = padding
|
|
|
|
menu_items[c].padding_right = padding
|
|
|
|
menu_items[c]:update()
|
2017-09-13 08:12:29 +00:00
|
|
|
end
|
|
|
|
available_width = available_width - 2*padding*#menu_items
|
|
|
|
end
|
|
|
|
local spacing_width = math.ceil(available_width / (#menu_items+1))
|
|
|
|
|
2017-09-12 16:34:30 +00:00
|
|
|
local icon_sep_black = LineWidget:new{
|
|
|
|
background = Blitbuffer.COLOR_BLACK,
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = icon_sep_width,
|
|
|
|
h = icons_height,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
local icon_sep_white = LineWidget:new{
|
|
|
|
background = Blitbuffer.COLOR_WHITE,
|
2017-09-11 18:54:27 +00:00
|
|
|
dimen = Geom:new{
|
|
|
|
w = icon_sep_width,
|
|
|
|
h = icons_height,
|
|
|
|
}
|
|
|
|
}
|
2014-03-13 13:52:43 +00:00
|
|
|
local spacing = HorizontalSpan:new{
|
2017-09-11 18:54:27 +00:00
|
|
|
width = spacing_width,
|
|
|
|
}
|
|
|
|
local spacing_line = LineWidget:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = spacing_width,
|
|
|
|
h = line_thickness,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
local sep_line = LineWidget:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = icon_sep_width,
|
|
|
|
h = line_thickness,
|
|
|
|
}
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
|
|
|
local menu_bar = HorizontalGroup:new{}
|
2017-09-11 18:54:27 +00:00
|
|
|
local line_bar = HorizontalGroup:new{}
|
2014-03-13 13:52:43 +00:00
|
|
|
|
|
|
|
for c = 1, #menu_items do
|
|
|
|
table.insert(menu_bar, spacing)
|
2017-09-11 18:54:27 +00:00
|
|
|
table.insert(line_bar, spacing_line)
|
|
|
|
if c == self.panel_index then
|
2017-09-12 16:34:30 +00:00
|
|
|
table.insert(menu_bar, icon_sep_black)
|
2017-09-11 18:54:27 +00:00
|
|
|
table.insert(line_bar, sep_line)
|
|
|
|
table.insert(menu_bar, menu_items[c])
|
|
|
|
table.insert(line_bar, LineWidget:new{
|
|
|
|
background = Blitbuffer.COLOR_WHITE,
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = menu_items[c]:getSize().w,
|
|
|
|
h = line_thickness,
|
|
|
|
}
|
|
|
|
})
|
2017-09-12 16:34:30 +00:00
|
|
|
table.insert(menu_bar, icon_sep_black)
|
2017-09-11 18:54:27 +00:00
|
|
|
table.insert(line_bar, sep_line)
|
|
|
|
else
|
2017-09-12 16:34:30 +00:00
|
|
|
table.insert(menu_bar, icon_sep_white)
|
|
|
|
table.insert(line_bar, sep_line)
|
2017-09-11 18:54:27 +00:00
|
|
|
table.insert(menu_bar, menu_items[c])
|
|
|
|
table.insert(line_bar, LineWidget:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = menu_items[c]:getSize().w,
|
|
|
|
h = line_thickness,
|
|
|
|
}
|
|
|
|
})
|
2017-09-12 16:34:30 +00:00
|
|
|
table.insert(menu_bar, icon_sep_white)
|
|
|
|
table.insert(line_bar, sep_line)
|
2017-09-11 18:54:27 +00:00
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
|
|
|
table.insert(menu_bar, spacing)
|
2017-09-11 18:54:27 +00:00
|
|
|
table.insert(line_bar, spacing_line)
|
2014-03-13 13:52:43 +00:00
|
|
|
|
|
|
|
self.dimen = Geom:new{ w = Screen:getWidth(), h = icons_height}
|
2017-09-11 18:54:27 +00:00
|
|
|
local vertical_menu = VerticalGroup:new{
|
|
|
|
line_bar,
|
|
|
|
menu_bar,
|
|
|
|
}
|
|
|
|
table.insert(self, vertical_menu)
|
|
|
|
|
2013-01-14 16:33:03 +00:00
|
|
|
end
|
|
|
|
|
2012-12-14 10:20:04 +00:00
|
|
|
--[[
|
2013-01-15 09:24:38 +00:00
|
|
|
Widget that displays config menubar and config panel
|
|
|
|
|
|
|
|
+----------------+
|
|
|
|
| |
|
|
|
|
| |
|
|
|
|
| |
|
|
|
|
| |
|
|
|
|
| |
|
|
|
|
+----------------+
|
|
|
|
| |
|
|
|
|
| Config Panel |
|
|
|
|
| |
|
|
|
|
+----------------+
|
|
|
|
| Menu Bar |
|
|
|
|
+----------------+
|
2013-03-12 17:18:53 +00:00
|
|
|
|
2012-12-14 10:20:04 +00:00
|
|
|
--]]
|
2013-01-15 09:24:38 +00:00
|
|
|
|
2018-03-22 20:01:38 +00:00
|
|
|
local ConfigDialog = FocusManager:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
--is_borderless = false,
|
|
|
|
panel_index = 1,
|
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
|
|
|
is_fresh = true,
|
2012-12-14 10:20:04 +00:00
|
|
|
}
|
|
|
|
|
2012-12-23 23:54:44 +00:00
|
|
|
function ConfigDialog:init()
|
2014-03-13 13:52:43 +00:00
|
|
|
------------------------------------------
|
|
|
|
-- start to set up widget layout ---------
|
|
|
|
------------------------------------------
|
|
|
|
self:update()
|
|
|
|
------------------------------------------
|
|
|
|
-- start to set up input event callback --
|
|
|
|
------------------------------------------
|
|
|
|
if Device:isTouchDevice() then
|
|
|
|
self.ges_events.TapCloseMenu = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "tap",
|
|
|
|
range = Geom:new{
|
|
|
|
x = 0, y = 0,
|
|
|
|
w = Screen:getWidth(),
|
|
|
|
h = Screen:getHeight(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-08-14 09:06:10 +00:00
|
|
|
self.ges_events.SwipeCloseMenu = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "swipe",
|
|
|
|
range = Geom:new{
|
|
|
|
x = 0, y = 0,
|
|
|
|
w = Screen:getWidth(),
|
|
|
|
h = Screen:getHeight(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-06-10 07:57:10 +00:00
|
|
|
end
|
|
|
|
if Device:hasKeys() then
|
2014-03-13 13:52:43 +00:00
|
|
|
-- set up keyboard events
|
2014-06-05 06:58:53 +00:00
|
|
|
self.key_events.Close = { {"Back"}, doc = "close config menu" }
|
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
|
|
|
end
|
|
|
|
if Device:hasDPad() then
|
2018-03-22 20:01:38 +00:00
|
|
|
self.key_events.Select = { {"Press"}, doc = "select current menu item" }
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2013-01-14 16:33:03 +00:00
|
|
|
end
|
|
|
|
|
2013-01-15 09:24:38 +00:00
|
|
|
function ConfigDialog:updateConfigPanel(index)
|
2014-05-28 12:05:38 +00:00
|
|
|
|
2013-07-22 14:08:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ConfigDialog:update()
|
2018-03-22 20:01:38 +00:00
|
|
|
self.layout = {}
|
2017-09-11 18:54:27 +00:00
|
|
|
self.config_menubar = MenuBar:new{
|
|
|
|
config_dialog = self,
|
|
|
|
panel_index = self.panel_index,
|
|
|
|
}
|
2014-03-13 13:52:43 +00:00
|
|
|
self.config_panel = ConfigPanel:new{
|
|
|
|
index = self.panel_index,
|
|
|
|
config_dialog = self,
|
|
|
|
}
|
|
|
|
self.dialog_frame = FrameContainer:new{
|
2014-10-22 13:34:11 +00:00
|
|
|
background = Blitbuffer.COLOR_WHITE,
|
2014-03-13 13:52:43 +00:00
|
|
|
VerticalGroup:new{
|
|
|
|
self.config_panel,
|
|
|
|
self.config_menubar,
|
|
|
|
},
|
|
|
|
}
|
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
|
|
|
-- Reset the focusmanager cursor
|
2018-03-22 20:01:38 +00:00
|
|
|
self.selected.y=#self.layout
|
|
|
|
self.selected.x=self.panel_index
|
2014-03-13 13:52:43 +00:00
|
|
|
|
|
|
|
self[1] = BottomContainer:new{
|
|
|
|
dimen = Screen:getSize(),
|
|
|
|
self.dialog_frame,
|
|
|
|
}
|
2012-12-14 10:20:04 +00:00
|
|
|
end
|
|
|
|
|
2014-12-01 14:39:41 +00:00
|
|
|
function ConfigDialog:onCloseWidget()
|
2018-06-02 16:10:55 +00:00
|
|
|
-- NOTE: As much as we would like to flash here, don't, because of adverse interactions with touchmenu that might lead to a double flash...
|
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()
|
2014-12-01 14:39:41 +00:00
|
|
|
return "partial", self.dialog_frame.dimen
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2013-01-15 09:24:38 +00:00
|
|
|
function ConfigDialog:onShowConfigPanel(index)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.panel_index = index
|
2014-11-30 11:26:35 +00:00
|
|
|
local old_dimen = self.dialog_frame.dimen and self.dialog_frame.dimen:copy()
|
2019-10-15 19:57:51 +00:00
|
|
|
local old_layout_h = self.layout and #self.layout
|
2014-03-13 13:52:43 +00:00
|
|
|
self:update()
|
2018-06-02 16:10:55 +00:00
|
|
|
-- NOTE: Keep that one as UI to avoid delay when both this and the topmenu are shown.
|
|
|
|
-- Plus, this is also called for each tab anyway, so that wouldn't have been great.
|
2019-10-15 19:57:51 +00:00
|
|
|
-- NOTE: And we also only need to repaint what's behind us when switching to a smaller dialog...
|
|
|
|
-- This is trickier than in touchmenu, because dimen appear to fluctuate before/after painting...
|
|
|
|
-- So we've settled instead for the amount of lines in the panel, as line-height is constant.
|
2020-05-07 18:24:12 +00:00
|
|
|
-- NOTE: line/widget-height is actually not constant (e.g. the font size widget on the emulator),
|
|
|
|
-- so do it only when the new nb of widgets is strictly greater than the previous one.
|
|
|
|
local keep_bg = old_layout_h and #self.layout > old_layout_h
|
2019-10-15 19:57:51 +00:00
|
|
|
UIManager:setDirty((self.is_fresh or keep_bg) and self or "all", function()
|
2014-11-30 11:26:35 +00:00
|
|
|
local refresh_dimen =
|
|
|
|
old_dimen and old_dimen:combine(self.dialog_frame.dimen)
|
|
|
|
or self.dialog_frame.dimen
|
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
|
|
|
self.is_fresh = false
|
2015-04-26 18:07:17 +00:00
|
|
|
return "ui", refresh_dimen
|
2014-11-30 11:26:35 +00:00
|
|
|
end)
|
2014-03-13 13:52:43 +00:00
|
|
|
return true
|
2012-12-14 10:20:04 +00:00
|
|
|
end
|
|
|
|
|
2013-02-02 20:42:59 +00:00
|
|
|
function ConfigDialog:onConfigChoice(option_name, option_value)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.configurable[option_name] = option_value
|
|
|
|
self.ui:handleEvent(Event:new("StartActivityIndicator"))
|
|
|
|
return true
|
2013-02-02 20:42:59 +00:00
|
|
|
end
|
|
|
|
|
2019-05-05 08:15:13 +00:00
|
|
|
function ConfigDialog:onConfigEvent(option_event, option_arg, refresh_callback)
|
|
|
|
self.ui:handleEvent(Event:new(option_event, option_arg, refresh_callback))
|
2014-03-13 13:52:43 +00:00
|
|
|
return true
|
2014-01-03 14:09:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ConfigDialog:onConfigEvents(option_events, arg_index)
|
2014-03-13 13:52:43 +00:00
|
|
|
for i=1, #option_events do
|
|
|
|
option_events[i].args = option_events[i].args or {}
|
|
|
|
self.ui:handleEvent(Event:new(option_events[i].event, option_events[i].args[arg_index]))
|
|
|
|
end
|
|
|
|
return true
|
2014-01-03 14:09:55 +00:00
|
|
|
end
|
|
|
|
|
2019-05-05 08:15:13 +00:00
|
|
|
function ConfigDialog:onConfigChoose(values, name, event, args, events, position, delay_repaint)
|
2018-06-02 16:10:55 +00:00
|
|
|
UIManager:tickAfterNext(function()
|
2019-05-05 08:15:13 +00:00
|
|
|
-- Repainting may be delayed depending on options
|
|
|
|
local refresh_dialog_func = function()
|
|
|
|
self.skip_paint = nil
|
|
|
|
if self.config_options.needs_redraw_on_change then
|
|
|
|
-- Some Kopt document event handlers just save their setting,
|
|
|
|
-- and need a full repaint for kopt to load these settings,
|
|
|
|
-- notice the change, and redraw the document
|
|
|
|
UIManager:setDirty("all", "partial")
|
|
|
|
else
|
|
|
|
-- CreDocument event handlers do their own refresh:
|
|
|
|
-- we can just redraw our frame
|
|
|
|
UIManager:setDirty(self, function()
|
|
|
|
return "ui", self.dialog_frame.dimen
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local refresh_callback = nil
|
|
|
|
if type(delay_repaint) == "number" then -- timeout
|
|
|
|
UIManager:scheduleIn(delay_repaint, refresh_dialog_func)
|
|
|
|
self.skip_paint = true
|
|
|
|
elseif delay_repaint then -- anything but nil or false: provide a callback
|
|
|
|
-- This needs the config option to have an "event" key
|
|
|
|
-- The event handler is responsible for calling this callback when
|
|
|
|
-- it considers it appropriate
|
|
|
|
refresh_callback = refresh_dialog_func
|
|
|
|
self.skip_paint = true
|
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
if values then
|
|
|
|
self:onConfigChoice(name, values[position])
|
|
|
|
end
|
|
|
|
if event then
|
|
|
|
args = args or {}
|
2019-05-05 08:15:13 +00:00
|
|
|
self:onConfigEvent(event, args[position], refresh_callback)
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
|
|
|
if events then
|
|
|
|
self:onConfigEvents(events, position)
|
|
|
|
end
|
2019-03-14 21:23:17 +00:00
|
|
|
-- Even if each toggle refreshes itself when toggled, we still
|
|
|
|
-- need to update and repaint the whole config panel, as other
|
|
|
|
-- toggles may have their state (enabled/disabled) modified
|
|
|
|
-- after this toggle update.
|
2015-03-16 13:49:53 +00:00
|
|
|
self:update()
|
2019-05-05 08:15:13 +00:00
|
|
|
if not delay_repaint then -- immediate refresh
|
|
|
|
refresh_dialog_func()
|
2019-03-14 21:23:17 +00:00
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
end)
|
2013-02-02 20:42:59 +00:00
|
|
|
end
|
|
|
|
|
2019-05-01 00:09:01 +00:00
|
|
|
-- Tweaked variant used with the fine_tune variant of buttonprogress (direction can only be "-" or "+")
|
2019-05-05 08:15:13 +00:00
|
|
|
function ConfigDialog:onConfigFineTuneChoose(values, name, event, args, events, direction, delay_repaint)
|
2019-05-01 00:09:01 +00:00
|
|
|
UIManager:tickAfterNext(function()
|
2019-05-05 08:15:13 +00:00
|
|
|
-- Repainting may be delayed depending on options
|
|
|
|
local refresh_dialog_func = function()
|
|
|
|
self.skip_paint = nil
|
|
|
|
if self.config_options.needs_redraw_on_change then
|
|
|
|
-- Some Kopt document event handlers just save their setting,
|
|
|
|
-- and need a full repaint for kopt to load these settings,
|
|
|
|
-- notice the change, and redraw the document
|
|
|
|
UIManager:setDirty("all", "partial")
|
|
|
|
else
|
|
|
|
-- CreDocument event handlers do their own refresh:
|
|
|
|
-- we can just redraw our frame
|
|
|
|
UIManager:setDirty(self, function()
|
|
|
|
return "ui", self.dialog_frame.dimen
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local refresh_callback = nil
|
|
|
|
if type(delay_repaint) == "number" then -- timeout
|
|
|
|
UIManager:scheduleIn(delay_repaint, refresh_dialog_func)
|
|
|
|
self.skip_paint = true
|
|
|
|
elseif delay_repaint then -- anything but nil or false: provide a callback
|
|
|
|
-- This needs the config option to have an "event" key
|
|
|
|
-- The event handler is responsible for calling this callback when
|
|
|
|
-- it considers it appropriate
|
|
|
|
refresh_callback = refresh_dialog_func
|
|
|
|
self.skip_paint = true
|
|
|
|
end
|
2019-05-01 00:09:01 +00:00
|
|
|
if values then
|
|
|
|
local value
|
|
|
|
if direction == "-" then
|
|
|
|
value = self.configurable[name] or values[1]
|
2019-09-01 19:26:11 +00:00
|
|
|
if type(value) == "table" then
|
|
|
|
for i=1, #value do
|
|
|
|
value[i] = value[i] - 1
|
|
|
|
if value[i] < 0 then
|
|
|
|
value[i] = 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
value = value - 1
|
|
|
|
if value < 0 then
|
|
|
|
value = 0
|
|
|
|
end
|
2019-05-01 00:09:01 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
value = self.configurable[name] or values[#values]
|
2019-09-01 19:26:11 +00:00
|
|
|
if type(value) == "table" then
|
|
|
|
for i=1, #value do
|
|
|
|
value[i] = value[i] + 1
|
|
|
|
end
|
|
|
|
else
|
|
|
|
value = value + 1
|
|
|
|
end
|
2019-05-01 00:09:01 +00:00
|
|
|
end
|
|
|
|
self:onConfigChoice(name, value)
|
|
|
|
end
|
|
|
|
if event then
|
|
|
|
args = args or {}
|
|
|
|
local arg
|
|
|
|
if direction == "-" then
|
|
|
|
arg = self.configurable[name] or args[1]
|
|
|
|
if not values then
|
|
|
|
arg = arg - 1
|
|
|
|
if arg < 0 then
|
|
|
|
arg = 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
arg = self.configurable[name] or args[#args]
|
|
|
|
if not values then
|
|
|
|
arg = arg + 1
|
|
|
|
end
|
|
|
|
end
|
2019-05-05 08:15:13 +00:00
|
|
|
self:onConfigEvent(event, arg, refresh_callback)
|
2019-05-01 00:09:01 +00:00
|
|
|
end
|
|
|
|
if events then
|
|
|
|
self:onConfigEvents(events, direction)
|
|
|
|
end
|
|
|
|
-- Even if each toggle refreshes itself when toggled, we still
|
|
|
|
-- need to update and repaint the whole config panel, as other
|
|
|
|
-- toggles may have their state (enabled/disabled) modified
|
|
|
|
-- after this toggle update.
|
|
|
|
self:update()
|
2019-05-05 08:15:13 +00:00
|
|
|
if not delay_repaint then -- immediate refresh
|
|
|
|
refresh_dialog_func()
|
2019-05-01 00:09:01 +00:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2019-09-14 14:30:25 +00:00
|
|
|
-- Tweaked variant used with the more options variant of buttonprogress and fine tune with numpicker
|
|
|
|
-- events are not supported
|
|
|
|
function ConfigDialog:onConfigMoreChoose(values, name, event, args, name_text, delay_repaint, more_options_param)
|
|
|
|
if not more_options_param then
|
|
|
|
more_options_param = {}
|
|
|
|
end
|
|
|
|
UIManager:tickAfterNext(function()
|
|
|
|
-- Repainting may be delayed depending on options
|
|
|
|
local refresh_dialog_func = function()
|
|
|
|
self.skip_paint = nil
|
|
|
|
if self.config_options.needs_redraw_on_change then
|
|
|
|
-- Some Kopt document event handlers just save their setting,
|
|
|
|
-- and need a full repaint for kopt to load these settings,
|
|
|
|
-- notice the change, and redraw the document
|
|
|
|
UIManager:setDirty("all", "partial")
|
|
|
|
else
|
|
|
|
-- CreDocument event handlers do their own refresh:
|
|
|
|
-- we can just redraw our frame
|
|
|
|
UIManager:setDirty(self, function()
|
|
|
|
return "ui", self.dialog_frame.dimen
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local refresh_callback = nil
|
|
|
|
if type(delay_repaint) == "number" then -- timeout
|
|
|
|
UIManager:scheduleIn(delay_repaint, refresh_dialog_func)
|
|
|
|
self.skip_paint = true
|
|
|
|
elseif delay_repaint then -- anything but nil or false: provide a callback
|
|
|
|
-- This needs the config option to have an "event" key
|
|
|
|
-- The event handler is responsible for calling this callback when
|
|
|
|
-- it considers it appropriate
|
|
|
|
refresh_callback = refresh_dialog_func
|
|
|
|
self.skip_paint = true
|
|
|
|
end
|
|
|
|
if values and event then
|
2019-09-27 10:58:40 +00:00
|
|
|
if more_options_param.name then
|
|
|
|
name = more_options_param.name
|
|
|
|
end
|
|
|
|
if more_options_param.name_text then
|
|
|
|
name_text = more_options_param.name_text
|
|
|
|
end
|
|
|
|
if more_options_param.event then
|
|
|
|
event = more_options_param.event
|
|
|
|
end
|
2020-05-09 11:16:12 +00:00
|
|
|
local widget
|
|
|
|
if more_options_param.left_min then -- DoubleSpingWidget
|
|
|
|
local DoubleSpinWidget = require("ui/widget/doublespinwidget")
|
|
|
|
-- (No support for value_table - add it if needed)
|
|
|
|
local curr_values = self.configurable[name]
|
|
|
|
widget = DoubleSpinWidget:new{
|
2020-06-12 23:56:36 +00:00
|
|
|
width = math.floor(Screen:getWidth() * 0.6),
|
2020-05-09 11:16:12 +00:00
|
|
|
left_text = more_options_param.left_text,
|
|
|
|
right_text = more_options_param.right_text,
|
|
|
|
left_value = curr_values[1],
|
|
|
|
left_min = more_options_param.left_min,
|
|
|
|
left_max = more_options_param.left_max,
|
|
|
|
left_step = more_options_param.left_step,
|
|
|
|
left_hold_step = more_options_param.left_hold_step,
|
|
|
|
right_value = curr_values[2],
|
|
|
|
right_min = more_options_param.right_min,
|
|
|
|
right_max = more_options_param.right_max,
|
|
|
|
right_step = more_options_param.right_step,
|
|
|
|
right_hold_step = more_options_param.right_hold_step,
|
|
|
|
title_text = name_text or _("Set values"),
|
|
|
|
info_text = more_options_param.info_text,
|
|
|
|
keep_shown_on_apply = true,
|
|
|
|
callback = function(left_value, right_value)
|
|
|
|
if widget:hasMoved() and not self._dialog_closed then
|
|
|
|
-- If it has been moved, assume the user wants more
|
|
|
|
-- space and close bottom dialog
|
|
|
|
self._dialog_closed = true
|
|
|
|
self:closeDialog()
|
2019-09-23 22:24:45 +00:00
|
|
|
end
|
2020-05-09 11:16:12 +00:00
|
|
|
local value_tables = { left_value, right_value }
|
|
|
|
self:onConfigChoice(name, value_tables)
|
|
|
|
if event then
|
|
|
|
args = args or {}
|
|
|
|
self:onConfigEvent(event, value_tables, refresh_callback)
|
2019-09-14 14:30:25 +00:00
|
|
|
self:update()
|
2020-05-09 11:16:12 +00:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
extra_text = _("Set as default"),
|
|
|
|
extra_callback = function(left_value, right_value)
|
|
|
|
local value_tables = { left_value, right_value }
|
|
|
|
local values_string
|
|
|
|
if more_options_param.show_true_value_func then
|
|
|
|
values_string = more_options_param.show_true_value_func(value_tables)
|
2019-09-23 22:24:45 +00:00
|
|
|
else
|
2020-05-09 11:16:12 +00:00
|
|
|
values_string = T("%1, %2", left_value, right_value)
|
|
|
|
end
|
|
|
|
UIManager:show(ConfirmBox:new{
|
|
|
|
text = T(_("Set default %1 to %2?"), (name_text or ""), values_string),
|
|
|
|
ok_text = T(_("Set as default")),
|
|
|
|
ok_callback = function()
|
|
|
|
name = self.config_options.prefix.."_"..name
|
|
|
|
G_reader_settings:saveSetting(name, value_tables)
|
|
|
|
self:update()
|
|
|
|
UIManager:setDirty(self, function()
|
|
|
|
return "ui", self.dialog_frame.dimen
|
|
|
|
end)
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
else -- SpinWidget with single value
|
|
|
|
local SpinWidget = require("ui/widget/spinwidget")
|
|
|
|
local value_hold_step = 0
|
|
|
|
if more_options_param.value_hold_step then
|
|
|
|
value_hold_step = more_options_param.value_hold_step
|
|
|
|
elseif values and #values > 1 then
|
|
|
|
value_hold_step = values[2] - values[1]
|
|
|
|
end
|
|
|
|
local curr_items = self.configurable[name]
|
|
|
|
local value_index = nil
|
|
|
|
if more_options_param.value_table then
|
|
|
|
if more_options_param.args_table then
|
|
|
|
for k,v in pairs(more_options_param.args_table) do
|
|
|
|
if v == curr_items then
|
|
|
|
value_index = k
|
|
|
|
break
|
|
|
|
end
|
2019-09-23 22:24:45 +00:00
|
|
|
end
|
|
|
|
else
|
2020-05-09 11:16:12 +00:00
|
|
|
value_index = curr_items
|
2019-09-23 22:24:45 +00:00
|
|
|
end
|
2020-05-09 11:16:12 +00:00
|
|
|
end
|
|
|
|
widget = SpinWidget:new{
|
2020-06-12 23:56:36 +00:00
|
|
|
width = math.floor(Screen:getWidth() * 0.6),
|
2020-05-09 11:16:12 +00:00
|
|
|
value = curr_items,
|
|
|
|
value_index = value_index,
|
|
|
|
value_table = more_options_param.value_table,
|
|
|
|
value_min = more_options_param.value_min or values[1],
|
|
|
|
value_step = more_options_param.value_step or 1,
|
|
|
|
value_hold_step = value_hold_step,
|
|
|
|
value_max = more_options_param.value_max or values[#values],
|
|
|
|
precision = more_options_param.precision or "%02d",
|
|
|
|
keep_shown_on_apply = true,
|
|
|
|
extra_text = _("Set as default"),
|
|
|
|
extra_callback = function(spin)
|
|
|
|
local value_string
|
|
|
|
if more_options_param.show_true_value_func then
|
|
|
|
value_string = more_options_param.show_true_value_func(spin.value)
|
|
|
|
else
|
|
|
|
value_string = spin.value
|
|
|
|
end
|
|
|
|
UIManager:show(ConfirmBox:new{
|
|
|
|
text = T(_("Set default %1 to %2?"), (name_text or ""), value_string),
|
|
|
|
ok_text = T(_("Set as default")),
|
|
|
|
ok_callback = function()
|
|
|
|
name = self.config_options.prefix.."_"..name
|
|
|
|
if more_options_param.value_table then
|
|
|
|
if more_options_param.args_table then
|
|
|
|
G_reader_settings:saveSetting(name, more_options_param.args_table[spin.value_index])
|
|
|
|
else
|
|
|
|
G_reader_settings:saveSetting(name, spin.value_index)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
G_reader_settings:saveSetting(name, spin.value)
|
|
|
|
end
|
|
|
|
self:update()
|
|
|
|
UIManager:setDirty(self, function()
|
|
|
|
return "ui", self.dialog_frame.dimen
|
|
|
|
end)
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
end,
|
|
|
|
title_text = name_text or _("Set value"),
|
|
|
|
info_text = more_options_param.info_text,
|
|
|
|
callback = function(spin)
|
|
|
|
if widget:hasMoved() and not self._dialog_closed then
|
|
|
|
-- If it has been moved, assume the user wants more
|
|
|
|
-- space and close bottom dialog
|
|
|
|
self._dialog_closed = true
|
|
|
|
self:closeDialog()
|
|
|
|
end
|
2019-09-23 22:24:45 +00:00
|
|
|
if more_options_param.value_table then
|
|
|
|
if more_options_param.args_table then
|
2020-05-09 11:16:12 +00:00
|
|
|
self:onConfigChoice(name, more_options_param.args_table[spin.value_index])
|
2019-09-23 22:24:45 +00:00
|
|
|
else
|
2020-05-09 11:16:12 +00:00
|
|
|
self:onConfigChoice(name, spin.value_index)
|
2019-09-23 22:24:45 +00:00
|
|
|
end
|
|
|
|
else
|
2020-05-09 11:16:12 +00:00
|
|
|
self:onConfigChoice(name, spin.value)
|
|
|
|
end
|
|
|
|
if event then
|
|
|
|
args = args or {}
|
|
|
|
if more_options_param.value_table then
|
|
|
|
if more_options_param.args_table then
|
|
|
|
self:onConfigEvent(event, more_options_param.args_table[spin.value_index], refresh_callback)
|
|
|
|
else
|
|
|
|
self:onConfigEvent(event, spin.value_index, refresh_callback)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
self:onConfigEvent(event, spin.value, refresh_callback)
|
|
|
|
end
|
|
|
|
self:update()
|
2019-09-23 22:24:45 +00:00
|
|
|
end
|
2019-09-14 14:30:25 +00:00
|
|
|
end
|
2020-05-09 11:16:12 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
UIManager:show(widget)
|
2019-09-14 14:30:25 +00:00
|
|
|
end
|
|
|
|
if not delay_repaint then -- immediate refresh
|
|
|
|
refresh_dialog_func()
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2014-07-03 08:30:24 +00:00
|
|
|
function ConfigDialog:onMakeDefault(name, name_text, values, labels, position)
|
2019-03-01 11:55:55 +00:00
|
|
|
local display_value = labels[position]
|
2017-06-19 00:34:01 +00:00
|
|
|
if name == "font_fine_tune" then
|
|
|
|
return
|
2019-03-01 11:55:55 +00:00
|
|
|
-- known table value, make it pretty
|
2019-05-01 00:09:01 +00:00
|
|
|
elseif name == "h_page_margins" then
|
2019-08-22 15:11:47 +00:00
|
|
|
display_value = T(_([[
|
|
|
|
|
2019-05-01 00:09:01 +00:00
|
|
|
left: %1
|
|
|
|
right: %2
|
2019-03-01 11:55:55 +00:00
|
|
|
]]),
|
2019-05-01 00:09:01 +00:00
|
|
|
display_value[1], display_value[2])
|
2019-03-01 11:55:55 +00:00
|
|
|
end
|
|
|
|
-- generic fallback to support table values
|
|
|
|
if type(display_value) == "table" then
|
|
|
|
display_value = dump(display_value)
|
2017-06-19 00:34:01 +00:00
|
|
|
end
|
|
|
|
|
2014-07-03 08:30:24 +00:00
|
|
|
UIManager:show(ConfirmBox:new{
|
2014-11-28 13:10:37 +00:00
|
|
|
text = T(
|
|
|
|
_("Set default %1 to %2?"),
|
|
|
|
(name_text or ""),
|
2019-03-01 11:55:55 +00:00
|
|
|
display_value
|
2014-11-28 13:10:37 +00:00
|
|
|
),
|
2020-05-09 11:16:12 +00:00
|
|
|
ok_text = T(_("Set as default")),
|
2014-07-03 08:30:24 +00:00
|
|
|
ok_callback = function()
|
2016-02-16 02:08:04 +00:00
|
|
|
name = self.config_options.prefix.."_"..name
|
2014-07-03 08:30:24 +00:00
|
|
|
G_reader_settings:saveSetting(name, values[position])
|
2019-03-15 22:15:05 +00:00
|
|
|
self:update()
|
|
|
|
UIManager:setDirty(self, function()
|
|
|
|
return "ui", self.dialog_frame.dimen
|
|
|
|
end)
|
2014-07-03 08:30:24 +00:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2019-05-01 00:09:01 +00:00
|
|
|
-- Tweaked variant used with the fine_tune variant of buttonprogress (direction can only be "-" or "+")
|
|
|
|
-- NOTE: This sets the defaults to the *current* value, as the -/+ buttons have no fixed value ;).
|
|
|
|
function ConfigDialog:onMakeFineTuneDefault(name, name_text, values, labels, direction)
|
2019-09-03 11:41:15 +00:00
|
|
|
local current_value = self.configurable[name] or direction == "-" and labels[1] or labels[#labels]
|
|
|
|
|
|
|
|
local display_value
|
|
|
|
-- known table value, make it pretty
|
|
|
|
if name == "h_page_margins" then
|
|
|
|
display_value = T(_([[
|
|
|
|
|
|
|
|
left: %1
|
|
|
|
right: %2
|
|
|
|
]]),
|
|
|
|
current_value[1], current_value[2])
|
|
|
|
elseif type(current_value) == "table" then
|
|
|
|
display_value = dump(current_value)
|
|
|
|
else
|
|
|
|
display_value = current_value
|
|
|
|
end
|
2019-05-01 00:09:01 +00:00
|
|
|
|
|
|
|
UIManager:show(ConfirmBox:new{
|
|
|
|
text = T(
|
|
|
|
_("Set default %1 to %2?"),
|
|
|
|
(name_text or ""),
|
|
|
|
display_value
|
|
|
|
),
|
2020-05-09 11:16:12 +00:00
|
|
|
ok_text = T(_("Set as default")),
|
2019-05-01 00:09:01 +00:00
|
|
|
ok_callback = function()
|
|
|
|
name = self.config_options.prefix.."_"..name
|
2019-09-03 11:41:15 +00:00
|
|
|
G_reader_settings:saveSetting(name, current_value)
|
2019-05-01 00:09:01 +00:00
|
|
|
self:update()
|
|
|
|
UIManager:setDirty(self, function()
|
|
|
|
return "ui", self.dialog_frame.dimen
|
|
|
|
end)
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2013-02-02 20:42:59 +00:00
|
|
|
function ConfigDialog:closeDialog()
|
2014-03-13 13:52:43 +00:00
|
|
|
UIManager:close(self)
|
|
|
|
if self.close_callback then
|
|
|
|
self.close_callback()
|
|
|
|
end
|
|
|
|
return true
|
2012-12-14 10:20:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ConfigDialog:onTapCloseMenu(arg, ges_ev)
|
2014-03-13 13:52:43 +00:00
|
|
|
if ges_ev.pos:notIntersectWith(self.dialog_frame.dimen) then
|
|
|
|
self:closeDialog()
|
|
|
|
return true
|
|
|
|
end
|
2012-12-23 23:54:44 +00:00
|
|
|
end
|
2013-10-18 20:38:07 +00:00
|
|
|
|
2017-08-14 09:06:10 +00:00
|
|
|
function ConfigDialog:onSwipeCloseMenu(arg, ges_ev)
|
|
|
|
local range = {
|
|
|
|
x = DTAP_ZONE_CONFIG.x * Screen:getWidth(),
|
|
|
|
y = DTAP_ZONE_CONFIG.y * Screen:getHeight(),
|
|
|
|
w = DTAP_ZONE_CONFIG.w * Screen:getWidth(),
|
|
|
|
h = DTAP_ZONE_CONFIG.h * Screen:getHeight(),
|
|
|
|
}
|
|
|
|
if ges_ev.direction == "south" and (ges_ev.pos:intersectWith(self.dialog_frame.dimen)
|
|
|
|
or ges_ev.pos:intersectWith(range)) then
|
|
|
|
self:closeDialog()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-06-10 07:57:10 +00:00
|
|
|
function ConfigDialog:onClose()
|
|
|
|
self:closeDialog()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2018-03-22 20:01:38 +00:00
|
|
|
function ConfigDialog:onSelect()
|
|
|
|
self:getFocusItem():handleEvent(Event:new("TapSelect"))
|
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
|
|
|
return true
|
2018-03-22 20:01:38 +00:00
|
|
|
end
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
return ConfigDialog
|