From 4c41dd9a62ce7bdae1332dc3bfbe69aaa57addb4 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Tue, 15 Jun 2021 13:13:07 -0400 Subject: [PATCH] Add createSubmenuItem() helper. --- include/helpers.hpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/include/helpers.hpp b/include/helpers.hpp index 52da8938..bbf8f696 100644 --- a/include/helpers.hpp +++ b/include/helpers.hpp @@ -225,7 +225,7 @@ inline ui::MenuItem* createCheckMenuItem(std::string text, std::function /** Creates a MenuItem that controls a boolean value with a check mark. */ -inline ui::MenuItem* createBoolMenuItem(std::string text, std::function getter, std::function setter) { +inline ui::MenuItem* createBoolMenuItem(std::string text, std::function getter, std::function setter) { struct Item : ui::MenuItem { std::function setter; bool val; @@ -254,9 +254,28 @@ ui::MenuItem* createBoolPtrMenuItem(std::string text, T* ptr) { } +/** Creates a MenuItem that opens a submenu. +*/ +inline ui::MenuItem* createSubmenuItem(std::string text, std::function createMenu) { + struct Item : ui::MenuItem { + std::function createMenu; + + ui::Menu* createChildMenu() override { + ui::Menu* menu = new ui::Menu; + createMenu(menu); + return menu; + } + }; + + Item* item = createMenuItem(text, RIGHT_ARROW); + item->createMenu = createMenu; + return item; +} + + /** Creates a MenuItem that when hovered, opens a submenu with several MenuItems indexed by an integer. */ -inline ui::MenuItem* createIndexSubmenuItem(std::string text, std::vector labels, std::function getter, std::function setter) { +inline ui::MenuItem* createIndexSubmenuItem(std::string text, std::vector labels, std::function getter, std::function setter) { struct IndexItem : ui::MenuItem { std::function setter; size_t index;