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)
202 using Widget::setSize;
281 bool addMenuItem(
const std::vector<String>& hierarchy,
bool createParents =
true);
328 bool removeMenuItem(
const std::vector<String>& hierarchy,
bool removeParentsWhenEmpty =
true);
462 std::vector<GetMenusElement> getMenus()
const;
482 void leftMousePressed(
Vector2f pos)
override;
487 void leftMouseReleased(
Vector2f pos)
override;
492 void mouseMoved(
Vector2f pos)
override;
532 std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const override;
538 void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers)
override;
546 return std::make_shared<MenuBar>(*
this);
559 void createMenu(std::vector<Menu>& menus,
const String& text);
564 Menu* findMenu(
const std::vector<String>& hierarchy,
unsigned int parentIndex, std::vector<Menu>& menus,
bool createParents);
569 const Menu* findMenu(
const std::vector<String>& hierarchy,
unsigned int parentIndex,
const std::vector<Menu>& menus)
const;
573 const Menu* findMenuItem(
const std::vector<String>& hierarchy)
const;
577 void loadMenus(
const std::unique_ptr<DataIO::Node>& node, std::vector<Menu>& menus);
581 void closeSubMenus(std::vector<Menu>& menus,
int& selectedMenu);
584 void deselectBottomItem();
587 void updateMenuTextColor(
Menu& menu,
bool selected);
590 void updateTextColors(std::vector<Menu>& menus,
int selectedMenu);
593 void updateTextOpacity(std::vector<Menu>& menus);
596 void updateTextFont(std::vector<Menu>& menus);
600 float calculateMenuWidth(
const Menu& menu)
const;
604 float getMenuItemHeight(
const Menu& menuItem)
const;
608 float calculateOpenMenuHeight(
const std::vector<Menu>& menuItems)
const;
611 Vector2f calculateSubmenuOffset(
const Menu& menu,
float globalLeftPos,
float menuWidth,
float subMenuWidth,
bool& openSubMenuToRight)
const;
614 bool isMouseOnTopOfMenu(
Vector2f menuPos,
Vector2f mousePos,
bool openSubMenuToRight,
const Menu& menu,
float menuWidth)
const;
617 bool findMenuItemBelowMouse(
Vector2f menuPos,
Vector2f mousePos,
bool openSubMenuToRight,
Menu& menu,
float menuWidth,
Menu** resultMenu,
int* resultSelectedMenuItem);
634 bool isMouseOnOpenMenu(
Vector2f pos)
const;
640 void leftMouseReleasedOnMenu();
647 void mouseMovedOnMenu(
Vector2f pos);
671 std::vector<Menu> m_menus;
672 std::shared_ptr<MenuBarMenuPlaceholder> m_menuWidgetPlaceholder;
674 int m_visibleMenu = -1;
676 float m_minimumSubMenuWidth = 125;
678 bool m_invertedMenuDirection =
false;
680 Sprite m_spriteBackground;
681 Sprite m_spriteItemBackground;
682 Sprite m_spriteSelectedItemBackground;
685 Color m_backgroundColorCached;
686 Color m_selectedBackgroundColorCached;
687 Color m_textColorCached;
688 Color m_selectedTextColorCached;
689 Color m_textColorDisabledCached;
690 Color m_separatorColorCached = Color::Black;
691 float m_separatorThicknessCached = 1;
692 float m_separatorVerticalPaddingCached = 0;
693 float m_separatorSidePaddingCached = 0;
694 float m_distanceToSideCached = 0;