TGUI  0.8-dev

Menu bar widget. More...

#include <MenuBar.hpp>

Inheritance diagram for tgui::MenuBar:
tgui::Widget tgui::SignalWidgetBase

Classes

struct  Menu
 

Public Types

typedef std::shared_ptr< MenuBarPtr
 Shared widget pointer.
 
typedef std::shared_ptr< const MenuBarConstPtr
 Shared constant widget pointer.
 
- Public Types inherited from tgui::Widget
typedef std::shared_ptr< WidgetPtr
 Shared widget pointer.
 
typedef std::shared_ptr< const WidgetConstPtr
 Shared constant widget pointer.
 

Public Member Functions

MenuBarRenderergetSharedRenderer ()
 Returns the renderer, which gives access to functions that determine how the widget is displayed. More...
 
MenuBarRenderergetRenderer ()
 Returns the renderer, which gives access to functions that determine how the widget is displayed. More...
 
void setSize (const Layout2d &size) override
 Changes the size of the menu bar. More...
 
void addMenu (const sf::String &text)
 Adds a new menu. More...
 
bool addMenuItem (const sf::String &menu, const sf::String &text)
 Adds a new menu item. More...
 
bool addMenuItem (const sf::String &text)
 Adds a new menu item to the last added menu. More...
 
bool removeMenu (const sf::String &menu)
 Removes a menu. More...
 
void removeAllMenus ()
 Removes all menus.
 
bool removeMenuItem (const sf::String &menu, const sf::String &menuItem)
 Removes a menu item. More...
 
void setTextSize (unsigned int size)
 Changes the character size of the text. More...
 
unsigned int getTextSize () const
 Returns 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...
 
std::map< sf::String, std::vector< sf::String > > getMenus () const
 Returns a copy of all the menus and their menu items. More...
 
void closeMenu ()
 Closes the open menu when one of the menus is open.
 
bool mouseOnWidget (sf::Vector2f pos) const override
 Returns whether the mouse position (which is relative to the parent widget) lies on top 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.
 
Widgetoperator= (const Widget &)
 Overload of copy assignment operator.
 
Widgetoperator= (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...
 
WidgetRenderergetSharedRenderer ()
 Returns the renderer, which gives access to functions that determine how the widget is displayed. More...
 
WidgetRenderergetRenderer ()
 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...
 
sf::Vector2f getPosition () const
 Gets the position of the widget. More...
 
void setSize (Layout width, Layout height)
 Changes the size of the widget. More...
 
sf::Vector2f getSize () const
 Returns the size of the widget. More...
 
virtual sf::Vector2f getFullSize () const
 Returns the entire size that the widget is using. More...
 
virtual sf::Vector2f getAbsolutePosition () const
 Get the absolute position of the widget instead of the relative position to its parent. More...
 
virtual sf::Vector2f getWidgetOffset () const
 Returns the distance between the position where the widget is drawn and where the widget is placed. More...
 
virtual void show ()
 Shows the widget. More...
 
virtual void showWithEffect (ShowAnimationType type, sf::Time duration)
 Shows the widget by introducing it with an animation. More...
 
virtual void hide ()
 Hides the widget. More...
 
virtual void hideWithEffect (ShowAnimationType type, sf::Time duration)
 Hides the widget by making it leave with an animation. More...
 
bool isVisible () const
 Returns true when the widget is visible. More...
 
virtual void enable ()
 Enables the widget. More...
 
virtual void disable ()
 Disables the widget. More...
 
bool isEnabled () const
 Returns true when the widget is enabled. More...
 
virtual void focus ()
 Focus the widget. More...
 
virtual void unfocus ()
 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...
 
ContainergetParent () const
 Returns a pointer to the parent widget. More...
 
virtual void moveToFront ()
 Places the widget before all other widgets. More...
 
virtual void moveToBack ()
 Places the widget behind all other widgets. 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 FontgetInheritedFont () 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...
 
void setToolTip (Widget::Ptr toolTip)
 Sets the tool tip that should be displayed when hovering over the widget. More...
 
Widget::Ptr getToolTip ()
 Returns the tool tip that is displayed when hovering over the widget. More...
 
- 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 &..., 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

SignalMenuItem 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.
 

Protected Member Functions

SignalgetSignal (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...
 
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.
 

Detailed Description

Menu bar widget.

Member Function Documentation

◆ addMenu()

void tgui::MenuBar::addMenu ( const sf::String &  text)

Adds a new menu.

Parameters
textThe text written on the menu

◆ addMenuItem() [1/2]

bool tgui::MenuBar::addMenuItem ( const sf::String &  menu,
const sf::String &  text 
)

Adds a new menu item.

Parameters
menuThe name of the menu to which the menu item will be added
textThe text written on this menu item
Returns
True when the item was added, false when menu was not found
menuBar->addMenu("File");
menuBar->addMenu("Edit");
menuBar->addMenuItem("File", "Load");
menuBar->addMenuItem("File", "Save");
menuBar->addMenuItem("Edit", "Undo");

◆ addMenuItem() [2/2]

bool tgui::MenuBar::addMenuItem ( const sf::String &  text)

Adds a new menu item to the last added menu.

Parameters
textThe text written on this menu item
Returns
True when the item was added, false when the menu bar doesn't contain any menus yet
menuBar->addMenu("File");
menuBar->addMenuItem("Load");
menuBar->addMenuItem("Save");
menuBar->addMenu("Edit");
menuBar->addMenuItem("Undo");

◆ clone()

Widget::Ptr tgui::MenuBar::clone ( ) const
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.

Returns
Copy of the widget

Implements tgui::Widget.

◆ copy()

static MenuBar::Ptr tgui::MenuBar::copy ( MenuBar::ConstPtr  menuBar)
static

Makes a copy of another menu bar.

Parameters
menuBarThe other menu bar
Returns
The new menu bar

◆ create()

static MenuBar::Ptr tgui::MenuBar::create ( )
static

Creates a new menu bar widget.

Returns
The new menu bar

◆ getInvertedMenuDirection()

bool tgui::MenuBar::getInvertedMenuDirection ( ) const

Returns whether the menus open above or below the menu bar.

Returns
Do menus open above the bar instead of below like it does by default?

◆ getMenus()

std::map<sf::String, std::vector<sf::String> > tgui::MenuBar::getMenus ( ) const

Returns a copy of all the menus and their menu items.

Returns
Map of menus and their items

◆ getMinimumSubMenuWidth()

float tgui::MenuBar::getMinimumSubMenuWidth ( ) const

Returns the distance between the text and the side of the menu item.

Returns
minimum width of the submenus
See also
setMinimumSubMenuWidth

◆ getRenderer()

MenuBarRenderer* tgui::MenuBar::getRenderer ( )

Returns the renderer, which gives access to functions that determine how the widget is displayed.

Returns
Temporary pointer to the renderer
Warning
After calling this function, the widget has its own copy of the renderer and it will no longer be shared.

◆ getSharedRenderer()

MenuBarRenderer* tgui::MenuBar::getSharedRenderer ( )

Returns the renderer, which gives access to functions that determine how the widget is displayed.

Returns
Temporary pointer to the renderer that may be shared with other widgets using the same renderer

◆ getSignal()

Signal& tgui::MenuBar::getSignal ( std::string  signalName)
overrideprotectedvirtual

Retrieves a signal based on its name.

Parameters
signalNameName of the signal
Returns
Signal that corresponds to the name
Exceptions
Exceptionwhen the name does not match any signal

Reimplemented from tgui::Widget.

◆ getTextSize()

unsigned int tgui::MenuBar::getTextSize ( ) const

Returns the character size of the text.

Returns
The text size

◆ mouseOnWidget()

bool tgui::MenuBar::mouseOnWidget ( sf::Vector2f  pos) const
overridevirtual

Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget.

Returns
Is the mouse on top of the widget?

Implements tgui::Widget.

◆ removeMenu()

bool tgui::MenuBar::removeMenu ( const sf::String &  menu)

Removes a menu.

Any menu items that belong to this menu will be removed as well.

Parameters
menuThe name of the menu to remove
Returns
True when the menu was removed, false when menu was not found

◆ removeMenuItem()

bool tgui::MenuBar::removeMenuItem ( const sf::String &  menu,
const sf::String &  menuItem 
)

Removes a menu item.

Parameters
menuThe name of the menu in which the menu item is located
menuItemThe name of the menu item to remove
Returns
True when the item was removed, false when menu or menuItem was not found

◆ rendererChanged()

void tgui::MenuBar::rendererChanged ( const std::string &  property)
overrideprotectedvirtual

Function called when one of the properties of the renderer is changed.

Parameters
propertyLowercase name of the property that was changed

Reimplemented from tgui::Widget.

◆ setInvertedMenuDirection()

void tgui::MenuBar::setInvertedMenuDirection ( bool  invertDirection)

Changes whether the menus open above or below the menu bar.

Parameters
invertDirectionShould the menus open above the bar instead of below like it does by default?

◆ setMinimumSubMenuWidth()

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.

Parameters
minimumWidthminimum width of the submenus

◆ setSize()

void tgui::MenuBar::setSize ( const Layout2d size)
overridevirtual

Changes the size of the menu bar.

Parameters
sizeThe 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.

◆ setTextSize()

void tgui::MenuBar::setTextSize ( unsigned int  size)

Changes the character size of the text.

Parameters
sizeThe new size of the text. If the size is 0 (default) then the text will be scaled to fit in the menu bar

Member Data Documentation

◆ onMenuItemClick

SignalMenuItem tgui::MenuBar::onMenuItemClick = {"MenuItemClicked"}

One of the menu items was clicked. Optional parameters:

  • The text of the clicked menu item
  • List containing both the name of the menu and the menu item that was clicked

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