33#define MAX_UI_ELEMENTS 1024
34#define MAX_UI_CONTAINERS 1024
35#define UI_SCALE_WIDTH 2560
36#define UI_SCALE_HEIGHT 1920
37#define MAX_TEXT_BOXES 1024
38#define MAX_TEXT_BOX_CHARACTERS 256
39#define MAX_UI_CHILDREN 1024
175 "JUSTIFY_TOP_CENTER",
178 "JUSTIFY_BOTTOM_CENTER",
179 "JUSTIFY_BOTTOM_LEFT",
180 "JUSTIFY_BOTTOM_RIGHT"
213 "UI_INTERACTABLE_NONE",
214 "UI_INTERACTABLE_SLIDER",
215 "UI_INTERACTABLE_DROPDOWN",
216 "UI_INTERACTABLE_LABEL"
389 void * (*bind_fn)(
void*,
void *);
596 .color = (
vec4){0,0,1,1},
597 .fill = (
vec4){0,0,0,0},
598 .size = (
vec2){0.5,0.5},
599 .center = (
vec2){0,0},
602 .scale = (
vec2){50,50},
603 .shadow_dir = (
vec2){0.5, 0.5},
606 .translation = (
vec2){20,100},
607 .base_pos = (
vec2){20,100},
612 .already_hovered =
false,
615 .parent_container = -1,
636 .parent_dropdown = -1,
646 .scroll_offset = (
vec2){0,0},
647 .delta_scroll_offset = (
vec2){0,0},
648 .scroll_dir = (
vec2){0,1},
650 .padding = (
vec4){0,0,0,0},
664 .color = (
vec4){1,1,1,1},
665 .fill = (
vec4){0,0,0,0},
669 .start = (
vec2){0,0},
670 .center = (
vec2){0,0},
674 .scale = (
vec2){1,1},
675 .shadow_dir = (
vec2){0.5, -0.5},
678 .translation = (
vec2){0,0},
682 .parent_container = -1,
907 if (menu < 0 || menu >=
MENUS.
count)
return false;
int uID
The ID inside of UIMenu.containers.
vec2 drag_center_start
The translation of the UISlider on initial drag.
int parent_dropdown
The dropdown parent.
bool free
If this UIContainer is empty or can be replaced.
vec2 max
The max in pixel space.
vec2 delta_scroll_offset
The difference between this frame's scroll offset and the current.
int box
The TextBox index inside of the UIMenu.
bool mask
If the UIElements and TextBoxes contained should not be rendered if outside.
vec2 scroll_dir
The direction this container moves in when scrolled.
float prev_val
The previous value.
void(*) free_data(void *)
The function that frees the bound data.
float h
The height of the box after pseudo-rendering in determine_text_box_dimensions().
UIInteractableType interactable
The special interactable type this UIElement may be.
int id
The ID of the Font in FONTS.
bool dragging
If we are dragging this UISlider.
bool already_hovered
To avoid triggering hover events multiple times if not necessary.
float angle
Angle of rotation.
float w
The width of the box after pseudo-rendering in determine_text_box_dimensions().
float angle
The angle to transform this box to.
int xadvance
How much the x advances when it is typed.
UIValueType type
The type of value that is inside of data.
float min_val
The minimum value of the slider.
int font_id
The Font ID inside of FONTS.
int container
The UIContainer this UIElement may control.
bool wrap
If UIElements and TextBoxes wrap around the container (unused).
union UIElement::@017317244344356306005252125357265110320354311371 as
TextBox text_boxes[1024]
The TextBoxes.
int container
The UIContainer that this UISlider scrolls.
int tex_w
The texture dimensions.
vec2 size
Size of the SDF.
char name[256]
The name of the file path.
vec2 min
The min in pixel space.
float scroll_scale
How much the scroll is supposed to influence the UIContainer.
vec2 start
The start of the text in relation to .
UIElement elements[1024]
The UIElements.
Glyph * glyphs
Glyphs for each character.
float val
The current value between min and max val.
vec2 translation
X and Y coords where Y+ is down.
int scrollbar
The scrollbar UISlider UIElement.
vec2 translation
Where to place the center of the TextBox on the GPU.
UICallback action_callback
The event to occur on action (press or hold) or unaction.
vec4 padding
The padding before UIElements and TextBoxes are wrapped or masked.
vec2 shadow_dir
Which direction to offset the drop shadow in.
int text_cap
The amount of characters allocated.
uint32_t uID
The index inside of MENUS.
int parent_container
The UIContainer that contains this UIElement.
vec2 center
The center in relation to .
int menu
The UIMenu this UIElement is inside.
vec4 color
The color of the text.
Justify justify
How the text is centered in relation to and/or its UILabel.
Justify align
How the TextBox is justified within this UIElement.
float len
The length in pixel space.
uint32_t layer
The layer of the UIElement.
UIContainer containers[1024]
The UIContainers.
bool bind_self
If the UIElement should bind itself to this callback.
int xoffset
The x offset before the character.
bool one_shot
If this event only occurs on initial event.
uint32_t layer
Rendering sort key (lower drawn first).
UICallback hover_callback
The event to occur on hover or unhover.
int id
This ID == '<char>' when looking up which Glyph to use (ascii).
int parent_container
The UIContainer that contains this TextBox.
void(*) unaction_fn(void *)
The function called when action is stopped (if there is one).
int yoffset
The y offset before the character.
uint32_t uID
The ID inside of UIMenu.text_boxes.
char * text
The characters to render.
vec4 fill
The fill of the text.
size_t glyph_count
The amount of Glyphs.
vec2 scroll_offset
The current offset from .
size_t box_count
The amount of TextBoxes contained.
int element
Which UIElement owns this UIContainer.
vec2 scale
The scale for this box on the GPU.
vec2 drag_mouse_start
The mouse position on initial drag.
void(*) action_fn(void *)
The function called on action (if there is one).
int children[1024]
The IDs for UIElements contained.
void * data
The bind data.
size_t child_count
The amount of UIElements contained.
UIValueBehavior behavior
The control upon reaching min or max.
bool free
If this TextBox is empty and can be overwritten.
bool free
If the UIElement can be replaced or is empty.
uint32_t uID
The ID inside of UIMenu.
size_t texture
The Image ID.
char id[256]
The unique name of this menu.
vec2 dir
The direction it slides in.
int box_children[1024]
The IDs of TextBoxes contained.
int highest_dist
Used to determine the amount of space to cursor shift for newlines.
UIValue val
The value to change.
int menu
The UIMenu that this box is within.
float max_proj
The maximum projected scalar value.
vec2 base_pos
Where the element was before it was scrolled or manipulated somehow.
float radius
The radius of the circle OR the radius of a rectangle's corners.
float drag_start_scalar
The scalar value the slider starts at based on initial drag position.
int tex_h
The texture dimensions.
float text_size
The size to render the Font.
vec4 color
Color of the shape.
void * data
The data, which may be simply a pointer that is passed into a function instead of manipulated directl...
float max_val
The maximum value of the slider.
int highest_y
Used to determine the amount of space to cursor shift for newlines.
float shadow_dist
How far the drop shadow is.
int get_ui_element_from_coords(vec2 pos, int *menu_idx)
Finds a UIElement based on a screen position.
void assign_element_to_container(UIElement *el, UIContainer *c)
Assigns a UIElement to be parented to a UIContainer.
const char * JUSTIFY_NAMES[]
The names of Justify for the Editor UI.
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 move_element_to_menu(int element_idx, int current_menu, int target_menu)
Moves a UIElement from its current UIMenu to another UIMenu.
UIState
UIStates for UIElements.
UIValueType
Types of values that may be controlled by a UI event function pointer.
void delete_ui_element(int menu, int id)
Deletes a UIElement, removing it from its possible parent UIContainer and deleting its own possible U...
void remove_element_from_container(UIContainer *c, UIElement *el)
Removes a UIElement from a UIContainer.
int create_ui_element(int menu_id)
Creates a UIElement on a given UIMenu.
UIValueBehavior
Types of ways that UIValues may be controlled when they reach a minimum or maximum value.
#define MAX_UI_CONTAINERS
int find_text_box_in_menu(UIMenu *m, const char *id)
Finds a TextBox inside of a UIMenu via name.
UICallback DEFAULT_CALLBACK
UIElement DEFAULT_UI_ELEMENT
UIInteractableType
UIElement types for the union that describe unique functions.
UIContainer DEFAULT_UI_CONTAINER
void update_ui_state(float mouse_x, float mouse_y)
Handles the persistent UI state from previous frames.
void align_text_box_label(UIElement *el)
Aligns a TextBox inside of a UILabel based on its Justify.
void create_slider(UIElement *element, vec2 dir, float len)
Creates a UISlider from a UIElement.
void delete_ui_container(UIElement *el)
Deletes a UIContainer, removing all references to it from existing TextBoxes and UIElements on the sa...
int find_container_in_menu(UIMenu *m, const char *id)
Finds a UIContainer inside of a UIMenu via name.
const char * UI_INTERACTABLE_NAMES[]
UIElement interactable names for the union that describe unique functions.
void UI_INIT()
Simply frees the MENUS buffer and reinitializes the Vector.
void remove_text_box_from_container(UIContainer *c, TextBox *tb)
Removes a TextBox from a UIContainer.
void reassign_elements_to_container(UIElement *el)
Assigns all children based on current UIContainer children.
UIContainer * create_ui_container(UIElement *el, int menu_id)
Creates a UIContainer from a given UIElement a given UIMenu.
Justify
Options for Justifying TextBoxes inside of containers but also around the origin .
UIMenu * create_menu()
Creates a new UIMenu, expanding the MENUS Vector and sets all arrays to free.
void assign_text_box_to_container(TextBox *tb, UIContainer *c)
Assigns a TextBox to be parented to a UIContainer.
int find_ui_element_in_menu(UIMenu *m, const char *id)
Finds a UIElement inside of a UIMenu via name.
void compute_slider_bounds(UIElement *element)
Computes the minimum and maximum in UI space for a UISlider.
bool container_is_valid(int container, int menu)
Checks if a UIContainer and UIMenu ID pairing is valid.
UIElementType
Types of SDF shapes that are handled on the GPU.
void handle_ui_event(SDL_Event event, int mouse_x, int mouse_y)
Handles an incoming UI event.
vec2 screenspace_to_ui(vec2 pos)
Transfers a position to local UI space by multiplying it by a ratio of the two resolutions.
int get_text_box_from_coords(vec2 pos, int *menu_idx)
Finds a TextBox based on a screen position.
@ UISTATE_SELECTED
If the UIElement is selected in the Editor.
@ UI_INTERACTABLE_SLIDER
UISlider that can interpolate on a plane.
@ UI_INTERACTABLE_LABEL
References a TextBox that is Justified.
@ UI_INTERACTABLE_NONE
Normal UIElement.
@ UI_INTERACTABLE_DROPDOWN
Unfinished type.
A Font and its Glyphs used for rendering TextBoxes.
A single Glyph in a Font.
A structure holding a Font ID and text to be rendered and transformed with its properties.
The GPU-side representation of a TextBox.
Describes function pointers for UIElements that determine behavior on events.
UIContainer that contains both TextBoxes and UIElements and can mask and scroll them.
Unfinished structure for a dropdown that spawns UIElements and TextBoxes when opened.
UIElements that are contained within a UIMenu that may receive events, be contained within UIContaine...
The GPU-side representation of a UIElement.
UIElement UILabels that contain a TextBox reference.
UIElement sliders that interpolate between two points on a line.
A value that is manipulated in some way when a UIElement receives an event.
void init_vector(Vector *v, size_t i, size_t type_size)
void * vector_expand(Vector *v, size_t i)
#define CAST_VEC(vec, type)