diff options
| author | ruki <[email protected]> | 2018-01-27 00:26:29 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-01-26 20:38:54 +0800 |
| commit | 7a92a39600bde235e99ac6363172cc317f7311f7 (patch) | |
| tree | 60487d49500c23f3d7271c7b3af1be5c30fac20a | |
| parent | 399a8c88d9a7ba0b8dfe3a851a5e2994397a695c (diff) | |
go back menu configs
| -rw-r--r-- | tests/ui/mconfdialog.lua | 16 | ||||
| -rw-r--r-- | xmake/core/ui/mconfdialog.lua | 7 | ||||
| -rw-r--r-- | xmake/core/ui/menuconf.lua | 50 | ||||
| -rw-r--r-- | xmake/core/ui/view.lua | 2 |
4 files changed, 59 insertions, 16 deletions
diff --git a/tests/ui/mconfdialog.lua b/tests/ui/mconfdialog.lua index 2968dacaf..5e12c1050 100644 --- a/tests/ui/mconfdialog.lua +++ b/tests/ui/mconfdialog.lua @@ -49,12 +49,26 @@ function demo:init() local mconfdialog = mconfdialog:new("mconfdialog.main", rect {1, 1, self:width() - 1, self:height() - 1}, "menu config") mconfdialog:action_set(action.ac_on_exit, function (v) self:quit() end) mconfdialog:action_set(action.ac_on_load, function (v) + + local configs_sub2 = {} + table.insert(configs_sub2, menuconf.boolean {description = "boolean config sub-item2"}) + table.insert(configs_sub2, menuconf.number {value = 10, default = 10, description = "number config sub-item2"}) + table.insert(configs_sub2, menuconf.string {value = "armv7", description = "string config sub-item2"}) + table.insert(configs_sub2, menuconf.menu {description = "menu config sub-item2"}) + + local configs_sub = {} + table.insert(configs_sub, menuconf.boolean {description = "boolean config sub-item"}) + table.insert(configs_sub, menuconf.number {value = 90, default = 10, description = "number config sub-item"}) + table.insert(configs_sub, menuconf.string {value = "arm64", description = "string config sub-item"}) + table.insert(configs_sub, menuconf.menu {description = "menu config sub-item", configs = configs_sub2}) + table.insert(configs_sub, menuconf.choice {value = 2, values = {2, 5, 16, 87}, description = "choice config sub-item"}) + local configs = {} table.insert(configs, menuconf.boolean {description = "boolean config item"}) table.insert(configs, menuconf.boolean {default = true, new = false, description = {"boolean config item2", "more"}}) table.insert(configs, menuconf.number {value = 6, default = 10, description = "number config item"}) table.insert(configs, menuconf.string {value = "x86_64", description = "string config item"}) - table.insert(configs, menuconf.menu {description = "menu config item"}) + table.insert(configs, menuconf.menu {description = "menu config item", configs = configs_sub}) table.insert(configs, menuconf.choice {value = 3, values = {1, 5, 6, 7}, description = "choice config item"}) v:menuconf():load(configs) end) diff --git a/xmake/core/ui/mconfdialog.lua b/xmake/core/ui/mconfdialog.lua index 8dc01563a..d10ad145b 100644 --- a/xmake/core/ui/mconfdialog.lua +++ b/xmake/core/ui/mconfdialog.lua @@ -98,21 +98,24 @@ Pressing <Y> includes, <N> excludes. Enter <Esc> to go back or exit, <?> for Hel dialog_input:extra_set("config", config) dialog_input:title():text_set(config:prompt()) dialog_input:textedit():text_set(tostring(config.value)) + dialog_input:panel():select(dialog_input:textedit()) if config.kind == "string" then dialog_input:text():text_set("Please enter a string value. Use the <TAB> key to move from the input fields to buttons below it.") else dialog_input:text():text_set("Please enter a decimal value. Fractions will not be accepted. Use the <TAB> key to move from the input field to the buttons below it.") end self:insert(dialog_input, {centerx = true, centery = true}) + return true -- show choice dialog - elseif config.kind == "choice" then + elseif config.kind == "choice" and config.values and #config.values > 0 then dialog_choice:title():text_set(config:prompt()) dialog_choice:choicebox():load(config.values, config.value) dialog_choice:choicebox():action_set(action.ac_on_selected, function (v, index, value) config.value = index end) self:insert(dialog_choice, {centerx = true, centery = true}) + return true end end) end @@ -138,7 +141,7 @@ function mconfdialog:event_on(e) end -- select config elseif e.type == event.ev_keyboard then - if e.key_name == "Down" or e.key_name == "Up" or e.key_name == " " then + if e.key_name == "Down" or e.key_name == "Up" or e.key_name == " " or e.key_name == "Esc" then return self:menuconf():event_on(e) end end diff --git a/xmake/core/ui/menuconf.lua b/xmake/core/ui/menuconf.lua index 50395452c..635373ee0 100644 --- a/xmake/core/ui/menuconf.lua +++ b/xmake/core/ui/menuconf.lua @@ -58,6 +58,14 @@ function menuconf:event_on(e) elseif e.key_name == "Enter" or e.key_name == " " then self:_do_select() return true + elseif e.key_name == "Esc" then + -- load the previous menu configs + local configs_prev = self._CONFIGS._PREV + if configs_prev then + self._CONFIGS._PREV = configs_prev._PREV + self:load(configs_prev) + return true + end end elseif e.type == event.ev_command and e.command == "cm_enter" then self:_do_select() @@ -71,10 +79,20 @@ function menuconf:load(configs) -- clear the views first self:clear() + -- detach the previous config and view + local configs_prev = self._CONFIGS._PREV + if configs_prev then + for _, config in ipairs(configs_prev) do + config._view = nil + end + end + -- insert configs self._CONFIGS = configs for _, config in ipairs(configs) do - self:_do_insert(config) + if self:count() < self:height() then + self:_do_insert(config) + end end -- select the first item @@ -109,19 +127,23 @@ function menuconf:_do_select() -- get the current config local config = item:extra("config") - -- get value - local value = config.value + -- clear new state + config.new = false + + -- do action: on selected + if self:action_on(action.ac_on_selected, config) then + return + end -- select the boolean config if config.kind == "boolean" then - config.value = not value + config.value = not config.value + -- show sub-menu configs + elseif config.kind == "menu" and config.configs and #config.configs > 0 then + local configs_prev = self._CONFIGS + self:load(config.configs) + self._CONFIGS._PREV = configs_prev end - - -- do action: on selected - self:action_on(action.ac_on_selected, config) - - -- clear new state - config.new = false end -- init config object @@ -200,9 +222,13 @@ function config:__tostring() elseif self.kind == "string" or (not self.kind and type(value) == "string") then -- string config? text = "(" .. tostring(value or "") .. ") " .. text elseif self.kind == "choice" then -- choice config? - text = " " .. text .. " (" .. tostring(self.values[value or 1]) .. ")" .. " --->" + if self.values and #self.values > 0 then + text = " " .. text .. " (" .. tostring(self.values[value or 1]) .. ")" .. " --->" + else + text = " " .. text .. " () ----" + end elseif self.kind == "menu" then -- menu config? - text = " " .. text .. " --->" + text = " " .. text .. (self.configs and #self.configs > 0 and " --->" or " ----") end -- new config? diff --git a/xmake/core/ui/view.lua b/xmake/core/ui/view.lua index f409fbd29..439db069e 100644 --- a/xmake/core/ui/view.lua +++ b/xmake/core/ui/view.lua @@ -375,7 +375,7 @@ function view:action_on(name, ...) end elseif type(on_action) == "function" then -- do action script - on_action(self, ...) + return on_action(self, ...) end end end |
