¶
luxe
API (2025.1.2
)¶
luxe: ui/control
module¶
Control¶
import "luxe: ui/control" for Control
Class for managing controls on UI modifiers. Note that all UI elements are controls, including UIImage, UILabel, UIButton, etc...
_ui = Entity.create(app.ui) UI.create(_ui, 0, 0, app.width, app.height, 0, app.ui_camera) var control = Control.create(_ui)
- create(ui_entity:
Entity
) - destroy(control:
Control
) - destroy_children(control:
Control
) - valid(control:
Control
) - get_ui(control:
Control
) - get(id:
String
) - exists(id:
String
) - clear(control:
Control
, uiclear_action:UIClear
) - press(control:
Control
, state:Bool
) - enter(control:
Control
, state:Bool
) - can_see(control:
Control
) - can_see_area(control:
Control
, area:Rect
) - can_see_point(control:
Control
, point:Vec
) - set_type(control:
Control
, type:String
) - get_type(control:
Control
) - set_id(control:
Control
, id:String
) - get_id(control:
Control
) - get_bounds_abs(control:
Control
, into:List
) - get_bounds(control:
Control
, into:List
) - set_allow_bounds_event(control:
Control
, state:Bool
) - get_allow_bounds_event(control:
Control
) - set_bounds_abs(control:
Control
, x:Num
, y:Num
, w:Num
, h:Num
) - set_bounds(control:
Control
, x:Num
, y:Num
, w:Num
, h:Num
) - set_pos_abs(control:
Control
, x:Num
, y:Num
) - set_pos(control:
Control
, x:Num
, y:Num
) - set_system_cursor(control:
Control
, cursor:SystemCursor
) - set_size(control:
Control
, w:Num
, h:Num
) - get_pos_x(control:
Control
) - get_pos_x_abs(control:
Control
) - get_pos_y(control:
Control
) - get_pos_y_abs(control:
Control
) - get_width(control:
Control
) - get_height(control:
Control
) - contains(control:
Control
, x:Num
, y:Num
) - get_entity(control:
Control
) - get_parent(control:
Control
) - get_allow_input(control:
Control
) - set_allow_input(control:
Control
, allow:Bool
) - set_allow_drag(control:
Control
, allow:Bool
, tag:String
) - set_droppable_payload(control:
Control
, value:Handle
) - get_droppable_payload(control:
Control
) - set_droppable_tags(control:
Control
, tags:List
) - get_droppable_tags(control:
Control
) - get_allow_keys(control:
Control
) - set_allow_keys(control:
Control
, allow:Bool
) - get_allow_tab(control:
Control
) - set_allow_tab(control:
Control
, allow:Bool
) - get_visible(control:
Control
) - set_visible(control:
Control
, visible:Bool
) - get_opacity(control:
Control
) - set_opacity(control:
Control
, opacity:Num
) - get_disabled(control:
Control
) - set_disabled(control:
Control
, disabled:Bool
) - get_enabled(control:
Control
) - set_enabled(control:
Control
, enabled:Bool
) - get_clip(control:
Control
) - set_clip(control:
Control
, clip:Bool
) - get_nodes(control:
Control
) - get_depth(control:
Control
) - get_depth_offset(control:
Control
) - set_depth_offset(control:
Control
, depth_offset:Num
) - get_input_inside(control:
Control
) - get_input_pressed(control:
Control
) - child_at_point(control:
Control
, x:Num
, y:Num
) - child_count(control:
Control
) - child_index(control:
Control
, child:Control
) - child_get(control:
Control
, index:Num
) - child_add(control:
Control
, child:Control
, internal:Bool
) - child_add(control:
Control
, child:Control
) - child_remove(control:
Control
, child:Control
) - children_bounds(control:
Control
, into:List
) - set_behave(control:
Control
, behave:UIBehave
) - get_behave(control:
Control
) - set_contain(control:
Control
, contain:UIContain
) - get_contain(control:
Control
) - set_margin(control:
Control
, left:Num
, top:Num
, right:Num
, bottom:Num
) - set_limits(control:
Control
, min_x:Num
, min_y:Num
, max_x:Num
, max_y:Num
) - get_margin(control:
Control
) - set_render(control:
Control
, fn:Fn
) - set_events(control:
Control
, fn:Fn
) - unset_events(control:
Control
, id:String
) - set_process(control:
Control
, fn:Fn
) - get_state_data(control:
Control
) - set_state_data(control:
Control
, data:Any
)
Entity
)
¶Control
Create a "blank" control for layout or custom input/drawing. Returns the new Control.
Control
)
¶None
Destroy an existing control.
var control = Control.create(_ui) //do stuff and then later... Control.destroy(control)
Control
)
¶None
Destroy the children of a control.
Control
)
¶Bool
Check if a control exists and has not been destroyed.
var control = Control.create(_ui) Log.print(Control.valid(control)) //true Control.destroy(control) Log.print(Control.valid(control)) //false
Control
)
¶Entity
Get UI entity a control is part of.
var control = Control.create(_ui) var control_ui = Control.get_ui(control) Log.print(control_ui == _ui) //true
String
)
¶Control
Get a control by its id.
var control = Control.create(_ui) Control.set_id(control, "test_id") var control_by_id = Control.get("test_id") Log.print(control == control_by_id) //true
String
)
¶Bool
Check if a control with a specific id exists.
Control
, uiclear_action: UIClear
)
¶None
Clear the children of a control in a specific manner.
Control
, state: Bool
)
¶None
Send a press or release event to the control (in the center of the control)
Control
, state: Bool
)
¶None
Send a enter or exit event to the control
Control
)
¶Bool
Returns true if this control can be seen, or false if clipped.
Control
, area: Rect
)
¶Bool
Returns true if the area at this control can be seen or false if clipped.
Control
, point: Vec
)
¶Bool
Returns true if the point at this control can be seen or false if clipped.
Control
, type: String
)
¶unknown
no docs found
Control
)
¶unknown
no docs found
Control
, id: String
)
¶unknown
Set the id of a control. Good for debugging and retrieving controls by their id. Must be unique, so adding
ID.unique()
to the id can be useful.var control = Control.create(_ui) Control.set_id(control, "good_recognizable_control_name_%(ID.unique())")
Control
)
¶String
Retrieve the id of a control.
Control
, into: List
)
¶None
Retrieve the bounds(position and size) of a control (relative to the UI modifier) into a list
[x, y, width, height]
. The passed list must have at least 4 elements and the function will write into the first 4. Passing a list into the function instead of returning a value is to avoid allocating memory where not needed.var parent = Control.create(_ui) Control.set_pos(parent, 50, 50) var child = Control.create(_ui) Control.child_add(parent, child) Control.set_pos(child, 100, 100) Control.set_size(child, 20, 20) var bounds = [0,0,0,0] Control.get_bounds_abs(child, bounds) Log.print(bounds) // [150, 150, 20, 20]
Control
, into: List
)
¶None
Retrieve the bounds(position and size) of a control (relative to their parent control or ui modifier if there is none) into a list
[x, y, width, height]
. The passed list must have at least 4 elements and the function will write into the first 4. Passing a list into the function instead of returning a value is to avoid allocating memory where not needed.var parent = Control.create(_ui) Control.set_pos(parent, 50, 50) var child = Control.create(_ui) Control.child_add(parent, child) Control.set_pos(child, 100, 100) Control.set_size(child, 20, 20) var bounds = [0,0,0,0] Control.get_bounds(child, bounds) Log.print(bounds) // [100, 100, 20, 20]
Control
, state: Bool
)
¶None
Enables bounds events for the control. Since there are many controls that may be resized during layout events, only ones that ask for the event will receive it to save time.
Control
)
¶Bool
Returns true if this control sends bounds events.
Control
, x: Num
, y: Num
, w: Num
, h: Num
)
¶None
Set the control bounds(position and size) relative to the UI modifier.
Control
, x: Num
, y: Num
, w: Num
, h: Num
)
¶None
Set the control bounds(position and size) relative to the parent control.
Control
, x: Num
, y: Num
)
¶None
Set the control position relative to the UI modifier.
Control
, x: Num
, y: Num
)
¶None
Set the control position relative to the parent control, or UI modifier if no parent exists.
Control
, cursor: SystemCursor
)
¶None
If the control has input enabled, when entered it will set the system cursor to the given type.
Control
, w: Num
, h: Num
)
¶None
Set the control size.
Control
)
¶Num
Get the control position x component relative to its parent control.
Control
)
¶Num
Get the control position x component.
Control
)
¶Num
Get the control position y component relative to its parent control.
Control
)
¶Num
Get the control position y component.
Control
)
¶Num
Get the control width.
Control
)
¶Num
Get the control height.
Control
, x: Num
, y: Num
)
¶Bool
Check whether the a point is within the control bounds
Control
)
¶Entity
Get the entity that has the UI modifier the control in.
Control
)
¶Control
Get the entity this entity is a child of or
null
if there isnt any.
Control
)
¶Bool
Get whether the control recieves input events in its
set_process
function.
Control
, allow: Bool
)
¶None
Set whether the control recieves input events in its
set_process
function.
Control
, allow: Bool
, tag: String
)
¶None
Set whether the control recieves drag events
Control
, value: Handle
)
¶None
Set a value that will be passed through the drag event to the drop event on the other side. This value is a handle/number, so you can pass api handles, a number, a hashed string, or a block instance
Control
)
¶Handle
Get the drop payload for this control
Control
, tags: List
)
¶None
Set the droppable tags that are allowed for this control, as an array of strings
Control
)
¶List
Get the droppable tags that are allowed for this control, as an array of strings
Control
)
¶Bool
Get whether the control recieves key events in its
set_process
function.
Control
, allow: Bool
)
¶None
Set whether the control recieves key events in its
set_process
function.
Control
)
¶Bool
Get whether the control can be "tabbed" to.
Control
, allow: Bool
)
¶None
Set whether the control can be "tabbed" to.
Control
)
¶Bool
Get whether a control is visible.
Control
, visible: Bool
)
¶None
Set whether a control (or its children) is visible. Note that when a control is not visible, it also doesnt contribute to the layout.
Control
)
¶Num
Get a control opacity value.
Control
, opacity: Num
)
¶None
Set a control opacity value. Affects children opacity as well.
Control
)
¶Bool
Get whether a control is disabled. This refers to the "inputable" state of inputs like buttons or text fields.
Control
, disabled: Bool
)
¶None
Set whether a control is disabled. This refers to the "inputable" state of inputs like buttons or text fields.
Control
)
¶Bool
Get whether a control is enabled. This refers to the "inputable" state of inputs like buttons or text fields.
Control
, enabled: Bool
)
¶None
Set whether a control is enabled. This refers to the "inputable" state of inputs like buttons or text fields.
Control
)
¶Bool
Get whether a control should clip its contents.
Control
, clip: Bool
)
¶None
Set whether a control should clip its contents.
Control
)
¶Num
Get how many child controls this control has recursively. So 1 if it doesnt have any children, 2 if it has 1 child, 3 if it has 2 children or if it has 1 child which itself has a child, etc... Only valid after
UI.commit
.
Control
)
¶Num
Get the depth generated for a control, not including the depth offset.
Control
)
¶Num
Get the depth offset of a control.
Control
, depth_offset: Num
)
¶None
Set the depth offset for a control, allowing you to move it in front or behind other controls if the generated depth doesnt work for you
Control
)
¶Bool
Check whether the input (usually mouse cursor) is currently in a control. (In sync with
UIEvent.enter
andUIEvent.exit
)
Control
)
¶Bool
Check whether the input (usually mouse cursor) is currently in a control and any of its buttons are pressed.
Control
, x: Num
, y: Num
)
¶Control
Get the top child control at a specific (absolute) point.
Control
)
¶Num
Get the amount of children a control has.
Control
, child: Control
)
¶Num
Get the index of a child control.
Control
, index: Num
)
¶Child
Get a child control by its index.
Control
, child: Control
, internal: Bool
)
¶None
Make a control the child control of another control. If you mark the child as internal, it wont be queried by other methods affecting children.
Control
, child: Control
)
¶None
Make a control the child control of another control. This means the childs position will be relative to its parent, layout depends a lot on those relationships and its used by functions like destroy_children.
//create parent var parent = Control.create(_ui) Control.set_bounds(parent, 200, 200, 100, 100) //create child var child = Control.create(_ui) Control.set_bounds(child, 25, 25, 50, 50) //parent child to parent Control.child_add(parent, child) var bounds = [0,0,0,0] Control.get_bounds_abs(child, bounds) Log.print(bounds) //[225, 225, 50, 50] Control.clear(parent, UIClear.destroy) Log.print(Control.child_count(parent)) //0 Log.print(Control.valid(child)) //false UI.commit(_ui)
Control
, child: Control
)
¶None
Remove a child from a control, unparenting it.
Control
, into: List
)
¶None
Get the combined bounds of all children of a control into a list
[x, y, width, height]
. The passed list must have at least 4 elements and the function will write into the first 4. Passing a list into the function instead of returning a value is to avoid allocating memory where not needed.
Control
, behave: UIBehave
)
¶None
Set how the control behaves in the layout as a child of its container. You can combine characteristics with a bit or operator (
|
).
Control
)
¶UIBehave
Returns the behave bitflags for the control
Control
, contain: UIContain
)
¶None
Set how the control behaves in the layout as a container of its children. You can combine characteristics with a bit or operator (
|
).
Control
)
¶UIContain
Returns the contain bitflags for the control
Control
, left: Num
, top: Num
, right: Num
, bottom: Num
)
¶None
Set the margins of a control. Only the margins set in
set_behave
are actually observed.
Control
, min_x: Num
, min_y: Num
, max_x: Num
, max_y: Num
)
¶None
Set the min and max size of a control when using layout.
Control
)
¶List
Get the margins of a control.
Control
, fn: Fn
)
¶None
Set a custom render function with the arguments
|control, state, x, y, w, h|
. Useful for making your own controls.
Control
, fn: Fn
)
¶String
Add a function to handle events on a control. Returns an
id
for the newly added event that can be used to remove it.var btn = UIButton.create(ui) UIButton.set_text(btn, "click me!") Control.set_events(btn) {|event| if(event.type == UIEvent.release) { Log.print("clicked button") } }
Control
, id: String
)
¶None
Remove an event handling function from a control. Takes in the id that was returned upon registering the function.
Control
, fn: Fn
)
¶None
Set a custom process function with the arguments
|control, state, event, x, y, w, h|
. Useful for making your own controls.
Control
)
¶Any
Get the state data associated with this control.
Control
, data: Any
)
¶None
Set state data associated with this control. Can be any wren object.