Container for Graphical User Interface (GUI) widgets. More...
#include <GuiContainer.h>
Public Types | |
using | Ptr = std::shared_ptr< GuiContainer > |
Shared gui container pointer. More... | |
Public Member Functions | |
GuiContainer () | |
Construct the gui. More... | |
GuiContainer (priv::RenderTarget &window) | |
Construct the gui and set the target on which the gui should be drawn. More... | |
GuiContainer (const GuiContainer &)=delete | |
Copy constructor. More... | |
GuiContainer & | operator= (const GuiContainer &)=delete |
Assignment operator. More... | |
GuiContainer (GuiContainer &&) noexcept | |
Move constructor. More... | |
GuiContainer & | operator= (GuiContainer &&) noexcept |
Move assignment operator. More... | |
void | setAbsoluteViewport (const FloatRect &viewport) |
Set the part of the window the gui will render on. More... | |
void | setRelativeViewport (const FloatRect &viewport) |
Set the part of the window the gui will render on as a ratio relative to the window size. More... | |
FloatRect | getViewport () const |
Get the part of the window the gui renders. More... | |
void | setAbsoluteView (const FloatRect &view) |
Set the part of the gui that will be used to fill the viewport. More... | |
void | setRelativeView (const FloatRect &view) |
Set the part of the gui that is used to fill the viewport. More... | |
FloatRect | getView () const |
Get the part of the gui that is used to fill the viewport. More... | |
void | setTextSize (unsigned int size) |
Set the character size of all existing and future child widgets. More... | |
unsigned int | getTextSize () const |
Get the text size of all existing and future child widgets. More... | |
void | setTarget (priv::RenderTarget &window) |
bool | isTargetSet () const |
Check if the target on which the gui should be drawn is set or not. More... | |
void | setTabKeyUsageEnabled (bool enabled) |
Enable tab usage. More... | |
bool | isTabKeyUsageEnabled () const |
Check if tab key usage is enabled or not. More... | |
void | draw () |
Draw all the widgets that were added to the gui. More... | |
void | setFont (const std::string &filename) |
Change the global font. More... | |
void | setOpacity (float opacity) |
Set the opacity of all widgets. More... | |
float | getOpacity () const |
Get the opacity of all the widgets. More... | |
void | setMouseCursor (CursorType cursorType) |
Change the mouse cursor that gets shown. More... | |
void | restoreMouseCursor () |
Restores the mouse cursor to the way it was prior to setMouseCursor. More... | |
void | requestMouseCursor (CursorType cursorType) |
Change the mouse cursor that is shown. More... | |
Widget * | addWidget (Widget::Ptr widget, const std::string &name="") |
Add a widget to the gui. More... | |
template<typename T > | |
T * | addWidget (Widget::Ptr widget, const std::string &name="") |
Add a widget to the gui. More... | |
Widget * | getWidget (const std::string &name) const |
Get a pointer to a widget in the gui. More... | |
template<class T > | |
T * | getWidget (const std::string &name) const |
Get a pointer to a widget in the gui. More... | |
bool | removeWidget (const std::string &widget) |
Remove a widget from the gui. More... | |
void | removeAllWidgets () |
Remove all widgets from the gui. More... | |
Widget * | getFocusedWidget () const |
Get the currently focused widget inside the container. More... | |
Widget * | getFocusedLeaf () const |
Get the currently focused widget inside the container. More... | |
Widget * | getWidgetAtPosition (Vector2f pos) const |
Get a widget at a given position. More... | |
Widget * | getWidgetBelowMouseCursor (Vector2f mousePos) const |
Get the widget below the mouse cursor. More... | |
bool | focusNextWidget (bool recursive=true) |
Focus the next widget in the gui. More... | |
bool | focusPreviousWidget (bool recursive=true) |
Focus the previous widget in the gui. More... | |
void | unfocusAllWidgets () |
Unfocus all widgets in the container. More... | |
void | moveWidgetToFront (const Widget *widget) |
Place a widget before all other widgets to the front. More... | |
void | moveWidgetToBack (const Widget *widget) |
Place a widget behind all other widgets. More... | |
size_t | moveWidgetForward (const Widget *widget) |
Place a widget one step forward in the z-order. More... | |
size_t | moveWidgetBackward (const Widget *widget) |
Place a widget one step backwards in the z-order. More... | |
void | moveWidgetToFront (const std::string &widget) |
Place a widget before all other widgets to the front. More... | |
void | moveWidgetToBack (const std::string &widget) |
Place a widget behind all other widgets. More... | |
size_t | moveWidgetForward (const std::string &widget) |
Place a widget one step forward in the z-order. More... | |
size_t | moveWidgetBackward (const std::string &widget) |
Place a widget one step backwards in the z-order. More... | |
void | handleEvent (Event event) |
void | update (Time deltaTime) |
~GuiContainer () | |
Destructor. More... | |
Container for Graphical User Interface (GUI) widgets.
This class is a container for all UI widgets. In order for a widget to receive events, updates and be rendered, it must exist in the gui container either directly (explicit addition) or indirectly (added to a container widget which is then added to the gui container)
This class is not meant to be instantiated directly, use ime::Scene::getGui or ime::Engine::getGui
Definition at line 56 of file GuiContainer.h.
using ime::ui::GuiContainer::Ptr = std::shared_ptr<GuiContainer> |
Shared gui container pointer.
Definition at line 58 of file GuiContainer.h.
ime::ui::GuiContainer::GuiContainer | ( | ) |
Construct the gui.
|
explicit |
Construct the gui and set the target on which the gui should be drawn.
window | Render target that will be used by the gui |
This constructor will set the target therefore there is no need to call setTarget
|
delete |
Copy constructor.
|
noexcept |
Move constructor.
ime::ui::GuiContainer::~GuiContainer | ( | ) |
Destructor.
Widget * ime::ui::GuiContainer::addWidget | ( | Widget::Ptr | widget, |
const std::string & | name = "" |
||
) |
Add a widget to the gui.
widget | The widget to be added |
name | Unique name of the widget |
The name parameter is kept for compatibility with v2.2.x and prior. Starting with v2.3.0, use ime::ui::Widget::setName
|
inline |
Add a widget to the gui.
widget | The widget to be added |
name | Unique name of the widget |
The name parameter is kept for compatibility with v2.2.x and prior. Starting with v2.3.0, use ime::ui::Widget::setName
This function that will return the widget pointer already casted to the desired type:
Definition at line 348 of file GuiContainer.h.
void ime::ui::GuiContainer::draw | ( | ) |
Draw all the widgets that were added to the gui.
bool ime::ui::GuiContainer::focusNextWidget | ( | bool | recursive = true | ) |
Focus the next widget in the gui.
recursive | Set true to focus next widget when the currently focused widget is a container or false to focus the sibling of that container |
bool ime::ui::GuiContainer::focusPreviousWidget | ( | bool | recursive = true | ) |
Focus the previous widget in the gui.
recursive | Set true to focus next widget when the currently focused widget is a container or false to focus the sibling of that container |
Widget * ime::ui::GuiContainer::getFocusedLeaf | ( | ) | const |
Get the currently focused widget inside the container.
Widget * ime::ui::GuiContainer::getFocusedWidget | ( | ) | const |
Get the currently focused widget inside the container.
float ime::ui::GuiContainer::getOpacity | ( | ) | const |
Get the opacity of all the widgets.
unsigned int ime::ui::GuiContainer::getTextSize | ( | ) | const |
Get the text size of all existing and future child widgets.
FloatRect ime::ui::GuiContainer::getView | ( | ) | const |
Get the part of the gui that is used to fill the viewport.
By default, the view will have the same size as the viewport
FloatRect ime::ui::GuiContainer::getViewport | ( | ) | const |
Get the part of the window the gui renders.
Widget * ime::ui::GuiContainer::getWidget | ( | const std::string & | name | ) | const |
Get a pointer to a widget in the gui.
name | Name of the widget to retrieve |
The gui will first search for widgets that are direct children of it, but when none of the child widgets match the given name, a recursive search will be performed
|
inline |
Get a pointer to a widget in the gui.
name | Name of the widget to retrieve |
Definition at line 374 of file GuiContainer.h.
Get a widget at a given position.
pos | The position of the widget relative to the gui view |
Get the widget below the mouse cursor.
mousePos | The position of the mouse cursor in pixel coordinates relative to the window |
bool ime::ui::GuiContainer::isTabKeyUsageEnabled | ( | ) | const |
Check if tab key usage is enabled or not.
bool ime::ui::GuiContainer::isTargetSet | ( | ) | const |
Check if the target on which the gui should be drawn is set or not.
size_t ime::ui::GuiContainer::moveWidgetBackward | ( | const std::string & | widget | ) |
Place a widget one step backwards in the z-order.
widget | The widget that should be moved one step backward |
size_t ime::ui::GuiContainer::moveWidgetBackward | ( | const Widget * | widget | ) |
Place a widget one step backwards in the z-order.
widget | The widget that should be moved one step backward |
size_t ime::ui::GuiContainer::moveWidgetForward | ( | const std::string & | widget | ) |
Place a widget one step forward in the z-order.
widget | The widget that should be moved one step forward |
size_t ime::ui::GuiContainer::moveWidgetForward | ( | const Widget * | widget | ) |
Place a widget one step forward in the z-order.
widget | The widget that should be moved one step forward |
void ime::ui::GuiContainer::moveWidgetToBack | ( | const std::string & | widget | ) |
Place a widget behind all other widgets.
widget | The widget to be moved to the back |
void ime::ui::GuiContainer::moveWidgetToBack | ( | const Widget * | widget | ) |
Place a widget behind all other widgets.
widget | The widget to be moved to the back |
void ime::ui::GuiContainer::moveWidgetToFront | ( | const std::string & | widget | ) |
Place a widget before all other widgets to the front.
widget | The widget to be moved to the front |
void ime::ui::GuiContainer::moveWidgetToFront | ( | const Widget * | widget | ) |
Place a widget before all other widgets to the front.
widget | The widget to be moved to the front |
|
delete |
Assignment operator.
|
noexcept |
Move assignment operator.
void ime::ui::GuiContainer::removeAllWidgets | ( | ) |
Remove all widgets from the gui.
bool ime::ui::GuiContainer::removeWidget | ( | const std::string & | widget | ) |
Remove a widget from the gui.
widget | Name of the widget to be removed from the gui |
void ime::ui::GuiContainer::requestMouseCursor | ( | CursorType | cursorType | ) |
Change the mouse cursor that is shown.
cursorType | The cursor to show |
This function is used by widgets to set the mouse cursor when the mouse enters or leaves a widget. If you want to choose a cursor that doesnt changed when moving the mouse, then use setMouseCursor. If the cursor is already set using the setMouseCursor function then this function wont be able to change the cursor. When the mouse cursor is restored restoreMouseCursor, then the mouse cursor will be changed to what was last requested here
void ime::ui::GuiContainer::restoreMouseCursor | ( | ) |
Restores the mouse cursor to the way it was prior to setMouseCursor.
The mouse cursor is changeable only if there are no active mouse cursor changes
void ime::ui::GuiContainer::setAbsoluteView | ( | const FloatRect & | view | ) |
Set the part of the gui that will be used to fill the viewport.
view |
Example code to use the contents of the gui container from top-left (200,100) to bottom-right (600, 400) and stretch it to fill the viewport (which equals the entire window by default):
void ime::ui::GuiContainer::setAbsoluteViewport | ( | const FloatRect & | viewport | ) |
Set the part of the window the gui will render on.
viewport | Rect of the window to which the gui should draw |
Example code to render the gui on only the right side of an 800x600 window:
By default, the gui fills the entire window
void ime::ui::GuiContainer::setFont | ( | const std::string & | filename | ) |
Change the global font.
filename | Filename of the new global font |
FileNotFoundException | if the font cannot be found on the disk |
void ime::ui::GuiContainer::setMouseCursor | ( | CursorType | cursorType | ) |
Change the mouse cursor that gets shown.
cursorType | The mouse cursor to show |
void ime::ui::GuiContainer::setOpacity | ( | float | opacity | ) |
Set the opacity of all widgets.
opacity | The new opacity of the widgets in the range [0, 1] |
O means completely transparent whilst 1 means fully opaque. The default opacity for all widgets is 1
void ime::ui::GuiContainer::setRelativeView | ( | const FloatRect & | view | ) |
Set the part of the gui that is used to fill the viewport.
view | Rect of the gui that will be stretched to fill the viewport relative to the viewport size |
The default view is (0, 0, 1, 1) so that no scaling happens when the viewport is changed
Example code to zoom in on the gui and display everything at 2x the size:
void ime::ui::GuiContainer::setRelativeViewport | ( | const FloatRect & | viewport | ) |
Set the part of the window the gui will render on as a ratio relative to the window size.
viewport | Rect of the window to which the gui should draw relative to the window size |
Example code to render the gui on only the right side of window:
The default viewport is (0, 0, 1, 1) so that the gui fills the entire window
void ime::ui::GuiContainer::setTabKeyUsageEnabled | ( | bool | enabled | ) |
Enable tab usage.
enabled | True to enable tab usage or false to disable it |
When the tab key usage is enabled, pressing tab will focus another widget
void ime::ui::GuiContainer::setTextSize | ( | unsigned int | size | ) |
Set the character size of all existing and future child widgets.
size | The new character size |
void ime::ui::GuiContainer::unfocusAllWidgets | ( | ) |
Unfocus all widgets in the container.