45 using Ptr = std::shared_ptr<MenuBar>;
46 using ConstPtr = std::shared_ptr<const MenuBar>;
48 static constexpr const char StaticWidgetType[] =
"MenuBar";
55 std::vector<GetMenusElement> menuItems;
63 int selectedMenuItem = -1;
64 std::vector<Menu> menuItems;
74 MenuBar(
const char* typeName = StaticWidgetType,
bool initRenderer =
true);
117 TGUI_NODISCARD
const MenuBarRenderer* getSharedRenderer()
const override;
139 template <
typename Func,
typename... Args>
142 return connectMenuItem({menu, menuItem}, std::forward<Func>(handler), args...);
158 template <
typename Func,
typename... Args>
159 unsigned int connectMenuItem(
const std::vector<String>& hierarchy, Func&& handler,
const Args&... args)
161#if defined(__cpp_lib_invoke) && (__cpp_lib_invoke >= 201411L)
162 return onMenuItemClick.connect(
163 [=](
const std::vector<String>& clickedMenuItem)
165 if (clickedMenuItem == hierarchy)
166 std::invoke(handler, args...);
170 return onMenuItemClick.connect(
171 [f=std::function<
void(
const Args&...)>(handler),args...,hierarchy](
const std::vector<String>& clickedMenuItem)
173 if (clickedMenuItem == hierarchy)
188 using Widget::setSize;
261 bool addMenuItem(
const std::vector<String>& hierarchy,
bool createParents =
true);
320 bool removeMenuItem(
const std::vector<String>& hierarchy,
bool removeParentsWhenEmpty =
true);
428 TGUI_NODISCARD std::vector<GetMenusElement>
getMenus()
const;
450 void leftMouseReleased(
Vector2f pos)
override;
455 void mouseMoved(
Vector2f pos)
override;
489 TGUI_NODISCARD std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const override;
494 void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers)
override;
514 void createMenu(std::vector<Menu>& menus,
const String& text);
519 TGUI_NODISCARD
Menu* findMenu(
const std::vector<String>& hierarchy,
unsigned int parentIndex, std::vector<Menu>& menus,
bool createParents);
524 TGUI_NODISCARD
const Menu* findMenu(
const std::vector<String>& hierarchy,
unsigned int parentIndex,
const std::vector<Menu>& menus)
const;
528 TGUI_NODISCARD
Menu* findMenuItem(
const std::vector<String>& hierarchy);
532 TGUI_NODISCARD
const Menu* findMenuItem(
const std::vector<String>& hierarchy)
const;
536 void loadMenus(
const std::unique_ptr<DataIO::Node>& node, std::vector<Menu>& menus);
540 void closeSubMenus(std::vector<Menu>& menus,
int& selectedMenu);
543 void deselectBottomItem();
546 void updateMenuTextColor(
Menu& menu,
bool selected);
549 void updateTextColors(std::vector<Menu>& menus,
int selectedMenu);
552 void updateTextOpacity(std::vector<Menu>& menus);
555 void updateTextFont(std::vector<Menu>& menus);
559 TGUI_NODISCARD
float calculateMenuWidth(
const Menu& menu)
const;
563 TGUI_NODISCARD
float getMenuItemHeight(
const Menu& menuItem)
const;
567 TGUI_NODISCARD
float calculateOpenMenuHeight(
const std::vector<Menu>& menuItems)
const;
570 TGUI_NODISCARD
Vector2f calculateSubmenuOffset(
const Menu& menu,
float globalLeftPos,
float menuWidth,
float subMenuWidth,
bool& openSubMenuToRight)
const;
573 TGUI_NODISCARD
bool isMouseOnTopOfMenu(
Vector2f menuPos,
Vector2f mousePos,
bool openSubMenuToRight,
const Menu& menu,
float menuWidth)
const;
576 TGUI_NODISCARD
bool findMenuItemBelowMouse(
Vector2f menuPos,
Vector2f mousePos,
bool openSubMenuToRight,
Menu& menu,
float menuWidth,
Menu** resultMenu, std::size_t* resultSelectedMenuItem);
592 TGUI_NODISCARD
bool isMouseOnOpenMenu(
Vector2f pos)
const;
598 void leftMouseReleasedOnMenu();
605 void mouseMovedOnMenu(
Vector2f pos);
627 std::vector<Menu> m_menus;
628 std::shared_ptr<MenuBarMenuPlaceholder> m_menuWidgetPlaceholder;
630 int m_visibleMenu = -1;
632 float m_minimumSubMenuWidth = 125;
634 bool m_invertedMenuDirection =
false;
636 Sprite m_spriteBackground;
637 Sprite m_spriteItemBackground;
638 Sprite m_spriteSelectedItemBackground;
641 Color m_backgroundColorCached;
642 Color m_selectedBackgroundColorCached;
643 Color m_textColorCached;
644 Color m_selectedTextColorCached;
645 Color m_textColorDisabledCached;
646 Color m_separatorColorCached = Color::Black;
647 float m_separatorThicknessCached = 1;
648 float m_separatorVerticalPaddingCached = 0;
649 float m_separatorSidePaddingCached = 0;
650 float m_distanceToSideCached = 0;
Backend-independent wrapper around the backend-specific text class.
Definition Text.hpp:48