Wrath of Zeus
Made by Torchlight Games for CSE 125 SP24
Loading...
Searching...
No Matches
Data Structures | Public Types | Public Member Functions | Static Public Member Functions
gui::widget::Flexbox Class Reference

#include <flexbox.hpp>

Inheritance diagram for gui::widget::Flexbox:
gui::widget::Widget

Data Structures

struct  Options
 

Public Types

using Ptr = std::unique_ptr< Flexbox >
 
- Public Types inherited from gui::widget::Widget
using Ptr = std::unique_ptr< Widget >
 

Public Member Functions

 Flexbox (glm::vec2 origin, glm::vec2 size, Options options)
 
 Flexbox (glm::vec2 origin, Options options)
 
void doClick (float x, float y) override
 Performs a click at the specified (x,y) position in the GUI coordinate frame. More...
 
void doHover (float x, float y) override
 Performs a hover action at the specified (x,y) position in the GUI coordinate frame. More...
 
void push (Widget::Ptr &&widget)
 adds a new widget to the flexbox, from the bottom up More...
 
void lock () override
 
void render () override
 ====================================================================================== More...
 
Widgetborrow (Handle handle) override
 Gives a pointer to the subwidget specified by the handle. More...
 
bool hasHandle (Handle handle) const override
 ====================================================================================== More...
 
- Public Member Functions inherited from gui::widget::Widget
 Widget (Type type, glm::vec2 origin)
 Sets the type and origin position of the widget, and assigns a new unique handle. More...
 
virtual ~Widget ()=default
 
void setOrigin (glm::vec2 origin)
 Overrides the current origin position with the newly specified one. More...
 
virtual void lock ()
 Function that is run after all of the widgets have been added to the screee but before any input handling has occurred. More...
 
CallbackHandle addOnClick (Callback callback)
 ====================================================================================== More...
 
CallbackHandle addOnHover (Callback callback)
 Register a new onHover callback function for this widget. More...
 
void removeOnClick (CallbackHandle handle)
 Removes the onClick callback function associated with the given handle. More...
 
void removeOnHover (CallbackHandle handle)
 Removes the onHover callback function associated with the given handle. More...
 
virtual void doClick (float x, float y)
 Performs a click at the specified (x,y) position in the GUI coordinate frame. More...
 
virtual void doHover (float x, float y)
 Performs a hover action at the specified (x,y) position in the GUI coordinate frame. More...
 
virtual void render ()=0
 ====================================================================================== More...
 
Type getType () const
 ====================================================================================== More...
 
const glm::vec2 & getOrigin () const
 Queries the origin position of the widget. More...
 
std::pair< std::size_t, std::size_t > getSize () const
 Queries the size of the widget in pixels. More...
 
Handle getHandle () const
 Queries the handle for this specific widget. More...
 
virtual bool hasHandle (Handle handle) const
 ====================================================================================== More...
 
virtual Widgetborrow (Handle handle)
 Gives a pointer to the subwidget specified by the handle. More...
 

Static Public Member Functions

template<typename... Params>
static Ptr make (Params &&... params)
 creates a flexbox unique ptr for use in the GUI More...
 

Additional Inherited Members

- Protected Attributes inherited from gui::widget::Widget
Handle handle
 ====================================================================================== More...
 
Type type
 Type of the widget. More...
 
glm::vec2 origin
 Origin position (bottom left) of the widget in GUI coordinates. More...
 
std::size_t width {0}
 Width of the widget, in pixels. More...
 
std::size_t height {0}
 Height of the widget, in pixels. More...
 
std::unordered_map< CallbackHandle, Callbackon_clicks
 all of the onClick handlers, indexable by handle More...
 
std::unordered_map< CallbackHandle, Callbackon_hovers
 all of the onHover handlers, indexable by handle More...
 
- Static Protected Attributes inherited from gui::widget::Widget
static std::size_t num_widgets = 0
 Static counter for the number of widgets that have been created, so a new identifier can be assigned to each widget as they are created. More...
 

Member Typedef Documentation

◆ Ptr

using gui::widget::Flexbox::Ptr = std::unique_ptr<Flexbox>

Constructor & Destructor Documentation

◆ Flexbox() [1/2]

gui::widget::Flexbox::Flexbox ( glm::vec2  origin,
glm::vec2  size,
Flexbox::Options  options 
)

◆ Flexbox() [2/2]

gui::widget::Flexbox::Flexbox ( glm::vec2  origin,
Flexbox::Options  options 
)

Member Function Documentation

◆ borrow()

Widget * gui::widget::Flexbox::borrow ( Handle  handle)
overridevirtual

Gives a pointer to the subwidget specified by the handle.

NOTE: if handle is not a valid handle for either (1) this widget or (2) any subwidgets, then this function will terminate the program and print out an error message.

Returns
a pointer to the widget specified by handle

Reimplemented from gui::widget::Widget.

◆ doClick()

void gui::widget::Flexbox::doClick ( float  x,
float  y 
)
overridevirtual

Performs a click at the specified (x,y) position in the GUI coordinate frame.

NOTE: This function's main role is to determine if a click at the specified (x,y) coordinate should trigger the onClick handlers for this widget. The default implementation of this checks to see if the (x,y) coordinate is within the bounds specified by origin and width and height, and if so calls all of the onClick handlers.

NOTE: One reason for a derived class to override this function is if the widget itself contains other widgets, because in that case doClick will not be called on those "subwidgets" unless this function passes the call down the chain

Parameters
xx coordinate of the click in GUI coordinates
yy coordinate of the click in GUI coordinates

Reimplemented from gui::widget::Widget.

◆ doHover()

void gui::widget::Flexbox::doHover ( float  x,
float  y 
)
overridevirtual

Performs a hover action at the specified (x,y) position in the GUI coordinate frame.

NOTE: see the documentation for doClick, as everything said there also applies here, but just for the hover actions.

Reimplemented from gui::widget::Widget.

◆ hasHandle()

bool gui::widget::Flexbox::hasHandle ( Handle  handle) const
overridevirtual

======================================================================================

=<WIDGET BORROWING>===================================================================

The following functions are incredibly important for GUI manipulation, especially in event handlers. They essentially define how outside users can gain internal access to widgets that are inside of the GUI

hasHandle should always be called before calling borrow if you aren't sure whether or not the widget actually has the specified handle, because borrow will terminate the program if the specified widget does not have the handle.

By default hasHandle and borrow only check the widget itself to see if the handle matches. This means that if some derived Widget acts as a container for some set of internal subwidgets, then these functions should be overridden to provide access to those subwidgets.

Checks to see whether or not this widget "has" the specified handle, whether because the handle is this widgets handle, or because this widget internally contains some subwidget that has that handle.

Parameters
handleHandle of the widget for which you want to query
Returns
True if this widget is or contains the specified widget, false otherwise

Reimplemented from gui::widget::Widget.

◆ lock()

void gui::widget::Flexbox::lock ( )
overridevirtual

IMPORTANT: must call once you are done adding every widget to the flexbox as this performs some final positioning adjustments for certain direction/alignment orientations

Reimplemented from gui::widget::Widget.

◆ make()

template<typename... Params>
static Ptr gui::widget::Flexbox::make ( Params &&...  params)
inlinestatic

creates a flexbox unique ptr for use in the GUI

NOTE: I don't think flexboxes inside of flexboxes will currently work, but I haven't tried.

Parameters
originBottom left (x,y) coordinate of the flexbox, from which the container grows upward
size(Optional) Size of the container in pixels. You should only specify a size in the axis that does not grow in the direction of pushing (e.g. set a static width if you have a VERTICAL flexbox).
options(Optional) Configurable options for the flexbox.
Returns
A Flexbox widget

◆ push()

void gui::widget::Flexbox::push ( Widget::Ptr &&  widget)

adds a new widget to the flexbox, from the bottom up

◆ render()

void gui::widget::Flexbox::render ( )
overridevirtual

======================================================================================

=<DISPLAY>============================================================================

Renders the widget to the screen

This is the only function that must be overridden by derived classes.

Implements gui::widget::Widget.


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