Untitled
Loading...
Searching...
No Matches
ui.h File Reference

The standalone UI library that controls text rendering, ui rendering, and events. More...

#include "utilities/utilities.h"
#include "SDL2/SDL.h"

Go to the source code of this file.

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...
struct  UICallback
 Describes function pointers for UIElements that determine behavior on events. 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...
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...
struct  UIMenu
 The top-most UI structure that contains UIElements, TextBoxes, and UIContainers. More...

Macros

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

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

Detailed Description

The standalone UI library that controls text rendering, ui rendering, and events.

Definition in file ui.h.