43 class TGUI_API MenuWidgetBase :
public Widget
51 std::vector<GetMenusElement> menuItems;
58 MenuWidgetBase(
const MenuWidgetBase& other);
63 MenuWidgetBase(MenuWidgetBase&& other)
noexcept;
68 MenuWidgetBase& operator=(
const MenuWidgetBase& other);
73 MenuWidgetBase& operator=(MenuWidgetBase&& other)
noexcept;
101 int selectedMenuItem = -1;
102 std::vector<Menu> menuItems;
135 void createMenu(std::vector<Menu>& menus,
const String& text);
140 [[nodiscard]]
Menu* findMenuItemParent(
const std::vector<String>& hierarchy,
141 unsigned int parentIndex,
142 std::vector<Menu>& menus,
148 [[nodiscard]]
const Menu* findMenuItemParent(
const std::vector<String>& hierarchy,
149 unsigned int parentIndex,
150 const std::vector<Menu>& menus)
const;
154 [[nodiscard]]
Menu* findMenuItem(
const std::vector<String>& hierarchy, std::vector<Menu>& menus);
158 [[nodiscard]]
const Menu* findMenuItem(
const std::vector<String>& hierarchy,
const std::vector<Menu>& menus)
const;
162 void loadMenus(
const std::unique_ptr<DataIO::Node>& node, std::vector<Menu>& menus);
166 void closeSubMenus(std::vector<Menu>& menus,
int& selectedMenu);
169 void updateMenuTextColor(
Menu& menu,
bool selected);
172 void updateTextColors(std::vector<Menu>& menus,
int selectedMenu);
175 void updateTextOpacity(std::vector<Menu>& menus);
178 void updateTextFont(std::vector<Menu>& menus);
182 [[nodiscard]]
float calculateMenuWidth(
const Menu& menu)
const;
186 [[nodiscard]]
float getMenuItemHeight(
const Menu& menuItem)
const;
190 [[nodiscard]]
float calculateOpenMenuHeight(
const std::vector<Menu>& menuItems)
const;
193 [[nodiscard]] Vector2f calculateSubmenuOffset(
198 bool& openSubMenuToRight)
const;
201 [[nodiscard]]
bool isMouseOnTopOfMenu(Vector2f menuPos, Vector2f mousePos,
bool openSubMenuToRight,
const Menu& menu,
float menuWidth)
const;
204 [[nodiscard]]
bool findMenuItemBelowMouse(
207 bool openSubMenuToRight,
211 std::size_t* resultSelectedMenuItem);
214 static bool isSeparator(
const Menu& menuItem);
217 static bool removeMenuImpl(
const std::vector<String>& hierarchy,
218 bool removeParentsWhenEmpty,
219 unsigned int parentIndex,
220 std::vector<Menu>& menus);
223 static bool removeSubMenusImpl(
const std::vector<String>& hierarchy,
unsigned int parentIndex, std::vector<Menu>& menus);
226 static void setTextSizeImpl(std::vector<Menu>& menus,
unsigned int textSize);
229 static std::vector<GetMenusElement> getMenusImpl(
const std::vector<Menu>& menus);
232 static void saveMenus(
const std::unique_ptr<DataIO::Node>& parentNode,
const std::vector<Menu>& menus);
241 bool openSubMenuToRight)
const;
244 void leftMouseReleasedOnMenu(
const Menu* menu);
247 bool isMouseOnOpenMenu(Vector2f pos,
const Menu& menu, Vector2f menuOffset)
const;
250 void mouseMovedOnMenu(Vector2f pos,
Menu& menu, Vector2f menuOffset);
253 void deselectDeepestItem(
Menu* menu);
262 virtual void emitMenuItemClick(
const std::vector<String>& hierarchy) = 0;
268 [[nodiscard]]
virtual float getDefaultMenuItemHeight()
const = 0;
274 virtual void leftMouseReleasedOnMenu() = 0;
282 [[nodiscard]]
virtual bool isMouseOnOpenMenu(Vector2f pos)
const = 0;
289 virtual void mouseMovedOnMenu(Vector2f pos) = 0;
295 virtual void deselectDeepestItem() = 0;
317 std::shared_ptr<OpenMenuPlaceholder> m_openMenuPlaceholder;
319 float m_minimumMenuWidth = 125;
321 Sprite m_spriteItemBackground;
322 Sprite m_spriteSelectedItemBackground;
325 Color m_backgroundColorCached;
326 Color m_selectedBackgroundColorCached;
327 Color m_textColorCached;
328 Color m_selectedTextColorCached;
329 Color m_textColorDisabledCached;
331 float m_separatorThicknessCached = 1;
332 float m_separatorVerticalPaddingCached = 0;
333 float m_separatorSidePaddingCached = 0;
334 float m_distanceToSideCached = 0;
336 bool m_invertedMenuDirection =
false;
Backend-independent wrapper around the backend-specific text class.
Definition Text.hpp:53