From 72012e97e144d30d8036e560a49199d7c082045e Mon Sep 17 00:00:00 2001 From: chrox Date: Mon, 16 Mar 2015 21:49:53 +0800 Subject: [PATCH] disable reflow options when reflow is not ON This should also fix #1061. --- frontend/ui/data/koptoptions.lua | 43 ++++++++++++++++++- frontend/ui/widget/configdialog.lua | 39 ++++++++--------- .../ui/widget/container/framecontainer.lua | 5 +++ frontend/ui/widget/toggleswitch.lua | 3 ++ 4 files changed, 69 insertions(+), 21 deletions(-) diff --git a/frontend/ui/data/koptoptions.lua b/frontend/ui/data/koptoptions.lua index 244de6c23..8e8cc4833 100644 --- a/frontend/ui/data/koptoptions.lua +++ b/frontend/ui/data/koptoptions.lua @@ -1,8 +1,19 @@ local Screen = require("device").screen local S = require("ui/data/strings") - local _ = require("gettext") +local function enable_if_equals(configurable, option, value) + return configurable[option] == value +end + +local function enable_if_greater_than(configurable, option, value) + return configurable[option] > value +end + +local function enable_if_less_than(configurable, option, value) + return configurable[option] < value +end + local KoptOptions = { prefix = 'kopt', { @@ -84,6 +95,9 @@ local KoptOptions = { }, values = {1,2,3}, default_value = DKOPTREADER_CONFIG_MAX_COLUMNS, + enabled_func = function(configurable) + return enable_if_equals(configurable, "text_wrap", 1) + end, }, { name = "justification", @@ -98,6 +112,9 @@ local KoptOptions = { values = {-1,0,1,2,3}, default_value = DKOPTREADER_CONFIG_JUSTIFICATION, advanced = true, + enabled_func = function(configurable) + return enable_if_equals(configurable, "text_wrap", 1) + end, }, } }, @@ -114,6 +131,9 @@ local KoptOptions = { values = {0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.6, 2.0}, default_value = DKOPTREADER_CONFIG_FONT_SIZE, event = "FontSizeUpdate", + enabled_func = function(configurable) + return enable_if_equals(configurable, "text_wrap", 1) + end, }, { name = "font_fine_tune", @@ -125,6 +145,9 @@ local KoptOptions = { args = {-0.05, 0.05}, alternate = false, height = 60, + enabled_func = function(configurable) + return enable_if_equals(configurable, "text_wrap", 1) + end, } } }, @@ -188,6 +211,9 @@ local KoptOptions = { toggle = {S.SMALL, S.AUTO, S.LARGE}, values = DKOPTREADER_CONFIG_WORD_SPACINGS, default_value = DKOPTREADER_CONFIG_DEFAULT_WORD_SPACING, + enabled_func = function(configurable) + return enable_if_equals(configurable, "text_wrap", 1) + end, }, { name = "writing_direction", @@ -195,6 +221,9 @@ local KoptOptions = { toggle = {S.LTR, S.RTL, S.TBRTL}, values = {0, 1, 2}, default_value = 0, + enabled_func = function(configurable) + return enable_if_equals(configurable, "text_wrap", 1) + end, }, { name = "quality", @@ -203,6 +232,9 @@ local KoptOptions = { values={0.5, 1.0, 1.5}, default_value = DKOPTREADER_CONFIG_RENDER_QUALITY, advanced = true, + enabled_func = function(configurable) + return enable_if_equals(configurable, "text_wrap", 1) + end, }, { name = "forced_ocr", @@ -220,6 +252,9 @@ local KoptOptions = { default_value = DKOPTREADER_CONFIG_DEFECT_SIZE, event = "DefectSizeUpdate", show = false, + enabled_func = function(configurable) + return enable_if_equals(configurable, "text_wrap", 1) + end, }, { name = "auto_straighten", @@ -228,6 +263,9 @@ local KoptOptions = { values = {0, 5, 10}, default_value = DKOPTREADER_CONFIG_AUTO_STRAIGHTEN, show = false, + enabled_func = function(configurable) + return enable_if_equals(configurable, "text_wrap", 1) + end, }, { name = "detect_indent", @@ -236,6 +274,9 @@ local KoptOptions = { values = {1, 0}, default_value = DKOPTREADER_CONFIG_DETECT_INDENT, show = false, + enabled_func = function(configurable) + return enable_if_equals(configurable, "text_wrap", 1) + end, }, } }, diff --git a/frontend/ui/widget/configdialog.lua b/frontend/ui/widget/configdialog.lua index 63f0aeb9d..3e25ab680 100644 --- a/frontend/ui/widget/configdialog.lua +++ b/frontend/ui/widget/configdialog.lua @@ -63,6 +63,7 @@ function OptionTextItem:init() end function OptionTextItem:onTapSelect() + if not self.enabled then return true end for _, item in pairs(self.items) do item[1].color = Blitbuffer.COLOR_WHITE end @@ -115,6 +116,7 @@ function OptionIconItem:init() end function OptionIconItem:onTapSelect() + if not self.enabled then return true end for _, item in pairs(self.items) do --item[1][1].invert = false item[1].color = Blitbuffer.COLOR_WHITE @@ -177,6 +179,10 @@ function ConfigOption:init() local items_spacing = HorizontalSpan:new{ width = Screen:scaleBySize(item_spacing_with) } + local enabled = true + if self.options[c].enabled_func then + enabled = self.options[c].enabled_func(self.config.configurable) + end local horizontal_group = HorizontalGroup:new{} if self.options[c].name_text then local option_name_container = RightContainer:new{ @@ -185,27 +191,12 @@ function ConfigOption:init() local option_name = TextWidget:new{ text = self.options[c].name_text, face = Font:getFace(name_font_face, name_font_size), + fgcolor = Blitbuffer.gray(enabled and 1.0 or 0.5), } table.insert(option_name_container, option_name) table.insert(horizontal_group, option_name_container) end - if self.options[c].widget == "ProgressWidget" then - local widget_container = CenterContainer:new{ - dimen = Geom:new{ - w = Screen:getWidth()*self.options[c].widget_align_center, - h = option_height - } - } - local widget = ProgressWidget:new{ - width = self.options[c].width, - height = self.options[c].height, - percentage = self.options[c].percentage, - } - table.insert(widget_container, widget) - table.insert(horizontal_group, widget_container) - end - local option_items_container = CenterContainer:new{ dimen = Geom:new{w = Screen:getWidth()*item_align, h = option_height} } @@ -292,18 +283,22 @@ function ConfigOption:init() FixedTextWidget:new{ text = self.options[c].item_text[d], face = Font:getFace(item_font_face, item_font_size[d]), + fgcolor = Blitbuffer.gray(enabled and 1.0 or 0.5), }, padding = 3, - color = d == current_item and Blitbuffer.COLOR_BLACK or Blitbuffer.COLOR_WHITE, + color = d == current_item and Blitbuffer.gray(enabled and 1.0 or 0.5) or Blitbuffer.COLOR_WHITE, + enabled = enabled, } else option_item = OptionTextItem:new{ TextWidget:new{ text = self.options[c].item_text[d], face = Font:getFace(item_font_face, item_font_size), + fgcolor = Blitbuffer.gray(enabled and 1.0 or 0.5), }, padding = -3, - color = d == current_item and Blitbuffer.COLOR_BLACK or Blitbuffer.COLOR_WHITE, + color = d == current_item and Blitbuffer.gray(enabled and 1.0 or 0.5) or Blitbuffer.COLOR_WHITE, + enabled = enabled, } end option_items[d] = option_item @@ -338,10 +333,12 @@ function ConfigOption:init() for d = 1, #self.options[c].item_icons do local option_item = OptionIconItem:new{ icon = ImageWidget:new{ - file = self.options[c].item_icons[d] + file = self.options[c].item_icons[d], + dim = not enabled, }, padding = -2, - color = d == current_item and Blitbuffer.COLOR_BLACK or Blitbuffer.COLOR_WHITE, + color = d == current_item and Blitbuffer.gray(enabled and 1.0 or 0.5) or Blitbuffer.COLOR_WHITE, + enabled = enabled, } option_items[d] = option_item option_item.items = option_items @@ -375,6 +372,7 @@ function ConfigOption:init() event = self.options[c].event, events = self.options[c].events, config = self.config, + enabled = enabled, } local position = current_item switch:setPosition(position) @@ -573,6 +571,7 @@ function ConfigDialog:onConfigChoose(values, name, event, args, events, position if events then self:onConfigEvents(events, position) end + self:update() UIManager:setDirty("all") end) end diff --git a/frontend/ui/widget/container/framecontainer.lua b/frontend/ui/widget/container/framecontainer.lua index 6d8bae051..25765f873 100644 --- a/frontend/ui/widget/container/framecontainer.lua +++ b/frontend/ui/widget/container/framecontainer.lua @@ -57,6 +57,11 @@ function FrameContainer:paintTo(bb, x, y) container_width - 2*self.bordersize, container_height - 2*self.bordersize) end + if self.dim then + bb:dimRect(x + self.bordersize, y + self.bordersize, + container_width - 2*self.bordersize, + container_height - 2*self.bordersize) + end end return FrameContainer diff --git a/frontend/ui/widget/toggleswitch.lua b/frontend/ui/widget/toggleswitch.lua index b63a74702..675ebf49c 100644 --- a/frontend/ui/widget/toggleswitch.lua +++ b/frontend/ui/widget/toggleswitch.lua @@ -31,6 +31,7 @@ local ToggleSwitch = InputContainer:new{ fgcolor = Blitbuffer.gray(0.5), -- focused item color font_face = "cfont", font_size = 16, + enabled = true, } function ToggleSwitch:init() @@ -43,6 +44,7 @@ function ToggleSwitch:init() radius = 7, bordersize = 1, padding = 2, + dim = not self.enabled, } self.toggle_content = HorizontalGroup:new{} @@ -124,6 +126,7 @@ function ToggleSwitch:togglePosition(position) end function ToggleSwitch:onTapSelect(arg, gev) + if not self.enabled then return true end local position = math.ceil( (gev.pos.x - self.dimen.x) / self.dimen.w * self.n_pos )