Usage
API Documentation and examples can be found here: API Documentation Basic stuff needed for the GUI to work In your console script:function update(dt)
GUI.step(dt)
end
function canvasClickEvent(position, button, pressed)
GUI.clickEvent(position, button, pressed)
end
function canvasKeyEvent(key, isKeyDown)
GUI.keyEvent(key, isKeyDown)
end
You can do cool stuff with bindings: Usage
For people unfamilar with lua,
sometable:somefunction(args)
is equivalent to
sometable.somefunction(sometable, args)
Generally, in this library, calls to functions in GUI will use the "." syntax,
and calls to functions in any GUI component will use the ":" syntax.
To add a top-level component:
GUI.add(component)
To add a component under another component:
parent:add(component)
Components
Image
local image = Image(3, 3, "/interface/cockpit/xdown.png")

Label
local label = Label(10, 10, "Hello")

Button
local button = Button(10, 10, 0, 0)
button:add(Image(3, 3, 9, 11, "/interface/cockpit/xdown.png"))
button:pack(3)
button.onClick = function(button)
console.dismiss()
end
TextButton
local testbutton = TextButton(10, 10, 100, 16, "Button")
testbutton.onClick = function(button)
testbutton.text = "hi"
end
TextField
local testfield = TextField(10, 10, 100, 16, "text")
testfield.onEnter = function(field)
field.defaultText = field.text
end
Frame
local frame = Frame(10, 10)
local button = TextButton(10, 10, 100, 16, "Close")
button.onClick = function(button)
GUI.remove(frame)
end
frame:add(button)
frame:pack(10)
Panel
local panel = Panel(10, 10)
panel:add(RadioButton(0, 0, 16))
panel:add(RadioButton(0, 20, 16))

CheckBox
local checkbox = CheckBox(10, 10, 16)
checkbox:addListener("selected", function(t, k, prev, selected)
if selected then
world.logInfo("selected")
end
end
RadioButton
local panel = Panel(10, 10)
panel:add(RadioButton(0, 0, 16))
panel:add(RadioButton(0, 20, 16))
List
Example in API docs.
Slider
Example in API docs.
Planned Components
- ComboBox
Code Samples
Sample 1
In your .object file:
In your console script:
{
"scripts" : ["/penguingui/Util.lua", "/your/object/script.lua"],
"interactionConfig" : {
"gui" : {
"background" : {
"zlevel" : 0,
"type" : "background",
"fileHeader" : "/path/to/header.png",
"fileBody" : "/path/to/body.png"
},
"scriptCanvas" : {
"zlevel" : 1,
"type" : "canvas",
"rect" : [canvasXOffset, canvasYOffset, canvasWidth, canvasHeight],
"captureMouseEvents" : true,
"captureKeyboardEvents" : true
},
"close" : {
"zlevel" : 2,
"type" : "button",
"base" : "/interface/cockpit/xup.png",
"hover" : "/interface/cockpit/xdown.png",
"pressed" : "/interface/cockpit/xdown.png",
"callback" : "close",
"position" : [closeButtonX, closeButtonY],
"pressedOffset" : [0, -1]
}
},
"scripts" : ["/path/to/penguingui.lua", "/path/to/your/console/script.lua"],
"scriptDelta" : 5,
"scriptCanvas" : "scriptCanvas"
}
}
In your object script:
function init(virtual)
if not virtual then
entity.setInteractive(true)
end
end
function onInteraction(args)
local interactionConfig = entity.configParameter("interactionConfig")
return {"ScriptConsole", interactionConfig}
end
To make this:
function init()
local testbutton = TextButton(10, 10, 100, 16, "Make window")
testbutton.onClick = testButtonClick
GUI.add(testbutton)
end
function testButtonClick(button, mouseButton)
local frame = Frame(100, 50)
GUI.add(frame)
local testTextButton = TextButton(80, 20, 100, 16, "text")
testTextButton.onClick = function(button)
GUI.remove(frame)
end
frame:add(testTextButton)
local testField = TextField(20, 20, 50, 16, "text")
testField.onEnter = function(field)
testTextButton.text = field.text
end
frame:add(testField)
frame:pack(20)
end
function update(dt)
GUI.step(dt)
end
function canvasClickEvent(position, button, pressed)
GUI.clickEvent(position, button, pressed)
end
function canvasKeyEvent(key, isKeyDown)
GUI.keyEvent(key, isKeyDown)
end