Page Handler
A UI element, that holds multiple other UI elements and draws them together.
Contents:
Properties
Name |
Type |
Default |
---|---|---|
|
|
|
|
|
|
|
|
x
X component of the position on the screen.
uilib.Group.x = nil
Type:
number
Default:
nil
y
Y component of the position on the screen.
uilib.Group.y = nil
Type:
number
Default:
nil
elements
List of all UI elements included within the group.
uilib.Group.elements = {}
Type:
table
Default:
{}
visible
Contains information about the group being visible or not.
uilib.Group.visible = true
Type:
boolean
Default:
true
Functions
new()
Function to create a new instance of Group.
function M.Group:new(x, y, elements)
...
return group
end
Arguments:
Name |
Type |
Default |
Description |
---|---|---|---|
x |
|
|
X component of position of the group. |
y |
|
|
Y component of position of the group. |
elements |
|
|
List of all contained UI elements. |
Important
The elements
list must contain the elements with a string key attached to them, e.g. {label = elementVar}
.
Important
When you add a UI element to a group, the x
and y
parameters will become local to the group, which means that the actual position of the UI element would be:
(group.x + element.x - 1, group.y + element.y - 1)
.
Returns:
Type |
Description |
---|---|
Instance of Group with specified properties. |
Example:
local uilib = require("uilib")
local label = uilib.Label("I am a Label!", 4, 5, uilib.Style:new(colors.red, colors.black))
local group = uilib.Group:new(2, 2, {label = label})
This would create an instance of a Group and a Label within the created group.
The Label would be drawn at position (5, 6)
.
draw()
Function to draw the group.
function M.Group:draw()
...
end
Arguments: nil
Returns: nil
Example:
local uilib = require("uilib")
local label = uilib.Label("I am a Label!", 4, 5, uilib.Style:new(colors.red, colors.black))
local group = uilib.Group:new(2, 2, {label = label})
group:draw()
This would create an instance of a Group and a Label within the created group and draw it to the screen.
add()
Function to add a UI element to the group.
function M.Group:add(element, id)
...
end
Arguments:
Name |
Type |
Default |
Description |
---|---|---|---|
element |
|
|
UI element to add. |
id |
|
|
ID to refer to the UI element. |
Important
When you add a UI element to a group, the x
and y
parameters will become local to the group, which means that the actual position of the UI element would be:
(group.x + element.x - 1, group.y + element.y - 1)
.
Returns: nil
Example:
local uilib = require("uilib")
local label = uilib.Label("I am a Label!", 4, 5, uilib.Style:new(colors.red, colors.black))
local group = uilib.Group:new(2, 2, {})
group:add(label, "label")
This would create an instance of a Group and a Label, which is being added to the group with the ID "label2
.
remove()
Function to remove a UI element from the group.
function M.Group:remove(id)
...
end
Arguments:
Name |
Type |
Default |
Description |
---|---|---|---|
id |
|
|
ID of the element. |
Returns: nil
Example:
local uilib = require("uilib")
local label = uilib.Label("I am a Label!", 4, 5, uilib.Style:new(colors.red, colors.black))
local group = uilib.Group:new(2, 2, {label = label})
group:remove("label")
This would create an instance of a Group and a Label within the created group. It would then remove the created label from the group.
get()
Function to get a specific UI element from the group.
function M.Group:get(id)
...
end
Arguments:
Name |
Type |
Default |
Description |
---|---|---|---|
id |
|
|
ID of the UI element. |
Returns:
Type |
Description |
---|---|
|
UI element with the specified id in the group. |
Warning
This function returns -1
instead of the above, if one of these conditions is met:
No UI element with the specified ID exists.
Example:
local uilib = require("uilib")
local label = uilib.Label("I am a Label!", 4, 5, uilib.Style:new(colors.red, colors.black))
local group = uilib.Group:new(2, 2, {label = label})
local labelAgain = group:get("label")
This would create an instance of a Group and a Label within the created group.
After that it would store the label element with the ID "label"
in labelAgain
.
show()
Function to make the group visible.
function uilib.Group:show()
...
end
Arguments: nil
Returns: nil
Example:
local uilib = require("uilib")
local label = uilib.Label("I am a Label!", 4, 5, uilib.Style:new(colors.red, colors.black))
local group = uilib.Group:new(2, 2, {label = label})
group:show()
This would create an instance of a Group and a Label within the created group and make it visible.
hide()
Function to make the group invisible.
function uilib.Group:hide()
...
end
Arguments: nil
Returns: nil
Example:
local uilib = require("uilib")
local label = uilib.Label("I am a Label!", 4, 5, uilib.Style:new(colors.red, colors.black))
local group = uilib.Group:new(2, 2, {label = label})
group:hide()
This would create an instance of a Group and a Label within the created group and make it invisible.