TGUI
0.8.9
|
#include <TGUI/Widgets/MenuBar.hpp>
Classes | |
struct | GetAllMenusElement |
Used for return value of getAllMenus. More... | |
struct | GetMenuListElement |
Used for return value of getMenuList. More... | |
struct | Menu |
Public Types | |
typedef std::shared_ptr< MenuBar > | Ptr |
Shared widget pointer. | |
typedef std::shared_ptr< const MenuBar > | ConstPtr |
Shared constant widget pointer. | |
Public Types inherited from tgui::Widget | |
typedef std::shared_ptr< Widget > | Ptr |
Shared widget pointer. | |
typedef std::shared_ptr< const Widget > | ConstPtr |
Shared constant widget pointer. | |
Public Member Functions | |
MenuBarRenderer * | getSharedRenderer () |
Returns the renderer, which gives access to functions that determine how the widget is displayed. More... | |
MenuBarRenderer * | getRenderer () |
Returns the renderer, which gives access to functions that determine how the widget is displayed. More... | |
template<typename Func , typename... Args> | |
unsigned int | connectMenuItem (const sf::String &menu, const sf::String &menuItem, Func &&handler, const Args &... args) |
Connects a signal handler to the "MenuItemClicked" callback that will only be called when a specific menu item was clicked. More... | |
template<typename Func , typename... Args> | |
unsigned int | connectMenuItem (const std::vector< sf::String > &hierarchy, Func &&handler, const Args &... args) |
Connects a signal handler to the "MenuItemClicked" callback that will only be called when a specific menu item was clicked. More... | |
void | setSize (const Layout2d &size) override |
Changes the size of the menu bar. More... | |
void | setEnabled (bool enabled) override |
Enables or disables the widget. More... | |
void | addMenu (const sf::String &text) |
Adds a new menu. More... | |
bool | addMenuItem (const sf::String &text) |
Adds a new menu item to the last added menu. More... | |
bool | addMenuItem (const sf::String &menu, const sf::String &text) |
Adds a new menu item to an existing menu. More... | |
bool | addMenuItem (const std::vector< sf::String > &hierarchy, bool createParents=true) |
Adds a new menu item (or sub menu item) More... | |
void | removeAllMenus () |
Removes all menus. | |
bool | removeMenu (const sf::String &menu) |
Removes a menu. More... | |
bool | removeMenuItem (const sf::String &menu, const sf::String &menuItem) |
Removes a menu item. More... | |
bool | removeMenuItem (const std::vector< sf::String > &hierarchy, bool removeParentsWhenEmpty=true) |
Removes a menu item (or sub menu item) More... | |
bool | removeMenuItems (const sf::String &menu) |
Removes all menu items from a menu. More... | |
bool | removeSubMenuItems (const std::vector< sf::String > &hierarchy) |
Removes a all menu items below a (sub) menu. More... | |
bool | setMenuEnabled (const sf::String &menu, bool enabled) |
Enable or disable an entire menu. More... | |
bool | getMenuEnabled (const sf::String &menu) const |
Check if an entire menu is enabled or disabled. More... | |
bool | setMenuItemEnabled (const sf::String &menu, const sf::String &menuItem, bool enabled) |
Enable or disable a menu item. More... | |
bool | setMenuItemEnabled (const std::vector< sf::String > &hierarchy, bool enabled) |
Enable or disable a menu item. More... | |
bool | getMenuItemEnabled (const sf::String &menu, const sf::String &menuItem) const |
Check if a menu item is enabled or disabled. More... | |
bool | getMenuItemEnabled (const std::vector< sf::String > &hierarchy) const |
Check if a menu item is enabled or disabled. More... | |
void | setTextSize (unsigned int size) override |
Changes the character size of the text. More... | |
void | setMinimumSubMenuWidth (float minimumWidth) |
Changes the minimum width of the submenus. More... | |
float | getMinimumSubMenuWidth () const |
Returns the distance between the text and the side of the menu item. More... | |
void | setInvertedMenuDirection (bool invertDirection) |
Changes whether the menus open above or below the menu bar. More... | |
bool | getInvertedMenuDirection () const |
Returns whether the menus open above or below the menu bar. More... | |
void | closeMenu () |
Closes the open menu when one of the menus is open. | |
bool | mouseOnWidget (Vector2f pos) const override |
Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget. More... | |
virtual void | setSize (const Layout2d &size) |
Changes the size of the widget. More... | |
void | setSize (Layout width, Layout height) |
Changes the size of the widget. More... | |
Public Member Functions inherited from tgui::Widget | |
Widget () | |
Default constructor. | |
Widget (const Widget &) | |
Copy constructor. | |
Widget (Widget &&) | |
Move constructor. | |
~Widget () | |
Destructor. | |
Widget & | operator= (const Widget &) |
Overload of copy assignment operator. | |
Widget & | operator= (Widget &&) |
Move assignment. | |
void | setRenderer (std::shared_ptr< RendererData > rendererData) |
Sets a new renderer for the widget. The renderer determines how the widget looks. More... | |
WidgetRenderer * | getSharedRenderer () |
Returns the renderer, which gives access to functions that determine how the widget is displayed. More... | |
WidgetRenderer * | getRenderer () |
Returns the renderer, which gives access to functions that determine how the widget is displayed. More... | |
virtual void | setPosition (const Layout2d &position) |
sets the position of the widget More... | |
void | setPosition (Layout x, Layout y) |
Sets the position of the widget. More... | |
Vector2f | getPosition () const |
Gets the position of the widget. More... | |
void | setSize (Layout width, Layout height) |
Changes the size of the widget. More... | |
Vector2f | getSize () const |
Returns the size of the widget. More... | |
virtual Vector2f | getFullSize () const |
Returns the entire size that the widget is using. More... | |
virtual Vector2f | getAbsolutePosition () const |
Get the absolute position of the widget instead of the relative position to its parent. More... | |
virtual Vector2f | getWidgetOffset () const |
Returns the distance between the position where the widget is drawn and where the widget is placed. More... | |
virtual void | showWithEffect (ShowAnimationType type, sf::Time duration) |
Shows the widget by introducing it with an animation. More... | |
virtual void | hideWithEffect (ShowAnimationType type, sf::Time duration) |
Hides the widget by making it leave with an animation. More... | |
virtual void | setVisible (bool visible) |
Shows or hides a widget. More... | |
bool | isVisible () const |
Returns true when the widget is visible. More... | |
bool | isEnabled () const |
Returns true when the widget is enabled. More... | |
virtual void | setFocused (bool focused) |
Focus or unfocus the widget. More... | |
bool | isFocused () const |
Returns true when the widget is focused and false otherwise. More... | |
const std::string & | getWidgetType () const |
Returns the type of the widget. More... | |
Container * | getParent () const |
Returns a pointer to the parent widget. More... | |
bool | isAnimationPlaying () const |
Returns whether there is an active animation (started with showWithEffect or hideWithEffect) More... | |
virtual void | moveToFront () |
Places the widget before all other widgets. More... | |
virtual void | moveToBack () |
Places the widget behind all other widgets. More... | |
void | setUserData (std::any userData) |
Stores some data into the widget. More... | |
template<typename T > | |
T | getUserData () const |
Returns data stored in the widget. More... | |
void | setInheritedFont (const Font &font) |
Sets the font of the widget that is used when no font is set in the renderer. More... | |
const Font & | getInheritedFont () const |
Returns the font of the widget that is used when no font is set in the renderer. More... | |
void | setInheritedOpacity (float opacity) |
Sets the opacity of the widget that will be multiplied with the opacity set in the renderer. More... | |
float | getInheritedOpacity () const |
Returns the opacity of the widget that is multiplied with the opacity set in the renderer. More... | |
virtual unsigned int | getTextSize () const |
Returns the character size of text in this widget. More... | |
void | setToolTip (Widget::Ptr toolTip) |
Sets the tool tip that should be displayed when hovering over the widget. More... | |
Widget::Ptr | getToolTip () const |
Returns the tool tip that is displayed when hovering over the widget. More... | |
void | setWidgetName (const sf::String &name) |
Changes the name of a widget. More... | |
sf::String | getWidgetName () const |
Returns the name of a widget. More... | |
void | setFocusable (bool focusable) |
Changes whether a widget could be focused. More... | |
bool | isFocusable () const |
Returns whether a widget could be focused. More... | |
virtual bool | canGainFocus () const |
Returns whether the widget can currently gain focus. More... | |
bool | isContainer () const |
Returns whether the widget is a container widget or not. More... | |
template<typename WidgetType > | |
std::shared_ptr< const WidgetType > | cast () const |
Downcast const widget. | |
template<typename WidgetType > | |
std::shared_ptr< WidgetType > | cast () |
Downcast widget. | |
Public Member Functions inherited from tgui::SignalWidgetBase | |
template<typename Func , typename... Args, typename std::enable_if< std::is_convertible< Func, std::function< void(const Args &...)> >::value >::type * = nullptr> | |
unsigned int | connect (std::string signalName, Func &&handler, const Args &... args) |
Connects a signal handler that will be called when this signal is emitted. More... | |
template<typename Func , typename... BoundArgs, typename std::enable_if<!std::is_convertible< Func, std::function< void(const BoundArgs &...)> >::value &&std::is_convertible< Func, std::function< void(const BoundArgs &..., std::shared_ptr< Widget >, const std::string &)> >::value , ::type * = nullptr> | |
unsigned int | connect (std::string signalName, Func &&handler, BoundArgs &&... args) |
Connects a signal handler that will be called when this signal is emitted. More... | |
template<typename Func , typename... BoundArgs, typename std::enable_if<!std::is_convertible< Func, std::function< void(const BoundArgs &...)> >::value &&!std::is_convertible< Func, std::function< void(const BoundArgs &..., std::shared_ptr< Widget >, const std::string &)> >::value , ::type * = nullptr> | |
unsigned int | connect (std::string signalName, Func &&handler, BoundArgs &&... args) |
Connects a signal handler that will be called when this signal is emitted. More... | |
template<typename Func , typename... BoundArgs> | |
unsigned int | connect (std::initializer_list< std::string > signalNames, Func &&handler, BoundArgs &&... args) |
Connect a signal handler to multiple signals. More... | |
bool | disconnect (unsigned int id) |
Disconnects a signal handler. More... | |
void | disconnectAll (std::string signalName) |
Disconnects all signal handler from a certain signal. More... | |
void | disconnectAll () |
Disconnects all signal handlers from signals. | |
Static Public Member Functions | |
static MenuBar::Ptr | create () |
Creates a new menu bar widget. More... | |
static MenuBar::Ptr | copy (MenuBar::ConstPtr menuBar) |
Makes a copy of another menu bar. More... | |
Public Attributes | |
SignalItemHierarchy | onMenuItemClick = {"MenuItemClicked"} |
Public Attributes inherited from tgui::Widget | |
SignalVector2f | onPositionChange = {"PositionChanged"} |
The position of the widget changed. Optional parameter: new position. | |
SignalVector2f | onSizeChange = {"SizeChanged"} |
The size of the widget changed. Optional parameter: new size. | |
Signal | onFocus = {"Focused"} |
The widget was focused. | |
Signal | onUnfocus = {"Unfocused"} |
The widget was unfocused. | |
Signal | onMouseEnter = {"MouseEntered"} |
The mouse entered the widget. | |
Signal | onMouseLeave = {"MouseLeft"} |
The mouse left the widget. | |
SignalAnimation | onAnimationFinished = {"AnimationFinished"} |
A show or hide animation finished. Optional parameters: animation type, new widget visibility or both. | |
Protected Member Functions | |
Signal & | getSignal (std::string signalName) override |
Retrieves a signal based on its name. More... | |
void | rendererChanged (const std::string &property) override |
Function called when one of the properties of the renderer is changed. More... | |
std::unique_ptr< DataIO::Node > | save (SavingRenderersMap &renderers) const override |
Saves the widget as a tree node in order to save it to a file. | |
void | load (const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override |
Loads the widget from a tree of nodes. | |
Widget::Ptr | clone () const override |
Makes a copy of the widget if you don't know its exact type. More... | |
Protected Member Functions inherited from tgui::Widget | |
virtual void | mouseEnteredWidget () |
This function is called when the mouse enters the widget. | |
Menu bar widget.
void tgui::MenuBar::addMenu | ( | const sf::String & | text | ) |
Adds a new menu.
text | The text written on the menu |
bool tgui::MenuBar::addMenuItem | ( | const sf::String & | menu, |
const sf::String & | text | ||
) |
Adds a new menu item to an existing menu.
menu | The name of the menu to which the menu item will be added |
text | The text written on this menu item |
bool tgui::MenuBar::addMenuItem | ( | const sf::String & | text | ) |
Adds a new menu item to the last added menu.
text | The text written on this menu item |
bool tgui::MenuBar::addMenuItem | ( | const std::vector< sf::String > & | hierarchy, |
bool | createParents = true |
||
) |
Adds a new menu item (or sub menu item)
hierarchy | Hierarchy of the menu items, starting with the menu and ending with menu item to be added |
createParents | Should the hierarchy be created if it did not exist yet? |
|
inlineoverrideprotectedvirtual |
Makes a copy of the widget if you don't know its exact type.
This function should only be used when you don't know the type of the widget. If you know what kind of widget you are copying, you should use the copy function.
Implements tgui::Widget.
|
inline |
Connects a signal handler to the "MenuItemClicked" callback that will only be called when a specific menu item was clicked.
menu | Menu containing the menu item |
menuItem | Menu item which should trigger the signal |
handler | Callback function to call |
args | Optional extra arguments to pass to the signal handler when the signal is emitted |
The hierarchy does not need to exist yet and the signal will still exist when removing and readding the menu items.
|
inline |
Connects a signal handler to the "MenuItemClicked" callback that will only be called when a specific menu item was clicked.
hierarchy | Hierarchy of the menu items, starting with the menu and ending with menu item that should trigger the signal when pressed |
handler | Callback function to call |
args | Optional extra arguments to pass to the signal handler when the signal is emitted |
The hierarchy does not need to exist yet and the signal will still exist when removing and readding the menu items.
|
static |
Makes a copy of another menu bar.
menuBar | The other menu bar |
|
static |
Creates a new menu bar widget.
bool tgui::MenuBar::getInvertedMenuDirection | ( | ) | const |
Returns whether the menus open above or below the menu bar.
bool tgui::MenuBar::getMenuEnabled | ( | const sf::String & | menu | ) | const |
Check if an entire menu is enabled or disabled.
menu | The name of the menu to check |
bool tgui::MenuBar::getMenuItemEnabled | ( | const sf::String & | menu, |
const sf::String & | menuItem | ||
) | const |
Check if a menu item is enabled or disabled.
menu | The name of the menu in which the menu item is located |
menuItem | The name of the menu item to check |
bool tgui::MenuBar::getMenuItemEnabled | ( | const std::vector< sf::String > & | hierarchy | ) | const |
Check if a menu item is enabled or disabled.
hierarchy | Hierarchy of menu items, starting with the menu and ending with the menu item to check |
float tgui::MenuBar::getMinimumSubMenuWidth | ( | ) | const |
Returns the distance between the text and the side of the menu item.
MenuBarRenderer * tgui::MenuBar::getRenderer | ( | ) |
Returns the renderer, which gives access to functions that determine how the widget is displayed.
MenuBarRenderer * tgui::MenuBar::getSharedRenderer | ( | ) |
Returns the renderer, which gives access to functions that determine how the widget is displayed.
|
overrideprotectedvirtual |
Retrieves a signal based on its name.
signalName | Name of the signal |
Exception | when the name does not match any signal |
Reimplemented from tgui::Widget.
|
overridevirtual |
Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget.
Implements tgui::Widget.
bool tgui::MenuBar::removeMenu | ( | const sf::String & | menu | ) |
Removes a menu.
Any menu items that belong to this menu will be removed as well.
menu | The name of the menu to remove |
bool tgui::MenuBar::removeMenuItem | ( | const sf::String & | menu, |
const sf::String & | menuItem | ||
) |
Removes a menu item.
menu | The name of the menu in which the menu item is located |
menuItem | The name of the menu item to remove |
bool tgui::MenuBar::removeMenuItem | ( | const std::vector< sf::String > & | hierarchy, |
bool | removeParentsWhenEmpty = true |
||
) |
Removes a menu item (or sub menu item)
hierarchy | Hierarchy of the menu item, starting with the menu and ending with menu item to be deleted |
removeParentsWhenEmpty | Also delete the parent of the deleted menu item if it has no other children |
bool tgui::MenuBar::removeMenuItems | ( | const sf::String & | menu | ) |
Removes all menu items from a menu.
menu | The name of the menu for which all menu items should be removed |
bool tgui::MenuBar::removeSubMenuItems | ( | const std::vector< sf::String > & | hierarchy | ) |
Removes a all menu items below a (sub) menu.
hierarchy | Hierarchy of the menu item, starting with the menu and ending with the sub menu containing the items |
|
overrideprotectedvirtual |
Function called when one of the properties of the renderer is changed.
property | Lowercase name of the property that was changed |
Reimplemented from tgui::Widget.
|
overridevirtual |
Enables or disables the widget.
enabled | Is the widget enabled? |
The disabled widget will no longer receive events and thus no longer send callbacks. All widgets are enabled by default.
Reimplemented from tgui::Widget.
void tgui::MenuBar::setInvertedMenuDirection | ( | bool | invertDirection | ) |
Changes whether the menus open above or below the menu bar.
invertDirection | Should the menus open above the bar instead of below like it does by default? |
bool tgui::MenuBar::setMenuEnabled | ( | const sf::String & | menu, |
bool | enabled | ||
) |
Enable or disable an entire menu.
menu | The name of the menu to enable or disable |
enabled | Should the menu be enabled or disabled? |
bool tgui::MenuBar::setMenuItemEnabled | ( | const sf::String & | menu, |
const sf::String & | menuItem, | ||
bool | enabled | ||
) |
Enable or disable a menu item.
menu | The name of the menu in which the menu item is located |
menuItem | The name of the menu item to enable or disable |
enabled | Should the menu item be enabled or disabled? |
bool tgui::MenuBar::setMenuItemEnabled | ( | const std::vector< sf::String > & | hierarchy, |
bool | enabled | ||
) |
Enable or disable a menu item.
hierarchy | Hierarchy of menu items, starting with the menu and ending with the menu item to enable/disable |
enabled | Should the menu item be enabled or disabled? |
void tgui::MenuBar::setMinimumSubMenuWidth | ( | float | minimumWidth | ) |
Changes the minimum width of the submenus.
When a submenu is displayed, the width will be either this or the width of the longest text in the submenu. The default minimum width is 125 pixels.
minimumWidth | minimum width of the submenus |
|
virtual |
Changes the size of the widget.
size | Size of the widget |
Usage examples:
Reimplemented from tgui::Widget.
|
overridevirtual |
Changes the size of the menu bar.
size | The new size of the menu bar |
By default, the menu bar has the same width as the window and the height is 20 pixels.
Reimplemented from tgui::Widget.
Changes the size of the widget.
width | Width of the widget |
height | Height of the widget |
|
overridevirtual |
Changes the character size of the text.
size | The new size of the text. |
Reimplemented from tgui::Widget.
SignalItemHierarchy tgui::MenuBar::onMenuItemClick = {"MenuItemClicked"} |
One of the menu items was clicked. Optional parameters: