Module GUI
Base handler for all the GUI stuff.
Usage:
-- A simple script that creates a button that closes the console. function init() local button = TextButton(0, 0, 100, 16, "Close") button.onClick = function(mouseButton) console.dismiss() end GUI.add(button) 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
Functions
add (component) | Add a new top-level component to be handled by PenguinGUI. |
clickEvent (position, button, pressed) | Must be called in canvasClickEvent to handle mouse events. |
keyEvent (key, pressed) | Must be called in canvasKeyEvent to handle keyboard events. |
remove (component) | Removes a component to be handled. |
setFocusedComponent (component) | Sets the keyboard focus of the GUI to the specified component. |
step (dt) | Draws and updates every component managed by this GUI. |
Tables
GUI | GUI Table |
Functions
- add (component)
-
Add a new top-level component to be handled by PenguinGUI.
Parameters:
- component The top-level component to be added.
- clickEvent (position, button, pressed)
-
Must be called in canvasClickEvent to handle mouse events.
Parameters:
- position The position of the click.
- button The mouse button of the click.
- pressed Whether the event is pressed or released.
- keyEvent (key, pressed)
-
Must be called in canvasKeyEvent to handle keyboard events.
Parameters:
- key The keycode of the key that spawned the event.
- pressed Whether the key was pressed or released.
- remove (component)
-
Removes a component to be handled.
Parameters:
- component The component to be removed.
Returns:
-
Whether the component was removed.
- setFocusedComponent (component)
-
Sets the keyboard focus of the GUI to the specified component.
Parameters:
- component The component to receive keyboard focus.
- step (dt)
-
Draws and updates every component managed by this GUI.
Must be called in update() for the GUI to update and render.
Parameters:
- dt The time elapsed since the last draw, in seconds.