From fe8902d3805c6862fa998fbbe96150030400b9ad Mon Sep 17 00:00:00 2001 From: chrox Date: Tue, 15 Jan 2013 00:33:03 +0800 Subject: [PATCH 1/5] make the dimension of config dialog change according to the size of current config options I can't find a way to resize a WidgetContainer in runtime so when switching config options new ConfigDialog is created with requested option panel. --- frontend/ui/config.lua | 110 +++++++++++++++++++++++------------------ 1 file changed, 62 insertions(+), 48 deletions(-) diff --git a/frontend/ui/config.lua b/frontend/ui/config.lua index 2446ac0e8..6a4fa026f 100644 --- a/frontend/ui/config.lua +++ b/frontend/ui/config.lua @@ -43,12 +43,7 @@ function MenuBarItem:init() end function MenuBarItem:onTapSelect() - for _, item in pairs(self.items) do - item[1].invert = false - end - self[1].invert = true - self.config:onShowOptions(self.options) - UIManager.repaint_all = true + self.config:onShowOptions(self.options, self.index) return true end @@ -93,12 +88,12 @@ function OptionTextItem:onTapSelect() option_arg = self.args[self.current_item] self.config:onConfigChoice(self.name, option_arg, self.event) end - UIManager.repaint_all = true + UIManager:setDirty(self, "partial") return true end -ConfigIcons = HorizontalGroup:new{} -function ConfigIcons:init() +MenuBar = HorizontalGroup:new{} +function MenuBar:init() for c = 1, #self.icons do table.insert(self, self.spacing) table.insert(self, self.icons[c]) @@ -106,13 +101,19 @@ function ConfigIcons:init() table.insert(self, self.spacing) end -ConfigOption = CenterContainer:new{dimen = Geom:new{ w = Screen:getWidth(), h = math.floor(150*Screen:getWidth()/600)}} +function MenuBar:invert(index) + self.icons[index][1].invert = true +end + +ConfigOption = CenterContainer:new{} function ConfigOption:init() local default_name_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_option_height = math.floor(30*Screen:getWidth()/600) + local default_option_height = math.floor(40*Screen:getWidth()/600) + local default_option_padding = math.floor(50*Screen:getWidth()/600) local vertical_group = VerticalGroup:new{} + table.insert(vertical_group, VerticalSpan:new{ width = default_option_padding }) for c = 1, #self.options do 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 @@ -228,7 +229,9 @@ function ConfigOption:init() table.insert(vertical_group, horizontal_group) end -- if end -- for + table.insert(vertical_group, VerticalSpan:new{ width = default_option_padding }) self[1] = vertical_group + self.dimen = vertical_group:getSize() end ConfigPanel = VerticalGroup:new{} @@ -236,9 +239,6 @@ function ConfigPanel:init() local default_option = ConfigOption:new{ options = self.config_options.default_options } - local menu_bar = FrameContainer:new{ - background = 0, - } local menu_items = {} local icons_width = 0 local icons_height = 0 @@ -252,26 +252,32 @@ function ConfigPanel:init() menu_items[c] = MenuBarItem:new{ menu_icon, + index = c, options = ConfigOption:new{ options = self.config_options[c].options, config = self.config_dialog, }, config = self.config_dialog, - items = menu_items, } end - menu_bar[1] = ConfigIcons:new{ - icons = menu_items, - spacing = HorizontalSpan:new{ - width = (Screen:getWidth() - icons_width) / (#menu_items+1) + local menu_bar = FrameContainer:new{ + background = 0, + dimen = Geom:new{ w = Screen:getWidth(), h = icons_height}, + MenuBar:new{ + icons = menu_items, + spacing = HorizontalSpan:new{ + width = (Screen:getWidth() - icons_width) / (#menu_items+1) + } } - } - menu_bar.dimen = Geom:new{ w = Screen:getWidth(), h = icons_height} - + } self[1] = default_option self[2] = menu_bar end +function ConfigPanel:getMenuBar() + return self[2][1] +end + --[[ Widget that displays config menu --]] @@ -283,28 +289,7 @@ function ConfigDialog:init() ------------------------------------------ -- start to set up widget layout --------- ------------------------------------------ - self.config_panel = ConfigPanel:new{ - config_options = self.config_options, - config_dialog = self, - } - - local config_panel_size = self.config_panel:getSize() - - 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:updateDialog() ------------------------------------------ -- start to set up input event callback -- ------------------------------------------ @@ -327,11 +312,41 @@ function ConfigDialog:init() end self.key_events.Select = { {"Press"}, doc = "select current menu item"} - UIManager.repaint_all = true + UIManager:setDirty(self, "partial") +end + +function ConfigDialog:updateDialog(panel_options) + self.config_panel = ConfigPanel:new{ + config_options = self.config_options, + config_dialog = self, + } + + if panel_options then + self.config_panel[1] = panel_options + end + + local config_panel_size = self.config_panel:getSize() + + 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, + } + } end -function ConfigDialog:onShowOptions(options) - self.config_panel[1] = options +function ConfigDialog:onShowOptions(options, index) + self:updateDialog(options) + self.config_panel:getMenuBar():invert(index) UIManager.repaint_all = true return true end @@ -347,7 +362,6 @@ end function ConfigDialog:onTapCloseMenu(arg, ges_ev) if ges_ev.pos:notIntersectWith(self.menu_dimen) then self:onCloseMenu() - --self.ui:handleEvent(Event:new("GotoPageRel", 0)) return true end end From 3f2e810fe48d7035691007769be990863dc12a75 Mon Sep 17 00:00:00 2001 From: chrox Date: Tue, 15 Jan 2013 12:35:37 +0800 Subject: [PATCH 2/5] force repaint all when changing options --- frontend/ui/config.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/ui/config.lua b/frontend/ui/config.lua index 6a4fa026f..c4ebe8cc3 100644 --- a/frontend/ui/config.lua +++ b/frontend/ui/config.lua @@ -88,7 +88,7 @@ function OptionTextItem:onTapSelect() option_arg = self.args[self.current_item] self.config:onConfigChoice(self.name, option_arg, self.event) end - UIManager:setDirty(self, "partial") + UIManager.repaint_all = true return true end From 62c3e1dfec3cf01854fcafe534710bca856ca462 Mon Sep 17 00:00:00 2001 From: chrox Date: Tue, 15 Jan 2013 17:24:38 +0800 Subject: [PATCH 3/5] invert icon color temporarily when tapping on menubar --- frontend/ui/config.lua | 149 ++++++++++++++++++++++++----------------- 1 file changed, 87 insertions(+), 62 deletions(-) diff --git a/frontend/ui/config.lua b/frontend/ui/config.lua index c4ebe8cc3..589963e12 100644 --- a/frontend/ui/config.lua +++ b/frontend/ui/config.lua @@ -43,10 +43,17 @@ function MenuBarItem:init() end function MenuBarItem:onTapSelect() - self.config:onShowOptions(self.options, self.index) + self[1].invert = true + self.config:onShowConfigPanel(self.index) + UIManager:scheduleIn(1.0, function() self:invert(false) end) return true end +function MenuBarItem:invert(invert) + self[1].invert = invert + UIManager:setDirty(self.config, "partial") +end + OptionTextItem = InputContainer:new{} function OptionTextItem:init() local text_widget = self[1] @@ -92,19 +99,6 @@ function OptionTextItem:onTapSelect() return true end -MenuBar = HorizontalGroup:new{} -function MenuBar: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 - -function MenuBar:invert(index) - self.icons[index][1].invert = true -end - ConfigOption = CenterContainer:new{} function ConfigOption:init() local default_name_font_size = math.floor(20*Screen:getWidth()/600) @@ -234,17 +228,28 @@ function ConfigOption:init() self.dimen = vertical_group:getSize() end -ConfigPanel = VerticalGroup:new{} +ConfigPanel = FrameContainer:new{ background = 0, bordersize = 0, } function ConfigPanel:init() - local default_option = ConfigOption:new{ - options = self.config_options.default_options + local config_options = self.config_dialog.config_options + local default_option = config_options.default_options and config_options.default_options + or config_options[1].options + local panel = ConfigOption:new{ + 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 icons_width = 0 local icons_height = 0 - for c = 1, #self.config_options do + for c = 1, #config_options do local menu_icon = ImageWidget:new{ - file = self.config_options[c].icon + file = config_options[c].icon } local icon_dimen = menu_icon:getSize() icons_width = icons_width + icon_dimen.w @@ -253,34 +258,45 @@ function ConfigPanel:init() menu_items[c] = MenuBarItem:new{ menu_icon, index = c, - options = ConfigOption:new{ - options = self.config_options[c].options, - config = self.config_dialog, - }, config = self.config_dialog, } end - local menu_bar = FrameContainer:new{ - background = 0, - dimen = Geom:new{ w = Screen:getWidth(), h = icons_height}, - MenuBar:new{ - icons = menu_items, - spacing = HorizontalSpan:new{ - width = (Screen:getWidth() - icons_width) / (#menu_items+1) - } - } - } - self[1] = default_option - self[2] = menu_bar -end - -function ConfigPanel:getMenuBar() - return self[2][1] + + local spacing = HorizontalSpan:new{ + width = (Screen:getWidth() - icons_width) / (#menu_items+1) + } + + local menu_bar = HorizontalGroup:new{} + + 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 --[[ -Widget that displays config menu +Widget that displays config menubar and config panel + + +----------------+ + | | + | | + | | + | | + | | + +----------------+ + | | + | Config Panel | + | | + +----------------+ + | Menu Bar | + +----------------+ + --]] + ConfigDialog = InputContainer:new{ --is_borderless = false, } @@ -289,7 +305,13 @@ function ConfigDialog:init() ------------------------------------------ -- start to set up widget layout --------- ------------------------------------------ - self:updateDialog() + self.config_panel = ConfigPanel:new{ + config_dialog = self, + } + self.config_menubar = MenuBar:new{ + config_dialog = self, + } + self:makeDialog() ------------------------------------------ -- start to set up input event callback -- ------------------------------------------ @@ -315,38 +337,41 @@ function ConfigDialog:init() UIManager:setDirty(self, "partial") end -function ConfigDialog:updateDialog(panel_options) - self.config_panel = ConfigPanel:new{ - config_options = self.config_options, +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, + } - if panel_options then - self.config_panel[1] = panel_options - end - - local config_panel_size = self.config_panel:getSize() + local dialog_size = dialog:getSize() - 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(), + dimen = dialog_size, background = 0, - self.config_panel, + 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 -function ConfigDialog:onShowOptions(options, index) - self:updateDialog(options) - self.config_panel:getMenuBar():invert(index) +function ConfigDialog:onShowConfigPanel(index) + self:updateConfigPanel(index) + self:makeDialog() UIManager.repaint_all = true return true end @@ -360,7 +385,7 @@ function ConfigDialog:onCloseMenu() end 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() return true end From 6ed1a9012b7b988cdc3a7b9b97648ab694a347f3 Mon Sep 17 00:00:00 2001 From: chrox Date: Tue, 15 Jan 2013 19:11:16 +0800 Subject: [PATCH 4/5] show more options --- frontend/document/koptinterface.lua | 37 +++++++++++++---------------- frontend/ui/config.lua | 4 ++-- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/frontend/document/koptinterface.lua b/frontend/document/koptinterface.lua index 2f14c8bde..3c3dc52f5 100644 --- a/frontend/document/koptinterface.lua +++ b/frontend/document/koptinterface.lua @@ -46,14 +46,6 @@ KoptOptions = { { icon = "resources/icons/appbar.column.two.large.png", 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_text = "Page Margin", @@ -118,11 +110,11 @@ KoptOptions = { event = "RedrawCurrentPage", }, { - name = "word_spacing", - name_text = "Word Gap", - item_text = {"small", "medium", "large"}, - values = {0.05, 0.15, 0.375}, - default_value = 0.15, + name = "max_columns", + name_text = "Columns", + item_text = {"1","2","3","4"}, + values = {1,2,3,4}, + default_value = 2, }, { name = "quality", @@ -130,7 +122,6 @@ KoptOptions = { item_text = {"low", "default", "high"}, values={0.5, 0.8, 1.0}, default_value = 0.8, - show = false, }, { name = "auto_straighten", @@ -140,12 +131,11 @@ KoptOptions = { default_value = 0, }, { - name = "detect_indent", - name_text = "Indentation", - item_text = {"enable","disable"}, - values = {1, 0}, - default_value = 1, - show = false, + name = "word_spacing", + name_text = "Word Gap", + item_text = {"small", "medium", "large"}, + values = {0.05, 0.15, 0.375}, + default_value = 0.15, }, { name = "defect_size", @@ -153,6 +143,13 @@ KoptOptions = { item_text = {"small","medium","large"}, values = {0.5, 1.0, 2.0}, default_value = 1.0, + }, + { + name = "detect_indent", + name_text = "Indentation", + item_text = {"enable","disable"}, + values = {1, 0}, + default_value = 1, show = false, }, } diff --git a/frontend/ui/config.lua b/frontend/ui/config.lua index 589963e12..485abcc12 100644 --- a/frontend/ui/config.lua +++ b/frontend/ui/config.lua @@ -45,7 +45,7 @@ end function MenuBarItem:onTapSelect() self[1].invert = true self.config:onShowConfigPanel(self.index) - UIManager:scheduleIn(1.0, function() self:invert(false) end) + UIManager:scheduleIn(0.5, function() self:invert(false) end) return true end @@ -105,7 +105,7 @@ function ConfigOption:init() local default_item_font_size = math.floor(20*Screen:getWidth()/600) local default_items_spacing = math.floor(30*Screen:getWidth()/600) local default_option_height = math.floor(40*Screen:getWidth()/600) - local default_option_padding = math.floor(50*Screen:getWidth()/600) + local default_option_padding = math.floor(40*Screen:getWidth()/600) local vertical_group = VerticalGroup:new{} table.insert(vertical_group, VerticalSpan:new{ width = default_option_padding }) for c = 1, #self.options do From 494585ce41b877f25ee845dcdbea4ff761284c80 Mon Sep 17 00:00:00 2001 From: chrox Date: Tue, 15 Jan 2013 19:39:42 +0800 Subject: [PATCH 5/5] rename 'screen rotation' option in koptinterface to 'vertical text' --- frontend/document/koptinterface.lua | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/frontend/document/koptinterface.lua b/frontend/document/koptinterface.lua index 3c3dc52f5..3d625debf 100644 --- a/frontend/document/koptinterface.lua +++ b/frontend/document/koptinterface.lua @@ -23,11 +23,10 @@ KoptOptions = { icon = "resources/icons/appbar.transform.rotate.right.large.png", options = { { - name="screen_rotation", - name_text = "Screen Rotation", + name="screen_mode", + name_text = "Screen Mode", item_text = {"portrait", "landscape"}, - values = {0, 90}, - default_value = 0, + -- TODO: add screen mode changing command } } }, @@ -116,6 +115,13 @@ KoptOptions = { values = {1,2,3,4}, default_value = 2, }, + { + name="screen_rotation", + name_text = "Vertical Text", + item_text = {"true", "false"}, + values = {90, 0}, + default_value = 0, + }, { name = "quality", name_text = "Render Quality",