resize mconfdialog

This commit is contained in:
ruki
2020-05-05 23:48:32 +08:00
parent cafdf174d7
commit 868fc3e4d5
2 changed files with 40 additions and 11 deletions

View File

@@ -55,6 +55,10 @@ Pressing <Y> includes, <N> excludes. Enter <Esc> or <Back> to go back, <?> for H
-- insert menu config -- insert menu config
self:box():panel():insert(self:menuconf()) 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) -- disable to select to box (disable Tab switch and only response to buttons)
self:box():option_set("selectable", false) self:box():option_set("selectable", false)
@@ -135,7 +139,7 @@ end
-- get input dialog -- get input dialog
function mconfdialog:inputdialog() function mconfdialog:inputdialog()
if not self._INPUTDIALOG then 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:background_set(self:frame():background())
dialog_input:frame():background_set("cyan") dialog_input:frame():background_set("cyan")
dialog_input:textedit():option_set("multiline", false) dialog_input:textedit():option_set("multiline", false)
@@ -163,7 +167,7 @@ end
-- get choice dialog -- get choice dialog
function mconfdialog:choicedialog() function mconfdialog:choicedialog()
if not self._CHOICEDIALOG then 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:background_set(self:frame():background())
dialog_choice:frame():background_set("cyan") dialog_choice:frame():background_set("cyan")
dialog_choice:box():frame():background_set("cyan") dialog_choice:box():frame():background_set("cyan")
@@ -175,7 +179,7 @@ end
-- get search dialog -- get search dialog
function mconfdialog:searchdialog() function mconfdialog:searchdialog()
if not self._SEARCHDIALOG then 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:background_set(self:frame():background())
dialog_search:frame():background_set("cyan") dialog_search:frame():background_set("cyan")
dialog_search:textedit():option_set("multiline", false) dialog_search:textedit():option_set("multiline", false)
@@ -305,5 +309,15 @@ function mconfdialog:on_event(e)
return boxdialog.on_event(self, e) return boxdialog.on_event(self, e)
end 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 module
return mconfdialog return mconfdialog

View File

@@ -72,14 +72,29 @@ function demo:init()
table.insert(configs, menuconf.choice {value = 3, values = {1, 5, 6, 7}, description = "choice config item"}) table.insert(configs, menuconf.choice {value = 3, values = {1, 5, 6, 7}, description = "choice config item"})
-- init menu config dialog -- init menu config dialog
local mconfdialog = mconfdialog:new("mconfdialog.main", rect {1, 1, self:width() - 1, self:height() - 1}, "menu config") self:dialog_mconf():load(configs)
mconfdialog:load(configs) self:insert(self:dialog_mconf())
mconfdialog:action_set(action.ac_on_exit, function (v) self:quit() end) end
mconfdialog:action_set(action.ac_on_save, function (v)
-- 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 -- TODO save configs
mconfdialog:quit() dialog_mconf:quit()
end) end)
self:insert(mconfdialog) 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 end
-- run demo -- run demo