26#ifndef TGUI_MENU_BAR_HPP
27#define TGUI_MENU_BAR_HPP
30#include <TGUI/Widget.hpp>
31#include <TGUI/Renderers/MenuBarRenderer.hpp>
32#include <TGUI/CopiedSharedPtr.hpp>
33#include <TGUI/Text.hpp>
39 class MenuBarMenuPlaceholder;
49 typedef std::shared_ptr<MenuBar>
Ptr;
50 typedef std::shared_ptr<const MenuBar>
ConstPtr;
57 std::vector<GetMenusElement> menuItems;
65 int selectedMenuItem = -1;
66 std::vector<Menu> menuItems;
77 MenuBar(
const char* typeName =
"MenuBar",
bool initRenderer =
true);
150 template <
typename Func,
typename... Args>
153 return connectMenuItem({menu, menuItem}, std::forward<Func>(handler), args...);
170 template <
typename Func,
typename... Args>
171 unsigned int connectMenuItem(
const std::vector<String>& hierarchy, Func&& handler,
const Args&... args)
173#if defined(__cpp_lib_invoke) && (__cpp_lib_invoke >= 201411L)
174 return onMenuItemClick.connect(
175 [=](
const std::vector<String>& clickedMenuItem)
177 if (clickedMenuItem == hierarchy)
178 std::invoke(handler, args...);
182 return onMenuItemClick.connect(
183 [f=std::function<
void(
const Args&...)>(handler),args...,hierarchy](
const std::vector<String>& clickedMenuItem)
185 if (clickedMenuItem == hierarchy)
281 bool addMenuItem(
const std::vector<String>& hierarchy,
bool createParents =
true);
328 bool removeMenuItem(
const std::vector<String>& hierarchy,
bool removeParentsWhenEmpty =
true);
455 std::vector<GetMenusElement> getMenus()
const;
475 void leftMousePressed(
Vector2f pos)
override;
480 void leftMouseReleased(
Vector2f pos)
override;
485 void mouseMoved(
Vector2f pos)
override;
525 std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const override;
531 void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers)
override;
555 void createMenu(std::vector<Menu>& menus,
const String& text);
560 Menu* findMenu(
const std::vector<String>& hierarchy,
unsigned int parentIndex, std::vector<Menu>& menus,
bool createParents);
565 const Menu* findMenu(
const std::vector<String>& hierarchy,
unsigned int parentIndex,
const std::vector<Menu>& menus)
const;
569 const Menu* findMenuItem(
const std::vector<String>& hierarchy)
const;
573 void loadMenus(
const std::unique_ptr<DataIO::Node>& node, std::vector<Menu>& menus);
577 void closeSubMenus(std::vector<Menu>& menus,
int& selectedMenu);
580 void deselectBottomItem();
583 void updateMenuTextColor(
Menu& menu,
bool selected);
586 void updateTextColors(std::vector<Menu>& menus,
int selectedMenu);
589 void updateTextOpacity(std::vector<Menu>& menus);
592 void updateTextFont(std::vector<Menu>& menus);
596 float calculateMenuWidth(
const Menu& menu)
const;
600 float getMenuItemHeight(
const Menu& menuItem)
const;
604 float calculateOpenMenuHeight(
const std::vector<Menu>& menuItems)
const;
607 Vector2f calculateSubmenuOffset(
const Menu& menu,
float globalLeftPos,
float menuWidth,
float subMenuWidth,
bool& openSubMenuToRight)
const;
610 bool isMouseOnTopOfMenu(
Vector2f menuPos,
Vector2f mousePos,
bool openSubMenuToRight,
const Menu& menu,
float menuWidth)
const;
613 bool findMenuItemBelowMouse(
Vector2f menuPos,
Vector2f mousePos,
bool openSubMenuToRight,
Menu& menu,
float menuWidth,
Menu** resultMenu,
int* resultSelectedMenuItem);
630 bool isMouseOnOpenMenu(
Vector2f pos)
const;
636 void leftMouseReleasedOnMenu();
643 void mouseMovedOnMenu(
Vector2f pos);
667 std::vector<Menu> m_menus;
668 std::shared_ptr<MenuBarMenuPlaceholder> m_menuWidgetPlaceholder;
670 int m_visibleMenu = -1;
672 float m_minimumSubMenuWidth = 125;
674 bool m_invertedMenuDirection =
false;
676 Sprite m_spriteBackground;
677 Sprite m_spriteItemBackground;
678 Sprite m_spriteSelectedItemBackground;
681 Color m_backgroundColorCached;
682 Color m_selectedBackgroundColorCached;
683 Color m_textColorCached;
684 Color m_selectedTextColorCached;
685 Color m_textColorDisabledCached;
687 float m_separatorThicknessCached = 1;
688 float m_separatorVerticalPaddingCached = 0;
689 float m_separatorSidePaddingCached = 0;
690 float m_distanceToSideCached = 0;
757 void leftMouseButtonNoLongerDown()
override;
762 void mouseMoved(
Vector2f pos)
override;
774 bool m_mouseWasOnMenuBar =
true;
Base class for render targets.
Definition: BackendRenderTarget.hpp:48
Wrapper for colors.
Definition: Color.hpp:63
static const Color Black
Black predefined color.
Definition: Color.hpp:253
Class to store the position or size of a widget.
Definition: Layout.hpp:284
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:859
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:58
Definition: Sprite.hpp:45
Wrapper class to store strings.
Definition: String.hpp:79
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
States used for drawing.
Definition: RenderStates.hpp:39