mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 13:37:42 -05:00
ui: Added API to add custom layouts, imhex application and api cleanup
This commit is contained in:
41
plugins/builtin/source/content/layouts.cpp
Normal file
41
plugins/builtin/source/content/layouts.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
#include <hex/api/content_registry.hpp>
|
||||
|
||||
#include <imgui.h>
|
||||
#include <imgui_internal.h>
|
||||
#include <hex/views/view.hpp>
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
|
||||
static void openViewAndDockTo(const std::string &unlocalizedName, ImGuiID dockId) {
|
||||
auto view = ContentRegistry::Views::getViewByName(unlocalizedName);
|
||||
|
||||
if (view != nullptr) {
|
||||
view->getWindowOpenState() = true;
|
||||
ImGui::DockBuilderDockWindow(view->getName().c_str(), dockId);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void registerLayouts() {
|
||||
|
||||
ContentRegistry::Interface::addLayout("hex.builtin.layouts.default", [](ImGuiID dockMain) {
|
||||
ImGuiID hexEditor = ImGui::DockBuilderSplitNode(dockMain, ImGuiDir_Left, 0.7F, nullptr, &dockMain);
|
||||
ImGuiID utils = ImGui::DockBuilderSplitNode(dockMain, ImGuiDir_Right, 0.8F, nullptr, &dockMain);
|
||||
ImGuiID patternData = ImGui::DockBuilderSplitNode(hexEditor, ImGuiDir_Down, 0.3F, nullptr, &hexEditor);
|
||||
ImGuiID inspector = ImGui::DockBuilderSplitNode(hexEditor, ImGuiDir_Right, 0.3F, nullptr, &hexEditor);
|
||||
|
||||
openViewAndDockTo("hex.builtin.view.hexeditor.name", hexEditor);
|
||||
openViewAndDockTo("hex.builtin.view.data_inspector.name", inspector);
|
||||
openViewAndDockTo("hex.builtin.view.pattern_data.name", patternData);
|
||||
|
||||
openViewAndDockTo("hex.builtin.view.pattern_editor.name", utils);
|
||||
openViewAndDockTo("hex.builtin.view.hashes.name", utils);
|
||||
openViewAndDockTo("hex.builtin.view.data_information.name", utils);
|
||||
openViewAndDockTo("hex.builtin.view.strings.name", utils);
|
||||
openViewAndDockTo("hex.builtin.view.bookmarks.name", utils);
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
57
plugins/builtin/source/content/main_menu_items.cpp
Normal file
57
plugins/builtin/source/content/main_menu_items.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
#include <hex/api/content_registry.hpp>
|
||||
|
||||
#include <imgui.h>
|
||||
#include <implot.h>
|
||||
|
||||
#include <hex/views/view.hpp>
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
|
||||
static bool g_demoWindowOpen = false;
|
||||
|
||||
void registerMainMenuEntries() {
|
||||
|
||||
ContentRegistry::Interface::registerMainMenuItem("hex.builtin.menu.file");
|
||||
ContentRegistry::Interface::registerMainMenuItem("hex.builtin.menu.edit");
|
||||
|
||||
ContentRegistry::Interface::registerMainMenuItem("hex.builtin.menu.view", [] {
|
||||
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", [] {
|
||||
for (auto &[layoutName, func] : ContentRegistry::Interface::getLayouts()) {
|
||||
if (ImGui::MenuItem(LangEntry(layoutName), "", false, ImHexApi::Provider::isValid())) {
|
||||
auto dock = ContentRegistry::Interface::getDockSpaceId();
|
||||
|
||||
for (auto &[viewName, view] : ContentRegistry::Views::getEntries()) {
|
||||
view->getWindowOpenState() = false;
|
||||
}
|
||||
|
||||
ImGui::DockBuilderRemoveNode(dock);
|
||||
ImGui::DockBuilderAddNode(dock);
|
||||
func(dock);
|
||||
ImGui::DockBuilderFinish(dock);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
(void) EventManager::subscribe<EventFrameEnd>([]{
|
||||
if (g_demoWindowOpen) {
|
||||
ImGui::ShowDemoWindow(&g_demoWindowOpen);
|
||||
ImPlot::ShowDemoWindow(&g_demoWindowOpen);
|
||||
}
|
||||
});
|
||||
|
||||
ContentRegistry::Interface::registerMainMenuItem("hex.builtin.menu.help");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -160,7 +160,7 @@ namespace hex::plugin::builtin {
|
||||
}
|
||||
|
||||
void ViewHelp::drawMenu() {
|
||||
if (ImGui::BeginMenu("hex.menu.help"_lang)) {
|
||||
if (ImGui::BeginMenu("hex.builtin.menu.help"_lang)) {
|
||||
if (ImGui::MenuItem("hex.builtin.view.help.about.name"_lang, "")) {
|
||||
View::doLater([] { ImGui::OpenPopup(View::toWindowName("hex.builtin.view.help.about.name").c_str()); });
|
||||
this->m_aboutWindowOpen = true;
|
||||
|
||||
@@ -180,9 +180,9 @@ namespace hex::plugin::builtin {
|
||||
if (ImGui::Begin(View::toWindowName("hex.builtin.view.hexeditor.name").c_str())) {
|
||||
|
||||
if (ImGui::IsMouseReleased(ImGuiMouseButton_Right) && ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows))
|
||||
ImGui::OpenPopup("hex.menu.edit"_lang);
|
||||
ImGui::OpenPopup("hex.builtin.menu.edit"_lang);
|
||||
|
||||
if (ImGui::BeginPopup("hex.menu.edit"_lang)) {
|
||||
if (ImGui::BeginPopup("hex.builtin.menu.edit"_lang)) {
|
||||
this->drawEditPopup();
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
@@ -339,7 +339,7 @@ namespace hex::plugin::builtin {
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
bool providerValid = ImHexApi::Provider::isValid();
|
||||
|
||||
if (ImGui::BeginMenu("hex.menu.file"_lang)) {
|
||||
if (ImGui::BeginMenu("hex.builtin.menu.file"_lang)) {
|
||||
if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.open_file"_lang, "CTRL + O")) {
|
||||
|
||||
hex::openFileBrowser("hex.builtin.view.hexeditor.open_file"_lang, DialogMode::Open, { }, [](const auto &path) {
|
||||
@@ -598,7 +598,7 @@ namespace hex::plugin::builtin {
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
if (ImGui::BeginMenu("hex.menu.edit"_lang)) {
|
||||
if (ImGui::BeginMenu("hex.builtin.menu.edit"_lang)) {
|
||||
this->drawEditPopup();
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
@@ -209,7 +209,7 @@ namespace hex::plugin::builtin {
|
||||
}
|
||||
|
||||
void ViewPatternEditor::drawMenu() {
|
||||
if (ImGui::BeginMenu("hex.menu.file"_lang)) {
|
||||
if (ImGui::BeginMenu("hex.builtin.menu.file"_lang)) {
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace hex::plugin::builtin {
|
||||
}
|
||||
|
||||
void ViewProviderSettings::drawContent() {
|
||||
if (ImGui::Begin(View::toWindowName("hex.builtin.view.provider_settings.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
|
||||
if (ImGui::Begin(this->getName().c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
|
||||
auto provider = hex::ImHexApi::Provider::get();
|
||||
|
||||
if (provider != nullptr)
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace hex::plugin::builtin {
|
||||
}
|
||||
|
||||
void ViewSettings::drawMenu() {
|
||||
if (ImGui::BeginMenu("hex.menu.help"_lang)) {
|
||||
if (ImGui::BeginMenu("hex.builtin.menu.help"_lang)) {
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
|
||||
@@ -235,7 +235,7 @@ namespace hex::plugin::builtin {
|
||||
}
|
||||
|
||||
void ViewStore::drawMenu() {
|
||||
if (ImGui::BeginMenu("hex.menu.help"_lang)) {
|
||||
if (ImGui::BeginMenu("hex.builtin.menu.help"_lang)) {
|
||||
if (ImGui::MenuItem("hex.builtin.view.store.name"_lang)) {
|
||||
View::doLater([]{ ImGui::OpenPopup(View::toWindowName("hex.builtin.view.store.name").c_str()); });
|
||||
this->getWindowOpenState() = true;
|
||||
|
||||
@@ -8,12 +8,6 @@ namespace hex::plugin::builtin {
|
||||
|
||||
ContentRegistry::Language::addLocalizations("de-DE", {
|
||||
/* ImHex default functionality */
|
||||
{ "hex.menu.file", "Datei" },
|
||||
{ "hex.menu.edit", "Bearbeiten" },
|
||||
{ "hex.menu.view", "Ansicht" },
|
||||
{ "hex.menu.view.fps", "FPS anzeigen" },
|
||||
{ "hex.menu.view.demo", "ImGui Demo anzeigen" },
|
||||
{ "hex.menu.help", "Hilfe" },
|
||||
{ "hex.menu.feedback", "Feedback hinterlassen" },
|
||||
{ "hex.menu.debug_build", "Debug build"},
|
||||
|
||||
@@ -91,6 +85,14 @@ namespace hex::plugin::builtin {
|
||||
|
||||
/* Builtin plugin features */
|
||||
|
||||
{ "hex.builtin.menu.file", "Datei" },
|
||||
{ "hex.builtin.menu.edit", "Bearbeiten" },
|
||||
{ "hex.builtin.menu.view", "Ansicht" },
|
||||
{ "hex.builtin.menu.layout", "Layout" },
|
||||
{ "hex.builtin.menu.view.fps", "FPS anzeigen" },
|
||||
{ "hex.builtin.menu.view.demo", "ImGui Demo anzeigen" },
|
||||
{ "hex.builtin.menu.help", "Hilfe" },
|
||||
|
||||
{ "hex.builtin.view.bookmarks.name", "Lesezeichen" },
|
||||
{ "hex.builtin.view.bookmarks.default_title", "Lesezeichen [0x{0:X} - 0x{1:X}]" },
|
||||
{ "hex.builtin.view.bookmarks.no_bookmarks", "Noch kein Lesezeichen erstellt. Füge eines hinzu mit Bearbeiten -> Lesezeichen erstellen" },
|
||||
@@ -695,6 +697,8 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.provider.disk.disk_size", "Datenträgergrösse" },
|
||||
{ "hex.builtin.provider.disk.sector_size", "Sektorgrösse" },
|
||||
{ "hex.builtin.provider.disk.reload", "Neu laden" },
|
||||
|
||||
{ "hex.builtin.layouts.default", "Standard" }
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -8,12 +8,6 @@ namespace hex::plugin::builtin {
|
||||
|
||||
ContentRegistry::Language::addLocalizations("en-US", {
|
||||
/* ImHex default functionality */
|
||||
{ "hex.menu.file", "File" },
|
||||
{ "hex.menu.edit", "Edit" },
|
||||
{ "hex.menu.view", "View" },
|
||||
{ "hex.menu.view.fps", "Display FPS" },
|
||||
{ "hex.menu.view.demo", "Show ImGui Demo" },
|
||||
{ "hex.menu.help", "Help" },
|
||||
{ "hex.menu.feedback", "Leave Feedback" },
|
||||
{ "hex.menu.debug_build", "Debug build"},
|
||||
|
||||
@@ -90,6 +84,14 @@ namespace hex::plugin::builtin {
|
||||
|
||||
/* Builtin plugin features */
|
||||
|
||||
{ "hex.builtin.menu.file", "File" },
|
||||
{ "hex.builtin.menu.edit", "Edit" },
|
||||
{ "hex.builtin.menu.view", "View" },
|
||||
{ "hex.builtin.menu.layout", "Layout" },
|
||||
{ "hex.builtin.menu.view.fps", "Display FPS" },
|
||||
{ "hex.builtin.menu.view.demo", "Show ImGui Demo" },
|
||||
{ "hex.builtin.menu.help", "Help" },
|
||||
|
||||
{ "hex.builtin.view.bookmarks.name", "Bookmarks" },
|
||||
{ "hex.builtin.view.bookmarks.default_title", "Bookmark [0x{0:X} - 0x{1:X}]" },
|
||||
{ "hex.builtin.view.bookmarks.no_bookmarks", "No bookmarks created yet. Add one with Edit -> Create Bookmark" },
|
||||
@@ -698,6 +700,8 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.provider.disk.disk_size", "Disk Size" },
|
||||
{ "hex.builtin.provider.disk.sector_size", "Sector Size" },
|
||||
{ "hex.builtin.provider.disk.reload", "Reload" },
|
||||
|
||||
{ "hex.builtin.layouts.default", "Default" }
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -8,12 +8,6 @@ namespace hex::plugin::builtin {
|
||||
|
||||
ContentRegistry::Language::addLocalizations("it-IT", {
|
||||
/* ImHex default functionality */
|
||||
{ "hex.menu.file", "File" },
|
||||
{ "hex.menu.edit", "Modifica" },
|
||||
{ "hex.menu.view", "Vista" },
|
||||
{ "hex.menu.view.fps", "Mostra FPS" },
|
||||
{ "hex.menu.view.demo", "Mostra la demo di ImGui" },
|
||||
{ "hex.menu.help", "Aiuto" },
|
||||
{ "hex.menu.feedback", "Lascia una Recensione" },
|
||||
{ "hex.menu.debug_build", "Build di Debug"},
|
||||
|
||||
@@ -89,6 +83,14 @@ namespace hex::plugin::builtin {
|
||||
|
||||
/* Builtin plugin features */
|
||||
|
||||
{ "hex.builtin.menu.file", "File" },
|
||||
{ "hex.builtin.menu.edit", "Modifica" },
|
||||
{ "hex.builtin.menu.view", "Vista" },
|
||||
//{ "hex.builtin.menu.layout", "Layout" },
|
||||
{ "hex.builtin.menu.view.fps", "Mostra FPS" },
|
||||
{ "hex.builtin.menu.view.demo", "Mostra la demo di ImGui" },
|
||||
{ "hex.builtin.menu.help", "Aiuto" },
|
||||
|
||||
{ "hex.builtin.view.bookmarks.name", "Segnalibri" },
|
||||
{ "hex.builtin.view.bookmarks.default_title", "Segnalibro [0x{0:X} - 0x{1:X}]" },
|
||||
{ "hex.builtin.view.bookmarks.no_bookmarks", "Non è stato creato alcun segnalibro. Aggiungine uno andando su Modifica -> Crea Segnalibro" },
|
||||
@@ -692,6 +694,8 @@ namespace hex::plugin::builtin {
|
||||
//{ "hex.builtin.provider.disk.disk_size", "Disk Size" },
|
||||
//{ "hex.builtin.provider.disk.sector_size", "Sector Size" },
|
||||
//{ "hex.builtin.provider.disk.reload", "Reload" },
|
||||
|
||||
//{ "hex.builtin.layouts.default", "Default" }
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -8,12 +8,6 @@ namespace hex::plugin::builtin {
|
||||
|
||||
ContentRegistry::Language::addLocalizations("zh-CN", {
|
||||
/* ImHex default functionality */
|
||||
{ "hex.menu.file", "文件" },
|
||||
{ "hex.menu.edit", "编辑" },
|
||||
{ "hex.menu.view", "视图" },
|
||||
{ "hex.menu.view.fps", "显示FPS" },
|
||||
{ "hex.menu.view.demo", "显示ImGui演示" },
|
||||
{ "hex.menu.help", "帮助" },
|
||||
{ "hex.menu.feedback", "反馈" },
|
||||
{ "hex.menu.debug_build", "调试构建"},
|
||||
|
||||
@@ -90,6 +84,14 @@ namespace hex::plugin::builtin {
|
||||
|
||||
/* Builtin plugin features */
|
||||
|
||||
{ "hex.builtin.menu.file", "文件" },
|
||||
{ "hex.builtin.menu.edit", "编辑" },
|
||||
{ "hex.builtin.menu.view", "视图" },
|
||||
//{ "hex.builtin.menu.layout", "Layout" },
|
||||
{ "hex.builtin.menu.view.fps", "显示FPS" },
|
||||
{ "hex.builtin.menu.view.demo", "显示ImGui演示" },
|
||||
{ "hex.builtin.menu.help", "帮助" },
|
||||
|
||||
{ "hex.builtin.view.bookmarks.name", "书签" },
|
||||
{ "hex.builtin.view.bookmarks.default_title", "书签 [0x{0:X} - 0x{1:X}]" },
|
||||
{ "hex.builtin.view.bookmarks.no_bookmarks", "空空如也。通过 编辑->添加书签" },
|
||||
@@ -693,6 +695,8 @@ namespace hex::plugin::builtin {
|
||||
//{ "hex.builtin.provider.disk.disk_size", "Disk Size" },
|
||||
//{ "hex.builtin.provider.disk.sector_size", "Sector Size" },
|
||||
//{ "hex.builtin.provider.disk.reload", "Reload" },
|
||||
|
||||
//{ "hex.builtin.layouts.default", "Default" }
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@ namespace hex::plugin::builtin {
|
||||
void registerDataProcessorNodes();
|
||||
void registerProviders();
|
||||
void registerDataFormatters();
|
||||
void registerLayouts();
|
||||
void registerMainMenuEntries();
|
||||
|
||||
void addFooterItems();
|
||||
void addToolbarItems();
|
||||
@@ -40,6 +42,8 @@ IMHEX_PLUGIN_SETUP("Built-in", "WerWolv", "Default ImHex functionality") {
|
||||
|
||||
addFooterItems();
|
||||
addToolbarItems();
|
||||
registerLayouts();
|
||||
registerMainMenuEntries();
|
||||
|
||||
registerLanguageEnUS();
|
||||
registerLanguageDeDE();
|
||||
|
||||
Reference in New Issue
Block a user