CPP-TOOLBOX
Loading...
Searching...
No Matches
UI Class Reference

#include <ui.hpp>

Public Member Functions

 UI (float z_layer, UniqueIDGenerator &abs_pos_object_id_generator)
 
void process_mouse_position (const glm::vec2 &mouse_pos_ndc)
 
void process_mouse_just_clicked (const glm::vec2 &mouse_pos_ndc)
 
bool process_mouse_just_clicked_on_clickable_textboxes (const glm::vec2 &mouse_pos_ndc)
 
bool process_mouse_just_clicked_on_input_boxes (const glm::vec2 &mouse_pos_ndc)
 
bool process_mouse_just_clicked_on_dropdown_options (const glm::vec2 &mouse_pos_ndc)
 
bool process_mouse_just_clicked_on_dropdowns (const glm::vec2 &mouse_pos_ndc)
 
void unfocus_input_box (UIInputBox &ib)
 
void unfocus_input_box (int input_box_eid)
 
void focus_input_box (UIInputBox &ib)
 
void focus_input_box (int input_box_eid)
 
void update_dropdown_option (UIDropdown &dropdown, const std::string &option_name)
 
void process_key_press (const std::string &character_pressed)
 
void process_confirm_action ()
 
void process_delete_action ()
 
void add_colored_rectangle (vertex_geometry::Rectangle ndc_rectangle, const glm::vec3 &normalized_rgb)
 
void add_colored_rectangle (float x_pos_ndc, float y_pos_ndc, float width, float height, const glm::vec3 &normalized_rgb)
 
int add_textbox (const std::string &text, vertex_geometry::Rectangle ndc_text_rectangle, const glm::vec3 &normalized_rgb)
 
int add_textbox (const std::string &text, float center_x_pos_ndc, float center_y_pos_ndc, float width, float height, const glm::vec3 &normalized_rgb)
 
void hide_textbox (int doid)
 
void unhide_textbox (int doid)
 
void modify_text_of_a_textbox (int doid, std::string new_text)
 
void modify_colored_rectangle (int doid, vertex_geometry::Rectangle ndc_rectangle)
 
UITextBoxget_textbox (int doid)
 
UIInputBoxget_inputbox (int doid)
 
UIRectget_colored_rectangle (int doid)
 
int add_clickable_textbox (std::function< void()> on_click, std::function< void()> on_hover, const std::string &text, float x_pos_ndc, float y_pos_ndc, float width, float height, const glm::vec3 &regular_color, const glm::vec3 &hover_color)
 
int add_clickable_textbox (std::function< void()> on_click, std::function< void()> on_hover, const std::string &text, vertex_geometry::Rectangle &rect, const glm::vec3 &regular_color, const glm::vec3 &hover_color)
 
int add_dropdown (std::function< void()> on_click, std::function< void()> on_hover, int dropdown_option_idx, const vertex_geometry::Rectangle &rect, const glm::vec3 &regular_color, const glm::vec3 &hover_color, const std::vector< std::string > &options, std::function< void(std::string)> option_on_click, std::function< void(std::string)> option_on_hover, const glm::vec3 &option_color=glm::vec3(0), const glm::vec3 &option_hover_color=glm::vec3(0))
 Adds a dropdown UI element with a main button and multiple selectable options.
 
bool remove_clickable_textbox (int do_id)
 
bool remove_textbox (int do_id)
 
UIClickableTextBoxget_clickable_textbox (int do_id)
 
int add_input_box (std::function< void(std::string)> on_confirm, const std::string &placeholder_text, const vertex_geometry::Rectangle &ndc_rect, const glm::vec3 &regular_color, const glm::vec3 &focused_color)
 
int add_input_box (std::function< void(std::string)> on_confirm, const std::string &placeholder_text, float x_pos_ndc, float y_pos_ndc, float width, float height, const glm::vec3 &regular_color, const glm::vec3 &focused_color)
 
const std::vector< UIClickableTextBox > & get_clickable_text_boxes () const
 
const std::vector< UIDropdown > & get_dropdowns () const
 
const std::vector< UIInputBox > & get_input_boxes () const
 
const std::vector< UITextBox > & get_text_boxes () const
 
const std::vector< UIRect > & get_colored_boxes () const
 

Public Attributes

Logger logger {"ui"}
 
float z_layer
 
float background_layer
 
float text_layer
 
float dropdown_background_layer
 
float dropdown_text_layer
 
UniqueIDGenerator ui_id_generator
 
UniqueIDGeneratorabs_pos_object_id_generator
 

Constructor & Destructor Documentation

◆ UI()

UI::UI ( float z_layer,
UniqueIDGenerator & abs_pos_object_id_generator )
inline

Member Function Documentation

◆ add_clickable_textbox() [1/2]

int UI::add_clickable_textbox ( std::function< void()> on_click,
std::function< void()> on_hover,
const std::string & text,
float x_pos_ndc,
float y_pos_ndc,
float width,
float height,
const glm::vec3 & regular_color,
const glm::vec3 & hover_color )

◆ add_clickable_textbox() [2/2]

int UI::add_clickable_textbox ( std::function< void()> on_click,
std::function< void()> on_hover,
const std::string & text,
vertex_geometry::Rectangle & rect,
const glm::vec3 & regular_color,
const glm::vec3 & hover_color )

◆ add_colored_rectangle() [1/2]

void UI::add_colored_rectangle ( float x_pos_ndc,
float y_pos_ndc,
float width,
float height,
const glm::vec3 & normalized_rgb )

◆ add_colored_rectangle() [2/2]

void UI::add_colored_rectangle ( vertex_geometry::Rectangle ndc_rectangle,
const glm::vec3 & normalized_rgb )

◆ add_dropdown()

int UI::add_dropdown ( std::function< void()> on_click,
std::function< void()> on_hover,
int dropdown_option_idx,
const vertex_geometry::Rectangle & rect,
const glm::vec3 & regular_color,
const glm::vec3 & hover_color,
const std::vector< std::string > & options,
std::function< void(std::string)> option_on_click,
std::function< void(std::string)> option_on_hover,
const glm::vec3 & option_color = glm::vec3(0),
const glm::vec3 & option_hover_color = glm::vec3(0) )

Adds a dropdown UI element with a main button and multiple selectable options.

This function creates a dropdown menu consisting of a main button (displaying one of the given options) and a list of selectable dropdown options. Each element in the dropdown (main button and options) is represented as rectangles with text overlays, and is assigned unique internal IDs for rendering and event handling.

Parameters
on_clickCallback triggered when the main dropdown button is clicked.
on_hoverCallback triggered when the main dropdown button is hovered over.
dropdown_option_idxIndex of the option in options to display as the initially selected option.
rectThe rectangle defining the size and position of the dropdown button.
regular_colorThe background color of the main dropdown button in its normal state.
hover_colorThe background color of the main dropdown button when hovered over.
optionsA list of strings representing the dropdown options to display.
option_on_clickCallback triggered when a dropdown option is clicked. Receives the option string as input.
option_on_hoverCallback triggered when a dropdown option is hovered over. Receives the option string as input.
option_colorThe background color of dropdown options in their normal state. If (0,0,0), a default darker variant of regular_color is used.
option_hover_colorThe background color of dropdown options when hovered. If (0,0,0), a default darker variant of hover_color is used.
Returns
int A unique ID representing the created dropdown element. This ID can be used to reference or remove the dropdown from the UI system later.
Note
  • Each dropdown option is positioned below the main button by sliding the rectangle downward.
  • Colors default to dimmed versions of the main button colors if option-specific colors are not provided.
  • All internal geometry is generated and registered with unique IDs for rendering and event management.
Bug
options must not be empty or else it crashes, also dropdown_option_idx must be a valid index of options
See also
UIDropdown, UIDropdownOption

◆ add_input_box() [1/2]

int UI::add_input_box ( std::function< void(std::string)> on_confirm,
const std::string & placeholder_text,
const vertex_geometry::Rectangle & ndc_rect,
const glm::vec3 & regular_color,
const glm::vec3 & focused_color )

◆ add_input_box() [2/2]

int UI::add_input_box ( std::function< void(std::string)> on_confirm,
const std::string & placeholder_text,
float x_pos_ndc,
float y_pos_ndc,
float width,
float height,
const glm::vec3 & regular_color,
const glm::vec3 & focused_color )

◆ add_textbox() [1/2]

int UI::add_textbox ( const std::string & text,
float center_x_pos_ndc,
float center_y_pos_ndc,
float width,
float height,
const glm::vec3 & normalized_rgb )

◆ add_textbox() [2/2]

int UI::add_textbox ( const std::string & text,
vertex_geometry::Rectangle ndc_text_rectangle,
const glm::vec3 & normalized_rgb )

◆ focus_input_box() [1/2]

void UI::focus_input_box ( int input_box_eid)

◆ focus_input_box() [2/2]

void UI::focus_input_box ( UIInputBox & ib)

◆ get_clickable_text_boxes()

const std::vector< UIClickableTextBox > & UI::get_clickable_text_boxes ( ) const

◆ get_clickable_textbox()

UIClickableTextBox * UI::get_clickable_textbox ( int do_id)

◆ get_colored_boxes()

const std::vector< UIRect > & UI::get_colored_boxes ( ) const

◆ get_colored_rectangle()

UIRect * UI::get_colored_rectangle ( int doid)

◆ get_dropdowns()

const std::vector< UIDropdown > & UI::get_dropdowns ( ) const

◆ get_input_boxes()

const std::vector< UIInputBox > & UI::get_input_boxes ( ) const

◆ get_inputbox()

UIInputBox * UI::get_inputbox ( int doid)

◆ get_text_boxes()

const std::vector< UITextBox > & UI::get_text_boxes ( ) const

◆ get_textbox()

UITextBox * UI::get_textbox ( int doid)

◆ hide_textbox()

void UI::hide_textbox ( int doid)

◆ modify_colored_rectangle()

void UI::modify_colored_rectangle ( int doid,
vertex_geometry::Rectangle ndc_rectangle )

◆ modify_text_of_a_textbox()

void UI::modify_text_of_a_textbox ( int doid,
std::string new_text )

◆ process_confirm_action()

void UI::process_confirm_action ( )

◆ process_delete_action()

void UI::process_delete_action ( )

◆ process_key_press()

void UI::process_key_press ( const std::string & character_pressed)

◆ process_mouse_just_clicked()

void UI::process_mouse_just_clicked ( const glm::vec2 & mouse_pos_ndc)

◆ process_mouse_just_clicked_on_clickable_textboxes()

bool UI::process_mouse_just_clicked_on_clickable_textboxes ( const glm::vec2 & mouse_pos_ndc)

◆ process_mouse_just_clicked_on_dropdown_options()

bool UI::process_mouse_just_clicked_on_dropdown_options ( const glm::vec2 & mouse_pos_ndc)

◆ process_mouse_just_clicked_on_dropdowns()

bool UI::process_mouse_just_clicked_on_dropdowns ( const glm::vec2 & mouse_pos_ndc)

◆ process_mouse_just_clicked_on_input_boxes()

bool UI::process_mouse_just_clicked_on_input_boxes ( const glm::vec2 & mouse_pos_ndc)

◆ process_mouse_position()

void UI::process_mouse_position ( const glm::vec2 & mouse_pos_ndc)

◆ remove_clickable_textbox()

bool UI::remove_clickable_textbox ( int do_id)

◆ remove_textbox()

bool UI::remove_textbox ( int do_id)

◆ unfocus_input_box() [1/2]

void UI::unfocus_input_box ( int input_box_eid)

◆ unfocus_input_box() [2/2]

void UI::unfocus_input_box ( UIInputBox & ib)

◆ unhide_textbox()

void UI::unhide_textbox ( int doid)

◆ update_dropdown_option()

void UI::update_dropdown_option ( UIDropdown & dropdown,
const std::string & option_name )

Member Data Documentation

◆ abs_pos_object_id_generator

UniqueIDGenerator& UI::abs_pos_object_id_generator

◆ background_layer

float UI::background_layer

◆ dropdown_background_layer

float UI::dropdown_background_layer

◆ dropdown_text_layer

float UI::dropdown_text_layer

◆ logger

Logger UI::logger {"ui"}

◆ text_layer

float UI::text_layer

◆ ui_id_generator

UniqueIDGenerator UI::ui_id_generator

◆ z_layer

float UI::z_layer

The documentation for this class was generated from the following files: