Untitled
Loading...
Searching...
No Matches
UI System

The structures, functions, constants, and variables within the UI and text rendering system. More...

Data Structures

struct  Glyph
 A single Glyph in a Font. More...
struct  Font
 A Font and its Glyphs used for rendering TextBoxes. More...
struct  TextBoxGPU
 The GPU-side representation of a TextBox. More...
struct  UIElementGPU
 The GPU-side representation of a UIElement. More...
struct  UIContainer
 UIContainer that contains both TextBoxes and UIElements and can mask and scroll them. More...
struct  TextBox
 A structure holding a Font ID and text to be rendered and transformed with its properties. More...
struct  UIValue
 A value that is manipulated in some way when a UIElement receives an event. More...
union  UIValue::[union].min_val
 The minimum value data can become. More...
union  UIValue::[union].max_val
 The maximum value data can become. More...
union  UIValue::[union].inc_val
 How much data should be incremented. More...
struct  UICallback
 Describes function pointers for UIElements that determine behavior on events. More...
struct  UILabel
 UIElement UILabels that contain a TextBox reference. More...
struct  UIElement
 UIElements that are contained within a UIMenu that may receive events, be contained within UIContainers, or be UIContainers themselves. More...
union  UIElement::[union].as
struct  UIMenu
 The top-most UI structure that contains UIElements, TextBoxes, and UIContainers. More...
struct  UISlider
 UIElement sliders that interpolate between two points on a line. More...
struct  UIDropdown
 Unfinished structure for a dropdown that spawns UIElements and TextBoxes when opened. More...

Enumerations

enum  Justify {
  JUSTIFY_CENTER , JUSTIFY_LEFT , JUSTIFY_RIGHT , JUSTIFY_TOP_CENTER , JUSTIFY_TOP_LEFT , JUSTIFY_TOP_RIGHT , JUSTIFY_BOTTOM_CENTER , JUSTIFY_BOTTOM_LEFT ,
  JUSTIFY_BOTTOM_RIGHT , JUSTIFY_MAX
}
 Options for Justifying TextBoxes inside of containers but also around the origin \((0,0)\). More...
enum  UIState { UISTATE_NONE , UISTATE_HOVERED , UISTATE_PRESSED , UISTATE_SELECTED }
 UIStates for UIElements. More...
enum  UIInteractableType { UI_INTERACTABLE_NONE , UI_INTERACTABLE_SLIDER , UI_INTERACTABLE_DROPDOWN , UI_INTERACTABLE_LABEL , UI_INTERACTABLE_MAX }
 UIElement types for the union that describe unique functions. More...
enum  UIElementType { UIELEMENT_RECT , UIELEMENT_CIRCLE , UIELEMENT_TYPE_MAX }
 Types of SDF shapes that are handled on the GPU. More...
enum  UIValueType { UIVAL_NONE , UIVAL_BOOL , UIVAL_INT , UIVAL_FLOAT , UIVAL_CALLBACK }
 Types of values that may be controlled by a UI event function pointer. More...
enum  UIValueBehavior { UIVALBEHAVIOR_NONE , UIVALBEHAVIOR_WRAP , UIVALBEHAVIOR_CLAMP }
 Types of ways that UIValues may be controlled when they reach a minimum or maximum value. More...

Functions

int move_element_to_menu (int element_idx, int current_menu, int target_menu)
 Moves a UIElement from its current UIMenu to another UIMenu.
int move_text_box_to_menu (int tb_idx, int current_menu, int target_menu)
 Moves a TextBox from its current UIMenu to another UIMenu.
int get_text_box_from_coords (vec2 pos, int *menu_idx)
 Finds a TextBox based on a screen position.
int get_ui_element_from_coords (vec2 pos, int *menu_idx)
 Finds a UIElement based on a screen position.
int create_ui_element (int menu_id)
 Creates a UIElement on a given UIMenu.
UIContainer * create_ui_container (UIElement *el, int menu_id)
 Creates a UIContainer from a given UIElement a given UIMenu.
void delete_ui_element (int menu, int id)
 Deletes a UIElement, removing it from its possible parent UIContainer and deleting its own possible UIContainer.
void delete_ui_container (UIElement *el)
 Deletes a UIContainer, removing all references to it from existing TextBoxes and UIElements on the same UIMenu.
void handle_ui_event (SDL_Event event, int mouse_x, int mouse_y)
 Handles an incoming UI event.
void update_ui_state (float mouse_x, float mouse_y)
 Handles the persistent UI state from previous frames.
void compute_slider_bounds (UIElement *element)
 Computes the minimum and maximum in UI space for a UISlider.
void create_slider (UIElement *element, vec2 dir, float len)
 Creates a UISlider from a UIElement.
void remove_element_from_container (UIContainer *c, UIElement *el)
 Removes a UIElement from a UIContainer.
void remove_text_box_from_container (UIContainer *c, TextBox *tb)
 Removes a TextBox from a UIContainer.
int find_ui_element_in_menu (UIMenu *m, const char *id)
 Finds a UIElement inside of a UIMenu via name.
int find_text_box_in_menu (UIMenu *m, const char *id)
 Finds a TextBox inside of a UIMenu via name.
int find_container_in_menu (UIMenu *m, const char *id)
 Finds a UIContainer inside of a UIMenu via name.
void align_text_box_label (UIElement *el)
 Aligns a TextBox inside of a UILabel based on its Justify.
void assign_element_to_container (UIElement *el, UIContainer *c)
 Assigns a UIElement to be parented to a UIContainer.
void assign_text_box_to_container (TextBox *tb, UIContainer *c)
 Assigns a TextBox to be parented to a UIContainer.
void reassign_elements_to_container (UIElement *el)
 Assigns all children based on current UIContainer children.
void UI_INIT ()
 Simply frees the MENUS buffer and reinitializes the Vector.
UIMenu * create_menu ()
 Creates a new UIMenu, expanding the MENUS Vector and sets all arrays to free.
bool container_is_valid (int container, int menu)
 Checks if a UIContainer and UIMenu ID pairing is valid.
vec2 screenspace_to_ui (vec2 pos)
 Transfers a position to local UI space by multiplying it by a ratio of the two resolutions.

Variables

Vector MENUS
 All UIMenus.
const char * JUSTIFY_NAMES []
 The names of Justify for the Editor UI.
const char * UI_INTERACTABLE_NAMES []
 UIElement interactable names for the union that describe unique functions.

FBO Size

The size of the rendering FBO, used to convert from screenspace to local UI space.

int TEXT_WIDTH
int TEXT_HEIGHT

Default Structures

Safe defaults for each UI structure.

UICallback DEFAULT_CALLBACK
UIElement DEFAULT_UI_ELEMENT
UISlider DEFAULT_SLIDER
UILabel DEFAULT_LABEL
UIContainer DEFAULT_UI_CONTAINER
TextBox DEFAULT_TEXT_BOX

UI Constants

Sizes of UI arrays and UI Scale.

Todo
Make UI scale dynamic.
#define MAX_UI_ELEMENTS   1024
#define MAX_UI_CONTAINERS   1024
#define UI_SCALE_WIDTH   2560
#define UI_SCALE_HEIGHT   1920
#define MAX_TEXT_BOXES   1024
#define MAX_TEXT_BOX_CHARACTERS   256
#define MAX_UI_CHILDREN   1024
#define MAX_GLYPHS   256

Detailed Description

The structures, functions, constants, and variables within the UI and text rendering system.


Data Structure Documentation

◆ Glyph

struct Glyph

A single Glyph in a Font.

Note
w_t and h_t are the texture size of the Font Image (parsed from json). x and y are the positions on the texture. w_c and h_c are the character sizes from json.
See also
Font
TextBox

Definition at line 52 of file ui.h.

Data Fields
int id This ID == '<char>' when looking up which Glyph to use (ascii).
float u0 \(x/w_t\).
float v0 \(y/h_t\).
float u1 \((x+w_c)/w_t\).
float v1 \((y+h_c)/h_t\).
int width \(w_c\).
int height \(h_c\).
int xoffset The x offset before the character.
int yoffset The y offset before the character.
int xadvance How much the x advances when it is typed.

◆ Font

struct Font

A Font and its Glyphs used for rendering TextBoxes.

Todo
Figure out if highest_y is actually used.
See also
Glyph
TextBox
FONTS

Definition at line 74 of file ui.h.

Data Fields
int id The ID of the Font in FONTS.
size_t texture The Image ID.
Glyph * glyphs Glyphs for each character.
size_t glyph_count The amount of Glyphs.
int tex_w The texture dimensions.
int tex_h The texture dimensions.
int highest_y Used to determine the amount of space to cursor shift for newlines.
int highest_dist Used to determine the amount of space to cursor shift for newlines.
char name[256] The name of the file path.

◆ TextBoxGPU

struct TextBoxGPU

The GPU-side representation of a TextBox.

See also
Glyph
TextBox
FONTS

Definition at line 94 of file ui.h.

Data Fields
uint32_t visible
uint32_t hovered
uint32_t shadow
float shadow_dist
uint32_t container_id
uint32_t mask
vec2 shadow_dir
uint32_t state
uint32_t pad0
uint32_t pad1
uint32_t pad2
vec4 color
vec4 fill
mat4 model

◆ UIElementGPU

struct UIElementGPU

The GPU-side representation of a UIElement.

See also
UIElement
UIContainer
UIMenu

Definition at line 120 of file ui.h.

Data Fields
uint32_t visible
uint32_t hovered
uint32_t shadow
float shadow_dist
vec2 pos
vec2 size
vec2 shadow_dir
uint32_t state
uint32_t type
vec4 color
vec4 fill
vec4 padding
vec2 translation
vec2 scale
float radius
uint32_t masked
uint32_t container_id
uint32_t pad0
mat4 model

◆ UIContainer

struct UIContainer

UIContainer that contains both TextBoxes and UIElements and can mask and scroll them.

See also
UIElement
TextBox

Definition at line 224 of file ui.h.

Data Fields
int uID The ID inside of UIMenu.containers.
bool free If this UIContainer is empty or can be replaced.
vec2 scroll_offset The current offset from \((0,0)\).
vec2 delta_scroll_offset The difference between this frame's scroll offset and the current.
vec2 scroll_dir The direction this container moves in when scrolled.
bool wrap If UIElements and TextBoxes wrap around the container (unused).
vec4 padding The padding before UIElements and TextBoxes are wrapped or masked.
bool mask If the UIElements and TextBoxes contained should not be rendered if outside.
int children[1024] The IDs for UIElements contained.
size_t child_count The amount of UIElements contained.
int box_children[1024] The IDs of TextBoxes contained.
size_t box_count The amount of TextBoxes contained.
int element Which UIElement owns this UIContainer.
Note
-1 if empty.
int scrollbar The scrollbar UISlider UIElement.
Note
-1 if empty.
char id[256] The name of this UIContainer.
Note
default is "default".

◆ TextBox

struct TextBox

A structure holding a Font ID and text to be rendered and transformed with its properties.

See also
Font
UIMenu
Todo
Go through some of these members like hovered and see if necessary.

Definition at line 5 of file text.vert.

Data Fields
uint visible
uint hovered
uint shadow
float shadow_dist How far the drop shadow is.
uint container_id
uint mask
vec2 shadow_dir Which direction to offset the drop shadow in.
uint state
uint pad0
uint pad1
uint pad2
vec4 color The color of the text.
vec4 fill The fill of the text.

(unused)

mat4 model
bool hovered Currently this indicates if this TextBox is hovered since it does not receive events.
bool shadow If there is a drop shadow.
bool visible If the TextBox is visible.
bool free If this TextBox is empty and can be overwritten.
int font_id The Font ID inside of FONTS.
uint32_t uID The ID inside of UIMenu.text_boxes.
Justify justify How the text is centered in relation to \((0,0)\) and/or its UILabel.
char * text The characters to render.
Note
Allocated, set to NULL.
int text_cap The amount of characters allocated.
float text_size The size to render the Font.
float w The width of the box after pseudo-rendering in determine_text_box_dimensions().
float h The height of the box after pseudo-rendering in determine_text_box_dimensions().
vec2 translation Where to place the center of the TextBox on the GPU.
float angle The angle to transform this box to.
vec2 scale The scale for this box on the GPU.
vec2 center The center in relation to \((0,0)\).
vec2 start The start of the text in relation to \((0,0)\).
uint32_t layer Rendering sort key (lower drawn first).
UIState state Only currently indicates if this TextBox is selected in the editor UI.
int menu The UIMenu that this box is within.
int parent_container The UIContainer that contains this TextBox.
Note
Defaults to -1.
char id[256] The name of this TextBox.
Note
Default is "default".

◆ UIValue

struct UIValue

A value that is manipulated in some way when a UIElement receives an event.

See also
UIElement
process_ui_event()

Definition at line 343 of file ui.h.

Data Fields
UIValueType type The type of value that is inside of data.
UIValueBehavior behavior The control upon reaching min or max.
union min_val
union max_val
union inc_val
void * data The data, which may be simply a pointer that is passed into a function instead of manipulated directly.

◆ UIValue::[union].min_val

union UIValue::[union].min_val

The minimum value data can become.

Definition at line 350 of file ui.h.

Data Fields
int min_int
float min_flt

◆ UIValue::[union].max_val

union UIValue::[union].max_val

The maximum value data can become.

Definition at line 359 of file ui.h.

Data Fields
int max_int
float max_flt

◆ UIValue::[union].inc_val

union UIValue::[union].inc_val

How much data should be incremented.

Definition at line 367 of file ui.h.

Data Fields
int inc_int
float inc_flt

◆ UICallback

struct UICallback

Describes function pointers for UIElements that determine behavior on events.

See also
UIElement
UIValue
process_ui_event()

Definition at line 382 of file ui.h.

Data Fields
bool bind_self If the UIElement should bind itself to this callback.
bool one_shot If this event only occurs on initial event.
UIValue val The value to change.
void(*) action_fn(void *) The function called on action (if there is one).
void(*) unaction_fn(void *) The function called when action is stopped (if there is one).
void *(*) bind_fn(void *, void *) The function that binds data to data on initialization.
void * data The bind data.
void(*) free_data(void *) The function that frees the bound data.
char id[256] The name of this UICallback inside of its registry.

◆ UILabel

struct UILabel

UIElement UILabels that contain a TextBox reference.

UI_INTERACTABLE_LABEL

See also
UIElement
UIContainer
UIInteractableType
TextBox

Definition at line 490 of file ui.h.

Data Fields
int box The TextBox index inside of the UIMenu.
Justify align How the TextBox is justified within this UIElement.
int parent_dropdown The dropdown parent.
Note
Defaults to -1.

◆ UIElement

struct UIElement

UIElements that are contained within a UIMenu that may receive events, be contained within UIContainers, or be UIContainers themselves.

See also
UIContainer
UIMenu
UIInteractableType
Todo
Clear unused fields.

Definition at line 31 of file text.vert.

Data Fields
uint visible
uint hovered
uint shadow
float shadow_dist Unused.
vec2 pos
vec2 size Size of the SDF.
See also
ui/ui.frag
vec2 shadow_dir Unused.
uint state
uint type
vec4 color Color of the shape.
vec4 fill Unused.
vec4 padding
vec2 translation X and Y coords where Y+ is down.
vec2 scale Scale.
float radius The radius of the circle OR the radius of a rectangle's corners.
uint masked
uint container_id
uint pad0
mat4 model
bool shadow Unused - If the UIElement has a shadow.
bool visible If the UIElement is visible.
bool free If the UIElement can be replaced or is empty.
UIElementType type The type of SDF function to render.
uint32_t uID The ID inside of UIMenu.
vec2 base_pos Where the element was before it was scrolled or manipulated somehow.

So that we have an anchor point.

float angle Angle of rotation.
vec2 center The center.

Should be at \((0,0)\).

uint32_t layer The layer of the UIElement.

Lower = bottom-most and drawn first. Higher elements consume events.

UICallback action_callback The event to occur on action (press or hold) or unaction.
UICallback hover_callback The event to occur on hover or unhover.
bool already_hovered To avoid triggering hover events multiple times if not necessary.
UIState state The current state of the element.
int menu The UIMenu this UIElement is inside.
Warning
Defaults to undefined value.
int container The UIContainer this UIElement may control.
Note
Defaults to -1.
int parent_container The UIContainer that contains this UIElement.
Note
Defaults to -1.
char id[256] The name of this UIElement.
Note
Defaults to "default".
UIInteractableType interactable The special interactable type this UIElement may be.
union as

◆ UIElement::[union].as

union UIElement::[union].as

Definition at line 545 of file ui.h.

Data Fields
UIDropdown dropdown
UILabel label
UISlider slider

◆ UIMenu

struct UIMenu

The top-most UI structure that contains UIElements, TextBoxes, and UIContainers.

See also
UIContainer
UIElement
TextBox

Definition at line 561 of file ui.h.

Data Fields
uint32_t uID The index inside of MENUS.
char id[256] The unique name of this menu.
UIElement elements[1024] The UIElements.
TextBox text_boxes[1024] The TextBoxes.
UIContainer containers[1024] The UIContainers.

◆ UISlider

struct UISlider

UIElement sliders that interpolate between two points on a line.

AKA scrollbars. UI_INTERACTABLE_SLIDER

See also
UIElement
UIContainer
UIInteractableType
process_ui_event()
update_ui_state()
compute_slider_bounds()

Definition at line 406 of file ui.h.

Data Fields
vec2 dir The direction it slides in.
vec2 min The min in pixel space.
vec2 max The max in pixel space.
float len The length in pixel space.
float val The current value between min and max val.
Note
\(d_s\) = UISlider.drag_mouse_start
\(v\) = UISlider.dir
\(m_p\) = UISlider.max_proj
\(s\) = UISlider.drag_start_scalar
\(m\) = \(\mathrm{Mouse\ Coords} * (\mathrm{UI\ Scale} / \mathrm{FBO\ Size})\)
\(n_v\) = UISlider.val
\(n_v = clamp(((m - d_s) \cdot v) + s, 0, m_p) / m_p\)
float prev_val The previous value.
float min_val The minimum value of the slider.
float max_val The maximum value of the slider.
float scroll_scale How much the scroll is supposed to influence the UIContainer.
bool dragging If we are dragging this UISlider.
vec2 drag_mouse_start The mouse position on initial drag.
vec2 drag_center_start The translation of the UISlider on initial drag.
float drag_start_scalar The scalar value the slider starts at based on initial drag position.
Note
\(e\) = UIElement.translation
\(x_0\) = UISlider.min
\(v\) = UISlider.dir
\(m_p\) = UISlider.max_proj
\(s\) = UISlider.drag_start_scalar
\(s = clamp((e - x_0) \cdot v, 0, m_p)\)
float max_proj The maximum projected scalar value.
Note
\(x_0\) = UISlider.min
\(x_1\) = UISlider.max
\(m_p\) = UISlider.max_proj
\(m_p = ||x_1 - x_0||\)
int container The UIContainer that this UISlider scrolls.
Note
Defaults to -1.

◆ UIDropdown

struct UIDropdown

Unfinished structure for a dropdown that spawns UIElements and TextBoxes when opened.

Definition at line 461 of file ui.h.

Macro Definition Documentation

◆ MAX_UI_ELEMENTS

◆ MAX_UI_CONTAINERS

◆ UI_SCALE_WIDTH

◆ UI_SCALE_HEIGHT

◆ MAX_TEXT_BOXES

◆ MAX_TEXT_BOX_CHARACTERS

#define MAX_TEXT_BOX_CHARACTERS   256

Definition at line 38 of file ui.h.

Referenced by init().

◆ MAX_UI_CHILDREN

#define MAX_UI_CHILDREN   1024

Definition at line 39 of file ui.h.

◆ MAX_GLYPHS

#define MAX_GLYPHS   256

Definition at line 40 of file ui.h.

Enumeration Type Documentation

◆ Justify

enum Justify

Options for Justifying TextBoxes inside of containers but also around the origin \((0,0)\).

Enumerator
JUSTIFY_CENTER 
JUSTIFY_LEFT 
JUSTIFY_RIGHT 
JUSTIFY_TOP_CENTER 
JUSTIFY_TOP_LEFT 
JUSTIFY_TOP_RIGHT 
JUSTIFY_BOTTOM_CENTER 
JUSTIFY_BOTTOM_LEFT 
JUSTIFY_BOTTOM_RIGHT 
JUSTIFY_MAX 

Definition at line 151 of file ui.h.

◆ UIState

enum UIState

UIStates for UIElements.

Enumerator
UISTATE_NONE 
UISTATE_HOVERED 
UISTATE_PRESSED 
UISTATE_SELECTED 

If the UIElement is selected in the Editor.

Definition at line 186 of file ui.h.

◆ UIInteractableType

UIElement types for the union that describe unique functions.

Enumerator
UI_INTERACTABLE_NONE 

Normal UIElement.

UI_INTERACTABLE_SLIDER 

UISlider that can interpolate on a plane.

UI_INTERACTABLE_DROPDOWN 

Unfinished type.

UI_INTERACTABLE_LABEL 

References a TextBox that is Justified.

UI_INTERACTABLE_MAX 

Definition at line 197 of file ui.h.

◆ UIElementType

Types of SDF shapes that are handled on the GPU.

See also
ui/ui.frag
UIElement
Enumerator
UIELEMENT_RECT 
UIELEMENT_CIRCLE 
UIELEMENT_TYPE_MAX 

Definition at line 301 of file ui.h.

◆ UIValueType

Types of values that may be controlled by a UI event function pointer.

See also
UIElement
process_ui_event()
Enumerator
UIVAL_NONE 
UIVAL_BOOL 
UIVAL_INT 
UIVAL_FLOAT 
UIVAL_CALLBACK 

Definition at line 312 of file ui.h.

◆ UIValueBehavior

Types of ways that UIValues may be controlled when they reach a minimum or maximum value.

See also
UIElement
process_ui_event()
Enumerator
UIVALBEHAVIOR_NONE 
UIVALBEHAVIOR_WRAP 
UIVALBEHAVIOR_CLAMP 

Definition at line 328 of file ui.h.

Function Documentation

◆ move_element_to_menu()

int move_element_to_menu ( int element_idx,
int current_menu,
int target_menu )

Moves a UIElement from its current UIMenu to another UIMenu.

Parameters
element_idxThe UIElement index into the current UIMenu.
current_menuThe current UIMenu.
target_menuThe target UIMenu.
Returns
The resulting index into the new UIMenu.

Definition at line 299 of file ui.c.

References CAST_VEC, UIElement::container, delete_ui_container(), delete_ui_element(), UIMenu::elements, find_empty_element_slot(), UIElement::menu, MENUS, move_element_to_menu(), UIElement::parent_container, and UIElement::uID.

Referenced by move_element_to_menu(), and render_ui_menu().

◆ move_text_box_to_menu()

int move_text_box_to_menu ( int tb_idx,
int current_menu,
int target_menu )

Moves a TextBox from its current UIMenu to another UIMenu.

Parameters
tb_idxThe TextBox index inside of the current UIMenu.
current_menuThe current UIMenu.
target_menuThe target UIMenu.
Returns
The resulting index into the new UIMenu.

Definition at line 329 of file ui.c.

References CAST_VEC, delete_text_box(), find_empty_text_box_slot(), TextBox::menu, MENUS, move_text_box_to_menu(), TextBox::text, UIMenu::text_boxes, TextBox::text_cap, and TextBox::uID.

Referenced by move_text_box_to_menu(), and render_text_menu().

◆ get_text_box_from_coords()

int get_text_box_from_coords ( vec2 pos,
int * menu_idx )

Finds a TextBox based on a screen position.

Transfers the screenspace pos to UI space.

Parameters
posThe screenspace position.
menu_idxThe out pointer to a UIMenu index.
Returns
The TextBox index.
Warning
returns -1 if none found.

Definition at line 515 of file ui.c.

References CAST_VEC, Vector::count, TextBox::free, get_text_box_from_coords(), TextBox::h, TextBox::layer, MAX_TEXT_BOXES, MENUS, TextBox::scale, screenspace_to_ui(), TextBox::start, UIMenu::text_boxes, TEXT_HEIGHT, TEXT_WIDTH, TextBox::translation, UI_SCALE_HEIGHT, UI_SCALE_WIDTH, vec2_add(), vec2_inside_bounds(), TextBox::visible, TextBox::w, vec2::x, and vec2::y.

Referenced by get_text_box_from_coords(), and handle_ui_selection_event().

◆ get_ui_element_from_coords()

int get_ui_element_from_coords ( vec2 pos,
int * menu_idx )

Finds a UIElement based on a screen position.

Transfers the screenspace pos to UI space.

Parameters
posThe screenspace position.
menu_idxThe out pointer to a UIMenu index.
Returns
The UIElement index.
Warning
returns -1 if none found.

Definition at line 570 of file ui.c.

References CAST_VEC, Vector::count, UIMenu::elements, UIElement::free, get_ui_element_from_coords(), UIElement::layer, MAX_UI_ELEMENTS, MENUS, point_inside_ui_element(), screenspace_to_ui_element_local(), TEXT_HEIGHT, TEXT_WIDTH, UI_SCALE_HEIGHT, UI_SCALE_WIDTH, and UIElement::visible.

Referenced by get_ui_element_from_coords(), handle_ui_event(), and handle_ui_selection_event().

◆ create_ui_element()

int create_ui_element ( int menu_id)

◆ create_ui_container()

UIContainer * create_ui_container ( UIElement * el,
int menu_id )

Creates a UIContainer from a given UIElement a given UIMenu.

Parameters
elThe target UIElement.
menu_idThe target UIMenu.
Todo
menu_id should be the same as the UIElement's menu_id. Just use the UIElement's.
Returns
The pointer to the UIContainer.

Definition at line 197 of file ui.c.

References CAST_VEC, UIElement::container, UIMenu::containers, create_ui_container(), DEFAULT_UI_CONTAINER, UIContainer::element, find_empty_container_slot(), MENUS, UIContainer::uID, and UIElement::uID.

Referenced by create_ui_container(), and render_ui_menu().

◆ delete_ui_element()

void delete_ui_element ( int menu,
int id )

Deletes a UIElement, removing it from its possible parent UIContainer and deleting its own possible UIContainer.

Parameters
menuThe target UIMenu.
idThe target UIElement.

Definition at line 176 of file ui.c.

References CAST_VEC, UIElement::container, UIMenu::containers, delete_ui_container(), delete_ui_element(), UIMenu::elements, UIElement::free, MENUS, UIElement::parent_container, and remove_element_from_container().

Referenced by delete_ui_element(), execute_ui_element_undo(), move_element_to_menu(), and render_ui_menu().

◆ delete_ui_container()

void delete_ui_container ( UIElement * el)

Deletes a UIContainer, removing all references to it from existing TextBoxes and UIElements on the same UIMenu.

Parameters
elThe pointer to the UIElement that owns the UIContainer.
Todo
Possible that a pointer is too much to ask, but think through the cases.

Definition at line 68 of file ui.c.

References CAST_VEC, UIElement::container, UIMenu::containers, DEFAULT_UI_CONTAINER, delete_ui_container(), UIMenu::elements, TextBox::free, UIContainer::free, UIElement::free, MAX_TEXT_BOXES, MAX_UI_ELEMENTS, UIElement::menu, MENUS, TextBox::parent_container, UIElement::parent_container, UIMenu::text_boxes, and UIContainer::uID.

Referenced by delete_ui_container(), delete_ui_element(), execute_ui_element_undo(), move_element_to_menu(), and render_ui_menu().

◆ handle_ui_event()

void handle_ui_event ( SDL_Event event,
int mouse_x,
int mouse_y )

◆ update_ui_state()

void update_ui_state ( float mouse_x,
float mouse_y )

◆ compute_slider_bounds()

void compute_slider_bounds ( UIElement * element)

Computes the minimum and maximum in UI space for a UISlider.

Parameters
elementThe UIElement that is the UISlider.

Definition at line 663 of file ui.c.

References UIElement::as, compute_slider_bounds(), UISlider::dir, UISlider::len, UISlider::max, UISlider::max_proj, UISlider::min, UIElement::translation, vec2_add(), vec2_length(), vec2_scale(), and vec2_sub().

Referenced by compute_slider_bounds(), create_slider(), and render_ui_menu().

◆ create_slider()

void create_slider ( UIElement * element,
vec2 dir,
float len )

Creates a UISlider from a UIElement.

Parameters
elementThe target UIElement.
dirThe UISlider direction.
lenThe length of the UISlider.

Definition at line 682 of file ui.c.

References UIElement::as, compute_slider_bounds(), UIElement::container, create_slider(), UIElement::interactable, and UI_INTERACTABLE_SLIDER.

Referenced by create_slider().

◆ remove_element_from_container()

void remove_element_from_container ( UIContainer * c,
UIElement * el )

◆ remove_text_box_from_container()

void remove_text_box_from_container ( UIContainer * c,
TextBox * tb )

Removes a TextBox from a UIContainer.

Shifts the rest of the children array forward.

Parameters
cThe TextBox.
elThe UIElement.

Definition at line 157 of file ui.c.

References UIContainer::box_children, UIContainer::box_count, REMOVE_FROM_ARR, remove_text_box_from_container(), and TextBox::uID.

Referenced by delete_text_box(), execute_text_box_undo(), remove_text_box_from_container(), and render_text_menu().

◆ find_ui_element_in_menu()

int find_ui_element_in_menu ( UIMenu * m,
const char * id )

Finds a UIElement inside of a UIMenu via name.

Parameters
mThe UIMenu to search.
idThe name string to compare.
Returns
The index of the UIElement.

Definition at line 242 of file ui.c.

References UIMenu::elements, find_ui_element_in_menu(), UIElement::free, UIElement::id, MAX_UI_ELEMENTS, and UIElement::uID.

Referenced by find_ui_element_in_menu().

◆ find_text_box_in_menu()

int find_text_box_in_menu ( UIMenu * m,
const char * id )

Finds a TextBox inside of a UIMenu via name.

Parameters
mThe UIMenu to search.
idThe name string to compare.
Returns
The index of the TextBox.

Definition at line 261 of file ui.c.

References find_text_box_in_menu(), TextBox::free, TextBox::id, MAX_TEXT_BOXES, UIMenu::text_boxes, and TextBox::uID.

Referenced by find_text_box_in_menu(), and render_ui_menu().

◆ find_container_in_menu()

int find_container_in_menu ( UIMenu * m,
const char * id )

Finds a UIContainer inside of a UIMenu via name.

Parameters
mThe UIMenu to search.
idThe name string to compare.
Returns
The index of the UIContainer.

Definition at line 280 of file ui.c.

References UIMenu::containers, find_container_in_menu(), UIContainer::free, UIContainer::id, MAX_UI_CONTAINERS, and UIContainer::uID.

Referenced by find_container_in_menu().

◆ align_text_box_label()

◆ assign_element_to_container()

void assign_element_to_container ( UIElement * el,
UIContainer * c )

◆ assign_text_box_to_container()

void assign_text_box_to_container ( TextBox * tb,
UIContainer * c )

Assigns a TextBox to be parented to a UIContainer.

Parameters
elThe TextBox to assign.
cThe target parent UIContainer.

Definition at line 388 of file ui.c.

References assign_text_box_to_container(), UIContainer::box_children, UIContainer::box_count, TextBox::parent_container, TextBox::uID, and UIContainer::uID.

Referenced by assign_text_box_to_container(), execute_text_box_undo(), and render_text_menu().

◆ reassign_elements_to_container()

void reassign_elements_to_container ( UIElement * el)

Assigns all children based on current UIContainer children.

Note
This is used during redo, where all of the children have been changed and we need to relink them.
Parameters
elThe UIElement that is the UIContainer.

Definition at line 114 of file ui.c.

References UIContainer::box_children, UIContainer::box_count, CAST_VEC, UIContainer::child_count, UIContainer::children, UIElement::container, UIMenu::containers, UIMenu::elements, UIElement::menu, MENUS, TextBox::parent_container, UIElement::parent_container, reassign_elements_to_container(), UIMenu::text_boxes, and UIContainer::uID.

Referenced by execute_ui_element_undo(), and reassign_elements_to_container().

◆ UI_INIT()

void UI_INIT ( )
inline

Simply frees the MENUS buffer and reinitializes the Vector.

Definition at line 864 of file ui.h.

References Vector::buffer, init_vector(), MENUS, and UI_INIT().

Referenced by init(), and UI_INIT().

◆ create_menu()

UIMenu * create_menu ( )
inline

◆ container_is_valid()

bool container_is_valid ( int container,
int menu )
inline

Checks if a UIContainer and UIMenu ID pairing is valid.

Note
Used in the Editor to see if UIElements have valid UIContainers.
Parameters
containerThe UIContainer ID.
menuThe UIMenu ID.
Returns
True if the container is valid.

Definition at line 905 of file ui.h.

References CAST_VEC, container_is_valid(), UIMenu::containers, Vector::count, UIContainer::free, MAX_UI_CONTAINERS, MENUS, and UIContainer::uID.

Referenced by container_is_valid(), GPU_upload_singular_element(), GPU_upload_ui_elements(), render_text_menu(), render_ui_menu(), and upload_parent_container().

◆ screenspace_to_ui()

vec2 screenspace_to_ui ( vec2 pos)
inline

Transfers a position to local UI space by multiplying it by a ratio of the two resolutions.

Parameters
posThe position to transfer.
Returns
The UI space position.

Definition at line 934 of file ui.h.

References screenspace_to_ui(), TEXT_HEIGHT, TEXT_WIDTH, UI_SCALE_HEIGHT, UI_SCALE_WIDTH, vec2::x, and vec2::y.

Referenced by get_text_box_from_coords(), handle_ui_selection_event(), and screenspace_to_ui().

Variable Documentation

◆ TEXT_WIDTH

◆ TEXT_HEIGHT

◆ MENUS

◆ JUSTIFY_NAMES

const char* JUSTIFY_NAMES[]
Initial value:
=
{
"JUSTIFY_CENTER",
"JUSTIFY_LEFT",
"JUSTIFY_RIGHT",
"JUSTIFY_TOP_CENTER",
"JUSTIFY_TOP_LEFT",
"JUSTIFY_TOP_RIGHT",
"JUSTIFY_BOTTOM_CENTER",
"JUSTIFY_BOTTOM_LEFT",
"JUSTIFY_BOTTOM_RIGHT"
}

The names of Justify for the Editor UI.

Definition at line 170 of file ui.h.

Referenced by render_ui_menu().

◆ UI_INTERACTABLE_NAMES

const char* UI_INTERACTABLE_NAMES[]
Initial value:
=
{
"UI_INTERACTABLE_NONE",
"UI_INTERACTABLE_SLIDER",
"UI_INTERACTABLE_DROPDOWN",
"UI_INTERACTABLE_LABEL"
}

UIElement interactable names for the union that describe unique functions.

Definition at line 211 of file ui.h.

Referenced by render_ui_menu().

◆ DEFAULT_CALLBACK

UICallback DEFAULT_CALLBACK
Initial value:
=
{
.id = "empty",
.action_fn = NULL,
.unaction_fn = NULL,
.bind_fn = NULL,
.bind_self = true,
.data = NULL,
.free_data = NULL,
.val.data = NULL,
.val.type = UIVAL_NONE,
.one_shot = false
}
@ UIVAL_NONE
Definition ui.h:315

Definition at line 579 of file ui.h.

Referenced by create_ui_element().

◆ DEFAULT_UI_ELEMENT

UIElement DEFAULT_UI_ELEMENT
Initial value:
=
{
.free = 0,
.color = (vec4){0,0,1,1},
.fill = (vec4){0,0,0,0},
.size = (vec2){0.5,0.5},
.center = (vec2){0,0},
.uID = 0,
.angle = 0,
.scale = (vec2){50,50},
.shadow_dir = (vec2){0.5, 0.5},
.shadow = true,
.shadow_dist = 20,
.translation = (vec2){20,100},
.base_pos = (vec2){20,100},
.type = UIELEMENT_RECT,
.radius = 0.0f,
.visible = true,
.layer = 0,
.already_hovered = false,
.state = UISTATE_NONE,
.container = -1,
.parent_container = -1,
.id = "default",
.interactable = UI_INTERACTABLE_NONE
}
@ UISTATE_NONE
Definition ui.h:188
@ UI_INTERACTABLE_NONE
Normal UIElement.
Definition ui.h:200
@ UIELEMENT_RECT
Definition ui.h:303
Definition types.h:13

Definition at line 593 of file ui.h.

Referenced by create_ui_element().

◆ DEFAULT_SLIDER

UISlider DEFAULT_SLIDER
Initial value:
=
{
.container = -1,
.len = 100,
.dir = (vec2){0, 1},
.scroll_scale = 1,
.min_val = 0,
.max_val = 100
}
Definition types.h:11

Definition at line 620 of file ui.h.

Referenced by render_ui_menu().

◆ DEFAULT_LABEL

UILabel DEFAULT_LABEL
Initial value:
=
{
.box = -1,
.parent_dropdown = -1,
.align = JUSTIFY_CENTER
}
@ JUSTIFY_CENTER
Definition ui.h:154

Definition at line 632 of file ui.h.

Referenced by render_ui_menu().

◆ DEFAULT_UI_CONTAINER

UIContainer DEFAULT_UI_CONTAINER
Initial value:
=
{
.free = 0,
.uID = -1,
.scroll_offset = (vec2){0,0},
.delta_scroll_offset = (vec2){0,0},
.scroll_dir = (vec2){0,1},
.wrap = false,
.padding = (vec4){0,0,0,0},
.mask = true,
.children = {0},
.child_count = 0,
.box_children = {0},
.box_count = 0,
.element = -1,
.scrollbar = -1,
.id = "default"
}

Definition at line 642 of file ui.h.

Referenced by create_ui_container(), and delete_ui_container().

◆ DEFAULT_TEXT_BOX

TextBox DEFAULT_TEXT_BOX
Initial value:
=
{
.free = 0,
.color = (vec4){1,1,1,1},
.fill = (vec4){0,0,0,0},
.font_id = 0,
.w = 500,
.h = 500,
.start = (vec2){0,0},
.center = (vec2){0,0},
.uID = 0,
.text_size = 0.6,
.angle = 0,
.scale = (vec2){1,1},
.shadow_dir = (vec2){0.5, -0.5},
.shadow = true,
.shadow_dist = 20,
.translation = (vec2){0,0},
.text = NULL,
.justify = JUSTIFY_CENTER,
.visible = true,
.parent_container = -1,
.menu = -1,
.id = "default",
.text_cap = 0,
.layer = 0
}

Definition at line 661 of file ui.h.

Referenced by create_performance_overlay(), create_text_box(), and delete_text_box().