Custom UI
Overview
The Lua Menu Element Window module provides a range of functions for creating and managing custom GUI windows in Lua scripts. This module allows developers to design sophisticated interfaces with various visual elements and controls.
Create New Window 📃
core.menu.window.new(id)
-
id: String - The unique identifier for the window. -
Returns:
window- A new window instance.
Creates a new window with the specified ID. Remember this should always be called outside of the render callback, since we are creating a new unique instance of a window.
Set Initial Size 📃
window:set_initial_size(size)
size: vec2 - The initial size of the window.
This function just sets the initial size of the window. It can be overriden later, either by user input or by code by calling this function inside the render callback (this is not the recommended behaviour)
Set Initial Position 📃
window:set_initial_position(pos)
pos: vec2 - The initial position of the window.
This function just sets the initial position of the window. It can be overriden later, either by user input or by code by calling the "force_next_begin_window_pos" function inside the render callback (this is not the recommended behaviour)
Set Next Close Cross Position Offset 📃
window:set_next_close_cross_pos_offset(pos_offset)
pos_offset: vec2 - The position offset for the close cross.
This function will add an offset on the close cross position. By default, it is rendered at the top-right corner of the window.
Add Menu Element Position Offset 📃
window:add_menu_element_pos_offset(pos_offset)
pos_offset: vec2 - The position offset for menu elements.
This function will add a position offset to the internal dynamic position variable. See "The Advanceds - Explaining Dynamic Drawing" for a more in-depth explanation on the matter.
Get Window Size 📃
window:get_size()
- Returns: vec2 - The current size of the window.
Get Window Position 📃
window:get_position()
- Returns: vec2 - The current position of the window.
Get Mouse Position 📃
window:get_mouse_pos()
- Returns: vec2 - The current mouse position relative to the window.
Get Current Context Dynamic Drawing Offset 📃
window:get_current_context_dynamic_drawing_offset()
- Returns: vec2 - The current context dynamic drawing offset.
Retrieves the internal dynamic position variable's current value. See "The Advanceds - Explaining Dynamic Drawing" for a more in-depth explanation on the matter.
Get Text Size 📃
window:get_text_size(str)
-
str: String - The text to measure. -
Returns: vec2 - The size of the text.
Get Centered Text X Position 📃
window:get_text_centered_x_pos(text)
-
text: String - The text to center. -
Returns: Number - The X position offset for centered text.
After we get the centered text x position offset, we just need to add this value to the dynamic drawing offset by using "window:get_current_context_dynamic_drawing_offset()". Another option is to use the "Center Text" function directly (recommended)
Center Text 📃
window:center_text(text)
text: String - The text to center.
After calling this function, we just need to render the text using the "add_text_on_dynamic_pos" function. You will see that the text is centered in the middle of the window.
Render Text 🖌️
window:render_text(font_id, pos_offset, color, text)
font_id: Integer - The ID of the font to use.pos_offset: vec2 - The position offset for the text.color: color - The color of the text.text: String - The text to render.
Renders a text at the specified position with the given font and color. This function renders statically, so this text is not taken into account for the dynamic position offset.
Render Rectangle 🖌️
window:render_rect(pos_min_offset, pos_max_offset, color, rounding, thickness [, flags])
pos_min_offset: vec2 - The minimum position offset for the rectangle.pos_max_offset: vec2 - The maximum position offset for the rectangle.color: color - The color of the rectangle.rounding: Number - The rounding radius for the rectangle corners.thickness: Number - The thickness of the rectangle border.flags(Optional): Integer - Flags for rectangle rendering. Default is0.
NO_ROUNDING
ROUND_TOP_LEFT_CORNERS
ROUND_TOP_RIGHT_CORNERS
ROUND_BOTTOM_LEFT_CORNER
ROUND_BOTTOM_RIGHT_CORNER
ROUND_TOP_CORNERS
ROUND_BOTTOM_CORNERS
ROUND_LEFT_CORNERS
ROUND_RIGHT_CORNERS
ROUND_ALL_CORNERS
Renders a rectangle at the specified position with the given properties. This function renders statically, so this rectangle is not taken into account for the dynamic position offset.
Render Filled Rectangle 🖌️
window:render_rect_filled(pos_min_offset, pos_max_offset, color, rounding [, flags])
pos_min_offset: vec2 - The minimum position offset for the filled rectangle.pos_max_offset: vec2 - The maximum position offset for the filled rectangle.color: color - The fill color of the rectangle.rounding: Number - The rounding radius for the rectangle corners.flags(Optional): Integer - Flags for rectangle rendering. Default is0.
NO_ROUNDING
ROUND_TOP_LEFT_CORNERS
ROUND_TOP_RIGHT_CORNERS
ROUND_BOTTOM_LEFT_CORNER
ROUND_BOTTOM_RIGHT_CORNER
ROUND_TOP_CORNERS
ROUND_BOTTOM_CORNERS
ROUND_LEFT_CORNERS
ROUND_RIGHT_CORNERS
ROUND_ALL_CORNERS
Renders a filled rectangle at the specified position with the given properties. This function renders statically, so this rectangle is not taken into account for the dynamic position offset.
Render Filled Rectangle with Multiple Colors 🖌️
window:render_rect_filled_multicolor(pos_min_offset, pos_max_offset, col_upr_left, col_upr_right, col_bot_right, col_bot_left, rounding [, flags])
pos_min_offset: vec2 - The minimum position offset for the filled rectangle.pos_max_offset: vec2 - The maximum position offset for the filled rectangle.col_upr_left: color - The color for the upper-left corner.col_upr_right: color - The color for the upper-right corner.col_bot_right: color - The color for the bottom-right corner.col_bot_left: color - The color for the bottom-left corner.rounding: Number - The rounding radius for the rectangle corners.flags(Optional): Integer - Flags for rectangle rendering. Default is0.
NO_ROUNDING
ROUND_TOP_LEFT_CORNERS
ROUND_TOP_RIGHT_CORNERS
ROUND_BOTTOM_LEFT_CORNER
ROUND_BOTTOM_RIGHT_CORNER
ROUND_TOP_CORNERS
ROUND_BOTTOM_CORNERS
ROUND_LEFT_CORNERS
ROUND_RIGHT_CORNERS
ROUND_ALL_CORNERS
Renders a filled rectangle at the specified position with the given properties. This function renders statically, so this rectangle is not taken into account for the dynamic position offset. The specified colors will be blended so we recommend testing to get used to this function. You can achieve cool-looking visuals with this function. An example is the height / width resizing rectangles that appear when the mouse is hovering the draggable regions of the window. (You can see that on the bottom of the main menu, for example.)
Render Circle 🖌️
window:render_circle(center, radius, color [, num_segments [, thickness]])
center: vec2 - The center position of the circle.radius: Number - The radius of the circle.color: color - The color of the circle.num_segments(Optional): Integer - The number of segments for the circle. Default is0.thickness(Optional): Number - The thickness of the circle outline. Default is1.0.
Renders a circunference (non-filled circle) at the specified position with the given properties. This function renders statically, so this circle is not taken into account for the dynamic position offset.
Render Filled Circle 🖌️
window:render_circle_filled(center, radius, color [, num_segments])
center: vec2 - The center position of the circle.radius: Number - The radius of the circle.color: color - The fill color of the circle.num_segments(Optional): Integer - The number of segments for the circle. Default is0.
Renders a filled circle at the specified position with the given properties. This function renders statically, so this circle is not taken into account for the dynamic position offset.
Render Quadratic Bezier Curve 🖌️
window:render_bezier_quadratic(p1, p2, p3, color, num_segments, thickness)
p1: vec2 - The start point of the curve.p2: vec2 - The control point of the curve.p3: vec2 - The end point of the curve.color: color - The color of the curve.num_segments: Integer - The number of segments for the curve.thickness: Number - The thickness of the curve.
Renders a quadratic bezier curve at the specified position with the given properties. This function renders statically, so this curve is not taken into account for the dynamic position offset.