43 class TGUI_API MenuWidgetBase :
public Widget
52 std::vector<GetMenusElement> menuItems;
59 MenuWidgetBase(
const MenuWidgetBase& other);
64 MenuWidgetBase(MenuWidgetBase&& other)
noexcept;
69 MenuWidgetBase& operator=(
const MenuWidgetBase& other);
74 MenuWidgetBase& operator=(MenuWidgetBase&& other)
noexcept;
102 int selectedMenuItem = -1;
103 std::vector<Menu> menuItems;
136 void createMenu(std::vector<Menu>& menus,
const String& text);
141 TGUI_NODISCARD
Menu* findMenuItemParent(
const std::vector<String>& hierarchy,
unsigned int parentIndex, std::vector<Menu>& menus,
bool createParents);
146 TGUI_NODISCARD
const Menu* findMenuItemParent(
const std::vector<String>& hierarchy,
unsigned int parentIndex,
const std::vector<Menu>& menus)
const;
150 TGUI_NODISCARD
Menu* findMenuItem(
const std::vector<String>& hierarchy, std::vector<Menu>& menus);
154 TGUI_NODISCARD
const Menu* findMenuItem(
const std::vector<String>& hierarchy,
const std::vector<Menu>& menus)
const;
158 void loadMenus(
const std::unique_ptr<DataIO::Node>& node, std::vector<Menu>& menus);
162 void closeSubMenus(std::vector<Menu>& menus,
int& selectedMenu);
165 void updateMenuTextColor(
Menu& menu,
bool selected);
168 void updateTextColors(std::vector<Menu>& menus,
int selectedMenu);
171 void updateTextOpacity(std::vector<Menu>& menus);
174 void updateTextFont(std::vector<Menu>& menus);
178 TGUI_NODISCARD
float calculateMenuWidth(
const Menu& menu)
const;
182 TGUI_NODISCARD
float getMenuItemHeight(
const Menu& menuItem)
const;
186 TGUI_NODISCARD
float calculateOpenMenuHeight(
const std::vector<Menu>& menuItems)
const;
189 TGUI_NODISCARD Vector2f calculateSubmenuOffset(
const Menu& menu,
float globalLeftPos,
float menuWidth,
float subMenuWidth,
bool& openSubMenuToRight)
const;
192 TGUI_NODISCARD
bool isMouseOnTopOfMenu(Vector2f menuPos, Vector2f mousePos,
bool openSubMenuToRight,
const Menu& menu,
float menuWidth)
const;
195 TGUI_NODISCARD
bool findMenuItemBelowMouse(Vector2f menuPos, Vector2f mousePos,
bool openSubMenuToRight,
Menu& menu,
float menuWidth,
Menu** resultMenu, std::size_t* resultSelectedMenuItem);
198 static bool isSeparator(
const Menu& menuItem);
201 static bool removeMenuImpl(
const std::vector<String>& hierarchy,
bool removeParentsWhenEmpty,
unsigned int parentIndex, std::vector<Menu>& menus);
204 static bool removeSubMenusImpl(
const std::vector<String>& hierarchy,
unsigned int parentIndex, std::vector<Menu>& menus);
207 static void setTextSizeImpl(std::vector<Menu>& menus,
unsigned int textSize);
210 static std::vector<GetMenusElement> getMenusImpl(
const std::vector<Menu>& menus);
213 static void saveMenus(
const std::unique_ptr<DataIO::Node>& parentNode,
const std::vector<Menu>& menus);
220 void leftMouseReleasedOnMenu(
const Menu* menu);
223 bool isMouseOnOpenMenu(Vector2f pos,
const Menu& menu, Vector2f menuOffset)
const;
226 void mouseMovedOnMenu(Vector2f pos,
Menu& menu, Vector2f menuOffset);
229 void deselectDeepestItem(
Menu* menu);
238 virtual void emitMenuItemClick(
const std::vector<String>& hierarchy) = 0;
244 TGUI_NODISCARD
virtual float getDefaultMenuItemHeight()
const = 0;
250 virtual void leftMouseReleasedOnMenu() = 0;
258 TGUI_NODISCARD
virtual bool isMouseOnOpenMenu(Vector2f pos)
const = 0;
265 virtual void mouseMovedOnMenu(Vector2f pos) = 0;
271 virtual void deselectDeepestItem() = 0;
293 std::shared_ptr<OpenMenuPlaceholder> m_openMenuPlaceholder;
295 float m_minimumMenuWidth = 125;
297 Sprite m_spriteItemBackground;
298 Sprite m_spriteSelectedItemBackground;
301 Color m_backgroundColorCached;
302 Color m_selectedBackgroundColorCached;
303 Color m_textColorCached;
304 Color m_selectedTextColorCached;
305 Color m_textColorDisabledCached;
307 float m_separatorThicknessCached = 1;
308 float m_separatorVerticalPaddingCached = 0;
309 float m_separatorSidePaddingCached = 0;
310 float m_distanceToSideCached = 0;
312 bool m_invertedMenuDirection =
false;
Backend-independent wrapper around the backend-specific text class.
Definition Text.hpp:48