1
0
mirror of synced 2024-11-30 18:34:29 +01:00

impr: Clean up old layout stuff

This commit is contained in:
WerWolv 2023-05-11 23:21:52 +02:00
parent 0b21e30e44
commit 0649e0dcd3
8 changed files with 18 additions and 73 deletions

View File

@ -493,14 +493,8 @@ namespace hex {
using DrawCallback = std::function<void()>;
using MenuCallback = std::function<void()>;
using EnabledCallback = std::function<bool()>;
using LayoutFunction = std::function<void(u32)>;
using ClickCallback = std::function<void()>;
struct Layout {
std::string unlocalizedName;
LayoutFunction callback;
};
struct MainMenuItem {
std::string unlocalizedName;
};
@ -535,8 +529,6 @@ namespace hex {
std::vector<impl::SidebarItem> &getSidebarItems();
std::vector<impl::TitleBarButton> &getTitleBarButtons();
std::vector<impl::Layout> &getLayouts();
}
/**
@ -608,14 +600,6 @@ namespace hex {
*/
void addTitleBarButton(const std::string &icon, const std::string &unlocalizedTooltip, const impl::ClickCallback &function);
/**
* @brief Adds a new layout definition to the Layout menu
* @param unlocalizedName The unlocalized name of the layout
* @param function The function to call to setup the layout
*/
void addLayout(const std::string &unlocalizedName, const impl::LayoutFunction &function);
}
/* Provider Registry. Allows adding new data providers to be created from the UI */

View File

@ -26,6 +26,7 @@ namespace hex {
static void process();
static void reload();
static void reset();
private:
LayoutManager() = default;

View File

@ -581,12 +581,6 @@ namespace hex {
impl::getTitleBarButtons().push_back({ icon, unlocalizedTooltip, function });
}
void addLayout(const std::string &unlocalizedName, const impl::LayoutFunction &function) {
log::debug("Added new layout: {}", unlocalizedName);
impl::getLayouts().push_back({ unlocalizedName, function });
}
namespace impl {
std::multimap<u32, impl::MainMenuItem> &getMainMenuItems() {
@ -626,12 +620,6 @@ namespace hex {
return buttons;
}
std::vector<impl::Layout> &getLayouts() {
static std::vector<impl::Layout> layouts;
return layouts;
}
}
}

View File

@ -5,6 +5,8 @@
#include <imgui.h>
#include <fmt/format.h>
namespace hex {
std::optional<std::fs::path> LayoutManager::s_layoutPathToLoad;
@ -72,4 +74,10 @@ namespace hex {
}
}
void LayoutManager::reset() {
s_layoutPathToLoad.reset();
s_layoutStringToLoad.reset();
s_layouts.clear();
}
}

View File

@ -3,13 +3,17 @@
#include <imgui.h>
#include <romfs/romfs.hpp>
#include <hex/helpers/http_requests.hpp>
#include <hex/helpers/fs.hpp>
#include <hex/helpers/logger.hpp>
#include <hex/api_urls.hpp>
#include <hex/api/content_registry.hpp>
#include <hex/api/project_file_manager.hpp>
#include <hex/api/theme_manager.hpp>
#include <hex/helpers/http_requests.hpp>
#include <hex/helpers/fs.hpp>
#include <hex/helpers/logger.hpp>
#include <hex/api/plugin_manager.hpp>
#include <hex/api/layout_manager.hpp>
#include <hex/ui/view.hpp>
#include <hex/ui/popup.hpp>
@ -17,8 +21,6 @@
#include <fonts/codicons_font.h>
#include <fonts/unifont_font.h>
#include <hex/api/plugin_manager.hpp>
#include <filesystem>
#include <nlohmann/json.hpp>
@ -312,7 +314,6 @@ namespace hex::init {
ContentRegistry::Interface::impl::getMenuItems().clear();
ContentRegistry::Interface::impl::getSidebarItems().clear();
ContentRegistry::Interface::impl::getTitleBarButtons().clear();
ContentRegistry::Interface::impl::getLayouts().clear();
ShortcutManager::clearShortcuts();
@ -324,6 +325,8 @@ namespace hex::init {
ContentRegistry::FileHandler::impl::getEntries().clear();
ContentRegistry::Hashes::impl::getHashes().clear();
LayoutManager::reset();
ThemeManager::reset();
{

View File

@ -18,7 +18,6 @@ add_library(${PROJECT_NAME} SHARED
source/content/providers.cpp
source/content/views.cpp
source/content/data_formatters.cpp
source/content/layouts.cpp
source/content/main_menu_items.cpp
source/content/welcome_screen.cpp
source/content/data_visualizers.cpp

View File

@ -1,36 +0,0 @@
#include <hex/api/content_registry.hpp>
#include <hex/ui/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.hex_editor.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.find.name", utils);
openViewAndDockTo("hex.builtin.view.bookmarks.name", utils);
});
}
}

View File

@ -22,7 +22,6 @@ namespace hex::plugin::builtin {
void registerHashes();
void registerProviders();
void registerDataFormatters();
void registerLayouts();
void registerMainMenuEntries();
void createWelcomeScreen();
void registerViews();
@ -70,7 +69,6 @@ IMHEX_PLUGIN_SETUP("Built-in", "WerWolv", "Default ImHex functionality") {
addToolbarItems();
addGlobalUIItems();
registerLayouts();
registerMainMenuEntries();
handleBorderlessWindowMode();