Symphony Of Empires
UI::Widget Class Reference

The master widget all the other widgets inherit from, do not use directly instead use one of the many derivated widgets - unless you're making a new widget type. More...

#include <widget.hpp>

Inheritance diagram for UI::Widget:
Collaboration diagram for UI::Widget:

Public Member Functions

 Widget ()=default
 
 Widget (Widget *parent, int x, int y, unsigned w, unsigned h, WidgetType type)
 
 Widget (Widget *parent, int x, int y, unsigned w, unsigned h, WidgetType type, std::shared_ptr< Eng3D::Texture > tex)
 
 Widget (const Widget &)=default
 
 Widget (Widget &&) noexcept=default
 
Widgetoperator= (Widget &) noexcept=default
 
Widgetoperator= (const Widget &)=default
 
virtual ~Widget ()
 
constexpr void move_by (const glm::ivec2 offset)
 Moves a widget by x and y. More...
 
void add_child (UI::Widget &child)
 Adds a children to the widget. More...
 
template<typename T , typename ... Targs>
T & make_widget (Targs &&...args)
 
virtual void on_render (Context &, Eng3D::Rect viewport)
 
virtual void set_text (const std::string &text)
 Generates text for the widget and overrides the current text texture. More...
 
virtual void set_tooltip (UI::Tooltip *tooltip)
 Set the tooltip to be shown when this widget is hovered, overrides the previous tooltip. More...
 
virtual void set_tooltip (const std::string &text)
 Set the tooltip to be shown when this widget is hovered, but generate it from a string instead of taking an already existing widget. More...
 
virtual void set_tooltip (std::function< std::string()> tooltip_text_creator)
 Set the tooltip to be shown when this widget is hovered, but generate when used needed. It is created from a string instead of taking an already existing widget. More...
 
glm::ivec2 get_y_bounds () const
 Obtains the height of the top and bottom overflow in widget That is the space that the children of this widget take up but cannot be seen. More...
 
void scroll (int y)
 Scrolls all the children of this widget by a factor of y. More...
 
constexpr void set_y (int _y)
 
constexpr void above_of (const UI::Widget &rhs)
 
constexpr void below_of (const UI::Widget &rhs)
 
constexpr void left_side_of (const UI::Widget &rhs)
 
constexpr void right_side_of (const UI::Widget &rhs)
 
virtual void set_on_click (std::function< void(UI::Widget &)> _on_click)
 Sets the on_click function of this widget. More...
 
virtual void set_on_each_tick (std::function< void(UI::Widget &)> _on_each_tick)
 Sets the on_each_tick function of this widget. More...
 
virtual void set_on_drag (std::function< void(glm::ivec2, glm::ivec2)> _on_drag)
 
template<typename F >
void sort_children (F &&comp)
 Sort the children of this widget. More...
 
void kill ()
 Kills the current widget, setting it up for deletion when dead widgets are cleared by the UI context. More...
 
void kill_children ()
 
size_t max_height () const
 

Public Attributes

bool is_pinned = false
 
bool is_render = true
 
bool is_scroll = false
 
uint32_t is_hover = 0
 
bool is_float = false
 
bool is_fullscreen = false
 
bool is_transparent = false
 
bool managed = true
 
UI::Widgetparent = nullptr
 
std::vector< std::unique_ptr< UI::Widget > > children
 
bool have_shadow = false
 
UI::Origin origin = UI::Origin::UPPER_LEFT
 
UI::WidgetType type
 
int x = 0
 
int y = 0
 
glm::ivec2 padding { 0 }
 
size_t width = 0
 
size_t height = 0
 
std::shared_ptr< Eng3D::Texturecurrent_texture
 
std::shared_ptr< Eng3D::Texturetext_texture
 
int text_offset_x = 4
 
int text_offset_y = 4
 
UI::Align text_align_y = UI::Align::START
 
UI::Align text_align_x = UI::Align::START
 
Eng3D::Color text_color = Eng3D::Color(0.f, 0.f, 0.f)
 
std::shared_ptr< Eng3D::TrueType::Fontfont
 
UI::Border border
 
Eng3D::Color background_color = Eng3D::Color(1.f, 1.f, 1.f, 0.f)
 
UI::Flex flex = UI::Flex::NONE
 
UI::FlexJustify flex_justify = UI::FlexJustify::START
 
UI::Align flex_align = UI::Align::START
 
UI::Overflow overflow = UI::Overflow::CLAMP
 
size_t flex_gap = 0
 
UI::Tooltiptooltip = nullptr
 
std::function< UI::Tooltip *()> tooltip_creator
 
void * user_data = nullptr
 
std::function< void(glm::ivec2 mouse_pos, glm::ivec2 mouse_delta)> on_drag
 
std::function< void(UI::Widget &)> on_update
 
std::function< void(UI::Widget &)> on_click
 
std::function< void(UI::Widget &)> on_click_outside
 
std::function< void(UI::Widget &)> on_each_tick
 
std::function< void(UI::Widget &, int i)> on_pos_recalc
 
std::function< void(UI::Widget &, glm::ivec2 mouse_pos, glm::ivec2 widget_pos)> on_hover
 
int lua_on_update = 0
 
int lua_on_click = 0
 
int lua_on_click_outside = 0
 
int lua_on_each_tick = 0
 
int dpad_index = 0
 Index for select_dpad_ui_widget, 0 means index=Auto (first to last) More...
 
int scrolled_y = 0
 Total amount of scroll. More...
 

Protected Member Functions

void draw_rectangle (int x, int y, unsigned w, unsigned h, Eng3D::Rect viewport, const Eng3D::Texture *tex)
 
void draw_rect (const Eng3D::Texture *tex, Eng3D::Rect rect_pos, Eng3D::Rect rect_tex, Eng3D::Rect viewport)
 

Protected Attributes

bool clickable_effect = true
 

Friends

class Context
 

Detailed Description

The master widget all the other widgets inherit from, do not use directly instead use one of the many derivated widgets - unless you're making a new widget type.

Definition at line 176 of file widget.hpp.

Constructor & Destructor Documentation

◆ Widget() [1/5]

UI::Widget::Widget ( )
default
Here is the caller graph for this function:

◆ Widget() [2/5]

Widget::Widget ( Widget parent,
int  x,
int  y,
unsigned  w,
unsigned  h,
WidgetType  type 
)

Definition at line 46 of file widget.cpp.

Here is the call graph for this function:

◆ Widget() [3/5]

Widget::Widget ( Widget parent,
int  x,
int  y,
unsigned  w,
unsigned  h,
WidgetType  type,
std::shared_ptr< Eng3D::Texture tex 
)

Definition at line 64 of file widget.cpp.

Here is the call graph for this function:

◆ Widget() [4/5]

UI::Widget::Widget ( const Widget )
default

◆ Widget() [5/5]

UI::Widget::Widget ( Widget &&  )
defaultnoexcept

◆ ~Widget()

Widget::~Widget ( )
virtual

Definition at line 83 of file widget.cpp.

Member Function Documentation

◆ above_of()

constexpr void UI::Widget::above_of ( const UI::Widget rhs)
inlineconstexpr

Definition at line 242 of file widget.hpp.

◆ add_child()

void Widget::add_child ( UI::Widget child)

Adds a children to the widget.

Parameters
childWidget to add as a children

Definition at line 427 of file widget.cpp.

Here is the caller graph for this function:

◆ below_of()

constexpr void UI::Widget::below_of ( const UI::Widget rhs)
inlineconstexpr

Definition at line 246 of file widget.hpp.

Here is the caller graph for this function:

◆ draw_rect()

void Widget::draw_rect ( const Eng3D::Texture tex,
Eng3D::Rect  rect_pos,
Eng3D::Rect  rect_tex,
Eng3D::Rect  viewport 
)
protected
Todo:
rect_tex

Definition at line 90 of file widget.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ draw_rectangle()

void Widget::draw_rectangle ( int  x,
int  y,
unsigned  w,
unsigned  h,
Eng3D::Rect  viewport,
const Eng3D::Texture tex 
)
protected

Definition at line 221 of file widget.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_y_bounds()

glm::ivec2 UI::Widget::get_y_bounds ( ) const

Obtains the height of the top and bottom overflow in widget That is the space that the children of this widget take up but cannot be seen.

Definition at line 483 of file widget.cpp.

Here is the caller graph for this function:

◆ kill()

void UI::Widget::kill ( )
inline

Kills the current widget, setting it up for deletion when dead widgets are cleared by the UI context.

Definition at line 283 of file widget.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ kill_children()

void UI::Widget::kill_children ( )
inline

Definition at line 289 of file widget.hpp.

Here is the caller graph for this function:

◆ left_side_of()

constexpr void UI::Widget::left_side_of ( const UI::Widget rhs)
inlineconstexpr

Definition at line 250 of file widget.hpp.

◆ make_widget()

template<typename T , typename ... Targs>
T& UI::Widget::make_widget ( Targs &&...  args)
inline

Definition at line 222 of file widget.hpp.

Here is the caller graph for this function:

◆ max_height()

size_t UI::Widget::max_height ( ) const
inline

Definition at line 294 of file widget.hpp.

Here is the caller graph for this function:

◆ move_by()

constexpr void UI::Widget::move_by ( const glm::ivec2  offset)
inlineconstexpr

Moves a widget by x and y.

Parameters
offsetOffset to move by

Definition at line 214 of file widget.hpp.

◆ on_render()

void Widget::on_render ( Context ctx,
Eng3D::Rect  viewport 
)
virtual

Reimplemented in UI::ProgressBar, UI::WaffleChart, UI::PieChart, UI::Group, UI::Chart, UI::CandleChart, UI::BarChart, and UI::Text.

Definition at line 229 of file widget.cpp.

Here is the call graph for this function:

◆ operator=() [1/2]

Widget& UI::Widget::operator= ( const Widget )
default

◆ operator=() [2/2]

Widget& UI::Widget::operator= ( Widget )
defaultnoexcept

◆ right_side_of()

constexpr void UI::Widget::right_side_of ( const UI::Widget rhs)
inlineconstexpr

Definition at line 254 of file widget.hpp.

Here is the caller graph for this function:

◆ scroll()

void UI::Widget::scroll ( int  _y)

Scrolls all the children of this widget by a factor of y.

Parameters
yFactor to scroll by

Definition at line 497 of file widget.cpp.

Here is the caller graph for this function:

◆ set_on_click()

virtual void UI::Widget::set_on_click ( std::function< void(UI::Widget &)>  _on_click)
inlinevirtual

Sets the on_click function of this widget.

Definition at line 259 of file widget.hpp.

Here is the caller graph for this function:

◆ set_on_drag()

virtual void UI::Widget::set_on_drag ( std::function< void(glm::ivec2, glm::ivec2)>  _on_drag)
inlinevirtual

Definition at line 268 of file widget.hpp.

Here is the caller graph for this function:

◆ set_on_each_tick()

virtual void UI::Widget::set_on_each_tick ( std::function< void(UI::Widget &)>  _on_each_tick)
inlinevirtual

Sets the on_each_tick function of this widget.

Definition at line 264 of file widget.hpp.

Here is the caller graph for this function:

◆ set_text()

void Widget::set_text ( const std::string &  _text)
virtual

Generates text for the widget and overrides the current text texture.

Parameters
_text

Reimplemented in UI::Tooltip, UI::Text, UI::Checkbox, and UI::Label.

Definition at line 445 of file widget.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_tooltip() [1/3]

void Widget::set_tooltip ( const std::string &  text)
virtual

Set the tooltip to be shown when this widget is hovered, but generate it from a string instead of taking an already existing widget.

Parameters
textText for the new tooltip

Definition at line 466 of file widget.cpp.

Here is the call graph for this function:

◆ set_tooltip() [2/3]

void Widget::set_tooltip ( std::function< std::string()>  tooltip_text_creator)
virtual

Set the tooltip to be shown when this widget is hovered, but generate when used needed. It is created from a string instead of taking an already existing widget.

Parameters
_tooltip_text_creatorthe function that creates the text for the tooltip

Definition at line 474 of file widget.cpp.

◆ set_tooltip() [3/3]

void Widget::set_tooltip ( UI::Tooltip _tooltip)
virtual

Set the tooltip to be shown when this widget is hovered, overrides the previous tooltip.

Parameters
_tooltipNew tooltip to set

Definition at line 458 of file widget.cpp.

Here is the caller graph for this function:

◆ set_y()

constexpr void UI::Widget::set_y ( int  _y)
inlineconstexpr

Definition at line 236 of file widget.hpp.

◆ sort_children()

template<typename F >
void UI::Widget::sort_children ( F &&  comp)
inline

Sort the children of this widget.

Template Parameters
Flambda function type
Parameters
compComparison function

Definition at line 276 of file widget.hpp.

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ Context

friend class Context
friend

Definition at line 367 of file widget.hpp.

Member Data Documentation

◆ background_color

Eng3D::Color UI::Widget::background_color = Eng3D::Color(1.f, 1.f, 1.f, 0.f)

Definition at line 335 of file widget.hpp.

◆ border

UI::Border UI::Widget::border

Definition at line 334 of file widget.hpp.

◆ children

std::vector<std::unique_ptr<UI::Widget> > UI::Widget::children

Definition at line 315 of file widget.hpp.

◆ clickable_effect

bool UI::Widget::clickable_effect = true
protected

Definition at line 199 of file widget.hpp.

◆ current_texture

std::shared_ptr<Eng3D::Texture> UI::Widget::current_texture

Definition at line 327 of file widget.hpp.

◆ dpad_index

int UI::Widget::dpad_index = 0

Index for select_dpad_ui_widget, 0 means index=Auto (first to last)

Definition at line 362 of file widget.hpp.

◆ flex

UI::Flex UI::Widget::flex = UI::Flex::NONE

Definition at line 337 of file widget.hpp.

◆ flex_align

UI::Align UI::Widget::flex_align = UI::Align::START

Definition at line 339 of file widget.hpp.

◆ flex_gap

size_t UI::Widget::flex_gap = 0

Definition at line 341 of file widget.hpp.

◆ flex_justify

UI::FlexJustify UI::Widget::flex_justify = UI::FlexJustify::START

Definition at line 338 of file widget.hpp.

◆ font

std::shared_ptr<Eng3D::TrueType::Font> UI::Widget::font

Definition at line 333 of file widget.hpp.

◆ have_shadow

bool UI::Widget::have_shadow = false

Definition at line 317 of file widget.hpp.

◆ height

size_t UI::Widget::height = 0

Definition at line 325 of file widget.hpp.

◆ is_float

bool UI::Widget::is_float = false

Definition at line 309 of file widget.hpp.

◆ is_fullscreen

bool UI::Widget::is_fullscreen = false

Definition at line 310 of file widget.hpp.

◆ is_hover

uint32_t UI::Widget::is_hover = 0

Definition at line 308 of file widget.hpp.

◆ is_pinned

bool UI::Widget::is_pinned = false

Definition at line 302 of file widget.hpp.

◆ is_render

bool UI::Widget::is_render = true

Definition at line 303 of file widget.hpp.

◆ is_scroll

bool UI::Widget::is_scroll = false

Definition at line 306 of file widget.hpp.

◆ is_transparent

bool UI::Widget::is_transparent = false

Definition at line 311 of file widget.hpp.

◆ lua_on_click

int UI::Widget::lua_on_click = 0

Definition at line 359 of file widget.hpp.

◆ lua_on_click_outside

int UI::Widget::lua_on_click_outside = 0

Definition at line 359 of file widget.hpp.

◆ lua_on_each_tick

int UI::Widget::lua_on_each_tick = 0

Definition at line 359 of file widget.hpp.

◆ lua_on_update

int UI::Widget::lua_on_update = 0

Definition at line 359 of file widget.hpp.

◆ managed

bool UI::Widget::managed = true

Definition at line 312 of file widget.hpp.

◆ on_click

std::function<void(UI::Widget&)> UI::Widget::on_click

Definition at line 350 of file widget.hpp.

◆ on_click_outside

std::function<void(UI::Widget&)> UI::Widget::on_click_outside

Definition at line 351 of file widget.hpp.

◆ on_drag

std::function<void(glm::ivec2 mouse_pos, glm::ivec2 mouse_delta)> UI::Widget::on_drag

Definition at line 348 of file widget.hpp.

◆ on_each_tick

std::function<void(UI::Widget&)> UI::Widget::on_each_tick

Definition at line 352 of file widget.hpp.

◆ on_hover

std::function<void(UI::Widget&, glm::ivec2 mouse_pos, glm::ivec2 widget_pos)> UI::Widget::on_hover

Definition at line 354 of file widget.hpp.

◆ on_pos_recalc

std::function<void(UI::Widget&, int i)> UI::Widget::on_pos_recalc

Definition at line 353 of file widget.hpp.

◆ on_update

std::function<void(UI::Widget&)> UI::Widget::on_update

Definition at line 349 of file widget.hpp.

◆ origin

UI::Origin UI::Widget::origin = UI::Origin::UPPER_LEFT

Definition at line 318 of file widget.hpp.

◆ overflow

UI::Overflow UI::Widget::overflow = UI::Overflow::CLAMP

Definition at line 340 of file widget.hpp.

◆ padding

glm::ivec2 UI::Widget::padding { 0 }

Definition at line 323 of file widget.hpp.

◆ parent

UI::Widget* UI::Widget::parent = nullptr

Definition at line 314 of file widget.hpp.

◆ scrolled_y

int UI::Widget::scrolled_y = 0

Total amount of scroll.

Definition at line 365 of file widget.hpp.

◆ text_align_x

UI::Align UI::Widget::text_align_x = UI::Align::START

Definition at line 331 of file widget.hpp.

◆ text_align_y

UI::Align UI::Widget::text_align_y = UI::Align::START

Definition at line 330 of file widget.hpp.

◆ text_color

Eng3D::Color UI::Widget::text_color = Eng3D::Color(0.f, 0.f, 0.f)

Definition at line 332 of file widget.hpp.

◆ text_offset_x

int UI::Widget::text_offset_x = 4

Definition at line 329 of file widget.hpp.

◆ text_offset_y

int UI::Widget::text_offset_y = 4

Definition at line 329 of file widget.hpp.

◆ text_texture

std::shared_ptr<Eng3D::Texture> UI::Widget::text_texture

Definition at line 328 of file widget.hpp.

◆ tooltip

UI::Tooltip* UI::Widget::tooltip = nullptr

Definition at line 343 of file widget.hpp.

◆ tooltip_creator

std::function<UI::Tooltip*()> UI::Widget::tooltip_creator

Definition at line 344 of file widget.hpp.

◆ type

UI::WidgetType UI::Widget::type

Definition at line 320 of file widget.hpp.

◆ user_data

void* UI::Widget::user_data = nullptr

Definition at line 346 of file widget.hpp.

◆ width

size_t UI::Widget::width = 0

Definition at line 325 of file widget.hpp.

◆ x

int UI::Widget::x = 0

Definition at line 322 of file widget.hpp.

◆ y

int UI::Widget::y = 0

Definition at line 322 of file widget.hpp.


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