Skip to content

luxe: ui/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…

var ui = Entity.create(ui)
UI.create(ui, 0, 0, width, height, 0, ui_camera)
var control = Control.create(ui)

Control.create(ui_entity : Entity) : Control

Create a “blank” control for layout or custom input/drawing. Returns the new Control.

Control.create(ui_entity : Entity, type_id : String) : Control

Create a typed control. Returns the new Control.

Control.destroy(control : Control) : None

Destroy an existing control.

var control = Control.create(_ui)
//do stuff and then later...
Control.destroy(control)

Control.destroy_children(control : Control) : None

Destroy the children of a control.

Control.valid(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.get_ui(control : 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

Control.get(id : 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

Control.exists(id : String) : Bool

Check if a control with a specific id exists.

Control.clear(control : Control, uiclear_action : UIClear) : None

Clear the children of a control in a specific manner.

Control.press(control : Control, state : Bool) : None

Send a press or release event to the control (in the center of the control)

Control.enter(control : Control, state : Bool) : None

Send a enter or exit event to the control

Control.can_see(control : Control) : Bool

Returns true if this control can be seen, or false if clipped.

Control.can_see_area(control : Control, area : Rect) : Bool

Returns true if the area at this control can be seen or false if clipped.

Control.can_see_point(control : Control, point : Vec) : Bool

Returns true if the point at this control can be seen or false if clipped.

Control.point_inside(control : Control, point : Vec) : Bool

Returns true if the point is inside the bounds of the control. Ignores visibility etc.

Control.get_data(control : Control) : Block

Get the data block for this control

Control.set_type(control : Control, type : String) : unknown

no docs found

Control.get_type(control : Control) : unknown

no docs found

Control.set_id(control : 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.get_id(control : Control) : String

Retrieve the id of a control.

Control.get_bounds_abs(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.get_bounds(control : 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.set_allow_bounds_event(control : 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.get_allow_bounds_event(control : Control) : Bool

Returns true if this control sends bounds events.

Control.set_bounds_abs(control : Control, x : Num, y : Num, w : Num, h : Num) : None

Set the control bounds(position and size) relative to the UI modifier.

Control.set_bounds(control : Control, x : Num, y : Num, w : Num, h : Num) : None

Set the control bounds(position and size) relative to the parent control.

Control.set_pos_abs(control : Control, x : Num, y : Num) : None

Set the control position relative to the UI modifier.

Control.set_pos(control : Control, x : Num, y : Num) : None

Set the control position relative to the parent control, or UI modifier if no parent exists.

Control.set_system_cursor(control : Control, cursor : SystemCursor) : None

If the control has input enabled, when entered it will set the system cursor to the given type.

Control.set_size(control : Control, w : Num, h : Num) : None

Set the control size.

Control.get_pos_x(control : Control) : Num

Get the control position x component relative to its parent control.

Control.get_pos_x_abs(control : Control) : Num

Get the control position x component.

Control.get_pos_y(control : Control) : Num

Get the control position y component relative to its parent control.

Control.get_pos_y_abs(control : Control) : Num

Get the control position y component.

Control.get_width(control : Control) : Num

Get the control width.

Control.get_height(control : Control) : Num

Get the control height.

Control.contains(control : Control, x : Num, y : Num) : Bool

Check whether the a point is within the control bounds

Control.get_entity(control : Control) : Entity

Get the entity that has the UI modifier the control in.

Control.get_parent(control : Control) : Control

Get the entity this entity is a child of or null if there isnt any.

Control.get_allow_input(control : Control) : Bool

Get whether the control recieves input events in its set_process function.

Control.set_allow_input(control : Control, allow : Bool) : None

Set whether the control recieves input events in its set_process function.

Control.set_allow_drag(control : Control, allow : Bool, tag : String) : None

Set whether the control recieves drag events

Control.set_droppable_payload(control : 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.get_droppable_payload(control : Control) : Handle

Get the drop payload for this control

Control.set_droppable_tags(control : Control, tags : List) : None

Set the droppable tags that are allowed for this control, as an array of strings

Control.get_droppable_tags(control : Control) : List

Get the droppable tags that are allowed for this control, as an array of strings

Control.get_attached(control : Control) : Entity

If used via luxe: system/ui/control.modifier, returns the entity this control belongs to. Entity.none is returned if not

Control.get_allow_keys(control : Control) : Bool

Get whether the control recieves key events in its set_process function.

Control.set_allow_keys(control : Control, allow : Bool) : None

Set whether the control recieves key events in its set_process function.

Control.get_allow_tab(control : Control) : Bool

Get whether the control can be “tabbed” to.

Control.set_allow_tab(control : Control, allow : Bool) : None

Set whether the control can be “tabbed” to.

Control.get_visible(control : Control) : Bool

Get whether a control is visible.

Control.set_visible(control : 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.get_opacity(control : Control) : Num

Get a control opacity value.

Control.set_opacity(control : Control, opacity : Num) : None

Set a control opacity value. Affects children opacity as well.

Control.get_disabled(control : Control) : Bool

Get whether a control is disabled. This refers to the “inputable” state of inputs like buttons or text fields.

Control.set_disabled(control : Control, disabled : Bool) : None

Set whether a control is disabled. This refers to the “inputable” state of inputs like buttons or text fields.

Control.get_enabled(control : Control) : Bool

Get whether a control is enabled. This refers to the “inputable” state of inputs like buttons or text fields.

Control.set_enabled(control : Control, enabled : Bool) : None

Set whether a control is enabled. This refers to the “inputable” state of inputs like buttons or text fields.

Control.get_clip(control : Control) : Bool

Get whether a control should clip its contents.

Control.set_clip(control : Control, clip : Bool) : None

Set whether a control should clip its contents.

Control.get_nodes(control : 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.get_depth(control : Control) : Num

Get the depth generated for a control, not including the depth offset.

Control.get_depth_offset(control : Control) : Num

Get the depth offset of a control.

Control.set_depth_offset(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.get_input_inside(control : Control) : Bool

Check whether the input (usually mouse cursor) is currently in a control. (In sync with UIEvent.enter and UIEvent.exit)

Control.get_input_pressed(control : Control) : Bool

Check whether the input (usually mouse cursor) is currently in a control and any of its buttons are pressed.

Control.child_at_point(control : Control, x : Num, y : Num) : Control

Get the top child control at a specific (absolute) point.

Control.child_count(control : Control) : Num

Get the amount of children a control has.

Control.child_index(control : Control, child : Control) : Num

Get the index of a child control.

Control.child_get(control : Control, index : Num) : Child

Get a child control by its index.

Control.child_add(control : 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_add(control : 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_remove(control : Control, child : Control) : None

Remove a child from a control, unparenting it.

Control.children_bounds(control : 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.set_behave(control : 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.get_behave(control : Control) : UIBehave

Returns the behave bitflags for the control

Control.set_contain(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.get_contain(control : Control) : UIContain

Returns the contain bitflags for the control

Control.set_margin(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.set_limits(control : 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.get_margin(control : Control) : List

Get the margins of a control.

Control.set_render(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.set_events(control : 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.unset_events(control : Control) : None

Remove all event handling functions from a control.

Control.unset_events(control : Control, id : String) : None

Remove an event handling function from a control. Takes in the id that was returned upon registering the function.

Control.set_process(control : 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.get_state_data(control : Control) : Any

Get the state data associated with this control.

Control.set_state_data(control : Control, data : Any) : None

Set state data associated with this control. Can be any wren object.

Control.data(control : Control) : Any

Get the data block for this control