crystal.UIElement

Base class for all UI building blocks.

Elements of this class draw nothing and cannot have children.

Constructor

crystal.UIElement:new()

Methods

Lifecycle

Name Description
update_tree Computes layout and runs update logic for this element and all its descendants.
draw_tree Draws this element and all its descendants.

Hierarchy

Name Description
is_root Returns whether this element is the root of its element tree.
is_within Returns whether this element is a descendant of another one.
joint Returns the joint specifying how this element should be laid out by its parent.
parent Returns this element’s parent.
remove_from_parent Removes this element from its parent.
root Returns the root of this element’s tree.

Layout

Name Description
size Returns this element’s width and height, as computed during update_tree.

Rendering

Name Description
color Returns this element’s color multiplier.
opacity Returns this element’s opacity.
pivot Returns this element’s pivot, around which it scales and rotates.
rotation Returns this element’s rotation angle.
scale Returns this element’s scaling factors.
set_color Sets this element’s color multiplier.
set_opacity Sets this element’s opacity.
set_pivot_x Sets the horizontal position of this element’s pivot.
set_pivot_y Sets the vertical position of this element’s pivot.
set_pivot Sets this element’s pivot, around which it scales and rotates.
set_rotation Sets this element’s rotation angle.
set_scale_x Sets this element’s horizontal scaling factor.
set_scale_y Sets this element’s vertical scaling factor.
set_scale Sets this element’s scaling factors.
set_translation_x Sets this element’s horizontal translation.
set_translation_y Sets this element’s vertical translation.
set_translation Sets this element’s translation.
translation Returns this element’s translation.

Input Handling

Name Description
action_pressed Executes callbacks bound to an action being pressed.
action_released Executes callbacks bound to an action being released.
active_bindings Returns a table of active input bindings within this element.
bind_input Binds an input action to a callback function.
can_receive_input Returns whether this element can currently receive input actions.
focus_tree Gives focus to the first focusable element within this one (including itself).
focus Gives focus to this element.
focused_element Returns a focused element within this one.
is_active Returns whether this element is active.
is_focusable Returns whether this element is focusable.
is_focused Returns whether this element is currently focused by a specific player.
player_index Returns which player is allowed to focus and emit inputs to this element and its descendents.
set_active Sets whether this element is active.
set_focusable Sets whether this element is focusable.
set_player_index Sets or clears which player is allowed to focus and emit inputs to this element and its descendents.
unbind_input Removes a previously bound input callback.
unfocus_tree Unfocuses all elements within this one (including itself).

Mouse Interactions

Name Description
update_mouse_target Executes callbacks related to mouse hovering according to cursor position.
disable_mouse Prevents this element from being the mouse target.
enable_mouse Allows this element to be the mouse target when hovered.
is_mouse_enabled Returns whether this element can be the mouse target.
is_mouse_inside Returns whether the mouse target is an element inside this one (or itself).
is_mouse_over Returns whether this element is the current mouse target.

Implementing Custom Elements

Advanced

Name Description
compute_desired_size Computes the size requested by this element for layout purposes.
desired_size Returns this element’s desired size.
draw_self Draws this element and all its descendants.
first_focusable Returns the first focusable element inside this one (or itself).
next_focusable Returns the next focusable element from this one in the specified direction.
overlaps_mouse Returns whether this element can become the mouse target, given a specific player index and mouse position.
set_relative_position Sets this element’s position relative to its parent top-left corner.
transform Returns the global Transform in use last time this element was drawn.
update Runs frame-based logic.

Callbacks

Name Description
on_focus Called when this element gains focus.
on_mouse_enter Called when this element or one of its descendents becomes the mouse target.
on_mouse_leave Called when the mouse target is no longer this element or one of its descendents.
on_mouse_out Called when this element is no longer the mouse target.
on_mouse_over Called when this element becomes the mouse target.
on_unfocus Called when this element loses focus.

This site uses Just the Docs, a documentation theme for Jekyll.