A widget that can be used to define different tabbed pages for the same area of a window. More...
#include <Tabs.h>
Public Types | |
using | Ptr = std::shared_ptr< Tabs > |
Shared widget pointer. More... | |
using | ConstPtr = std::shared_ptr< const Tabs > |
const shared widget pointer More... | |
Public Member Functions | |
Tabs (const Tabs &) | |
Copy constructor. More... | |
Tabs & | operator= (const Tabs &) |
Copy assignment operator. More... | |
Tabs (Tabs &&) noexcept | |
Move constructor. More... | |
Tabs & | operator= (Tabs &&) noexcept |
Move assignment operator. More... | |
Tabs::Ptr | copy () const |
Create a copy of this widget. More... | |
TabsRenderer * | getRenderer () |
Get the tabs renderer. More... | |
const TabsRenderer * | getRenderer () const |
void | setAutoSize (bool autoSize) |
Set whether or not the tabs auto-size. More... | |
bool | getAutoSize () const |
Check whether if the tabs are auto-sized or not. More... | |
std::size_t | add (const std::string &text, bool select=true) |
Add a new tab. More... | |
void | insert (std::size_t index, const std::string &text, bool select=true) |
Insert a new tab between other tabs. More... | |
std::string | getText (std::size_t index) const |
Get the text of a tab. More... | |
bool | changeText (std::size_t index, const std::string &text) |
Change the text of a tab. More... | |
bool | select (const std::string &text) |
Select tab with a given text. More... | |
bool | select (std::size_t index) |
Select a tab with a given index. More... | |
void | deselect () |
Deselect the selected tab. More... | |
bool | remove (const std::string &text) |
Remove a tab with a given text. More... | |
bool | remove (std::size_t index) |
Remove a tab with a given index. More... | |
void | removeAll () |
Remove all tabs. More... | |
std::string | getSelected () const |
Get the text that is drawn on the currently selected tab. More... | |
int | getSelectedIndex () const |
Get the index of the currently selected tab. More... | |
void | setTabVisible (std::size_t index, bool visible) |
Hide or show a tab. More... | |
bool | isTabVisible (std::size_t index) const |
Check if a tab is visible or not. More... | |
void | setTabEnabled (std::size_t index, bool enabled) |
Enable or disable a tab. More... | |
bool | isTabEnabled (std::size_t index) const |
Check whether a tab is enabled or not. More... | |
void | setTabHeight (float height) |
Set the height of the tabs. More... | |
void | setMaximumTabWidth (float maximumWidth) |
Set the maximum tab width of the tabs. More... | |
float | getMaximumTabWidth () const |
Get the maximum tab width of the tabs. More... | |
void | setMinimumTabWidth (float minimumWidth) |
Set the minimum width of the tabs. More... | |
float | getMinimumTabWidth () const |
Get teh minimum tab width of the tabs. More... | |
std::size_t | getTabsCount () const |
Get the number of tabs. More... | |
Widget::Ptr | clone () const override |
Make a copy of this widget. More... | |
std::string | getWidgetType () const override |
Get the type of the tab. More... | |
~Tabs () override | |
Destructor. 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 Tabs::Ptr | create () |
Create a new tabs widget. More... | |
Protected Member Functions | |
void | setAsContainer (bool container) |
Set whether or not the widget is a container. More... | |
A widget that can be used to define different tabbed pages for the same area of a window.
This widget can hold multiple tabs. If you want Tabs with panels, checkout the TabsContainer class
Name | Argument Type | Description |
---|---|---|
tabSelect | std::string | A tab was selected. Parameter = The text of the selected tab |
Event usage example:
using ime::ui::Tabs::ConstPtr = std::shared_ptr<const Tabs> |
using ime::ui::Tabs::Ptr = std::shared_ptr<Tabs> |
ime::ui::Tabs::Tabs | ( | const Tabs & | ) |
Copy constructor.
|
noexcept |
Move constructor.
|
override |
Destructor.
std::size_t ime::ui::Tabs::add | ( | const std::string & | text, |
bool | select = true |
||
) |
Add a new tab.
text | The text of the tab that will be drawn on top of it |
select | True to immediately select tab, otherwise false |
bool ime::ui::Tabs::changeText | ( | std::size_t | index, |
const std::string & | text | ||
) |
Change the text of a tab.
index | Index of the tab whose text is to be changed |
text | The new tab text |
|
overridevirtual |
Make 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
Implements ime::ui::Widget.
|
inherited |
Check if coordinates lie inside the widget.
x | X coordinate to be checked |
y | Y coordinate to be checked |
Tabs::Ptr ime::ui::Tabs::copy | ( | ) | const |
|
static |
Create a new tabs widget.
void ime::ui::Tabs::deselect | ( | ) |
Deselect the selected tab.
|
inlineinherited |
Emit a widget event.
event | Name of the event to be emitted |
args | Arguments to pass to event listeners |
This function will invoke all event listeners of the given event.
|
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
bool ime::ui::Tabs::getAutoSize | ( | ) | const |
Check whether if the tabs are auto-sized or not.
float ime::ui::Tabs::getMaximumTabWidth | ( | ) | const |
Get the maximum tab width of the tabs.
This property only has effect when the tabs are auto-sizing. If the text on the tab is longer than this width then it will be cropped to fit inside the tab.
By default, the maximum width is 0 which means that there is no limitation
float ime::ui::Tabs::getMinimumTabWidth | ( | ) | const |
Get teh minimum tab width of the tabs.
This property only has effect when the tabs are auto-sizing. Every tab is at least as wide as this minimum or twice the distance to side
|
inherited |
Get the mouse cursor that is displayed when the mouse is on top of the widget.
|
inherited |
|
overridevirtualinherited |
Get the local origin of the widget.
Implements ime::ITransformable.
|
overridevirtualinherited |
Get the position of the widget.
Implements ime::ITransformable.
TabsRenderer * ime::ui::Tabs::getRenderer | ( | ) |
Get the tabs renderer.
The renderer gives access to functions that determine how the tab 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.
std::string ime::ui::Tabs::getSelected | ( | ) | const |
Get the text that is drawn on the currently selected tab.
int ime::ui::Tabs::getSelectedIndex | ( | ) | const |
Get the index of the currently selected tab.
|
inherited |
Get the size of the widget.
This function only returns the size of the widget (It does not accommodate margin, outline thickness etc ...)
std::size_t ime::ui::Tabs::getTabsCount | ( | ) | const |
Get the number of tabs.
std::string ime::ui::Tabs::getText | ( | std::size_t | index | ) | const |
Get the text of a tab.
index | Index of the tab to get the text of |
The first tab has an index of 0
|
inherited |
Get the character size of the text.
|
overridevirtual |
|
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
void ime::ui::Tabs::insert | ( | std::size_t | index, |
const std::string & | text, | ||
bool | select = true |
||
) |
Insert a new tab between other tabs.
index | The index where the tab is inserted |
text | The text of the tab that will be drawn on top of it |
select | True to immediately select tab, otherwise false |
index of 0 means before the first tab and 1 means behind the first tab
|
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
|
inherited |
Check if widget is enabled or disabled.
|
inherited |
Check if widget is focused or not.
bool ime::ui::Tabs::isTabEnabled | ( | std::size_t | index | ) | const |
Check whether a tab is enabled or not.
index | The index of the tab to be checked |
bool ime::ui::Tabs::isTabVisible | ( | std::size_t | index | ) | const |
Check if a tab is visible or not.
index | Index of the tab to be checked |
|
inherited |
Check if the widget is visible or not.
|
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.
|
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.
|
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 callback is passed event arguments (if any) on invocation. Here is an example demonstrating an event listener listening to an event with and arguments
|
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 callback is passed a pointer to the widget as the first argument followed by the event arguments (if any) on invocation
bool ime::ui::Tabs::remove | ( | const std::string & | text | ) |
Remove a tab with a given text.
text | The text on the tab to remove |
bool ime::ui::Tabs::remove | ( | std::size_t | index | ) |
Remove a tab with a given index.
index | The index of the tab to remove |
void ime::ui::Tabs::removeAll | ( | ) |
Remove all tabs.
|
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.
factor | Offset to apply |
This function multiplies the current scale of the widget, unlike setScale 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.
bool ime::ui::Tabs::select | ( | const std::string & | text | ) |
Select tab with a given text.
text | The text of the tab t select |
If there are multiple tabs with the same text, then the first one will be selected. When false is returned, the selected tab will be deselected
bool ime::ui::Tabs::select | ( | std::size_t | index | ) |
Select a tab with a given index.
index | Index of the tab to be selected |
When false is returned, the selected tab will be deselected
|
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::Tabs::setAutoSize | ( | bool | autoSize | ) |
Set whether or not the tabs auto-size.
autoSize | True to enable auto-size, otherwise false |
When the tabs are in auto-size mode, the width of the tabs will be dependent on the text which they contain. Otherwise, all tabs have an equal width to fill the size of the widget
The tabs are auto-sized by default
|
inherited |
Enable or disable the widget.
isEnable | Set 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
|
inherited |
Focus or unfocus widget.
isFocused | True to focus or false to unfocus widget |
When the widget is focused, a previously focused widget will be unfocused
By default, the widget is not focused
|
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
void ime::ui::Tabs::setMaximumTabWidth | ( | float | maximumWidth | ) |
Set the maximum tab width of the tabs.
maximumWidth | Maximum width of a single tab |
This property only has effect when the tabs are auto-sizing. If the text on the tab is longer than this width then it will be cropped to fit inside the tab.
By default, the maximum width is 0 which means that there is no limitation
void ime::ui::Tabs::setMinimumTabWidth | ( | float | minimumWidth | ) |
Set the minimum width of the tabs.
minimumWidth | Minimum width of a single tab |
This property only has effect when the tabs are auto-sizing. Every tab is at least as wide as this minimum or twice the distance to side
|
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
|
inherited |
Set the name of the widget.
name | The name of the widget |
By default the widget is assigned a unique name. The naming convention is as follows:
widgetType + instantiation number
For example:
|
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.
|
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.
|
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.
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.
|
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.
|
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 factor of the widget.
scale | New scale |
This function completely overwrites the previous scale
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.
|
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 |
void ime::ui::Tabs::setTabEnabled | ( | std::size_t | index, |
bool | enabled | ||
) |
Enable or disable a tab.
index | Index of the tab t enable or disable |
enabled | True to enable or false to disable |
void ime::ui::Tabs::setTabHeight | ( | float | height | ) |
Set the height of the tabs.
height | New height of the tabs |
When the tabs are auto-sizing, this function allows changing the width of the tabs without setting a fixed width like calling setSize would do
void ime::ui::Tabs::setTabVisible | ( | std::size_t | index, |
bool | visible | ||
) |
Hide or show a tab.
index | Index of the tab to hide or show |
visible | True to show or false to hide |
|
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
|
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
|
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