ConfigDialog ButtonProgress: black border on default item (#4805)

Make the default (user set, or KOReader's default) item
among the button progress squares shown with a black border.
pull/4808/head
poire-z 5 years ago committed by GitHub
parent e357165f17
commit b16aa79636
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -19,6 +19,7 @@ local ButtonProgressWidget = InputContainer:new{
enabled = true,
num_buttons = 2,
position = 1,
default_position = nil,
thin_grey_style = false, -- default to black
}
@ -47,18 +48,24 @@ function ButtonProgressWidget:update()
local button_width = math.floor(self.width / self.num_buttons) - 2*button_padding - 2*button_margin - 2*button_bordersize
for i = 1, self.num_buttons do
local highlighted = i <= self.position
local is_default = i == self.default_position
local margin = button_margin
if self.thin_grey_style and highlighted then
margin = 0 -- moved outside button so it's not inverted
end
local extra_border_size = 0
if not self.thin_grey_style and is_default then
-- make the border a bit bigger on the default button
extra_border_size = Size.border.thin
end
local button = Button:new{
text = "",
radius = 0,
margin = margin,
padding = button_padding,
bordersize = button_bordersize,
bordersize = button_bordersize + extra_border_size,
enabled = true,
width = button_width,
width = button_width - 2*extra_border_size,
preselect = highlighted,
text_font_face = self.font_face,
text_font_size = self.font_size,
@ -73,7 +80,14 @@ function ButtonProgressWidget:update()
end,
}
if self.thin_grey_style then
button.frame.color = Blitbuffer.COLOR_DARK_GRAY -- no black border around gray squares
if is_default then
-- use a black border as a discreet visual hint
button.frame.color = Blitbuffer.COLOR_BLACK
else
-- otherwise, gray border, same as the filled
-- button, so looking as if no border
button.frame.color = Blitbuffer.COLOR_DARK_GRAY
end
if highlighted then
-- The button and its frame background will be inverted,
-- so invert the color we want so it gets inverted back
@ -94,8 +108,9 @@ function ButtonProgressWidget:update()
end)
end
function ButtonProgressWidget:setPosition(position)
function ButtonProgressWidget:setPosition(position, default_position)
self.position = position
self.default_position = default_position
self:update()
end

@ -302,8 +302,9 @@ function ConfigOption:init()
option_items_fixed = true
end
-- Find out currently selected item
-- Find out currently selected and default items indexes
local current_item = nil
local default_item = self.options[c].default_pos
local function value_diff(val1, val2, name)
if type(val1) ~= type(val2) then
logger.dbg("different data types in option")
@ -353,6 +354,34 @@ function ConfigOption:init()
end
end
end
local default_option_name = self.config.config_options.prefix.."_"..self.options[c].name
local default_value = G_reader_settings:readSetting(default_option_name)
if default_value then
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
end
-- Deal with the various kind of config widgets
@ -523,8 +552,7 @@ function ConfigOption:init()
show_parrent = self.config,
enabled = enabled,
}
local position = current_item
switch:setPosition(position)
switch:setPosition(current_item, default_item)
table.insert(option_items_group, switch)
end
@ -891,6 +919,10 @@ function ConfigDialog:onMakeDefault(name, name_text, values, labels, position)
ok_callback = function()
name = self.config_options.prefix.."_"..name
G_reader_settings:saveSetting(name, values[position])
self:update()
UIManager:setDirty(self, function()
return "ui", self.dialog_frame.dimen
end)
end,
})
end

Loading…
Cancel
Save