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 using Ptr = std::shared_ptr<MenuBar>;
50 using ConstPtr = std::shared_ptr<const MenuBar>;
52 static constexpr const char StaticWidgetType[] =
"MenuBar";
60 std::vector<GetMenusElement> menuItems;
68 int selectedMenuItem = -1;
69 std::vector<Menu> menuItems;
80 MenuBar(
const char* typeName = StaticWidgetType,
bool initRenderer =
true);
152 template <
typename Func,
typename... Args>
155 return connectMenuItem({menu, menuItem}, std::forward<Func>(handler), args...);
172 template <
typename Func,
typename... Args>
173 unsigned int connectMenuItem(
const std::vector<String>& hierarchy, Func&& handler,
const Args&... args)
175#if defined(__cpp_lib_invoke) && (__cpp_lib_invoke >= 201411L)
176 return onMenuItemClick.connect(
177 [=](
const std::vector<String>& clickedMenuItem)
179 if (clickedMenuItem == hierarchy)
180 std::invoke(handler, args...);
184 return onMenuItemClick.connect(
185 [f=std::function<
void(
const Args&...)>(handler),args...,hierarchy](
const std::vector<String>& clickedMenuItem)
187 if (clickedMenuItem == hierarchy)
204 using Widget::setSize;
283 bool addMenuItem(
const std::vector<String>& hierarchy,
bool createParents =
true);
349 bool removeMenuItem(
const std::vector<String>& hierarchy,
bool removeParentsWhenEmpty =
true);
476 std::vector<GetMenusElement> getMenus()
const;
496 void leftMousePressed(
Vector2f pos)
override;
501 void leftMouseReleased(
Vector2f pos)
override;
506 void mouseMoved(
Vector2f pos)
override;
546 std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const override;
552 void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers)
override;
576 void createMenu(std::vector<Menu>& menus,
const String& text);
581 Menu* findMenu(
const std::vector<String>& hierarchy,
unsigned int parentIndex, std::vector<Menu>& menus,
bool createParents);
586 const Menu* findMenu(
const std::vector<String>& hierarchy,
unsigned int parentIndex,
const std::vector<Menu>& menus)
const;
590 Menu* findMenuItem(
const std::vector<String>& hierarchy);
594 const Menu* findMenuItem(
const std::vector<String>& hierarchy)
const;
598 void loadMenus(
const std::unique_ptr<DataIO::Node>& node, std::vector<Menu>& menus);
602 void closeSubMenus(std::vector<Menu>& menus,
int& selectedMenu);
605 void deselectBottomItem();
608 void updateMenuTextColor(
Menu& menu,
bool selected);
611 void updateTextColors(std::vector<Menu>& menus,
int selectedMenu);
614 void updateTextOpacity(std::vector<Menu>& menus);
617 void updateTextFont(std::vector<Menu>& menus);
621 float calculateMenuWidth(
const Menu& menu)
const;
625 float getMenuItemHeight(
const Menu& menuItem)
const;
629 float calculateOpenMenuHeight(
const std::vector<Menu>& menuItems)
const;
632 Vector2f calculateSubmenuOffset(
const Menu& menu,
float globalLeftPos,
float menuWidth,
float subMenuWidth,
bool& openSubMenuToRight)
const;
635 bool isMouseOnTopOfMenu(
Vector2f menuPos,
Vector2f mousePos,
bool openSubMenuToRight,
const Menu& menu,
float menuWidth)
const;
638 bool findMenuItemBelowMouse(
Vector2f menuPos,
Vector2f mousePos,
bool openSubMenuToRight,
Menu& menu,
float menuWidth,
Menu** resultMenu, std::size_t* resultSelectedMenuItem);
655 bool isMouseOnOpenMenu(
Vector2f pos)
const;
661 void leftMouseReleasedOnMenu();
668 void mouseMovedOnMenu(
Vector2f pos);
692 std::vector<Menu> m_menus;
693 std::shared_ptr<MenuBarMenuPlaceholder> m_menuWidgetPlaceholder;
695 int m_visibleMenu = -1;
697 float m_minimumSubMenuWidth = 125;
699 bool m_invertedMenuDirection =
false;
701 Sprite m_spriteBackground;
702 Sprite m_spriteItemBackground;
703 Sprite m_spriteSelectedItemBackground;
706 Color m_backgroundColorCached;
707 Color m_selectedBackgroundColorCached;
708 Color m_textColorCached;
709 Color m_selectedTextColorCached;
710 Color m_textColorDisabledCached;
711 Color m_separatorColorCached = Color::Black;
712 float m_separatorThicknessCached = 1;
713 float m_separatorVerticalPaddingCached = 0;
714 float m_separatorSidePaddingCached = 0;
715 float m_distanceToSideCached = 0;
782 void leftMouseButtonNoLongerDown()
override;
787 void mouseMoved(
Vector2f pos)
override;
799 bool m_mouseWasOnMenuBar =
true;
Base class for render targets.
Definition: BackendRenderTarget.hpp:48
Wrapper for colors.
Definition: Color.hpp:63
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:960
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