40 class TGUI_API ContextMenu :
public MenuWidgetBase
44 using Ptr = std::shared_ptr<ContextMenu>;
45 using ConstPtr = std::shared_ptr<const ContextMenu>;
56 ContextMenu(
const char* typeName =
StaticWidgetType,
bool initRenderer =
true);
156 template <
typename Func,
typename... Args>
159 return connectMenuItem(std::vector<String>{menuItem}, std::forward<Func>(handler), args...);
174 template <
typename Func,
typename... Args>
175 unsigned int connectMenuItem(
const std::vector<String>& hierarchy, Func&& handler,
const Args&... args)
177#if defined(__cpp_lib_invoke) && (__cpp_lib_invoke >= 201411L)
179 [=](
const std::vector<String>& clickedMenuItem)
181 if (clickedMenuItem == hierarchy)
182 std::invoke(handler, args...);
187 [f=std::function<
void(
const Args&...)>(handler),args...,hierarchy](
const std::vector<String>& clickedMenuItem)
189 if (clickedMenuItem == hierarchy)
246 bool addMenuItem(
const std::vector<String>& hierarchy,
bool createParents =
true);
291 bool removeMenuItem(
const std::vector<String>& hierarchy,
bool removeParentsWhenEmpty =
true);
387 TGUI_NODISCARD std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const override;
392 void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers)
override;
408 void emitMenuItemClick(
const std::vector<String>& hierarchy)
override;
414 TGUI_NODISCARD
float getDefaultMenuItemHeight()
const override;
420 void leftMouseReleasedOnMenu()
override;
428 TGUI_NODISCARD
bool isMouseOnOpenMenu(Vector2f pos)
const override;
435 void mouseMovedOnMenu(Vector2f pos)
override;
441 void deselectDeepestItem()
override;
455 bool m_menuOpen =
false;
456 float m_itemHeight = 0;