SDRPlusPlus/core/src/gui/menu.cpp

43 lines
904 B
C++
Raw Normal View History

2020-09-20 00:19:39 +02:00
#include <gui/menu.h>
Menu::Menu() {
}
void Menu::registerEntry(std::string name, void (*drawHandler)(void* ctx), void* ctx) {
MenuItem_t item;
item.drawHandler = drawHandler;
item.ctx = ctx;
items[name] = item;
2020-09-24 19:36:57 +02:00
if (!isInOrderList(name)) {
order.push_back(name);
}
2020-09-20 00:19:39 +02:00
}
void Menu::removeEntry(std::string name) {
items.erase(name);
}
void Menu::draw() {
MenuItem_t item;
for (std::string name : order) {
2020-09-24 19:36:57 +02:00
if (items.find(name) == items.end()) {
continue;
}
2020-09-20 00:19:39 +02:00
item = items[name];
2020-09-24 19:36:57 +02:00
if (ImGui::CollapsingHeader(name.c_str(), ImGuiTreeNodeFlags_DefaultOpen)) {
item.drawHandler(item.ctx);
ImGui::Spacing();
2020-09-24 19:36:57 +02:00
}
}
}
bool Menu::isInOrderList(std::string name) {
for (std::string _name : order) {
if (_name == name) {
return true;
}
2020-09-20 00:19:39 +02:00
}
2020-09-24 19:36:57 +02:00
return false;
2020-09-20 00:19:39 +02:00
}