1
0
mirror of synced 2024-11-24 15:50:16 +01:00

api: Make main menus use the same priority API

This commit is contained in:
WerWolv 2022-01-23 20:45:51 +01:00
parent 914b26caec
commit 8397af5c9b
6 changed files with 23 additions and 23 deletions

View File

@ -229,7 +229,6 @@ namespace hex {
struct MainMenuItem {
std::string unlocalizedName;
DrawCallback callback;
};
struct MenuItem {
@ -246,7 +245,7 @@ namespace hex {
u32 getDockSpaceId();
void registerMainMenuItem(const std::string &unlocalizedName, const impl::DrawCallback &function = []{});
void registerMainMenuItem(const std::string &unlocalizedName, u32 priority);
void addMenuItem(const std::string &unlocalizedMainMenuName, u32 priority, const impl::DrawCallback &function);
void addWelcomeScreenEntry(const impl::DrawCallback &function);
@ -256,7 +255,7 @@ namespace hex {
void addLayout(const std::string &unlocalizedName, const impl::LayoutFunction &function);
std::vector<impl::MainMenuItem>& getMainMenuItems();
std::multimap<u32, impl::MainMenuItem>& getMainMenuItems();
std::multimap<u32, impl::MenuItem>& getMenuItems();
std::vector<impl::DrawCallback>& getWelcomeScreenEntries();

View File

@ -77,7 +77,7 @@ namespace hex {
static ImGuiID dockSpaceId;
static std::vector<ContentRegistry::Interface::impl::MainMenuItem> mainMenuItems;
static std::multimap<u32, ContentRegistry::Interface::impl::MainMenuItem> mainMenuItems;
static std::multimap<u32, ContentRegistry::Interface::impl::MenuItem> menuItems;
static std::vector<ContentRegistry::Interface::impl::DrawCallback> welcomeScreenEntries;
static std::vector<ContentRegistry::Interface::impl::DrawCallback> footerItems;

View File

@ -294,10 +294,10 @@ namespace hex {
return SharedData::dockSpaceId;
}
void ContentRegistry::Interface::registerMainMenuItem(const std::string &unlocalizedName, const impl::DrawCallback &function) {
void ContentRegistry::Interface::registerMainMenuItem(const std::string &unlocalizedName, u32 priority) {
log::info("Registered new main menu item: {}", unlocalizedName);
getMainMenuItems().push_back({ unlocalizedName, function });
getMainMenuItems().insert({ priority, { unlocalizedName } });
}
void ContentRegistry::Interface::addMenuItem(const std::string &unlocalizedMainMenuName, u32 priority, const impl::DrawCallback &function) {
@ -329,7 +329,7 @@ namespace hex {
}
std::vector<ContentRegistry::Interface::impl::MainMenuItem>& ContentRegistry::Interface::getMainMenuItems() {
std::multimap<u32, ContentRegistry::Interface::impl::MainMenuItem>& ContentRegistry::Interface::getMainMenuItems() {
return SharedData::mainMenuItems;
}
std::multimap<u32, ContentRegistry::Interface::impl::MenuItem>& ContentRegistry::Interface::getMenuItems() {

View File

@ -27,7 +27,7 @@ namespace hex {
ImGuiID SharedData::dockSpaceId;
std::vector<ContentRegistry::Interface::impl::MainMenuItem> SharedData::mainMenuItems;
std::multimap<u32, ContentRegistry::Interface::impl::MainMenuItem> SharedData::mainMenuItems;
std::multimap<u32, ContentRegistry::Interface::impl::MenuItem> SharedData::menuItems;
std::vector<ContentRegistry::Interface::impl::DrawCallback> SharedData::welcomeScreenEntries;

View File

@ -431,9 +431,8 @@ namespace hex {
ImGui::SetCursorPosX(5);
ImGui::Image(this->m_logoTexture, ImVec2(menuBarHeight, menuBarHeight));
for (const auto &[name, function] : ContentRegistry::Interface::getMainMenuItems()) {
if (ImGui::BeginMenu(LangEntry(name))) {
function();
for (const auto &[priority, menuItem] : ContentRegistry::Interface::getMainMenuItems()) {
if (ImGui::BeginMenu(LangEntry(menuItem.unlocalizedName))) {
ImGui::EndMenu();
}
}

View File

@ -11,22 +11,26 @@ namespace hex::plugin::builtin {
void registerMainMenuEntries() {
ContentRegistry::Interface::registerMainMenuItem("hex.builtin.menu.file");
ContentRegistry::Interface::registerMainMenuItem("hex.builtin.menu.edit");
ContentRegistry::Interface::registerMainMenuItem("hex.builtin.menu.file", 1000);
ContentRegistry::Interface::registerMainMenuItem("hex.builtin.menu.edit", 2000);
ContentRegistry::Interface::registerMainMenuItem("hex.builtin.menu.view", 3000);
ContentRegistry::Interface::registerMainMenuItem("hex.builtin.menu.layout", 4000);
ContentRegistry::Interface::registerMainMenuItem("hex.builtin.menu.help", 5000);
ContentRegistry::Interface::registerMainMenuItem("hex.builtin.menu.view", [] {
ContentRegistry::Interface::addMenuItem("hex.builtin.menu.view", 1000, []{
for (auto &[name, view] : ContentRegistry::Views::getEntries()) {
if (view->hasViewMenuItemEntry())
ImGui::MenuItem(LangEntry(view->getUnlocalizedName()), "", &view->getWindowOpenState());
}
#if defined(DEBUG)
ImGui::Separator();
ImGui::MenuItem("hex.builtin.menu.view.demo"_lang, "", &g_demoWindowOpen);
#endif
});
ContentRegistry::Interface::registerMainMenuItem("hex.builtin.menu.layout", [] {
#if defined(DEBUG)
ContentRegistry::Interface::addMenuItem("hex.builtin.menu.view", 2000, []{
ImGui::MenuItem("hex.builtin.menu.view.demo"_lang, "", &g_demoWindowOpen);
});
#endif
ContentRegistry::Interface::addMenuItem("hex.builtin.menu.layout", 1000, [] {
for (auto &[layoutName, func] : ContentRegistry::Interface::getLayouts()) {
if (ImGui::MenuItem(LangEntry(layoutName), "", false, ImHexApi::Provider::isValid())) {
auto dock = ContentRegistry::Interface::getDockSpaceId();
@ -43,15 +47,13 @@ namespace hex::plugin::builtin {
}
});
(void) EventManager::subscribe<EventFrameEnd>([]{
if (g_demoWindowOpen) {
ImGui::ShowDemoWindow(&g_demoWindowOpen);
ImPlot::ShowDemoWindow(&g_demoWindowOpen);
}
});
ContentRegistry::Interface::registerMainMenuItem("hex.builtin.menu.help");
}
}