api: Make main menus use the same priority API
This commit is contained in:
parent
914b26caec
commit
8397af5c9b
@ -229,7 +229,6 @@ namespace hex {
|
|||||||
|
|
||||||
struct MainMenuItem {
|
struct MainMenuItem {
|
||||||
std::string unlocalizedName;
|
std::string unlocalizedName;
|
||||||
DrawCallback callback;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MenuItem {
|
struct MenuItem {
|
||||||
@ -246,7 +245,7 @@ namespace hex {
|
|||||||
|
|
||||||
u32 getDockSpaceId();
|
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 addMenuItem(const std::string &unlocalizedMainMenuName, u32 priority, const impl::DrawCallback &function);
|
||||||
|
|
||||||
void addWelcomeScreenEntry(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);
|
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::multimap<u32, impl::MenuItem>& getMenuItems();
|
||||||
|
|
||||||
std::vector<impl::DrawCallback>& getWelcomeScreenEntries();
|
std::vector<impl::DrawCallback>& getWelcomeScreenEntries();
|
||||||
|
@ -77,7 +77,7 @@ namespace hex {
|
|||||||
|
|
||||||
static ImGuiID dockSpaceId;
|
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::multimap<u32, ContentRegistry::Interface::impl::MenuItem> menuItems;
|
||||||
static std::vector<ContentRegistry::Interface::impl::DrawCallback> welcomeScreenEntries;
|
static std::vector<ContentRegistry::Interface::impl::DrawCallback> welcomeScreenEntries;
|
||||||
static std::vector<ContentRegistry::Interface::impl::DrawCallback> footerItems;
|
static std::vector<ContentRegistry::Interface::impl::DrawCallback> footerItems;
|
||||||
|
@ -294,10 +294,10 @@ namespace hex {
|
|||||||
return SharedData::dockSpaceId;
|
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);
|
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) {
|
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;
|
return SharedData::mainMenuItems;
|
||||||
}
|
}
|
||||||
std::multimap<u32, ContentRegistry::Interface::impl::MenuItem>& ContentRegistry::Interface::getMenuItems() {
|
std::multimap<u32, ContentRegistry::Interface::impl::MenuItem>& ContentRegistry::Interface::getMenuItems() {
|
||||||
|
@ -27,7 +27,7 @@ namespace hex {
|
|||||||
|
|
||||||
ImGuiID SharedData::dockSpaceId;
|
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::multimap<u32, ContentRegistry::Interface::impl::MenuItem> SharedData::menuItems;
|
||||||
|
|
||||||
std::vector<ContentRegistry::Interface::impl::DrawCallback> SharedData::welcomeScreenEntries;
|
std::vector<ContentRegistry::Interface::impl::DrawCallback> SharedData::welcomeScreenEntries;
|
||||||
|
@ -431,9 +431,8 @@ namespace hex {
|
|||||||
ImGui::SetCursorPosX(5);
|
ImGui::SetCursorPosX(5);
|
||||||
ImGui::Image(this->m_logoTexture, ImVec2(menuBarHeight, menuBarHeight));
|
ImGui::Image(this->m_logoTexture, ImVec2(menuBarHeight, menuBarHeight));
|
||||||
|
|
||||||
for (const auto &[name, function] : ContentRegistry::Interface::getMainMenuItems()) {
|
for (const auto &[priority, menuItem] : ContentRegistry::Interface::getMainMenuItems()) {
|
||||||
if (ImGui::BeginMenu(LangEntry(name))) {
|
if (ImGui::BeginMenu(LangEntry(menuItem.unlocalizedName))) {
|
||||||
function();
|
|
||||||
ImGui::EndMenu();
|
ImGui::EndMenu();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,22 +11,26 @@ namespace hex::plugin::builtin {
|
|||||||
|
|
||||||
void registerMainMenuEntries() {
|
void registerMainMenuEntries() {
|
||||||
|
|
||||||
ContentRegistry::Interface::registerMainMenuItem("hex.builtin.menu.file");
|
ContentRegistry::Interface::registerMainMenuItem("hex.builtin.menu.file", 1000);
|
||||||
ContentRegistry::Interface::registerMainMenuItem("hex.builtin.menu.edit");
|
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()) {
|
for (auto &[name, view] : ContentRegistry::Views::getEntries()) {
|
||||||
if (view->hasViewMenuItemEntry())
|
if (view->hasViewMenuItemEntry())
|
||||||
ImGui::MenuItem(LangEntry(view->getUnlocalizedName()), "", &view->getWindowOpenState());
|
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()) {
|
for (auto &[layoutName, func] : ContentRegistry::Interface::getLayouts()) {
|
||||||
if (ImGui::MenuItem(LangEntry(layoutName), "", false, ImHexApi::Provider::isValid())) {
|
if (ImGui::MenuItem(LangEntry(layoutName), "", false, ImHexApi::Provider::isValid())) {
|
||||||
auto dock = ContentRegistry::Interface::getDockSpaceId();
|
auto dock = ContentRegistry::Interface::getDockSpaceId();
|
||||||
@ -43,15 +47,13 @@ namespace hex::plugin::builtin {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
(void) EventManager::subscribe<EventFrameEnd>([]{
|
(void) EventManager::subscribe<EventFrameEnd>([]{
|
||||||
if (g_demoWindowOpen) {
|
if (g_demoWindowOpen) {
|
||||||
ImGui::ShowDemoWindow(&g_demoWindowOpen);
|
ImGui::ShowDemoWindow(&g_demoWindowOpen);
|
||||||
ImPlot::ShowDemoWindow(&g_demoWindowOpen);
|
ImPlot::ShowDemoWindow(&g_demoWindowOpen);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ContentRegistry::Interface::registerMainMenuItem("hex.builtin.menu.help");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user