From 0def54716218730c4a8dbdab4da088cd70afd9de Mon Sep 17 00:00:00 2001 From: Robert Date: Sat, 4 Nov 2017 15:31:41 +0100 Subject: [PATCH] More contrast settings (#3463) Close: #2133 More info: #2133 --- frontend/ui/data/koptoptions.lua | 10 +-- frontend/ui/widget/buttonprogresswidget.lua | 89 +++++++++++++++++++++ frontend/ui/widget/configdialog.lua | 31 ++++++- 3 files changed, 123 insertions(+), 7 deletions(-) create mode 100644 frontend/ui/widget/buttonprogresswidget.lua diff --git a/frontend/ui/data/koptoptions.lua b/frontend/ui/data/koptoptions.lua index 7a5eb762f..90ac4728f 100644 --- a/frontend/ui/data/koptoptions.lua +++ b/frontend/ui/data/koptoptions.lua @@ -147,14 +147,12 @@ local KoptOptions = { { name = "contrast", name_text = S.CONTRAST, - name_align_right = 0.25, - item_text = {S.LIGHTER, S.DEFAULT, S.DARKER, S.DARKEST}, - item_font_size = 18, - item_align_center = 0.7, - values = {1.5, 1.0, 0.5, 0.2}, + buttonprogress = true, + values = {1/0.8, 1/1.0, 1/1.5, 1/2.0, 1/3.0, 1/4.0, 1/6.0, 1/9.0}, + default_pos = 2, default_value = DKOPTREADER_CONFIG_CONTRAST, event = "GammaUpdate", - args = {0.8, 1.0, 2.0, 4.0}, + args = {0.8, 1.0, 1.5, 2.0, 3.0, 4.0, 6.0, 9.0}, } } }, diff --git a/frontend/ui/widget/buttonprogresswidget.lua b/frontend/ui/widget/buttonprogresswidget.lua new file mode 100644 index 000000000..d0ecf922a --- /dev/null +++ b/frontend/ui/widget/buttonprogresswidget.lua @@ -0,0 +1,89 @@ +local Blitbuffer = require("ffi/blitbuffer") +local Button = require("ui/widget/button") +local Device = require("device") +local Geom = require("ui/geometry") +local HorizontalGroup = require("ui/widget/horizontalgroup") +local InputContainer = require("ui/widget/container/inputcontainer") +local FrameContainer = require("ui/widget/container/framecontainer") +local Size = require("ui/size") +local UIManager = require("ui/uimanager") +local _ = require("gettext") +local Screen = Device.screen + +local ButtonProgressWidget = InputContainer:new{ + width = Screen:scaleBySize(216), + height = Size.item.height_default, + font_face = "cfont", + font_size = 16, + enabled = true, + num_buttons = 2, + position = 1, +} + +function ButtonProgressWidget:init() + self.buttonprogress_frame = FrameContainer:new{ + background = Blitbuffer.COLOR_WHITE, + color = Blitbuffer.COLOR_GREY, + radius = Size.radius.window, + bordersize = 0, + padding = Size.padding.small, + dim = not self.enabled, + width = self.width, + height = self.height, + } + + self.buttonprogress_content = HorizontalGroup:new{} + self:update() + self.buttonprogress_frame[1] = self.buttonprogress_content + self[1] = self.buttonprogress_frame + self.dimen = Geom:new(self.buttonprogress_frame:getSize()) +end + +function ButtonProgressWidget:update() + self.buttonprogress_content:clear() + local button_margin = Size.margin.tiny + local button_padding = Size.padding.button + local button_bordersize = Size.border.button + local preselect + 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 + if self.position >= i then + preselect = true + else + preselect = false + end + local button = Button:new{ + text = "", + radius = 0, + margin = button_margin, + padding = button_padding, + bordersize = button_bordersize, + enabled = true, + width = button_width, + preselect = preselect, + text_font_face = self.font_face, + text_font_size = self.font_size, + callback = function() + self.callback(i) + self.position = i + self:update() + end, + hold_callback = function() + self.hold_callback(i) + end, + } + table.insert(self.buttonprogress_content, button) + end + + UIManager:setDirty(self.show_parrent, function() + return "ui", self.dimen + end) +UIManager:setDirty("all") +end + +function ButtonProgressWidget:setPosition(position) + self.position = position + self:update() +end + +return ButtonProgressWidget diff --git a/frontend/ui/widget/configdialog.lua b/frontend/ui/widget/configdialog.lua index 79ecd804e..75d03b1d2 100644 --- a/frontend/ui/widget/configdialog.lua +++ b/frontend/ui/widget/configdialog.lua @@ -1,4 +1,5 @@ local Button = require("ui/widget/button") +local ButtonProgressWidget = require("ui/widget/buttonprogresswidget") local Blitbuffer = require("ffi/blitbuffer") local BottomContainer = require("ui/widget/container/bottomcontainer") local CenterContainer = require("ui/widget/container/centercontainer") @@ -398,7 +399,7 @@ function ConfigOption:init() end if self.options[c].toggle then - local max_toggle_width = Screen:getWidth() * item_align + local max_toggle_width = Screen:getWidth() * item_align * 0.95 local toggle_width = Screen:scaleBySize(self.options[c].width or max_toggle_width) local row_count = self.options[c].row_count or 1 local toggle_height = Screen:scaleBySize(self.options[c].height @@ -425,6 +426,34 @@ function ConfigOption:init() table.insert(option_items_group, switch) end + if self.options[c].buttonprogress then + local max_buttonprogress_width = Screen:getWidth() * item_align * 0.95 + local buttonprogress_width = Screen:scaleBySize(self.options[c].width or max_buttonprogress_width) + local switch = ButtonProgressWidget:new{ + width = math.min(max_buttonprogress_width, buttonprogress_width), + height = option_height, + font_face = item_font_face, + font_size = item_font_size, + num_buttons = #self.options[c].values, + position = self.options[c].default_pos, + callback = function(arg) + UIManager:nextTick(function() + self.config:onConfigChoice(self.options[c].name, self.options[c].values[arg]) + self.config:onConfigEvent(self.options[c].event, self.options[c].args[arg]) + UIManager:setDirty("all") + end) + end, + hold_callback = function(arg) + self.config:onMakeDefault(self.options[c].name, self.options[c].name_text, self.options[c].values, + self.options[c].args, arg) + end, + show_parrent = self.config, + enabled = enabled, + } + local position = current_item + switch:setPosition(position) + table.insert(option_items_group, switch) + end table.insert(option_items_container, option_items_group) table.insert(horizontal_group, option_items_container) table.insert(vertical_group, horizontal_group)