52 printf(
"No empty element slot found\n");
72 if (el->
menu == -1)
return;
83 if (el->
free)
continue;
95 if (box->
free)
continue;
201 UIMenu * m = &ms[menu_id];
208 printf(
"No empty container slot found\n");
215 container->
uID = empty;
250 if (el->
free)
continue;
252 if (strcmp(el->
id,
id) == 0)
269 if (tb->
free)
continue;
271 if (strcmp(tb->
id,
id) == 0)
288 if (c->
free)
continue;
290 if (strcmp(c->
id,
id) == 0)
303 if (current_menu == -1 || element_idx == -1 || target_menu == -1)
return -1;
304 UIMenu * m = &ms[current_menu];
306 UIMenu * target = &ms[target_menu];
309 if (target_slot == -1)
return -1;
316 int uID = new_el->
uID;
321 new_el->
menu = target_menu;
322 new_el->
uID = target_slot;
333 if (current_menu == -1 || tb_idx == -1 || target_menu == -1)
return -1;
335 UIMenu * m = &ms[current_menu];
337 UIMenu * target = &ms[target_menu];
339 if (target_slot == -1)
return -1;
342 int uID = new_tb->
uID;
343 memcpy(new_tb, tb,
sizeof(
TextBox));
357 new_tb->
menu = target_menu;
358 new_tb->
uID = target_slot;
370 bool already_assigned =
false;
375 already_assigned =
true;
380 if (!already_assigned)
391 bool already_assigned =
false;
396 already_assigned =
true;
401 if (!already_assigned)
419 float el_hw = el->
scale.
x;
420 float el_hh = el->
scale.
y;
428 float left_tr = left_start + hw;
429 float right_tr = right_start - hw;
430 float top_tr = top_start;
431 float bottom_tr = bottom_start;
496 text_tr.
x *= scale_x;
497 text_tr.
y *= scale_y;
521 int highest_layer = -INFINITY;
522 int highest_tb_index = -1;
554 if (highest_layer < (
int)tb->
layer)
556 highest_layer = tb->
layer;
557 highest_tb_index = j;
565 return highest_tb_index;
577 int highest_layer = -INFINITY;
578 int highest_element_index = -1;
597 if (highest_layer < (
int)el->
layer)
599 highest_layer = el->
layer;
600 highest_element_index = j;
609 return highest_element_index;
666 float r = slider->
len / 2;
676 element->
as.label.box = box;
677 element->
as.label.parent_dropdown = parent_dropdown;
678 element->
as.label.align = justify;
687 element->
as.slider.len = len;
688 element->
as.slider.dir = dir;
689 element->
as.slider.scroll_scale = 1;
690 element->
as.slider.min_val = 0;
691 element->
as.slider.max_val = 100;
706 if (menu_idx != -1 && highest_ui_element_idx != -1)
709 highest_el = &els[highest_ui_element_idx];
727 bool processed_press =
false;
730 if (highest_el->
uID == el->
uID && menu_idx == i && event.type == SDL_MOUSEBUTTONDOWN)
732 processed_press =
true;
763 if (!processed_press)
829 if (el->
free)
continue;
840 vec2 mouse = {mouse_x * scale_x, mouse_y * scale_y};
848 new_scalar = fmaxf(0.0f, fminf(slider->
max_proj, new_scalar));
858 float start_scalar =
vec2_dot(from_min, slider->
dir);
859 start_scalar = fmaxf(0.0f, fminf(slider->
max_proj, start_scalar));
int find_empty_text_box_slot(UIMenu *m)
Finds an empty slot for a TextBox that is marked as free.
void delete_text_box(int menu, int id)
Deletes a TextBox and its text and frees it from the UIMenu.
Functions that modify TextBoxes and load Fonts.
int uID
The ID inside of UIMenu.containers.
vec2 drag_center_start
The translation of the UISlider on initial drag.
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.
char id[256]
The name of this TextBox.
vec2 scroll_dir
The direction this container moves in when scrolled.
float prev_val
The previous value.
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.
bool dragging
If we are dragging this UISlider.
bool already_hovered
To avoid triggering hover events multiple times if not necessary.
float w
The width of the box after pseudo-rendering in determine_text_box_dimensions().
UIValueType type
The type of value that is inside of data.
char id[256]
The name of this UIContainer.
float min_val
The minimum value of the slider.
int container
The UIContainer this UIElement may control.
union UIElement::@017317244344356306005252125357265110320354311371 as
TextBox text_boxes[1024]
The TextBoxes.
int container
The UIContainer that this UISlider scrolls.
vec2 size
Size of the SDF.
union UIValue::@252221077172357350267050072076221061202345253170 max_val
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.
float val
The current value between min and max val.
vec2 translation
X and Y coords where Y+ is down.
union UIValue::@033233014044001351273032017075321074265046133265 inc_val
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.
int text_cap
The amount of characters allocated.
int parent_container
The UIContainer that contains this UIElement.
char id[256]
The name of this UIElement.
int menu
The UIMenu this UIElement is inside.
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 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 parent_container
The UIContainer that contains this TextBox.
uint32_t uID
The ID inside of UIMenu.text_boxes.
char * text
The characters to render.
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.
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.
vec2 dir
The direction it slides in.
int box_children[1024]
The IDs of TextBoxes contained.
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.
union UIValue::@221204347253153306173144256317051244116101305363 min_val
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 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.
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.
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.
#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
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.
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 .
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.
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.
@ UI_INTERACTABLE_SLIDER
UISlider that can interpolate on a plane.
A structure holding a Font ID and text to be rendered and transformed with its properties.
Describes function pointers for UIElements that determine behavior on events.
UIContainer that contains both TextBoxes and UIElements and can mask and scroll them.
UIElements that are contained within a UIMenu that may receive events, be contained within UIContaine...
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.
float vec2_dot(vec2 a, vec2 b)
vec2 vec2_add(vec2 a, vec2 b)
vec2 vec2_scale(vec2 a, float b)
vec2 vec2_sub(vec2 a, vec2 b)
float lerp(float a, float b, float t)
float vec2_length(vec2 v)
float SDF_rect(vec2 p, vec2 center, vec2 size, float r)
float SDF_circle(vec2 p, vec2 center, float radius)
void process_ui_event(UICallback *callback)
int find_empty_container_slot(UIMenu *m)
void create_label(UIElement *element, int box, int parent_dropdown, Justify justify)
vec2 screenspace_to_ui_element_local(UIElement *el, float scale_x, float scale_y, vec2 pos)
void scroll_container(UIContainer *c, UISlider *slider, UIMenu *m)
bool point_inside_ui_element(UIElement *el, vec2 pos)
int find_empty_element_slot(UIMenu *m)
bool is_hovering_ui_element(UIElement *el, vec2 pos)
The standalone UI library that controls text rendering, ui rendering, and events.
#define CAST_VEC(vec, type)
bool vec2_inside_bounds(vec2 p, vec2 min, vec2 max)
#define REMOVE_FROM_ARR(arr, index, count)