diff options
| author | ruki <[email protected]> | 2018-06-12 22:51:01 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-06-12 11:06:12 +0800 |
| commit | 16b501fbc388f1b207faf1475602388b9e09983e (patch) | |
| tree | 531b8bd319294a37588cbd9ab1e8f2bbce45c932 | |
| parent | bbd866243423fab4d786586bd0bb7e400c1c5a88 (diff) | |
add back button to menuconf
| -rw-r--r-- | xmake/core/ui/dialog.lua | 2 | ||||
| -rw-r--r-- | xmake/core/ui/mconfdialog.lua | 3 | ||||
| -rw-r--r-- | xmake/core/ui/menuconf.lua | 32 |
3 files changed, 24 insertions, 13 deletions
diff --git a/xmake/core/ui/dialog.lua b/xmake/core/ui/dialog.lua index 37a19cebb..089a57293 100644 --- a/xmake/core/ui/dialog.lua +++ b/xmake/core/ui/dialog.lua @@ -72,7 +72,7 @@ function dialog:button_add(name, text, command) local index = 1 local width = self:buttons():width() local count = self:buttons():count() - local padding = math.floor(width / 6) + local padding = math.floor(width / 8) for v in self:buttons():views() do local x = padding + index * math.floor((width - padding * 2) / (count + 1)) - math.floor(v:width() / 2) if x + v:width() > width then diff --git a/xmake/core/ui/mconfdialog.lua b/xmake/core/ui/mconfdialog.lua index 819b0745e..1d83fce3b 100644 --- a/xmake/core/ui/mconfdialog.lua +++ b/xmake/core/ui/mconfdialog.lua @@ -46,11 +46,12 @@ function mconfdialog:init(name, bounds, title) -- init text self:text():text_set([[Arrow keys navigate the menu. <Enter> selects submenus ---> (or empty submenus ----). -Pressing <Y> includes, <N> excludes. Enter <Esc> to go back or exit, <?> for Help, </> for Search. Legend: [*] built-in [ ] excluded +Pressing <Y> includes, <N> excludes. Enter <Esc> or <Back> to go back, <?> for Help, </> for Search. Legend: [*] built-in [ ] excluded ]]) -- init buttons self:button_add("select", "< Select >", function (v, e) self:menuconf():event_on(event.command {"cm_enter"}) end) + self:button_add("back", "< Back >", function (v, e) self:menuconf():event_on(event.command {"cm_back"}) end) self:button_add("exit", "< Exit >", function (v, e) self:quit() end) self:button_add("help", "< Help >", function (v, e) self:show_help() end) self:button_add("save", "< Save >", function (v, e) self:action_on(action.ac_on_save) end) diff --git a/xmake/core/ui/menuconf.lua b/xmake/core/ui/menuconf.lua index acf2fb007..cf68a1450 100644 --- a/xmake/core/ui/menuconf.lua +++ b/xmake/core/ui/menuconf.lua @@ -50,6 +50,7 @@ end function menuconf:event_on(e) -- select config + local back = false if e.type == event.ev_keyboard then if e.key_name == "Down" then return self:select_next() @@ -65,18 +66,27 @@ function menuconf:event_on(e) self:_do_include(false) 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 + back = true end - elseif e.type == event.ev_command and e.command == "cm_enter" then - self:_do_select() - return true - end + elseif e.type == event.ev_command then + if e.command == "cm_enter" then + self:_do_select() + return true + elseif e.command == "cm_back" then + back = true + end + end + + -- back? + if back 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 end -- load configs |
