kOS/lib/ui.ks

87 lines
1.8 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 MakeToggle {
parameter p.
parameter l.
parameter f.
local btn is p:AddButton(l).
set btn:TOGGLE to true.
2021-08-25 05:13:20 +00:00
set btn:onToggle to f.
return btn.
}
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
}
function AddStockButtons {
parameter row.
parameter bootname.
MakeToggle(row, "Term", {
parameter d.
if d {
CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Open Terminal").
} else {
CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Close Terminal").
}
}).
MakeButton(row, "Update", {
switch to 0.
run reinstall(bootname).
}).
}