Merge pull request #714 from chrox/config_ui

some config UI changes
pull/2/merge
{Qingping,Dave} Hou 12 years ago
commit 55b2d4f993

@ -23,11 +23,10 @@ KoptOptions = {
icon = "resources/icons/appbar.transform.rotate.right.large.png", icon = "resources/icons/appbar.transform.rotate.right.large.png",
options = { options = {
{ {
name="screen_rotation", name="screen_mode",
name_text = "Screen Rotation", name_text = "Screen Mode",
item_text = {"portrait", "landscape"}, item_text = {"portrait", "landscape"},
values = {0, 90}, -- TODO: add screen mode changing command
default_value = 0,
} }
} }
}, },
@ -46,14 +45,6 @@ KoptOptions = {
{ {
icon = "resources/icons/appbar.column.two.large.png", icon = "resources/icons/appbar.column.two.large.png",
options = { options = {
{
name = "max_columns",
name_text = "Columns",
item_text = {"1","2","3","4"},
values = {1,2,3,4},
default_value = 2,
show = false
},
{ {
name = "page_margin", name = "page_margin",
name_text = "Page Margin", name_text = "Page Margin",
@ -118,11 +109,18 @@ KoptOptions = {
event = "RedrawCurrentPage", event = "RedrawCurrentPage",
}, },
{ {
name = "word_spacing", name = "max_columns",
name_text = "Word Gap", name_text = "Columns",
item_text = {"small", "medium", "large"}, item_text = {"1","2","3","4"},
values = {0.05, 0.15, 0.375}, values = {1,2,3,4},
default_value = 0.15, default_value = 2,
},
{
name="screen_rotation",
name_text = "Vertical Text",
item_text = {"true", "false"},
values = {90, 0},
default_value = 0,
}, },
{ {
name = "quality", name = "quality",
@ -130,7 +128,6 @@ KoptOptions = {
item_text = {"low", "default", "high"}, item_text = {"low", "default", "high"},
values={0.5, 0.8, 1.0}, values={0.5, 0.8, 1.0},
default_value = 0.8, default_value = 0.8,
show = false,
}, },
{ {
name = "auto_straighten", name = "auto_straighten",
@ -140,12 +137,11 @@ KoptOptions = {
default_value = 0, default_value = 0,
}, },
{ {
name = "detect_indent", name = "word_spacing",
name_text = "Indentation", name_text = "Word Gap",
item_text = {"enable","disable"}, item_text = {"small", "medium", "large"},
values = {1, 0}, values = {0.05, 0.15, 0.375},
default_value = 1, default_value = 0.15,
show = false,
}, },
{ {
name = "defect_size", name = "defect_size",
@ -153,6 +149,13 @@ KoptOptions = {
item_text = {"small","medium","large"}, item_text = {"small","medium","large"},
values = {0.5, 1.0, 2.0}, values = {0.5, 1.0, 2.0},
default_value = 1.0, default_value = 1.0,
},
{
name = "detect_indent",
name_text = "Indentation",
item_text = {"enable","disable"},
values = {1, 0},
default_value = 1,
show = false, show = false,
}, },
} }

@ -43,15 +43,17 @@ function MenuBarItem:init()
end end
function MenuBarItem:onTapSelect() function MenuBarItem:onTapSelect()
for _, item in pairs(self.items) do
item[1].invert = false
end
self[1].invert = true self[1].invert = true
self.config:onShowOptions(self.options) self.config:onShowConfigPanel(self.index)
UIManager.repaint_all = true UIManager:scheduleIn(0.5, function() self:invert(false) end)
return true return true
end end
function MenuBarItem:invert(invert)
self[1].invert = invert
UIManager:setDirty(self.config, "partial")
end
OptionTextItem = InputContainer:new{} OptionTextItem = InputContainer:new{}
function OptionTextItem:init() function OptionTextItem:init()
local text_widget = self[1] local text_widget = self[1]
@ -97,22 +99,15 @@ function OptionTextItem:onTapSelect()
return true return true
end end
ConfigIcons = HorizontalGroup:new{} ConfigOption = CenterContainer:new{}
function ConfigIcons:init()
for c = 1, #self.icons do
table.insert(self, self.spacing)
table.insert(self, self.icons[c])
end
table.insert(self, self.spacing)
end
ConfigOption = CenterContainer:new{dimen = Geom:new{ w = Screen:getWidth(), h = math.floor(150*Screen:getWidth()/600)}}
function ConfigOption:init() function ConfigOption:init()
local default_name_font_size = math.floor(20*Screen:getWidth()/600) local default_name_font_size = math.floor(20*Screen:getWidth()/600)
local default_item_font_size = math.floor(20*Screen:getWidth()/600) local default_item_font_size = math.floor(20*Screen:getWidth()/600)
local default_items_spacing = math.floor(30*Screen:getWidth()/600) local default_items_spacing = math.floor(30*Screen:getWidth()/600)
local default_option_height = math.floor(30*Screen:getWidth()/600) local default_option_height = math.floor(40*Screen:getWidth()/600)
local default_option_padding = math.floor(40*Screen:getWidth()/600)
local vertical_group = VerticalGroup:new{} local vertical_group = VerticalGroup:new{}
table.insert(vertical_group, VerticalSpan:new{ width = default_option_padding })
for c = 1, #self.options do for c = 1, #self.options do
if self.options[c].show ~= false then if self.options[c].show ~= false then
local name_align = self.options[c].name_align_right and self.options[c].name_align_right or 0.33 local name_align = self.options[c].name_align_right and self.options[c].name_align_right or 0.33
@ -228,23 +223,33 @@ function ConfigOption:init()
table.insert(vertical_group, horizontal_group) table.insert(vertical_group, horizontal_group)
end -- if end -- if
end -- for end -- for
table.insert(vertical_group, VerticalSpan:new{ width = default_option_padding })
self[1] = vertical_group self[1] = vertical_group
self.dimen = vertical_group:getSize()
end end
ConfigPanel = VerticalGroup:new{} ConfigPanel = FrameContainer:new{ background = 0, bordersize = 0, }
function ConfigPanel:init() function ConfigPanel:init()
local default_option = ConfigOption:new{ local config_options = self.config_dialog.config_options
options = self.config_options.default_options local default_option = config_options.default_options and config_options.default_options
} or config_options[1].options
local menu_bar = FrameContainer:new{ local panel = ConfigOption:new{
background = 0, options = self.index and config_options[self.index].options or default_option,
config = self.config_dialog,
} }
self.dimen = panel:getSize()
table.insert(self, panel)
end
MenuBar = FrameContainer:new{ background = 0, }
function MenuBar:init()
local config_options = self.config_dialog.config_options
local menu_items = {} local menu_items = {}
local icons_width = 0 local icons_width = 0
local icons_height = 0 local icons_height = 0
for c = 1, #self.config_options do for c = 1, #config_options do
local menu_icon = ImageWidget:new{ local menu_icon = ImageWidget:new{
file = self.config_options[c].icon file = config_options[c].icon
} }
local icon_dimen = menu_icon:getSize() local icon_dimen = menu_icon:getSize()
icons_width = icons_width + icon_dimen.w icons_width = icons_width + icon_dimen.w
@ -252,29 +257,46 @@ function ConfigPanel:init()
menu_items[c] = MenuBarItem:new{ menu_items[c] = MenuBarItem:new{
menu_icon, menu_icon,
options = ConfigOption:new{ index = c,
options = self.config_options[c].options,
config = self.config_dialog,
},
config = self.config_dialog, config = self.config_dialog,
items = menu_items,
} }
end end
menu_bar[1] = ConfigIcons:new{
icons = menu_items, local spacing = HorizontalSpan:new{
spacing = HorizontalSpan:new{ width = (Screen:getWidth() - icons_width) / (#menu_items+1)
width = (Screen:getWidth() - icons_width) / (#menu_items+1)
}
} }
menu_bar.dimen = Geom:new{ w = Screen:getWidth(), h = icons_height}
self[1] = default_option local menu_bar = HorizontalGroup:new{}
self[2] = menu_bar
for c = 1, #menu_items do
table.insert(menu_bar, spacing)
table.insert(menu_bar, menu_items[c])
end
table.insert(menu_bar, spacing)
self.dimen = Geom:new{ w = Screen:getWidth(), h = icons_height}
table.insert(self, menu_bar)
end end
--[[ --[[
Widget that displays config menu Widget that displays config menubar and config panel
+----------------+
| |
| |
| |
| |
| |
+----------------+
| |
| Config Panel |
| |
+----------------+
| Menu Bar |
+----------------+
--]] --]]
ConfigDialog = InputContainer:new{ ConfigDialog = InputContainer:new{
--is_borderless = false, --is_borderless = false,
} }
@ -283,28 +305,13 @@ function ConfigDialog:init()
------------------------------------------ ------------------------------------------
-- start to set up widget layout --------- -- start to set up widget layout ---------
------------------------------------------ ------------------------------------------
self.config_panel = ConfigPanel:new{ self.config_panel = ConfigPanel:new{
config_options = self.config_options,
config_dialog = self, config_dialog = self,
} }
self.config_menubar = MenuBar:new{
local config_panel_size = self.config_panel:getSize() config_dialog = self,
self.menu_dimen = Geom:new{
x = (Screen:getWidth() - config_panel_size.w)/2,
y = Screen:getHeight() - config_panel_size.h,
w = config_panel_size.w,
h = config_panel_size.h,
}
self[1] = BottomContainer:new{
dimen = Screen:getSize(),
FrameContainer:new{
dimen = self.config_panel:getSize(),
background = 0,
self.config_panel,
}
} }
self:makeDialog()
------------------------------------------ ------------------------------------------
-- start to set up input event callback -- -- start to set up input event callback --
------------------------------------------ ------------------------------------------
@ -327,11 +334,44 @@ function ConfigDialog:init()
end end
self.key_events.Select = { {"Press"}, doc = "select current menu item"} self.key_events.Select = { {"Press"}, doc = "select current menu item"}
UIManager.repaint_all = true UIManager:setDirty(self, "partial")
end
function ConfigDialog:updateConfigPanel(index)
self.config_panel = ConfigPanel:new{
index = index,
config_dialog = self,
}
end
function ConfigDialog:makeDialog()
local dialog = VerticalGroup:new{
self.config_panel,
self.config_menubar,
}
local dialog_size = dialog:getSize()
self[1] = BottomContainer:new{
dimen = Screen:getSize(),
FrameContainer:new{
dimen = dialog_size,
background = 0,
dialog,
}
}
self.dialog_dimen = Geom:new{
x = (Screen:getWidth() - dialog_size.w)/2,
y = Screen:getHeight() - dialog_size.h,
w = dialog_size.w,
h = dialog_size.h,
}
end end
function ConfigDialog:onShowOptions(options) function ConfigDialog:onShowConfigPanel(index)
self.config_panel[1] = options self:updateConfigPanel(index)
self:makeDialog()
UIManager.repaint_all = true UIManager.repaint_all = true
return true return true
end end
@ -345,9 +385,8 @@ function ConfigDialog:onCloseMenu()
end end
function ConfigDialog:onTapCloseMenu(arg, ges_ev) function ConfigDialog:onTapCloseMenu(arg, ges_ev)
if ges_ev.pos:notIntersectWith(self.menu_dimen) then if ges_ev.pos:notIntersectWith(self.dialog_dimen) then
self:onCloseMenu() self:onCloseMenu()
--self.ui:handleEvent(Event:new("GotoPageRel", 0))
return true return true
end end
end end

Loading…
Cancel
Save