TGUI  0.8-dev

Menu bar widget. More...

#include <MenuBar.hpp>

Inheritance diagram for tgui::MenuBar:
tgui::Widget tgui::Transformable 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

MenuBarRenderergetRenderer () const
 Returns the renderer, which gives access to functions that determine how the widget is displayed. More...
 
virtual 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...
 
- 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...
 
WidgetRenderergetRenderer () const
 Returns the renderer, which gives access to functions that determine how the widget is displayed. More...
 
virtual void setPosition (const Layout2d &position) override
 sets the position of the widget 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.
 
virtual void moveToBack ()
 Places the widget behind all other widgets.
 
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::Transformable
virtual ~Transformable ()=default
 Virtual destructor.
 
void setPosition (const Layout &x, const Layout &y)
 Sets the position of the widget. More...
 
sf::Vector2f getPosition () const
 Gets the position of the widget. More...
 
void move (const Layout2d &offset)
 Moves the widget by a given offset. More...
 
void move (const Layout &x, const Layout &y)
 Moves the widget by a given offset. More...
 
void setSize (const Layout &width, const Layout &height)
 Changes the size of the widget. More...
 
virtual 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...
 
void scale (const Layout2d &factors)
 Scales the widget. More...
 
void scale (const Layout &x, const Layout &y)
 Scales the widget. More...
 
- Public Member Functions inherited from tgui::SignalWidgetBase
virtual ~SignalWidgetBase ()
 Virtual destructor.
 
template<typename Func , typename... Args>
unsigned int connect (const std::string &signalNames, Func func, Args... args)
 Connects a signal handler function to one or more signals. More...
 
template<typename Func , typename... Args>
unsigned int connectEx (const std::string &signalName, Func func, Args... args)
 Connects a signal handler function to one or more signals. More...
 
void disconnect (unsigned int id)
 Disconnects a connection. More...
 
void disconnectAll (const std::string &signalName)
 Disconnects all connections from a certain signal. More...
 
void disconnectAll ()
 Disconnects all connections from a all 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...
 

Protected Member Functions

virtual void rendererChanged (const std::string &property) override
 Function called when one of the properties of the renderer is changed. More...
 
virtual 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.

Signals:

  • MenuItemClicked
    • Optional parameter sf::String: name of the item on which you clicked
    • Optional parameter std::vector<sf::String>: Which menu was open, followed by which item you clicked on
    • Uses Callback member 'text' (menu item name) and 'index' (index of the open menu)
  • Inherited signals from 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()

virtual 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 ( ) const
inline

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

Returns
Temporary pointer to the renderer

§ getTextSize()

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

Returns the character size of the text.

Returns
The text size

§ 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()

virtual 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()

virtual 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

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