From 868fc3e4d5020c00437a60ddfb0b24c1d3871aee Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 5 May 2020 23:48:32 +0800 Subject: [PATCH] resize mconfdialog --- src/ltui/mconfdialog.lua | 20 +++++++++++++++++--- tests/mconfdialog.lua | 31 +++++++++++++++++++++++-------- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/ltui/mconfdialog.lua b/src/ltui/mconfdialog.lua index cb69df5..1320ed2 100644 --- a/src/ltui/mconfdialog.lua +++ b/src/ltui/mconfdialog.lua @@ -55,6 +55,10 @@ Pressing includes, excludes. Enter or to go back, for H -- insert menu config self:box():panel():insert(self:menuconf()) + self:box():panel():action_add(action.ac_on_resized, function (v) + local bounds = self:box():panel():bounds() + self:menuconf():bounds_set(rect:new(0, 0, bounds:width(), bounds:height())) + end) -- disable to select to box (disable Tab switch and only response to buttons) self:box():option_set("selectable", false) @@ -135,7 +139,7 @@ end -- get input dialog function mconfdialog:inputdialog() if not self._INPUTDIALOG then - local dialog_input = inputdialog:new("mconfdialog.input", rect {0, 0, math.min(80, self:width() - 8), math.min(8, self:height())}, "input dialog") + local dialog_input = inputdialog:new("mconfdialog.input", rect{0, 0, math.min(80, self:width() - 8), math.min(8, self:height())}, "input dialog") dialog_input:background_set(self:frame():background()) dialog_input:frame():background_set("cyan") dialog_input:textedit():option_set("multiline", false) @@ -163,7 +167,7 @@ end -- get choice dialog function mconfdialog:choicedialog() if not self._CHOICEDIALOG then - local dialog_choice = choicedialog:new("mconfdialog.choice", rect {0, 0, math.min(80, self:width() - 8), math.min(20, self:height())}, "input dialog") + local dialog_choice = choicedialog:new("mconfdialog.choice", rect{0, 0, math.min(80, self:width() - 8), math.min(20, self:height())}, "input dialog") dialog_choice:background_set(self:frame():background()) dialog_choice:frame():background_set("cyan") dialog_choice:box():frame():background_set("cyan") @@ -175,7 +179,7 @@ end -- get search dialog function mconfdialog:searchdialog() if not self._SEARCHDIALOG then - local dialog_search = inputdialog:new("mconfdialog.input", rect {0, 0, math.min(80, self:width() - 8), math.min(8, self:height())}, "Search Configuration Parameter") + local dialog_search = inputdialog:new("mconfdialog.input", rect{0, 0, math.min(80, self:width() - 8), math.min(8, self:height())}, "Search Configuration Parameter") dialog_search:background_set(self:frame():background()) dialog_search:frame():background_set("cyan") dialog_search:textedit():option_set("multiline", false) @@ -305,5 +309,15 @@ function mconfdialog:on_event(e) return boxdialog.on_event(self, e) end +-- on resize +function mconfdialog:on_resize() + self:helpdialog():bounds_set(self:bounds()) + self:resultdialog():bounds_set(self:bounds()) + self:inputdialog():bounds_set(rect{0, 0, math.min(80, self:width() - 8), math.min(8, self:height())}) + self:choicedialog():bounds_set(rect{0, 0, math.min(80, self:width() - 8), math.min(20, self:height())}) + self:searchdialog():bounds_set(rect{0, 0, math.min(80, self:width() - 8), math.min(8, self:height())}) + boxdialog.on_resize(self) +end + -- return module return mconfdialog diff --git a/tests/mconfdialog.lua b/tests/mconfdialog.lua index 455b3bf..9e57d00 100644 --- a/tests/mconfdialog.lua +++ b/tests/mconfdialog.lua @@ -72,14 +72,29 @@ function demo:init() table.insert(configs, menuconf.choice {value = 3, values = {1, 5, 6, 7}, description = "choice config item"}) -- init menu config dialog - local mconfdialog = mconfdialog:new("mconfdialog.main", rect {1, 1, self:width() - 1, self:height() - 1}, "menu config") - mconfdialog:load(configs) - mconfdialog:action_set(action.ac_on_exit, function (v) self:quit() end) - mconfdialog:action_set(action.ac_on_save, function (v) - -- TODO save configs - mconfdialog:quit() - end) - self:insert(mconfdialog) + self:dialog_mconf():load(configs) + self:insert(self:dialog_mconf()) +end + +-- get mconfdialog +function demo:dialog_mconf() + local dialog_mconf = self._DIALOG_MCONF + if not dialog_mconf then + dialog_mconf = mconfdialog:new("mconfdialog.main", rect{1, 1, self:width() - 1, self:height() - 1}, "menu config") + dialog_mconf:action_set(action.ac_on_exit, function (v) self:quit() end) + dialog_mconf:action_set(action.ac_on_save, function (v) + -- TODO save configs + dialog_mconf:quit() + end) + self._DIALOG_MCONF = dialog_mconf + end + return dialog_mconf +end + +-- on resize +function demo:on_resize() + self:dialog_mconf():bounds_set(rect{1, 1, self:width() - 1, self:height() - 1}) + application.on_resize(self) end -- run demo