kOS/lib/ui.ks

56 lines
1.2 KiB
Plaintext
Raw Normal View History

2021-08-02 01:34:14 +00:00
2021-08-08 04:15:28 +00:00
function MakeRow {
2021-08-02 01:34:14 +00:00
parameter p.
return p:AddHLayout().
}
2021-08-08 04:15:28 +00:00
function MakeButton {
2021-08-02 01:34:14 +00:00
parameter p.
parameter l.
2021-08-08 04:15:28 +00:00
parameter f is {}.
2021-08-02 01:34:14 +00:00
local b is p:AddButton(l).
set b:onClick to f.
return b.
}
2021-08-08 04:15:28 +00:00
function MakeMenu {
parameter stack. // the stack where menu stuff goes
parameter btn. // the button that should show this menu
parameter options.
parameter execLabel.
parameter callback.
parameter preback is { parameter nil. }.
local top is stack:AddVLayout().
local sbox is top:AddScrollBox().
local optionList is Lex().
for option in options {
local row is MakeRow(sbox).
local name is option[0].
local type is option[1].
local field is 0.
if type = "SCALAR" {
row:AddLabel(name).
set field to row:AddTextField(option[2]).
} else if type = "BOOL" {
set field to row:AddCheckBox(name, option[2]).
} else if type = "RO" {
row:AddLabel(name).
set field to row:AddLabel(option[2]).
} else {
print "WARNING: Unsupported type passed to MakeMenu".
}
optionList:Add(name, field).
}
set btn:onClick to {
preback(optionList).
stack:ShowOnly(top).
}.
if execLabel <> "" {
set top:AddButton(execLabel):onClick to callback:Bind(optionList).
}
2021-08-08 04:15:28 +00:00
}