Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
ime::ui::MessageBox Class Reference

A widget that can be used to display a message to the user. More...

#include <MessageBox.h>

Inheritance diagram for ime::ui::MessageBox:
ime::ui::WidgetContainer ime::ui::Widget ime::ITransformable

Public Types

enum class  TitleAlignment { Left , Center , Right }
 Title alignments, possible options for the setTitleAlignment function. More...
 
using Ptr = std::unique_ptr< MessageBox >
 Unique widget pointer. More...
 
using ConstPtr = std::unique_ptr< const MessageBox >
 Unique constant widget pointer. More...
 

Public Member Functions

 MessageBox (const MessageBox &)
 Copy constructor. More...
 
MessageBoxoperator= (const MessageBox &)
 Copy assignment operator. More...
 
 MessageBox (MessageBox &&) noexcept
 Move constructor. More...
 
MessageBoxoperator= (MessageBox &&) noexcept
 Move assignment operator. More...
 
MessageBox::Ptr copy () const
 Create a copy of this widget. More...
 
Widget::Ptr clone () const override
 Make a copy of this widget. More...
 
MessageBoxRenderergetRenderer ()
 Get the message box's renderer. More...
 
const MessageBoxRenderergetRenderer () const
 
void setText (const std::string &text)
 Set the text displayed by the message box. More...
 
std::string getText () const
 Get the text displayed by the message box. More...
 
void addButton (const std::string &buttonCaption)
 Add a button to the message box. More...
 
void setClientSize (Vector2f size)
 Set the client size of the child window. More...
 
Vector2f getClientSize () const
 Get the client size of the child window. More...
 
void setMaximumSize (Vector2f size)
 Sets the maximum size of the child window. More...
 
Vector2f getMaximumSize () const
 Get the maximum size of the child window. More...
 
void setMinimumSize (Vector2f size)
 Sets the minimum size of the child window. More...
 
Vector2f getMinimumSize () const
 Get the minimum size of the child window. More...
 
void setTitle (const std::string &title)
 Set the title that is displayed in the title bar of the child window. More...
 
std::string getTitle () const
 Get the title that is displayed in the title bar of the child window. More...
 
void setTitleTextSize (unsigned int size)
 Set the character size of the title. More...
 
unsigned int getTitleTextSize () const
 Get the character size of the title. More...
 
void setTitleAlignment (TitleAlignment alignment)
 Set the title alignment. More...
 
TitleAlignment getTitleAlignment () const
 Get the title alignment. More...
 
void setTitleButtons (unsigned int buttons)
 Set the title buttons. More...
 
void close ()
 Try to close the window. More...
 
void destroy ()
 Close the window. More...
 
void setResizable (bool resizable=true)
 Set whether the child window can be resized by dragging its borders or not. More...
 
bool isResizable () const
 Check if window is resizable or not. More...
 
void setDraggable (bool draggable)
 Set whether the child window can be moved by dragging its title bar or not. More...
 
bool isDraggable () const
 Check if window is draggable or not. More...
 
void setKeepInParent (bool enabled=true)
 Set whether the child window should be kept inside its parent or not. More...
 
bool isKeptInParent () const
 Check whether the child window is kept inside its parent or not. More...
 
std::string getWidgetType () const override
 Get the type of the spin control. More...
 
 ~MessageBox () override
 Destructor. More...
 
WidgetaddWidget (Widget::Ptr widget, const std::string &name="")
 Add a widget to the container. More...
 
template<typename T >
T * addWidget (Widget::Ptr widget, const std::string &name="")
 Add a widget to the gui. More...
 
WidgetgetWidget (const std::string &name) const
 Get access to a widget in the container. More...
 
template<class T >
T * getWidget (const std::string &name) const
 Get access to a widget in the container. More...
 
WidgetgetWidgetAtPosition (Vector2f pos) const
 Get a widget at a given position. More...
 
bool removeWidget (const std::string &name)
 Remove a widget from the container. More...
 
void removeAllWidgets ()
 Remove all widgets from the container. More...
 
void moveWidgetToFront (const Widget *widget)
 Place a widget before all other widgets, to the front of the z-order. More...
 
void moveWidgetToFront (const std::string &widget)
 Place a widget before all other widgets to the front. More...
 
void moveWidgetToBack (const Widget *widget)
 Place a widget behind all other widgets, to the back of the z-order. More...
 
void moveWidgetToBack (const std::string &widget)
 Place a widget behind all other widgets. More...
 
std::size_t moveWidgetForward (const Widget *widget)
 Place a widget one step forward in the z-order. More...
 
size_t moveWidgetForward (const std::string &widget)
 Place a widget one step forward in the z-order. More...
 
std::size_t moveWidgetBackward (const Widget *widget)
 Place a widget one step backwards in the z-order. More...
 
size_t moveWidgetBackward (const std::string &widget)
 Place a widget one step backwards in the z-order. More...
 
WidgetgetFocusedWidget () const
 Get the currently focused widget inside the container. More...
 
WidgetgetFocusedLeaf () const
 Get the currently focused widget inside the container. More...
 
bool focusNextWidget (bool recursive=true)
 Focus the next widget in the container. More...
 
bool focusPreviousWidget (bool recursive=true)
 Focus the previous widget in the container. More...
 
std::size_t getCount () const
 Get the number of widgets in the container. More...
 
void forEach (const Callback< Widget * > &callback) const
 Apply a callback to each widget in the container. More...
 
void setName (const std::string &name)
 Set the name of the widget. More...
 
const std::string & getName () const
 Get the name of the widget. More...
 
void setRenderer (IWidgetRenderer::Ptr renderer)
 Set the widgets renderer. More...
 
void setPosition (float x, float y) override
 Set the position of the widget. More...
 
void setPosition (const Vector2f &position) override
 Set the position of the widget. More...
 
void setPosition (const std::string &x, const std::string &y)
 Set the position of the widget relative to the size of its parent. More...
 
Vector2f getPosition () const override
 Get the position of the widget. More...
 
Vector2f getAbsolutePosition () const
 Get the absolute position of the widget. More...
 
void setRotation (float angle) override
 Set the orientation of the widget. More...
 
void rotate (float angle) override
 Rotate the widget. More...
 
float getRotation () const override
 Get the orientation of the widget. More...
 
void setScale (float factorX, float factorY) override
 Set the scale factors of the widget. More...
 
void setScale (const Vector2f &scale) override
 Set the scale factor of the widget. More...
 
void scale (float factorX, float factorY) override
 Scale the widget by an offset. More...
 
void scale (const Vector2f &factor) override
 Scale the widget by an offset. More...
 
Vector2f getScale () const override
 Get the current scale of the widget. More...
 
void setOrigin (float x, float y) override
 Set the local origin of the widget. More...
 
void setOrigin (const Vector2f &origin) override
 Set the local origin of the widget. More...
 
Vector2f getOrigin () const override
 Get the local origin of the widget. More...
 
void move (float offsetX, float offsetY) override
 Move the widget by a given offset. More...
 
void move (const Vector2f &offset) override
 Move the widget by a given offset. More...
 
void setTextSize (unsigned int size)
 Set the character size of the text. More...
 
unsigned int getTextSize () const
 Get the character size of the text. More...
 
void setSize (float width, float height)
 Set the size of the widget. More...
 
void setSize (const std::string &width, const std::string &height)
 Set the size of the widget relative to the size of its parent. More...
 
Vector2f getSize () const
 Get the size of the widget. More...
 
Vector2f getAbsoluteSize ()
 Get the absolute size of the widget. More...
 
void setWidth (float width)
 Set the width of the widget. More...
 
void setWidth (const std::string &width)
 Set the width of the widget relative to its parent. More...
 
void setHeight (float height)
 Set the height of the widget. More...
 
void setHeight (const std::string &height)
 Set the height of the widget relative to its parent. More...
 
void setFocused (bool isFocused)
 Focus or unfocus widget. More...
 
bool isFocused () const
 Check if widget is focused or not. More...
 
void setEnabled (bool isEnable)
 Enable or disable the widget. More...
 
bool isEnabled () const
 Check if widget is enabled or disabled. More...
 
void toggleEnabled ()
 Disable the widget if its currently enabled and vice versa. More...
 
void setMouseCursor (CursorType cursor)
 Set the mouse cursor that is displayed when the mouse is on top of the widget. More...
 
CursorType getMouseCursor () const
 Get the mouse cursor that is displayed when the mouse is on top of the widget. More...
 
void showWithEffect (AnimationType type, Time duration)
 Show the widget with an animation. More...
 
void hideWithEffect (AnimationType type, Time duration)
 Hide the widget with an animation. More...
 
bool isAnimationPlaying () const
 Check whether or not an animation is currently playing. More...
 
void setVisible (bool visible)
 Show or hide a widget. More...
 
bool isVisible () const
 Check if the widget is visible or not. More...
 
void toggleVisibility ()
 Toggle the visibility of the widget. More...
 
bool isContainer () const
 Check if the widget is a container or not. More...
 
bool contains (float x, float y) const
 Check if coordinates lie inside the widget. More...
 
template<typename... Args>
int on (const std::string &event, Callback< Args... > callback)
 Add an event listener to a widget event. More...
 
template<typename... Args>
int on (const std::string &event, Callback< Widget *, Args... > callback)
 Add an event listener to a widget event. More...
 
template<typename... Args>
void emit (const std::string &event, Args &&...args)
 Emit a widget event. More...
 
bool unsubscribe (const std::string &event, int id)
 Remove an event listener from a widget event. More...
 
const std::shared_ptr< void > getInternalPtr () const
 

Static Public Member Functions

static MessageBox::Ptr create (const std::string &title="", const std::string &text="", const std::initializer_list< std::string > &buttons={})
 Create a new menu bar widget. More...
 

Protected Member Functions

void setAsContainer (bool container)
 Set whether or not the widget is a container. More...
 

Detailed Description

A widget that can be used to display a message to the user.

Events generated by ime::ui::MessageBox
Name Argument Type Description
close void The window was closed
minimize void The window was minimized
maximize void The window was maximized
escapeKeyPress void The escape key was pressed while window was focused
buttonPress std::string One of the buttons was pressed. Parameter = the text of the pressed button

Usage Example:

messageBox.on("close", ime::Callback<>([] {
std::cout << "Pop up window closed" << "\n";
}));
std::function< void(Args...)> Callback
Event listener.
Definition: EventEmitter.h:38

Definition at line 38 of file MessageBox.h.

Member Typedef Documentation

◆ ConstPtr

using ime::ui::MessageBox::ConstPtr = std::unique_ptr<const MessageBox>

Unique constant widget pointer.

Definition at line 41 of file MessageBox.h.

◆ Ptr

using ime::ui::MessageBox::Ptr = std::unique_ptr<MessageBox>

Unique widget pointer.

Definition at line 40 of file MessageBox.h.

Member Enumeration Documentation

◆ TitleAlignment

Title alignments, possible options for the setTitleAlignment function.

Enumerator
Left 

Places the title on the left side of the title bar.

Center 

Places the title in the middle of the title bar.

Right 

Places the title on the right side of the title bar.

Definition at line 46 of file MessageBox.h.

Constructor & Destructor Documentation

◆ MessageBox() [1/2]

ime::ui::MessageBox::MessageBox ( const MessageBox )

Copy constructor.

◆ MessageBox() [2/2]

ime::ui::MessageBox::MessageBox ( MessageBox &&  )
noexcept

Move constructor.

◆ ~MessageBox()

ime::ui::MessageBox::~MessageBox ( )
override

Destructor.

Member Function Documentation

◆ addButton()

void ime::ui::MessageBox::addButton ( const std::string &  buttonCaption)

Add a button to the message box.

Parameters
buttonCaptionThe caption of the button

◆ addWidget() [1/2]

Widget * ime::ui::WidgetContainer::addWidget ( Widget::Ptr  widget,
const std::string &  name = "" 
)
inherited

Add a widget to the container.

Parameters
widgetWidget to be added
nameUnique Name of the widget
Returns
Pointer to the widget if it was added to the container or nullptr if the container already has a widget with the same name as the specified widget name

The name parameter is kept for compatibility with v2.2.x and prior. Starting with v2.3.0, use ime::ui::Widget::setName

Warning
The name of the widget must not contain whitespaces

◆ addWidget() [2/2]

template<typename T >
T * ime::ui::WidgetContainer::addWidget ( Widget::Ptr  widget,
const std::string &  name = "" 
)
inlineinherited

Add a widget to the gui.

Parameters
widgetThe widget to be added
nameUnique name of the widget
Returns
Pointer to the widget if it was added to the container or a premature program exit if a widget with the same name as name already exist in the container

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:

using ime::ui;
// Here the type of lblGreeting is deduced to Widget*
auto* lblGreeting = gui.addWidget(Label::create("Hi there"), "lblGreeting");
// Here the type of lblGreeting is deduced to Label*
auto* lblGreeting = gui.addWidget<Label>(Label::create("Hi there"), "lblGreeting");
static Label::Ptr create(const std::string &text="")
Create a new label widget.
Container for all user interface classes anf functions.
Definition: Namespace.h:50
Warning
This function will return a nullptr if the argument widget is not convertible to T. In addition name must be unique

Definition at line 125 of file WidgetContainer.h.

◆ clone()

Widget::Ptr ime::ui::MessageBox::clone ( ) const
overridevirtual

Make a copy of this widget.

Returns
A copy of this widget

You should use this function if you don't care about the type of the widget, otherwise use the widgets copy function

See also
copy

Implements ime::ui::Widget.

◆ close()

void ime::ui::MessageBox::close ( )

Try to close the window.

This will trigger the onClosing event. If a callback function for this event sets the abort parameter to true then the window will remain open. Otherwise the onClose event is triggered and the window is removed from its parent.

If you want to close the window without those callbacks being triggered then you need to use the destroy function

See also
destroy

◆ contains()

bool ime::ui::Widget::contains ( float  x,
float  y 
) const
inherited

Check if coordinates lie inside the widget.

Parameters
xX coordinate to be checked
yY coordinate to be checked
Returns
true if coordinates lie inside the widget, false if coordinates do not lie inside the widget

◆ copy()

MessageBox::Ptr ime::ui::MessageBox::copy ( ) const

Create a copy of this widget.

Returns
A copy of this widget
See also
clone

◆ create()

static MessageBox::Ptr ime::ui::MessageBox::create ( const std::string &  title = "",
const std::string &  text = "",
const std::initializer_list< std::string > &  buttons = {} 
)
static

Create a new menu bar widget.

Parameters
titleThe text to display in the title bar of the message box
textThe text to be displayed inside the message box
buttonsButtons to display inside the message box
Returns
The new menu bar
ime::ui::MessageBox::create("Close application", "Are you sure you
want to close the application", {"Quit", "Cancel"});
static MessageBox::Ptr create(const std::string &title="", const std::string &text="", const std::initializer_list< std::string > &buttons={})
Create a new menu bar widget.

◆ destroy()

void ime::ui::MessageBox::destroy ( )

Close the window.

This function is equivalent to removing the window from its parent. If you want to be receive a callback and have the ability to abort the operation then you should use the close() function instead

◆ emit()

template<typename... Args>
void ime::ui::Widget::emit ( const std::string &  event,
Args &&...  args 
)
inlineinherited

Emit a widget event.

Parameters
eventName of the event to be emitted
argsArguments to pass to event listeners

This function will invoke all event listeners of the given event.

button.emit("click");
button.emit("click", ime::Vector2f{100, 200});

Definition at line 739 of file Widget.h.

◆ focusNextWidget()

bool ime::ui::WidgetContainer::focusNextWidget ( bool  recursive = true)
inherited

Focus the next widget in the container.

Parameters
recursiveSet true to focus next widget when the currently focused widget is a container or false to focus the sibling of that container
Returns
True if the next widget was focused, otherwise false

◆ focusPreviousWidget()

bool ime::ui::WidgetContainer::focusPreviousWidget ( bool  recursive = true)
inherited

Focus the previous widget in the container.

Parameters
recursiveSet true to focus next widget when the currently focused widget is a container or false to focus the sibling of that container
Returns
True if the next widget was focused, otherwise false

◆ forEach()

void ime::ui::WidgetContainer::forEach ( const Callback< Widget * > &  callback) const
inherited

Apply a callback to each widget in the container.

Parameters
callbackThe function to be applied

◆ getAbsolutePosition()

Vector2f ime::ui::Widget::getAbsolutePosition ( ) const
inherited

Get the absolute position of the widget.

Returns
The absolute position of the widget

Unlike getPosition, this function returns the absolute position of the top-left point of the widget instead of the relative position to its parent

See also
setPosition

◆ getAbsoluteSize()

Vector2f ime::ui::Widget::getAbsoluteSize ( )
inherited

Get the absolute size of the widget.

Returns
The absolute size of the widget

The absolute size includes the size of the widget, the padding, margin and outline thickness

See also
getSize

◆ getClientSize()

Vector2f ime::ui::MessageBox::getClientSize ( ) const

Get the client size of the child window.

Returns
Size of the child window contents

This is the size of the child window excluding the title bar and the borders

◆ getCount()

std::size_t ime::ui::WidgetContainer::getCount ( ) const
inherited

Get the number of widgets in the container.

Returns
The number of widgets in the container

Note that child widgets that are also containers are only counted as one

◆ getFocusedLeaf()

Widget * ime::ui::WidgetContainer::getFocusedLeaf ( ) const
inherited

Get the currently focused widget inside the container.

Returns
Pointer to the focused child widget or a nullptr if none of the widgets are currently focused
Note
Unlike getFocusedWidget which returns a pointer to a container when the focused widget is a child of another container within the container, this function will always return the focused widget regardless of whether its a direct child of the container or not
See also
getFocusedWidget

◆ getFocusedWidget()

Widget * ime::ui::WidgetContainer::getFocusedWidget ( ) const
inherited

Get the currently focused widget inside the container.

Returns
Pointer to the focused child widget or a nullptr if none of the widgets are currently focused
Note
If the focused widget is a container, then a pointer to the container is returned rather than a pointer to the focused widget inside that container
See also
getFocusedLeaf

◆ getMaximumSize()

Vector2f ime::ui::MessageBox::getMaximumSize ( ) const

Get the maximum size of the child window.

Returns
Maximum size of the child window

This size includes the title bar and the borders

◆ getMinimumSize()

Vector2f ime::ui::MessageBox::getMinimumSize ( ) const

Get the minimum size of the child window.

Returns
Minimum size of the child window

This size includes the title bar and the borders

◆ getMouseCursor()

CursorType ime::ui::Widget::getMouseCursor ( ) const
inherited

Get the mouse cursor that is displayed when the mouse is on top of the widget.

Returns
The cursor shown when hovering above the widget

◆ getName()

const std::string & ime::ui::Widget::getName ( ) const
inherited

Get the name of the widget.

Returns
The name of the widget
See also
setName

◆ getOrigin()

Vector2f ime::ui::Widget::getOrigin ( ) const
overridevirtualinherited

Get the local origin of the widget.

Returns
Local origin of the widget

Implements ime::ITransformable.

◆ getPosition()

Vector2f ime::ui::Widget::getPosition ( ) const
overridevirtualinherited

Get the position of the widget.

Returns
Current position of the widget

Implements ime::ITransformable.

◆ getRenderer()

MessageBoxRenderer * ime::ui::MessageBox::getRenderer ( )

Get the message box's renderer.

Returns
The message box's renderer

The renderer gives access to functions that determine how the message box is displayed. It allows you to manipulate things such as the background colour, border colour etc...

See also
setRenderer

◆ getRotation()

float ime::ui::Widget::getRotation ( ) const
overridevirtualinherited

Get the orientation of the widget.

Returns
Current rotation, in degrees

The rotation is always in the range [0, 360]

Implements ime::ITransformable.

◆ getScale()

Vector2f ime::ui::Widget::getScale ( ) const
overridevirtualinherited

Get the current scale of the widget.

Returns
Current scale of the widget

Implements ime::ITransformable.

◆ getSize()

Vector2f ime::ui::Widget::getSize ( ) const
inherited

Get the size of the widget.

Returns
Current size of the widget

This function only returns the size of the widget (It does not accommodate margin, outline thickness etc ...)

See also
getAbsoluteSize

◆ getText()

std::string ime::ui::MessageBox::getText ( ) const

Get the text displayed by the message box.

Returns
The text that is displayed by the message box

◆ getTextSize()

unsigned int ime::ui::Widget::getTextSize ( ) const
inherited

Get the character size of the text.

Returns
The character size of the text

◆ getTitle()

std::string ime::ui::MessageBox::getTitle ( ) const

Get the title that is displayed in the title bar of the child window.

Returns
Title of the child window

◆ getTitleAlignment()

TitleAlignment ime::ui::MessageBox::getTitleAlignment ( ) const

Get the title alignment.

Returns
The title alignment

◆ getTitleTextSize()

unsigned int ime::ui::MessageBox::getTitleTextSize ( ) const

Get the character size of the title.

Returns
The current title text size

◆ getWidget() [1/2]

Widget * ime::ui::WidgetContainer::getWidget ( const std::string &  name) const
inherited

Get access to a widget in the container.

Parameters
nameName of the widget to get access to
Returns
Pointer to the specified widget or nullptr if the container does not have a widget with the given name

The container 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.

◆ getWidget() [2/2]

template<class T >
T * ime::ui::WidgetContainer::getWidget ( const std::string &  name) const
inlineinherited

Get access to a widget in the container.

Parameters
nameName of the widget to get access to
Returns
Pointer to the specified widget or nullptr if the container does not have a widget with the given name

The container 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.

If the widget is found, it will be casted to the desired type

Warning
This function will return nullptr if the widget cannot be casted to the desired type

Definition at line 146 of file WidgetContainer.h.

◆ getWidgetAtPosition()

Widget * ime::ui::WidgetContainer::getWidgetAtPosition ( Vector2f  pos) const
inherited

Get a widget at a given position.

Parameters
posThe position of the widget relative to the container view
Returns
Pointer to the widget at the specified position or a nullptr if there is no widget at that position

◆ getWidgetType()

std::string ime::ui::MessageBox::getWidgetType ( ) const
overridevirtual

Get the type of the spin control.

Returns
The type of the spin control

Implements ime::ui::Widget.

◆ hideWithEffect()

void ime::ui::Widget::hideWithEffect ( AnimationType  type,
Time  duration 
)
inherited

Hide the widget with an animation.

Parameters
typeType of the animation
durationDuration of the animation

The animation will also be played if the widget currently hidden but it will not be seen

Note
During the animation the position, size and/or opacity opacity may change. Once the animation is done the widget will be back in the state in which it was when this function was called
See also
showWithEffect
isAnimationPlaying

◆ isAnimationPlaying()

bool ime::ui::Widget::isAnimationPlaying ( ) const
inherited

Check whether or not an animation is currently playing.

Returns
True if an animation is playing, otherwise false
See also
showWithEffect
hideWithEffect

◆ isContainer()

bool ime::ui::Widget::isContainer ( ) const
inherited

Check if the widget is a container or not.

Returns
True if the widget is a container, otherwise false

A container widget is a widget that can store other widgets inside it. Such widgets inherit from IWidget class

◆ isDraggable()

bool ime::ui::MessageBox::isDraggable ( ) const

Check if window is draggable or not.

Returns
True if draggable, otherwise false

◆ isEnabled()

bool ime::ui::Widget::isEnabled ( ) const
inherited

Check if widget is enabled or disabled.

Returns
True if widget is enabled, false if widget is disabled
See also
setEnabled

◆ isFocused()

bool ime::ui::Widget::isFocused ( ) const
inherited

Check if widget is focused or not.

Returns
True if widget is focused. Otherwise, false
See also
setFocused

◆ isKeptInParent()

bool ime::ui::MessageBox::isKeptInParent ( ) const

Check whether the child window is kept inside its parent or not.

Returns
True if window is kept inside parent, otherwise false

◆ isResizable()

bool ime::ui::MessageBox::isResizable ( ) const

Check if window is resizable or not.

Returns
True if window is resizable, otherwise false

◆ isVisible()

bool ime::ui::Widget::isVisible ( ) const
inherited

Check if the widget is visible or not.

Returns
True if the widget is visible or false if hidden

◆ move() [1/2]

void ime::ui::Widget::move ( const Vector2f offset)
overridevirtualinherited

Move the widget by a given offset.

Parameters
offsetOffset to apply

This function adds to the current position of the widget, unlike setPosition which overwrites it

See also
setPosition

Implements ime::ITransformable.

◆ move() [2/2]

void ime::ui::Widget::move ( float  offsetX,
float  offsetY 
)
overridevirtualinherited

Move the widget by a given offset.

Parameters
offsetXHorizontal offset
offsetYVertical offset

This function adds to the current position of the widget, unlike setPosition which overwrites it

See also
setPosition

Implements ime::ITransformable.

◆ moveWidgetBackward() [1/2]

size_t ime::ui::WidgetContainer::moveWidgetBackward ( const std::string &  widget)
inherited

Place a widget one step backwards in the z-order.

Parameters
widgetThe widget that should be moved one step backward
Returns
New index in the widgets list (one higher than the old index or the same if the widget was already in front),

◆ moveWidgetBackward() [2/2]

std::size_t ime::ui::WidgetContainer::moveWidgetBackward ( const Widget widget)
inherited

Place a widget one step backwards in the z-order.

Parameters
widgetThe widget that should be moved one step backward
Returns
New index in the widgets list (one higher than the old index or the same if the widget was already in front),

◆ moveWidgetForward() [1/2]

size_t ime::ui::WidgetContainer::moveWidgetForward ( const std::string &  widget)
inherited

Place a widget one step forward in the z-order.

Parameters
widgetThe widget that should be moved one step forward
Returns
New index in the widgets list (one higher than the old index or the same if the widget was already in front),

◆ moveWidgetForward() [2/2]

std::size_t ime::ui::WidgetContainer::moveWidgetForward ( const Widget widget)
inherited

Place a widget one step forward in the z-order.

Parameters
widgetThe widget that should be moved one step forward
Returns
New index in the widgets list (one higher than the old index or the same if the widget was already in front),

◆ moveWidgetToBack() [1/2]

void ime::ui::WidgetContainer::moveWidgetToBack ( const std::string &  widget)
inherited

Place a widget behind all other widgets.

Parameters
widgetThe widget to be moved to the back

◆ moveWidgetToBack() [2/2]

void ime::ui::WidgetContainer::moveWidgetToBack ( const Widget widget)
inherited

Place a widget behind all other widgets, to the back of the z-order.

Parameters
widgetThe widget that should be moved to the front

◆ moveWidgetToFront() [1/2]

void ime::ui::WidgetContainer::moveWidgetToFront ( const std::string &  widget)
inherited

Place a widget before all other widgets to the front.

Parameters
widgetThe widget to be moved to the front

◆ moveWidgetToFront() [2/2]

void ime::ui::WidgetContainer::moveWidgetToFront ( const Widget widget)
inherited

Place a widget before all other widgets, to the front of the z-order.

Parameters
widgetThe widget that should be moved to the front

◆ on() [1/2]

template<typename... Args>
int ime::ui::Widget::on ( const std::string &  event,
Callback< Args... >  callback 
)
inlineinherited

Add an event listener to a widget event.

Parameters
eventEvent to add an event listener to
callbackFunction to execute when the event is fired
Returns
The event listeners identification number

The callback is passed event arguments (if any) on invocation. Here is an example demonstrating an event listener listening to an event with and arguments

// Event without arguments
widget.on("mouseEnter", ime::Callback<>([] {
std::cout << "Mouse entered widget" << "\n";
}));
// Event with arguments
widget.on("positionChange", ime::Callback<ime::Vector2f>([](ime::Vector2f pos) {
std::cout << "Widget moved to {" << pos.x << ", " << pos.y << "}" << "\n";
})):
T x
X coordinate of the vector.
Definition: Vector2.h:109
T y
Y coordinate of the vector.
Definition: Vector2.h:110
See also
unsubscribe

Definition at line 689 of file Widget.h.

◆ on() [2/2]

template<typename... Args>
int ime::ui::Widget::on ( const std::string &  event,
Callback< Widget *, Args... >  callback 
)
inlineinherited

Add an event listener to a widget event.

Parameters
eventEvent to add an event listener to
callbackFunction to execute when the event is fired
Returns
The event listeners identification number

The callback is passed a pointer to the widget as the first argument followed by the event arguments (if any) on invocation

// Event without arguments
widget.on("mouseEnter", ime::Callback<ime::ui::Widget*>([](ime::ui::Widget* widget) {
std::cout << "Mouse entered " << widget->getName() << "\n";
}));
// Event with arguments
std::cout << "Widget " << widget->getName() << " moved to {" << pos.x << ", " << pos.y << "}" << "\n";
})):
An Abstract Base Class for Graphical User Interface (GUI) elements.
Definition: Widget.h:86
const std::string & getName() const
Get the name of the widget.
int on(const std::string &event, Callback< Args... > callback)
Add an event listener to a widget event.
Definition: Widget.h:689
Note
Event listeners without the context/widget pointer are invoked first
See also
unsubscribe

Definition at line 721 of file Widget.h.

◆ operator=() [1/2]

MessageBox & ime::ui::MessageBox::operator= ( const MessageBox )

Copy assignment operator.

◆ operator=() [2/2]

MessageBox & ime::ui::MessageBox::operator= ( MessageBox &&  )
noexcept

Move assignment operator.

◆ removeAllWidgets()

void ime::ui::WidgetContainer::removeAllWidgets ( )
inherited

Remove all widgets from the container.

◆ removeWidget()

bool ime::ui::WidgetContainer::removeWidget ( const std::string &  name)
inherited

Remove a widget from the container.

Parameters
nameName of the widget to be removed from the container
Returns
True if the widget was removed or false if the widget does not exist in the container

◆ rotate()

void ime::ui::Widget::rotate ( float  angle)
overridevirtualinherited

Rotate the widget.

Parameters
angleAngle of rotation, in degrees

This function adds to the current rotation of the widget, unlike setRotation which overwrites it

See also
setRotation

Implements ime::ITransformable.

◆ scale() [1/2]

void ime::ui::Widget::scale ( const Vector2f factor)
overridevirtualinherited

Scale the widget by an offset.

Parameters
factorOffset to apply

This function multiplies the current scale of the widget, unlike setScale which overwrites it

See also
setScale

Implements ime::ITransformable.

◆ scale() [2/2]

void ime::ui::Widget::scale ( float  factorX,
float  factorY 
)
overridevirtualinherited

Scale the widget by an offset.

Parameters
factorXHorizontal scale factor
factorYVertical scale factor

This function multiplies the current scale of the widget, unlike setScale which overwrites it

See also
setScale

Implements ime::ITransformable.

◆ setAsContainer()

void ime::ui::Widget::setAsContainer ( bool  container)
protectedinherited

Set whether or not the widget is a container.

Parameters
containerTrue to flag as container, otherwise false

A container widget is a widget that can store other widgets inside it. Such widgets inherit from IWidget class

All widgets are not containers by default

◆ setClientSize()

void ime::ui::MessageBox::setClientSize ( Vector2f  size)

Set the client size of the child window.

Parameters
sizeNew size of the child window contents

This sets the size of the child window excluding the title bar and the borders.

◆ setDraggable()

void ime::ui::MessageBox::setDraggable ( bool  draggable)

Set whether the child window can be moved by dragging its title bar or not.

Parameters
draggableTrue to make window draggable, otherwise false

A draggable window can be moved by dragging its title bar and one that is not will remain locked in place.

Note
Locking the position only affects user interaction, the setPosition function will still move the window.

◆ setEnabled()

void ime::ui::Widget::setEnabled ( bool  isEnable)
inherited

Enable or disable the widget.

Parameters
isEnableSet true to enable the widget or false to disable the widget

If the widget is disabled, it wont not receive events and hence does won't dispatch callbacks

By default, the widget is enabled

See also
isEnabled

◆ setFocused()

void ime::ui::Widget::setFocused ( bool  isFocused)
inherited

Focus or unfocus widget.

Parameters
isFocusedTrue to focus or false to unfocus widget

When the widget is focused, a previously focused widget will be unfocused

Note
This function only works properly if the widget has already been added to the gui (see ime::ui::GuiContainer)

By default, the widget is not focused

See also
isFocused

◆ setHeight() [1/2]

void ime::ui::Widget::setHeight ( const std::string &  height)
inherited

Set the height of the widget relative to its parent.

Parameters
heightNew height

The relative height is given in percentages as shown:

widget->setHeight("10%");

This function sets the height of the widget while keeping the width the same

See also
setSize

◆ setHeight() [2/2]

void ime::ui::Widget::setHeight ( float  height)
inherited

Set the height of the widget.

Parameters
heightNew height of the widget

This function sets the height while keeping the width the same

See also
setSize

◆ setKeepInParent()

void ime::ui::MessageBox::setKeepInParent ( bool  enabled = true)

Set whether the child window should be kept inside its parent or not.

Parameters
enabledTrue to keep window inside parent, otherwise false

By default, thw window can be moved outside of its parent

◆ setMaximumSize()

void ime::ui::MessageBox::setMaximumSize ( Vector2f  size)

Sets the maximum size of the child window.

Parameters
sizeNew maximum size of the child window

This function sets the maximum size of the entire window, including borders and title bar. If the window is larger than the new maximum size, it will automatically be shrunk

◆ setMinimumSize()

void ime::ui::MessageBox::setMinimumSize ( Vector2f  size)

Sets the minimum size of the child window.

Parameters
sizeNew minimum size of the child window

This function sets the minimum size of the entire window, including borders and title bar. If the window is smaller than the new minimum size, it will automatically be enlarged

◆ setMouseCursor()

void ime::ui::Widget::setMouseCursor ( CursorType  cursor)
inherited

Set the mouse cursor that is displayed when the mouse is on top of the widget.

Parameters
cursorThe cursor to be shown

By default, the arrow cursor is shown

◆ setName()

void ime::ui::Widget::setName ( const std::string &  name)
inherited

Set the name of the widget.

Parameters
nameThe name of the widget

By default the widget is assigned a unique name. The naming convention is as follows:

widgetType + instantiation number

For example:

ime::Button::Ptr myBtn = ime::Button::create("Click me");
std::cout << myBtn->getName(); // Button1
ime::Label::Ptr lblGreet = ime::Label::create("Hello");
std::cout << lblGreet->getName(); // Label1
std::cout << lblGreet->copy()->getName(); // Label2
Warning
The name must not contain white spaces
See also
getName

◆ setOrigin() [1/2]

void ime::ui::Widget::setOrigin ( const Vector2f origin)
overridevirtualinherited

Set the local origin of the widget.

Parameters
originNew origin

The origin of the widget defines the center point for all transformations (position, scale, rotation). The coordinates of this point must be relative to the top-left corner of the widget, and ignore all transformations (position, scale, rotation).

The default origin of the widget is (0, 0)

Implements ime::ITransformable.

◆ setOrigin() [2/2]

void ime::ui::Widget::setOrigin ( float  x,
float  y 
)
overridevirtualinherited

Set the local origin of the widget.

Parameters
xX coordinate of the new origin
yY coordinate of the new origin

The origin of the widget defines the center point for all transformations (position, scale, rotation). The coordinates of this point must be relative to the top-left corner of the widget, and ignore all transformations (position, scale, rotation).

The default origin of the widget is (0, 0)

Implements ime::ITransformable.

◆ setPosition() [1/3]

void ime::ui::Widget::setPosition ( const std::string &  x,
const std::string &  y 
)
inherited

Set the position of the widget relative to the size of its parent.

Parameters
xNew x coordinate of the widget
yNew y coordinate of the widget

The position is specified in percentages as shown below:

widget->setPosition("5%", "10%");

This function completely overwrites the previous position. Use the move function to apply an offset based on the previous position instead.

The default position of the widget is (0, 0)

See also
move

◆ setPosition() [2/3]

void ime::ui::Widget::setPosition ( const Vector2f position)
overridevirtualinherited

Set the position of the widget.

Parameters
positionNew position

This function completely overwrites the previous position. Use the move function to apply an offset based on the previous position instead.

The default position of the widget is (0, 0)

See also
move

Implements ime::ITransformable.

◆ setPosition() [3/3]

void ime::ui::Widget::setPosition ( float  x,
float  y 
)
overridevirtualinherited

Set the position of the widget.

Parameters
xX coordinate of the new position
yY coordinate of the new position

This function completely overwrites the previous position. use move function to apply an offset based on the previous position instead

The default position of a the widget is (0, 0)

See also
move

Implements ime::ITransformable.

◆ setRenderer()

void ime::ui::Widget::setRenderer ( IWidgetRenderer::Ptr  renderer)
inherited

Set the widgets renderer.

Parameters
rendererThe new renderer

The renderer determines how the widget is displayed.

See also
getRenderer

◆ setResizable()

void ime::ui::MessageBox::setResizable ( bool  resizable = true)

Set whether the child window can be resized by dragging its borders or not.

Parameters
resizableTrue to make window resizable, otherwise false

◆ setRotation()

void ime::ui::Widget::setRotation ( float  angle)
overridevirtualinherited

Set the orientation of the widget.

Parameters
angleNew rotation, in degrees

This function completely overwrites the previous rotation. See the rotate function to add an angle based on the previous rotation instead.

The default rotation of the widget is 0

See also
rotate

Implements ime::ITransformable.

◆ setScale() [1/2]

void ime::ui::Widget::setScale ( const Vector2f scale)
overridevirtualinherited

Set the scale factor of the widget.

Parameters
scaleNew scale

This function completely overwrites the previous scale

See also
scale

Implements ime::ITransformable.

◆ setScale() [2/2]

void ime::ui::Widget::setScale ( float  factorX,
float  factorY 
)
overridevirtualinherited

Set the scale factors of the widget.

Parameters
factorXNew horizontal scale factor
factorYNew vertical scale factor

This function completely overwrites the previous scale

See also
scale

Implements ime::ITransformable.

◆ setSize() [1/2]

void ime::ui::Widget::setSize ( const std::string &  width,
const std::string &  height 
)
inherited

Set the size of the widget relative to the size of its parent.

Parameters
widthThe new width of the widget
heightThe new height of the widget

The size is specified in percentages as shown below:

widget->setSize("20%", "5%");

◆ setSize() [2/2]

void ime::ui::Widget::setSize ( float  width,
float  height 
)
inherited

Set the size of the widget.

Parameters
widthThe width of the widget
heightThe height of the widget

◆ setText()

void ime::ui::MessageBox::setText ( const std::string &  text)

Set the text displayed by the message box.

Parameters
textThe text to be set

Note theta the text will be placed as one long string and the message box expand to accommodate the text, If you need to display multiple lines of text then add '
' inside the text yourself.

◆ setTextSize()

void ime::ui::Widget::setTextSize ( unsigned int  size)
inherited

Set the character size of the text.

Parameters
sizeNew character size

◆ setTitle()

void ime::ui::MessageBox::setTitle ( const std::string &  title)

Set the title that is displayed in the title bar of the child window.

Parameters
titleNew title for the child window

◆ setTitleAlignment()

void ime::ui::MessageBox::setTitleAlignment ( TitleAlignment  alignment)

Set the title alignment.

Parameters
alignmentAlignment to be set

◆ setTitleButtons()

void ime::ui::MessageBox::setTitleButtons ( unsigned int  buttons)

Set the title buttons.

Parameters
buttonsTitle buttons to set

By default ChildWindows only display a close button. The following example gives the ChildWindow both a minimize and close button.

childWindow->setTitleButtons(ChildWindow::TitleButtons::Minimize
| ChildWindow::TitleButtons::Close);

◆ setTitleTextSize()

void ime::ui::MessageBox::setTitleTextSize ( unsigned int  size)

Set the character size of the title.

Parameters
sizeThe new title text size

If the size is set to 0 then the character size is determined by the height of the title bar

◆ setVisible()

void ime::ui::Widget::setVisible ( bool  visible)
inherited

Show or hide a widget.

Parameters
visibleTrue to show or false to hide

If the widget is hidden, it won't receive events (and thus won't send callbacks) nor will it be drawn

The widget is visible by default.

◆ setWidth() [1/2]

void ime::ui::Widget::setWidth ( const std::string &  width)
inherited

Set the width of the widget relative to its parent.

Parameters
widthNew width

The relative width is given in percentages as shown:

widget->setWidth("10%");

This function sets the width of the widget while keeping the height the same

See also
setSize

◆ setWidth() [2/2]

void ime::ui::Widget::setWidth ( float  width)
inherited

Set the width of the widget.

Parameters
widthNew width of the widget

This function sets the width while keeping the height the same

See also
setSize

◆ showWithEffect()

void ime::ui::Widget::showWithEffect ( AnimationType  type,
Time  duration 
)
inherited

Show the widget with an animation.

Parameters
typeType of the animation
durationDuration of the animation

The animation will be played if the widget currently visible

Note
During the animation the position, size and/or opacity opacity may change. Once the animation is done the widget will be back in the state in which it was when this function was called
See also
hideWithEffect
isAnimationPlaying

◆ toggleEnabled()

void ime::ui::Widget::toggleEnabled ( )
inherited

Disable the widget if its currently enabled and vice versa.

If the widget is disabled, it wont not receive events and hence does won't dispatch callbacks

See also
setEnabled

◆ toggleVisibility()

void ime::ui::Widget::toggleVisibility ( )
inherited

Toggle the visibility of the widget.

This function will hide the widget if its currently visible and vice versa

See also
setVisible

◆ unsubscribe()

bool ime::ui::Widget::unsubscribe ( const std::string &  event,
int  id 
)
inherited

Remove an event listener from a widget event.

Parameters
eventEvent to remove event listener from
idId number of the event listener
Returns
True if the event listener was removed or false if the given event does not exist or the event does not have an event listener with the given id

The id is the number given when the event listener was registered

See also
on

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