disable reflow options when reflow is not ON

This should also fix #1061.
pull/1455/head
chrox 9 years ago
parent dac9c85c3b
commit 72012e97e1

@ -1,8 +1,19 @@
local Screen = require("device").screen local Screen = require("device").screen
local S = require("ui/data/strings") local S = require("ui/data/strings")
local _ = require("gettext") 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 = { local KoptOptions = {
prefix = 'kopt', prefix = 'kopt',
{ {
@ -84,6 +95,9 @@ local KoptOptions = {
}, },
values = {1,2,3}, values = {1,2,3},
default_value = DKOPTREADER_CONFIG_MAX_COLUMNS, default_value = DKOPTREADER_CONFIG_MAX_COLUMNS,
enabled_func = function(configurable)
return enable_if_equals(configurable, "text_wrap", 1)
end,
}, },
{ {
name = "justification", name = "justification",
@ -98,6 +112,9 @@ local KoptOptions = {
values = {-1,0,1,2,3}, values = {-1,0,1,2,3},
default_value = DKOPTREADER_CONFIG_JUSTIFICATION, default_value = DKOPTREADER_CONFIG_JUSTIFICATION,
advanced = true, 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}, values = {0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.6, 2.0},
default_value = DKOPTREADER_CONFIG_FONT_SIZE, default_value = DKOPTREADER_CONFIG_FONT_SIZE,
event = "FontSizeUpdate", event = "FontSizeUpdate",
enabled_func = function(configurable)
return enable_if_equals(configurable, "text_wrap", 1)
end,
}, },
{ {
name = "font_fine_tune", name = "font_fine_tune",
@ -125,6 +145,9 @@ local KoptOptions = {
args = {-0.05, 0.05}, args = {-0.05, 0.05},
alternate = false, alternate = false,
height = 60, 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}, toggle = {S.SMALL, S.AUTO, S.LARGE},
values = DKOPTREADER_CONFIG_WORD_SPACINGS, values = DKOPTREADER_CONFIG_WORD_SPACINGS,
default_value = DKOPTREADER_CONFIG_DEFAULT_WORD_SPACING, default_value = DKOPTREADER_CONFIG_DEFAULT_WORD_SPACING,
enabled_func = function(configurable)
return enable_if_equals(configurable, "text_wrap", 1)
end,
}, },
{ {
name = "writing_direction", name = "writing_direction",
@ -195,6 +221,9 @@ local KoptOptions = {
toggle = {S.LTR, S.RTL, S.TBRTL}, toggle = {S.LTR, S.RTL, S.TBRTL},
values = {0, 1, 2}, values = {0, 1, 2},
default_value = 0, default_value = 0,
enabled_func = function(configurable)
return enable_if_equals(configurable, "text_wrap", 1)
end,
}, },
{ {
name = "quality", name = "quality",
@ -203,6 +232,9 @@ local KoptOptions = {
values={0.5, 1.0, 1.5}, values={0.5, 1.0, 1.5},
default_value = DKOPTREADER_CONFIG_RENDER_QUALITY, default_value = DKOPTREADER_CONFIG_RENDER_QUALITY,
advanced = true, advanced = true,
enabled_func = function(configurable)
return enable_if_equals(configurable, "text_wrap", 1)
end,
}, },
{ {
name = "forced_ocr", name = "forced_ocr",
@ -220,6 +252,9 @@ local KoptOptions = {
default_value = DKOPTREADER_CONFIG_DEFECT_SIZE, default_value = DKOPTREADER_CONFIG_DEFECT_SIZE,
event = "DefectSizeUpdate", event = "DefectSizeUpdate",
show = false, show = false,
enabled_func = function(configurable)
return enable_if_equals(configurable, "text_wrap", 1)
end,
}, },
{ {
name = "auto_straighten", name = "auto_straighten",
@ -228,6 +263,9 @@ local KoptOptions = {
values = {0, 5, 10}, values = {0, 5, 10},
default_value = DKOPTREADER_CONFIG_AUTO_STRAIGHTEN, default_value = DKOPTREADER_CONFIG_AUTO_STRAIGHTEN,
show = false, show = false,
enabled_func = function(configurable)
return enable_if_equals(configurable, "text_wrap", 1)
end,
}, },
{ {
name = "detect_indent", name = "detect_indent",
@ -236,6 +274,9 @@ local KoptOptions = {
values = {1, 0}, values = {1, 0},
default_value = DKOPTREADER_CONFIG_DETECT_INDENT, default_value = DKOPTREADER_CONFIG_DETECT_INDENT,
show = false, show = false,
enabled_func = function(configurable)
return enable_if_equals(configurable, "text_wrap", 1)
end,
}, },
} }
}, },

@ -63,6 +63,7 @@ function OptionTextItem:init()
end end
function OptionTextItem:onTapSelect() function OptionTextItem:onTapSelect()
if not self.enabled then return true end
for _, item in pairs(self.items) do for _, item in pairs(self.items) do
item[1].color = Blitbuffer.COLOR_WHITE item[1].color = Blitbuffer.COLOR_WHITE
end end
@ -115,6 +116,7 @@ function OptionIconItem:init()
end end
function OptionIconItem:onTapSelect() function OptionIconItem:onTapSelect()
if not self.enabled then return true end
for _, item in pairs(self.items) do for _, item in pairs(self.items) do
--item[1][1].invert = false --item[1][1].invert = false
item[1].color = Blitbuffer.COLOR_WHITE item[1].color = Blitbuffer.COLOR_WHITE
@ -177,6 +179,10 @@ function ConfigOption:init()
local items_spacing = HorizontalSpan:new{ local items_spacing = HorizontalSpan:new{
width = Screen:scaleBySize(item_spacing_with) 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{} local horizontal_group = HorizontalGroup:new{}
if self.options[c].name_text then if self.options[c].name_text then
local option_name_container = RightContainer:new{ local option_name_container = RightContainer:new{
@ -185,27 +191,12 @@ function ConfigOption:init()
local option_name = TextWidget:new{ local option_name = TextWidget:new{
text = self.options[c].name_text, text = self.options[c].name_text,
face = Font:getFace(name_font_face, name_font_size), 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(option_name_container, option_name)
table.insert(horizontal_group, option_name_container) table.insert(horizontal_group, option_name_container)
end 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{ local option_items_container = CenterContainer:new{
dimen = Geom:new{w = Screen:getWidth()*item_align, h = option_height} dimen = Geom:new{w = Screen:getWidth()*item_align, h = option_height}
} }
@ -292,18 +283,22 @@ function ConfigOption:init()
FixedTextWidget:new{ FixedTextWidget:new{
text = self.options[c].item_text[d], text = self.options[c].item_text[d],
face = Font:getFace(item_font_face, item_font_size[d]), face = Font:getFace(item_font_face, item_font_size[d]),
fgcolor = Blitbuffer.gray(enabled and 1.0 or 0.5),
}, },
padding = 3, 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 else
option_item = OptionTextItem:new{ option_item = OptionTextItem:new{
TextWidget:new{ TextWidget:new{
text = self.options[c].item_text[d], text = self.options[c].item_text[d],
face = Font:getFace(item_font_face, item_font_size), face = Font:getFace(item_font_face, item_font_size),
fgcolor = Blitbuffer.gray(enabled and 1.0 or 0.5),
}, },
padding = -3, 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 end
option_items[d] = option_item option_items[d] = option_item
@ -338,10 +333,12 @@ function ConfigOption:init()
for d = 1, #self.options[c].item_icons do for d = 1, #self.options[c].item_icons do
local option_item = OptionIconItem:new{ local option_item = OptionIconItem:new{
icon = ImageWidget:new{ icon = ImageWidget:new{
file = self.options[c].item_icons[d] file = self.options[c].item_icons[d],
dim = not enabled,
}, },
padding = -2, 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_items[d] = option_item
option_item.items = option_items option_item.items = option_items
@ -375,6 +372,7 @@ function ConfigOption:init()
event = self.options[c].event, event = self.options[c].event,
events = self.options[c].events, events = self.options[c].events,
config = self.config, config = self.config,
enabled = enabled,
} }
local position = current_item local position = current_item
switch:setPosition(position) switch:setPosition(position)
@ -573,6 +571,7 @@ function ConfigDialog:onConfigChoose(values, name, event, args, events, position
if events then if events then
self:onConfigEvents(events, position) self:onConfigEvents(events, position)
end end
self:update()
UIManager:setDirty("all") UIManager:setDirty("all")
end) end)
end end

@ -57,6 +57,11 @@ function FrameContainer:paintTo(bb, x, y)
container_width - 2*self.bordersize, container_width - 2*self.bordersize,
container_height - 2*self.bordersize) container_height - 2*self.bordersize)
end 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 end
return FrameContainer return FrameContainer

@ -31,6 +31,7 @@ local ToggleSwitch = InputContainer:new{
fgcolor = Blitbuffer.gray(0.5), -- focused item color fgcolor = Blitbuffer.gray(0.5), -- focused item color
font_face = "cfont", font_face = "cfont",
font_size = 16, font_size = 16,
enabled = true,
} }
function ToggleSwitch:init() function ToggleSwitch:init()
@ -43,6 +44,7 @@ function ToggleSwitch:init()
radius = 7, radius = 7,
bordersize = 1, bordersize = 1,
padding = 2, padding = 2,
dim = not self.enabled,
} }
self.toggle_content = HorizontalGroup:new{} self.toggle_content = HorizontalGroup:new{}
@ -124,6 +126,7 @@ function ToggleSwitch:togglePosition(position)
end end
function ToggleSwitch:onTapSelect(arg, gev) function ToggleSwitch:onTapSelect(arg, gev)
if not self.enabled then return true end
local position = math.ceil( local position = math.ceil(
(gev.pos.x - self.dimen.x) / self.dimen.w * self.n_pos (gev.pos.x - self.dimen.x) / self.dimen.w * self.n_pos
) )

Loading…
Cancel
Save