Interface for clickable widgets. More...
#include <ClickableWidget.h>
Public Types | |
using | Ptr = std::shared_ptr< ClickableWidget > |
Shared widget pointer. More... | |
Public Member Functions | |
ClickableWidget (std::unique_ptr< priv::IWidgetImpl > widgetImpl) | |
ClickableWidget (const ClickableWidget &) | |
Copy constructor. More... | |
ClickableWidget & | operator= (const ClickableWidget &) |
Copy assignment operator. More... | |
ClickableWidget (ClickableWidget &&) noexcept | |
Move constructor. More... | |
ClickableWidget & | operator= (ClickableWidget &&) noexcept |
Move assignment operator. 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 widget if its currently enabled and vice versa. More... | |
void | setFocused (bool isFocused) |
Focus or unfocus widget. More... | |
bool | isFocused () const |
Check if widget is focused or not. More... | |
~ClickableWidget () override | |
Destructor. More... | |
void | setRenderer (IWidgetRenderer::Ptr renderer) |
Set the widgets renderer. More... | |
ui::IWidgetRenderer::Ptr | getRenderer () |
Get the widgets renderer. More... | |
const ui::IWidgetRenderer::Ptr | getRenderer () const |
void | setPosition (float x, float y) override |
Set the position of the widget. More... | |
void | setPosition (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 (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 (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 (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 (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 | 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... | |
virtual std::string | getWidgetType () const =0 |
Get the type of the widget. More... | |
void | showWithEffect (ShowAnimationType type, Time duration) |
Show the widget with an animation. More... | |
void | hideWithEffect (ShowAnimationType 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... | |
bool | unsubscribe (const std::string &event, int id) |
Remove an event listener from a widget event. More... | |
virtual Widget::Ptr | clone () const =0 |
Make a copy of the widget. More... | |
const std::shared_ptr< void > | getInternalPtr () const |
Protected Member Functions | |
template<typename... Args> | |
void | emit (const std::string &event, Args &&...args) |
Emit a widget event. More... | |
void | setAsContainer (bool container) |
Set whether or not the widget is a container. More... | |
Interface for clickable widgets.
Definition at line 38 of file ClickableWidget.h.
using ime::ui::ClickableWidget::Ptr = std::shared_ptr<ClickableWidget> |
Shared widget pointer.
Definition at line 40 of file ClickableWidget.h.
ime::ui::ClickableWidget::ClickableWidget | ( | const ClickableWidget & | ) |
Copy constructor.
|
noexcept |
Move constructor.
|
override |
Destructor.
|
pure virtualinherited |
Make a copy of the widget.
You should use this function if you don't care about the type of the widget, otherwise use the widgets copy function for copying purposes
Implemented in ime::ui::VerticalLayout, ime::ui::ToggleButton, ime::ui::TabsContainer, ime::ui::Tabs, ime::ui::SpinControl, ime::ui::Slider, ime::ui::Separator, ime::ui::ScrollablePanel, ime::ui::RadioButton, ime::ui::ProgressBar, ime::ui::Picture, ime::ui::Panel, ime::ui::MessageBox, ime::ui::MenuBar, ime::ui::Label, ime::ui::HorizontalLayout, ime::ui::EditBox, ime::ui::ChildWindow, ime::ui::CheckBox, ime::ui::Button, and ime::ui::BitmapButton.
|
inherited |
Check if coordinates lie inside the widget.
x | X coordinate to be checked |
y | Y coordinate to be checked |
|
inlineprotectedinherited |
|
inherited |
Get 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
|
inherited |
Get the absolute size of the widget.
The absolute size includes the size of the widget, the padding, margin and outline thickness
|
inherited |
Get the mouse cursor that is displayed when the mouse is on top of the widget.
|
overridevirtualinherited |
Get the local origin of the widget.
Implements ime::ITransformable.
|
overridevirtualinherited |
Get the position of the widget.
Implements ime::ITransformable.
|
inherited |
Get the widgets renderer.
The renderer gives access to functions that determine how the widget is displayed. It allows you to manipulate things such as the background colour, border colour etc...
|
overridevirtualinherited |
Get the orientation of the widget.
The rotation is always in the range [0, 360]
Implements ime::ITransformable.
|
overridevirtualinherited |
Get the current scale of the widget.
Implements ime::ITransformable.
|
inherited |
Get the size of the widget.
This function only returns the size of the widget (It does not accommodate margin, outline thickness etc ...)
|
inherited |
Get the character size of the text.
|
pure virtualinherited |
Get the type of the widget.
Implemented in ime::ui::VerticalLayout, ime::ui::ToggleButton, ime::ui::TabsContainer, ime::ui::Tabs, ime::ui::SpinControl, ime::ui::Slider, ime::ui::Separator, ime::ui::ScrollablePanel, ime::ui::RadioButton, ime::ui::ProgressBar, ime::ui::Picture, ime::ui::Panel, ime::ui::MessageBox, ime::ui::MenuBar, ime::ui::Label, ime::ui::HorizontalLayout, ime::ui::EditBox, ime::ui::ChildWindow, ime::ui::CheckBox, ime::ui::Button, and ime::ui::BitmapButton.
|
inherited |
Hide the widget with an animation.
type | Type of the animation |
duration | Duration of the animation |
The animation will also be played if the widget currently hidden but it will not be seen
|
inherited |
Check whether or not an animation is currently playing.
|
inherited |
Check if the widget is a container or not.
A container widget is a widget that can store other widgets inside it. Such widgets inherit from IWidget class
bool ime::ui::ClickableWidget::isEnabled | ( | ) | const |
Check if widget is enabled or disabled.
bool ime::ui::ClickableWidget::isFocused | ( | ) | const |
Check if widget is focused or not.
|
inherited |
Check if the widget is visible or not.
|
overridevirtualinherited |
Move the widget by a given offset.
offsetX | Horizontal offset |
offsetY | Vertical offset |
This function adds to the current position of the widget, unlike setPosition which overwrites it
Implements ime::ITransformable.
|
overridevirtualinherited |
Move the widget by a given offset.
offset | Offset to apply |
This function adds to the current position of the widget, unlike setPosition which overwrites it
Implements ime::ITransformable.
|
inlineinherited |
Add an event listener to a widget event.
event | Event to add an event listener to |
callback | Function to execute when the event is fired |
The id must if the event listener is to be removed later
|
noexcept |
Move assignment operator.
ClickableWidget& ime::ui::ClickableWidget::operator= | ( | const ClickableWidget & | ) |
Copy assignment operator.
|
overridevirtualinherited |
Rotate the widget.
angle | Angle of rotation, in degrees |
This function adds to the current rotation of the widget, unlike setRotation which overwrites it
Implements ime::ITransformable.
|
overridevirtualinherited |
Scale the widget by an offset.
factorX | Horizontal scale factor |
factorY | Vertical scale factor |
This function multiplies the current scale of the widget, unlike setScale which overwrites it
Implements ime::ITransformable.
|
overridevirtualinherited |
Scale the widget by an offset.
factor | Offset to apply |
This function multiplies the current scale of the widget, unlike setScale which overwrites it
Implements ime::ITransformable.
|
protectedinherited |
Set whether or not the widget is a container.
container | True 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
void ime::ui::ClickableWidget::setEnabled | ( | bool | isEnable | ) |
Enable or disable the widget.
isEnable | Set true to enable the widget, false to disable the widget |
The widget is enabled by default
void ime::ui::ClickableWidget::setFocused | ( | bool | isFocused | ) |
Focus or unfocus widget.
isFocused | True to focus or false to unfocus widget |
|
inherited |
Set the height of the widget relative to its parent.
height | New height |
The relative height is given in percentages as shown:
This function sets the height of the widget while keeping the width the same
|
inherited |
Set the height of the widget.
height | New height of the widget |
This function sets the height while keeping the width the same
|
inherited |
Set the mouse cursor that is displayed when the mouse is on top of the widget.
cursor | The cursor to be shown |
By default, the arrow cursor is shown
|
overridevirtualinherited |
Set the local origin of the widget.
x | X coordinate of the new origin |
y | Y 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.
|
overridevirtualinherited |
Set the local origin of the widget.
origin | 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.
|
inherited |
Set the position of the widget relative to the size of its parent.
x | New x coordinate of the widget |
y | New y coordinate of the widget |
The position is specified in percentages as shown below:
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)
|
overridevirtualinherited |
Set the position of the widget.
x | X coordinate of the new position |
y | Y 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)
Implements ime::ITransformable.
|
overridevirtualinherited |
Set the position of the widget.
position | New 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)
Implements ime::ITransformable.
|
inherited |
Set the widgets renderer.
renderer | The new renderer |
The renderer determines how the widget is displayed.
|
overridevirtualinherited |
Set the orientation of the widget.
angle | New 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
Implements ime::ITransformable.
|
overridevirtualinherited |
Set the scale factors of the widget.
factorX | New horizontal scale factor |
factorY | New vertical scale factor |
This function completely overwrites the previous scale
Implements ime::ITransformable.
|
overridevirtualinherited |
Set the scale factor of the widget.
scale | New scale |
This function completely overwrites the previous scale
Implements ime::ITransformable.
|
inherited |
Set the size of the widget relative to the size of its parent.
width | The new width of the widget |
height | The new height of the widget |
The size is specified in percentages as shown below:
|
inherited |
Set the size of the widget.
width | The width of the widget |
height | The height of the widget |
|
inherited |
Set the character size of the text.
size | New character size |
|
inherited |
Show or hide a widget.
visible | True 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.
|
inherited |
Set the width of the widget relative to its parent.
width | New width |
The relative width is given in percentages as shown:
This function sets the width of the widget while keeping the height the same
|
inherited |
Set the width of the widget.
width | New width of the widget |
This function sets the width while keeping the height the same
|
inherited |
Show the widget with an animation.
type | Type of the animation |
duration | Duration of the animation |
The animation will be played if the widget currently visible
void ime::ui::ClickableWidget::toggleEnabled | ( | ) |
Disable widget if its currently enabled and vice versa.
|
inherited |
Toggle the visibility of the widget.
This function will hide the widget if its currently visible and vice versa
|
inherited |
Remove an event listener from a widget event.
event | Event to remove event listener from |
id | Id number of the event listener |
The id is the number given when the event listener was registered