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

refactor: Streamline entire view system

This commit is contained in:
WerWolv 2023-11-21 13:47:50 +01:00
parent fc23efdb25
commit c89a870fe9
57 changed files with 2643 additions and 2644 deletions

View File

@ -11,6 +11,7 @@
using ImGuiID = unsigned int;
struct ImVec2;
struct ImFontAtlas;
namespace hex {
@ -340,12 +341,14 @@ namespace hex {
void setCustomFontPath(const std::fs::path &path);
void setFontSize(float size);
void setFontAtlas(ImFontAtlas *fontAtlas);
void setGPUVendor(const std::string &vendor);
void setPortableVersion(bool enabled);
void addInitArgument(const std::string &key, const std::string &value = { });
}
struct ProgramArguments {
@ -457,6 +460,12 @@ namespace hex {
*/
float getFontSize();
/**
* @brief Gets the current font atlas
* @return Current font atlas
*/
ImFontAtlas* getFontAtlas();
/**
* @brief Sets if ImHex should follow the system theme

View File

@ -274,6 +274,8 @@ namespace ImGuiExt {
void BeginSubWindow(const char *label, ImVec2 size = ImVec2(0, 0), ImGuiChildFlags flags = ImGuiChildFlags_None);
void EndSubWindow();
void ConfirmButtons(const char *textLeft, const char *textRight, const std::function<void()> &leftButtonCallback, const std::function<void()> &rightButtonCallback);
template<typename T>
constexpr ImGuiDataType getImGuiDataType() {
if constexpr (std::same_as<T, u8>) return ImGuiDataType_U8;

View File

@ -18,25 +18,72 @@
#include <hex/api/localization.hpp>
#include <functional>
#include <map>
#include <string>
namespace hex {
class View {
public:
explicit View(std::string unlocalizedName);
public:
virtual ~View() = default;
virtual void drawContent() = 0;
virtual void drawAlwaysVisible() { }
[[nodiscard]] virtual bool isAvailable() const;
[[nodiscard]] virtual bool shouldProcess() const { return this->isAvailable() && this->getWindowOpenState(); }
/**
* @brief Draws the view
* @note Do not override this method. Override drawContent() instead
*/
virtual void draw() = 0;
/**
* @brief Draws the content of the view
*/
virtual void drawContent() = 0;
/**
* @brief Draws content that should always be visible, even if the view is not open
*/
virtual void drawAlwaysVisibleContent() { }
/**
* @brief Whether or not the view window should be drawn
* @return True if the view window should be drawn, false otherwise
*/
[[nodiscard]] virtual bool shouldDraw() const;
/**
* @brief Whether or not the entire view should be processed
* If this returns false, the view will not be drawn and no shortcuts will be handled. This includes things
* drawn in the drawAlwaysVisibleContent() function.
* @return True if the view should be processed, false otherwise
*/
[[nodiscard]] virtual bool shouldProcess() const { return true; }
/**
* @brief Whether or not the view should have an entry in the view menu
* @return True if the view should have an entry in the view menu, false otherwise
*/
[[nodiscard]] virtual bool hasViewMenuItemEntry() const;
/**
* @brief Gets the minimum size of the view window
* @return The minimum size of the view window
*/
[[nodiscard]] virtual ImVec2 getMinSize() const;
/**
* @brief Gets the maximum size of the view window
* @return The maximum size of the view window
*/
[[nodiscard]] virtual ImVec2 getMaxSize() const;
/**
* @brief Gets additional window flags for the view window
* @return Additional window flags for the view window
*/
[[nodiscard]] virtual ImGuiWindowFlags getWindowFlags() const;
[[nodiscard]] bool &getWindowOpenState();
[[nodiscard]] const bool &getWindowOpenState() const;
@ -46,18 +93,15 @@ namespace hex {
[[nodiscard]] bool didWindowJustOpen();
void setWindowJustOpened(bool state);
static void confirmButtons(const std::string &textLeft, const std::string &textRight, const std::function<void()> &leftButtonFn, const std::function<void()> &rightButtonFn);
static void discardNavigationRequests();
static std::string toWindowName(const std::string &unlocalizedName) {
return LangEntry(unlocalizedName) + "###" + unlocalizedName;
}
[[nodiscard]] static std::string toWindowName(const std::string &unlocalizedName);
static ImFontAtlas *getFontAtlas();
static void setFontAtlas(ImFontAtlas *atlas);
static ImFontConfig getFontConfig();
static void setFontConfig(ImFontConfig config);
public:
class Window;
class Special;
class Floating;
class Modal;
private:
std::string m_unlocalizedViewName;
@ -68,4 +112,68 @@ namespace hex {
friend class ShortcutManager;
};
/**
* @brief A view that draws a regular window. This should be the default for most views
*/
class View::Window : public View {
public:
explicit Window(std::string unlocalizedName) : View(std::move(unlocalizedName)) {}
void draw() final {
if (this->shouldDraw()) {
ImGui::SetNextWindowSizeConstraints(this->getMinSize(), this->getMaxSize());
if (ImGui::Begin(View::toWindowName(this->getUnlocalizedName()).c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse | this->getWindowFlags())) {
this->drawContent();
}
ImGui::End();
}
}
};
/**
* @brief A view that doesn't handle any window creation and just draws its content.
* This should be used if you intend to draw your own special window
*/
class View::Special : public View {
public:
explicit Special(std::string unlocalizedName) : View(std::move(unlocalizedName)) {}
void draw() final {
if (this->shouldDraw()) {
this->drawContent();
}
}
};
/**
* @brief A view that draws a floating window. These are the same as regular windows but cannot be docked
*/
class View::Floating : public View::Window {
public:
explicit Floating(std::string unlocalizedName) : Window(std::move(unlocalizedName)) {}
[[nodiscard]] ImGuiWindowFlags getWindowFlags() const final { return ImGuiWindowFlags_NoDocking; }
};
/**
* @brief A view that draws a modal window. The window will always be drawn on top and will block input to other windows
*/
class View::Modal : public View {
public:
explicit Modal(std::string unlocalizedName) : View(std::move(unlocalizedName)) {}
void draw() final {
if (this->shouldDraw()) {
ImGui::SetNextWindowSizeConstraints(this->getMinSize(), this->getMaxSize());
if (ImGui::BeginPopupModal(View::toWindowName(this->getUnlocalizedName()).c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse | this->getWindowFlags())) {
this->drawContent();
}
ImGui::EndPopup();
}
}
};
}

View File

@ -421,6 +421,12 @@ namespace hex {
s_fontSize = size;
}
static ImFontAtlas *s_fontAtlas;
void setFontAtlas(ImFontAtlas* fontAtlas) {
s_fontAtlas = fontAtlas;
}
static std::string s_gpuVendor;
void setGPUVendor(const std::string &vendor) {
s_gpuVendor = vendor;
@ -508,6 +514,11 @@ namespace hex {
return impl::s_fontSize;
}
ImFontAtlas* getFontAtlas() {
return impl::s_fontAtlas;
}
static bool s_systemThemeDetection;

View File

@ -37,6 +37,10 @@ namespace hex {
return vector * ImHexApi::System::getGlobalScale();
}
ImVec2 scaled(float x, float y) {
return ImVec2(x, y) * ImHexApi::System::getGlobalScale();
}
std::string to_string(u128 value) {
char data[45] = { 0 };

View File

@ -917,6 +917,17 @@ namespace ImGuiExt {
ImGui::EndChild();
}
void ConfirmButtons(const char *textLeft, const char *textRight, const std::function<void()> &leftButtonCallback, const std::function<void()> &rightButtonCallback) {
auto width = ImGui::GetWindowWidth();
ImGui::SetCursorPosX(width / 9);
if (ImGui::Button(textLeft, ImVec2(width / 3, 0)))
leftButtonCallback();
ImGui::SameLine();
ImGui::SetCursorPosX(width / 9 * 5);
if (ImGui::Button(textRight, ImVec2(width / 3, 0)))
rightButtonCallback();
}
}
namespace ImGui {

View File

@ -7,16 +7,9 @@
namespace hex {
namespace {
ImFontAtlas *s_fontAtlas;
ImFontConfig s_fontConfig;
}
View::View(std::string unlocalizedName) : m_unlocalizedViewName(std::move(unlocalizedName)) { }
bool View::isAvailable() const {
bool View::shouldDraw() const {
return ImHexApi::Provider::isValid() && ImHexApi::Provider::get()->isAvailable();
}
@ -25,13 +18,18 @@ namespace hex {
}
ImVec2 View::getMinSize() const {
return scaled(ImVec2(300, 400));
return scaled({ 300, 400 });
}
ImVec2 View::getMaxSize() const {
return { FLT_MAX, FLT_MAX };
}
ImGuiWindowFlags View::getWindowFlags() const {
return ImGuiWindowFlags_None;
}
bool &View::getWindowOpenState() {
return this->m_windowOpen;
@ -50,11 +48,7 @@ namespace hex {
}
bool View::didWindowJustOpen() {
bool result = this->m_windowJustOpened;
this->m_windowJustOpened = false;
return result;
return std::exchange(this->m_windowJustOpened, false);
}
void View::setWindowJustOpened(bool state) {
@ -66,21 +60,8 @@ namespace hex {
ImGui::GetIO().ConfigFlags &= ~ImGuiConfigFlags_NavEnableKeyboard;
}
void View::confirmButtons(const std::string &textLeft, const std::string &textRight, const std::function<void()> &leftButtonFn, const std::function<void()> &rightButtonFn) {
auto width = ImGui::GetWindowWidth();
ImGui::SetCursorPosX(width / 9);
if (ImGui::Button(textLeft.c_str(), ImVec2(width / 3, 0)))
leftButtonFn();
ImGui::SameLine();
ImGui::SetCursorPosX(width / 9 * 5);
if (ImGui::Button(textRight.c_str(), ImVec2(width / 3, 0)))
rightButtonFn();
std::string View::toWindowName(const std::string &unlocalizedName) {
return LangEntry(unlocalizedName) + "###" + unlocalizedName;
}
ImFontAtlas *View::getFontAtlas() { return s_fontAtlas; }
void View::setFontAtlas(ImFontAtlas *atlas) { s_fontAtlas = atlas; }
ImFontConfig View::getFontConfig() { return s_fontConfig; }
void View::setFontConfig(ImFontConfig config) { s_fontConfig = std::move(config); }
}

View File

@ -325,8 +325,7 @@ namespace hex::init {
}
// Configure ImGui to use the font atlas
View::setFontAtlas(fonts);
View::setFontConfig(cfg);
ImHexApi::System::impl::setFontAtlas(fonts);
return true;
}

View File

@ -810,17 +810,14 @@ namespace hex {
ImGui::GetCurrentContext()->NextWindowData.ClearFlags();
// Draw always visible views
view->drawAlwaysVisible();
view->drawAlwaysVisibleContent();
// Skip views that shouldn't be processed currently
if (!view->shouldProcess())
continue;
// Draw view
if (view->isAvailable()) {
ImGui::SetNextWindowSizeConstraints(view->getMinSize(), view->getMaxSize());
view->drawContent();
}
view->draw();
if (view->getWindowOpenState()) {
auto window = ImGui::FindWindowByName(view->getName().c_str());
@ -1137,7 +1134,7 @@ namespace hex {
void Window::initImGui() {
IMGUI_CHECKVERSION();
auto fonts = View::getFontAtlas();
auto fonts = ImHexApi::System::getFontAtlas();
// Initialize ImGui and all other ImGui extensions
GImGui = ImGui::CreateContext(fonts);

View File

@ -8,13 +8,13 @@
namespace hex::plugin::builtin {
class ViewAbout : public View {
class ViewAbout : public View::Modal {
public:
ViewAbout();
void drawContent() override;
[[nodiscard]] bool isAvailable() const override { return true; }
[[nodiscard]] bool shouldDraw() const override { return true; }
[[nodiscard]] bool hasViewMenuItemEntry() const override { return false; }
[[nodiscard]] ImVec2 getMinSize() const override {
@ -22,8 +22,6 @@ namespace hex::plugin::builtin {
}
private:
bool m_aboutWindowOpen = false;
void drawAboutPopup();
void drawAboutMainPage();

View File

@ -5,15 +5,15 @@
namespace hex::plugin::builtin {
class ViewAchievements : public View {
class ViewAchievements : public View::Floating {
public:
ViewAchievements();
~ViewAchievements() override;
void drawContent() override;
void drawAlwaysVisible() override;
void drawAlwaysVisibleContent() override;
[[nodiscard]] bool isAvailable() const override { return true; }
[[nodiscard]] bool shouldDraw() const override { return true; }
[[nodiscard]] bool hasViewMenuItemEntry() const override { return false; }
[[nodiscard]] ImVec2 getMinSize() const override {
@ -28,8 +28,6 @@ namespace hex::plugin::builtin {
ImVec2 drawAchievementTree(ImDrawList *drawList, const AchievementManager::AchievementNode * prevNode, const std::vector<AchievementManager::AchievementNode*> &nodes, ImVec2 position);
private:
bool m_viewOpen = false;
std::list<const Achievement*> m_achievementUnlockQueue;
const Achievement *m_currAchievement = nullptr;
const Achievement *m_achievementToGoto = nullptr;

View File

@ -6,7 +6,7 @@
namespace hex::plugin::builtin {
class ViewBookmarks : public View {
class ViewBookmarks : public View::Window {
public:
ViewBookmarks();
~ViewBookmarks() override;

View File

@ -8,14 +8,15 @@
namespace hex::plugin::builtin {
class ViewCommandPalette : public View {
class ViewCommandPalette : public View::Special {
public:
ViewCommandPalette();
~ViewCommandPalette() override = default;
void drawContent() override;
void drawContent() override {}
void drawAlwaysVisibleContent() override;
[[nodiscard]] bool isAvailable() const override { return true; }
[[nodiscard]] bool shouldDraw() const override { return false; }
[[nodiscard]] bool shouldProcess() const override { return true; }
[[nodiscard]] bool hasViewMenuItemEntry() const override { return false; }

View File

@ -20,21 +20,13 @@ namespace hex::plugin::builtin {
std::string value;
};
class ViewConstants : public View {
class ViewConstants : public View::Window {
public:
explicit ViewConstants();
~ViewConstants() override = default;
void drawContent() override;
ImVec2 getMinSize() const override {
return scaled(ImVec2(300, 400));
}
ImVec2 getMaxSize() const override {
return { FLT_MAX, 800_scaled };
}
private:
void reloadConstants();

View File

@ -11,7 +11,7 @@
namespace hex::plugin::builtin {
class ViewDataInspector : public View {
class ViewDataInspector : public View::Window {
public:
explicit ViewDataInspector();
~ViewDataInspector() override;

View File

@ -11,7 +11,7 @@
namespace hex::plugin::builtin {
class ViewDataProcessor : public View {
class ViewDataProcessor : public View::Window {
public:
struct Workspace {
Workspace() = default;

View File

@ -12,12 +12,13 @@
namespace hex::plugin::builtin {
class ViewDiff : public View {
class ViewDiff : public View::Window {
public:
ViewDiff();
~ViewDiff() override;
void drawContent() override;
ImGuiWindowFlags getWindowFlags() const override { return ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse; }
public:
struct Column {

View File

@ -21,7 +21,7 @@ namespace hex::plugin::builtin {
std::string operators;
};
class ViewDisassembler : public View {
class ViewDisassembler : public View::Window {
public:
explicit ViewDisassembler();
~ViewDisassembler() override;

View File

@ -13,7 +13,7 @@
namespace hex::plugin::builtin {
class ViewFind : public View {
class ViewFind : public View::Window {
public:
ViewFind();
~ViewFind() override = default;

View File

@ -6,7 +6,7 @@
namespace hex::plugin::builtin {
class ViewHashes : public View {
class ViewHashes : public View::Window {
public:
explicit ViewHashes();
~ViewHashes() override;

View File

@ -9,12 +9,15 @@
namespace hex::plugin::builtin {
class ViewHexEditor : public View {
class ViewHexEditor : public View::Window {
public:
ViewHexEditor();
~ViewHexEditor() override;
void drawContent() override;
[[nodiscard]] ImGuiWindowFlags getWindowFlags() const override {
return ImGuiWindowFlags_NoNavInputs | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse;
}
class Popup {
public:

View File

@ -10,7 +10,7 @@
namespace hex::plugin::builtin {
class ViewInformation : public View {
class ViewInformation : public View::Window {
public:
explicit ViewInformation();
~ViewInformation() override;

View File

@ -4,19 +4,18 @@
namespace hex::plugin::builtin {
class ViewLogs : public View {
class ViewLogs : public View::Floating {
public:
ViewLogs();
~ViewLogs() override = default;
void drawContent() override;
[[nodiscard]] bool isAvailable() const override { return true; }
[[nodiscard]] bool shouldDraw() const override { return true; }
[[nodiscard]] bool hasViewMenuItemEntry() const override { return false; }
private:
int m_logLevel = 1;
bool m_viewOpen = false;
};
}

View File

@ -6,13 +6,13 @@
namespace hex::plugin::builtin {
class ViewPatches : public View {
class ViewPatches : public View::Window {
public:
explicit ViewPatches();
~ViewPatches() override = default;
void drawContent() override;
void drawAlwaysVisible() override;
void drawAlwaysVisibleContent() override;
private:
u64 m_selectedPatch = 0x00;

View File

@ -6,7 +6,7 @@
namespace hex::plugin::builtin {
class ViewPatternData : public View {
class ViewPatternData : public View::Window {
public:
ViewPatternData();
~ViewPatternData() override;

View File

@ -24,13 +24,16 @@ namespace pl::ptrn { class Pattern; }
namespace hex::plugin::builtin {
class ViewPatternEditor : public View {
class ViewPatternEditor : public View::Window {
public:
ViewPatternEditor();
~ViewPatternEditor() override;
void drawAlwaysVisible() override;
void drawAlwaysVisibleContent() override;
void drawContent() override;
[[nodiscard]] ImGuiWindowFlags getWindowFlags() const override {
return ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse;
}
private:
enum class DangerousFunctionPerms : u8 {
@ -79,7 +82,7 @@ namespace hex::plugin::builtin {
ImGui::NewLine();
ImGui::TextUnformatted("hex.builtin.view.pattern_editor.accept_pattern.question"_lang);
confirmButtons("hex.builtin.common.yes"_lang, "hex.builtin.common.no"_lang,
ImGuiExt::ConfirmButtons("hex.builtin.common.yes"_lang, "hex.builtin.common.no"_lang,
[this, provider] {
this->m_view->loadPatternFile(this->m_view->m_possiblePatternFiles.get(provider)[this->m_selectedPatternFile], provider);
this->close();

View File

@ -4,17 +4,16 @@
namespace hex::plugin::builtin {
class ViewProviderSettings : public hex::View {
class ViewProviderSettings : public View::Modal {
public:
ViewProviderSettings();
~ViewProviderSettings() override;
void drawContent() override;
void drawAlwaysVisible() override;
[[nodiscard]] bool hasViewMenuItemEntry() const override;
[[nodiscard]] bool isAvailable() const override;
[[nodiscard]] bool shouldDraw() const override { return true; }
};
}

View File

@ -4,14 +4,15 @@
namespace hex::plugin::builtin {
class ViewSettings : public View {
class ViewSettings : public View::Floating {
public:
explicit ViewSettings();
~ViewSettings() override;
void drawContent() override;
void drawContent() override {}
void drawAlwaysVisibleContent() override;
[[nodiscard]] bool isAvailable() const override { return true; }
[[nodiscard]] bool shouldDraw() const override { return false; }
[[nodiscard]] bool hasViewMenuItemEntry() const override { return false; }
[[nodiscard]] ImVec2 getMinSize() const override { return scaled({ 700, 400 }); }

View File

@ -44,14 +44,14 @@ namespace hex::plugin::builtin {
std::function<void()> downloadCallback;
};
class ViewStore : public View {
class ViewStore : public View::Floating {
public:
ViewStore();
~ViewStore() override = default;
void drawContent() override;
[[nodiscard]] bool isAvailable() const override { return true; }
[[nodiscard]] bool shouldDraw() const override { return false; }
[[nodiscard]] bool hasViewMenuItemEntry() const override { return false; }
[[nodiscard]] ImVec2 getMinSize() const override { return scaled({ 600, 400 }); }

View File

@ -6,19 +6,18 @@
namespace hex::plugin::builtin {
class ViewThemeManager : public View {
class ViewThemeManager : public View::Floating {
public:
ViewThemeManager();
~ViewThemeManager() override = default;
void drawContent() override;
[[nodiscard]] bool isAvailable() const override { return true; }
[[nodiscard]] bool shouldDraw() const override { return true; }
[[nodiscard]] bool hasViewMenuItemEntry() const override { return false; }
private:
std::string m_themeName;
bool m_viewOpen = false;
std::optional<ImColor> m_startingColor;
std::optional<u32> m_hoveredColorId;

View File

@ -7,13 +7,13 @@
namespace hex::plugin::builtin {
class ViewTools : public View {
class ViewTools : public View::Window {
public:
ViewTools();
~ViewTools() override = default;
void drawContent() override;
void drawAlwaysVisible() override;
void drawAlwaysVisibleContent() override;
private:
std::vector<ContentRegistry::Tools::impl::Entry>::iterator m_dragStartIterator;

View File

@ -8,7 +8,7 @@
namespace hex::plugin::builtin {
class ViewYara : public View {
class ViewYara : public View::Window {
public:
ViewYara();
~ViewYara() override;

View File

@ -16,12 +16,11 @@
namespace hex::plugin::builtin {
ViewAbout::ViewAbout() : View("hex.builtin.view.help.about.name") {
ViewAbout::ViewAbout() : View::Modal("hex.builtin.view.help.about.name") {
// Add "About" menu item to the help menu
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.help", "hex.builtin.view.help.about.name" }, 1000, Shortcut::None, [this] {
TaskManager::doLater([] { ImGui::OpenPopup(View::toWindowName("hex.builtin.view.help.about.name").c_str()); });
this->m_aboutWindowOpen = true;
TaskManager::doLater([this] { ImGui::OpenPopup(View::toWindowName(this->getUnlocalizedName()).c_str()); });
this->getWindowOpenState() = true;
});
@ -481,8 +480,6 @@ namespace hex::plugin::builtin {
Tab { "hex.builtin.view.help.about.license", &ViewAbout::drawLicensePage },
};
if (ImGui::BeginPopupModal(View::toWindowName("hex.builtin.view.help.about.name").c_str(), &this->m_aboutWindowOpen)) {
// Allow the window to be closed by pressing ESC
if (ImGui::IsKeyDown(ImGui::GetKeyIndex(ImGuiKey_Escape)))
ImGui::CloseCurrentPopup();
@ -504,15 +501,9 @@ namespace hex::plugin::builtin {
ImGui::EndTabBar();
}
ImGui::EndPopup();
}
}
void ViewAbout::drawContent() {
if (!this->m_aboutWindowOpen)
this->getWindowOpenState() = false;
this->drawAboutPopup();
}

View File

@ -9,10 +9,9 @@
namespace hex::plugin::builtin {
ViewAchievements::ViewAchievements() : View("hex.builtin.view.achievements.name") {
ViewAchievements::ViewAchievements() : View::Floating("hex.builtin.view.achievements.name") {
// Add achievements menu item to Extas menu
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.extras", "hex.builtin.view.achievements.name" }, 2600, Shortcut::None, [&, this] {
this->m_viewOpen = true;
this->getWindowOpenState() = true;
});
@ -24,7 +23,6 @@ namespace hex::plugin::builtin {
EventManager::subscribe<RequestOpenWindow>(this, [this](const std::string &name) {
if (name == "Achievements") {
TaskManager::doLater([this] {
this->m_viewOpen = true;
this->getWindowOpenState() = true;
});
}
@ -302,7 +300,6 @@ namespace hex::plugin::builtin {
}
void ViewAchievements::drawContent() {
if (ImGui::Begin(View::toWindowName("hex.builtin.view.achievements.name").c_str(), &this->m_viewOpen, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoDocking)) {
if (ImGui::BeginTabBar("##achievement_categories")) {
auto &startNodes = AchievementManager::getAchievementStartNodes();
@ -400,15 +397,11 @@ namespace hex::plugin::builtin {
ImGui::EndTabBar();
}
}
ImGui::End();
this->getWindowOpenState() = this->m_viewOpen;
this->m_achievementToGoto = nullptr;
}
void ViewAchievements::drawAlwaysVisible() {
void ViewAchievements::drawAlwaysVisibleContent() {
// Handle showing the achievement unlock popup
if (this->m_achievementUnlockQueueTimer >= 0 && this->m_showPopup) {
@ -439,8 +432,7 @@ namespace hex::plugin::builtin {
// Handle clicking on the popup
if (ImGui::IsWindowHovered() && ImGui::IsMouseReleased(ImGuiMouseButton_Left)) {
// Open the achievement window and jump to the achievement
this->m_viewOpen = true;
this->getWindowOpenState() = this->m_viewOpen;
this->getWindowOpenState() = true;
this->m_achievementToGoto = this->m_currAchievement;
}
}

View File

@ -17,7 +17,7 @@
namespace hex::plugin::builtin {
ViewBookmarks::ViewBookmarks() : View("hex.builtin.view.bookmarks.name") {
ViewBookmarks::ViewBookmarks() : View::Window("hex.builtin.view.bookmarks.name") {
// Handle bookmark add requests sent by the API
EventManager::subscribe<RequestAddBookmark>(this, [this](Region region, std::string name, std::string comment, color_t color) {
@ -201,7 +201,6 @@ namespace hex::plugin::builtin {
}
void ViewBookmarks::drawContent() {
if (ImGui::Begin(View::toWindowName("hex.builtin.view.bookmarks.name").c_str(), &this->getWindowOpenState())) {
auto provider = ImHexApi::Provider::get();
// Draw filter input
@ -387,8 +386,6 @@ namespace hex::plugin::builtin {
}
ImGui::EndChild();
}
ImGui::End();
}
bool ViewBookmarks::importBookmarks(prv::Provider *provider, const nlohmann::json &json) {
if (!json.contains("bookmarks"))

View File

@ -5,7 +5,7 @@
namespace hex::plugin::builtin {
ViewCommandPalette::ViewCommandPalette() : View("hex.builtin.view.command_palette.name") {
ViewCommandPalette::ViewCommandPalette() : View::Special("hex.builtin.view.command_palette.name") {
// Add global shortcut to open the command palette
ShortcutManager::addGlobalShortcut(CTRLCMD + SHIFT + Keys::P, "hex.builtin.view.command_palette.name", [this] {
EventManager::post<RequestOpenPopup>("hex.builtin.view.command_palette.name"_lang);
@ -20,7 +20,7 @@ namespace hex::plugin::builtin {
});
}
void ViewCommandPalette::drawContent() {
void ViewCommandPalette::drawAlwaysVisibleContent() {
// If the command palette is hidden, don't draw it
if (!this->m_commandPaletteOpen) return;

View File

@ -12,7 +12,7 @@
namespace hex::plugin::builtin {
ViewConstants::ViewConstants() : View("hex.builtin.view.constants.name") {
ViewConstants::ViewConstants() : View::Window("hex.builtin.view.constants.name") {
this->reloadConstants();
}
@ -63,8 +63,6 @@ namespace hex::plugin::builtin {
}
void ViewConstants::drawContent() {
if (ImGui::Begin(View::toWindowName("hex.builtin.view.constants.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
ImGui::PushItemWidth(-1);
if (ImGuiExt::InputTextIcon("##search", ICON_VS_FILTER, this->m_filter)) {
@ -148,7 +146,5 @@ namespace hex::plugin::builtin {
ImGui::EndTable();
}
}
ImGui::End();
}
}

View File

@ -19,7 +19,7 @@ namespace hex::plugin::builtin {
using NumberDisplayStyle = ContentRegistry::DataInspector::NumberDisplayStyle;
ViewDataInspector::ViewDataInspector() : View("hex.builtin.view.data_inspector.name") {
ViewDataInspector::ViewDataInspector() : View::Window("hex.builtin.view.data_inspector.name") {
// Handle region selection
EventManager::subscribe<EventRegionSelected>(this, [this](const auto &region) {
@ -208,7 +208,6 @@ namespace hex::plugin::builtin {
this->updateInspectorRows();
}
if (ImGui::Begin(View::toWindowName("hex.builtin.view.data_inspector.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
if (this->m_selectedProvider != nullptr && this->m_selectedProvider->isReadable() && this->m_validBytes > 0) {
u32 validLineCount = this->m_cachedData.size();
if (!this->m_tableEditingModeEnabled) {
@ -406,7 +405,5 @@ namespace hex::plugin::builtin {
ImGui::TextUnformatted(text.c_str());
}
}
ImGui::End();
}
}

View File

@ -347,7 +347,7 @@ namespace hex::plugin::builtin {
ViewDataProcessor::Workspace m_workspace;
};
ViewDataProcessor::ViewDataProcessor() : View("hex.builtin.view.data_processor.name") {
ViewDataProcessor::ViewDataProcessor() : View::Window("hex.builtin.view.data_processor.name") {
ContentRegistry::DataProcessorNode::add<NodeCustom>("hex.builtin.nodes.custom", "hex.builtin.nodes.custom.custom", this);
ContentRegistry::DataProcessorNode::add<NodeCustomInput>("hex.builtin.nodes.custom", "hex.builtin.nodes.custom.input");
ContentRegistry::DataProcessorNode::add<NodeCustomOutput>("hex.builtin.nodes.custom", "hex.builtin.nodes.custom.output");
@ -842,7 +842,6 @@ namespace hex::plugin::builtin {
auto &workspace = *this->m_workspaceStack->back();
bool popWorkspace = false;
if (ImGui::Begin(View::toWindowName("hex.builtin.view.data_processor.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
// Set the ImNodes context to the current workspace context
ImNodes::SetCurrentContext(workspace.context.get());
@ -1014,8 +1013,6 @@ namespace hex::plugin::builtin {
this->eraseNodes(workspace, selectedNodes);
}
}
}
ImGui::End();
// Remove the top-most workspace from the stack if requested
if (popWorkspace) {

View File

@ -15,7 +15,7 @@ namespace hex::plugin::builtin {
}
ViewDiff::ViewDiff() : View("hex.builtin.view.diff.name") {
ViewDiff::ViewDiff() : View::Window("hex.builtin.view.diff.name") {
// Clear the selected diff providers when a provider is closed
EventManager::subscribe<EventProviderClosed>(this, [this](prv::Provider *) {
@ -183,8 +183,6 @@ namespace hex::plugin::builtin {
}
void ViewDiff::drawContent() {
if (ImGui::Begin(View::toWindowName("hex.builtin.view.diff.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) {
auto &[a, b] = this->m_columns;
a.hexEditor.enableSyncScrolling(false);
@ -321,9 +319,6 @@ namespace hex::plugin::builtin {
ImGui::EndTable();
}
}
ImGui::End();
}
}

View File

@ -9,7 +9,7 @@ using namespace std::literals::string_literals;
namespace hex::plugin::builtin {
ViewDisassembler::ViewDisassembler() : View("hex.builtin.view.disassembler.name") {
ViewDisassembler::ViewDisassembler() : View::Window("hex.builtin.view.disassembler.name") {
EventManager::subscribe<EventProviderDeleted>(this, [this](const auto*) {
this->m_disassembly.clear();
});
@ -91,9 +91,6 @@ namespace hex::plugin::builtin {
}
void ViewDisassembler::drawContent() {
if (ImGui::Begin(View::toWindowName("hex.builtin.view.disassembler.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
auto provider = ImHexApi::Provider::get();
if (ImHexApi::Provider::isValid() && provider->isReadable()) {
ImGuiExt::Header("hex.builtin.view.disassembler.position"_lang, true);
@ -450,7 +447,5 @@ namespace hex::plugin::builtin {
}
}
}
ImGui::End();
}
}

View File

@ -14,7 +14,7 @@
namespace hex::plugin::builtin {
ViewFind::ViewFind() : View("hex.builtin.view.find.name") {
ViewFind::ViewFind() : View::Window("hex.builtin.view.find.name") {
const static auto HighlightColor = [] { return (ImGuiExt::GetCustomColorU32(ImGuiCustomCol_FindHighlight) & 0x00FFFFFF) | 0x70000000; };
ImHexApi::HexEditor::addBackgroundHighlightingProvider([this](u64 address, const u8* data, size_t size, bool) -> std::optional<color_t> {
@ -599,7 +599,6 @@ namespace hex::plugin::builtin {
}
void ViewFind::drawContent() {
if (ImGui::Begin(View::toWindowName("hex.builtin.view.find.name").c_str(), &this->getWindowOpenState())) {
auto provider = ImHexApi::Provider::get();
ImGui::BeginDisabled(this->m_searchTask.isRunning());
@ -937,9 +936,6 @@ namespace hex::plugin::builtin {
ImGui::EndTable();
}
}
ImGui::End();
}
}

View File

@ -42,21 +42,13 @@ namespace hex::plugin::builtin {
return ImGuiWindowFlags_AlwaysAutoResize;
}
[[nodiscard]] ImVec2 getMinSize() const override {
return scaled({ 400, 100 });
}
[[nodiscard]] ImVec2 getMaxSize() const override {
return scaled({ 600, 300 });
}
private:
std::string m_input;
std::string m_result;
ContentRegistry::Hashes::Hash::Function m_hash;
};
ViewHashes::ViewHashes() : View("hex.builtin.view.hashes.name") {
ViewHashes::ViewHashes() : View::Window("hex.builtin.view.hashes.name") {
EventManager::subscribe<EventRegionSelected>(this, [this](const auto &providerRegion) {
for (auto &function : this->m_hashFunctions.get(providerRegion.getProvider()))
function.reset();
@ -143,7 +135,6 @@ namespace hex::plugin::builtin {
this->m_selectedHash = hashes.front().get();
}
if (ImGui::Begin(View::toWindowName("hex.builtin.view.hashes.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
if (ImGui::BeginCombo("hex.builtin.view.hashes.function"_lang, this->m_selectedHash != nullptr ? LangEntry(this->m_selectedHash->getUnlocalizedName()) : "")) {
for (const auto &hash : hashes) {
@ -248,8 +239,6 @@ namespace hex::plugin::builtin {
ImGui::EndTable();
}
}
ImGui::End();
}
bool ViewHashes::importHashes(prv::Provider *provider, const nlohmann::json &json) {
if (!json.contains("hashes"))

View File

@ -347,7 +347,7 @@ namespace hex::plugin::builtin {
editor->closePopup();
}
View::confirmButtons("hex.builtin.common.set"_lang, "hex.builtin.common.cancel"_lang,
ImGuiExt::ConfirmButtons("hex.builtin.common.set"_lang, "hex.builtin.common.cancel"_lang,
[&, this]{
setBaseAddress(this->m_baseAddress);
editor->closePopup();
@ -381,7 +381,7 @@ namespace hex::plugin::builtin {
editor->closePopup();
}
View::confirmButtons("hex.builtin.common.set"_lang, "hex.builtin.common.cancel"_lang,
ImGuiExt::ConfirmButtons("hex.builtin.common.set"_lang, "hex.builtin.common.cancel"_lang,
[&, this]{
setPageSize(this->m_pageSize);
editor->closePopup();
@ -419,7 +419,7 @@ namespace hex::plugin::builtin {
editor->closePopup();
}
View::confirmButtons("hex.builtin.common.set"_lang, "hex.builtin.common.cancel"_lang,
ImGuiExt::ConfirmButtons("hex.builtin.common.set"_lang, "hex.builtin.common.cancel"_lang,
[&, this]{
this->resize(this->m_size);
editor->closePopup();
@ -449,7 +449,7 @@ namespace hex::plugin::builtin {
ImGuiExt::InputHexadecimal("hex.builtin.common.address"_lang, &this->m_address);
ImGuiExt::InputHexadecimal("hex.builtin.common.size"_lang, &this->m_size);
View::confirmButtons("hex.builtin.common.set"_lang, "hex.builtin.common.cancel"_lang,
ImGuiExt::ConfirmButtons("hex.builtin.common.set"_lang, "hex.builtin.common.cancel"_lang,
[&, this]{
insert(this->m_address, this->m_size);
editor->closePopup();
@ -480,7 +480,7 @@ namespace hex::plugin::builtin {
ImGuiExt::InputHexadecimal("hex.builtin.common.address"_lang, &this->m_address);
ImGuiExt::InputHexadecimal("hex.builtin.common.size"_lang, &this->m_size);
View::confirmButtons("hex.builtin.common.set"_lang, "hex.builtin.common.cancel"_lang,
ImGuiExt::ConfirmButtons("hex.builtin.common.set"_lang, "hex.builtin.common.cancel"_lang,
[&, this]{
remove(this->m_address, this->m_size);
editor->closePopup();
@ -515,7 +515,7 @@ namespace hex::plugin::builtin {
ImGuiExt::InputTextIcon("hex.builtin.common.bytes"_lang, ICON_VS_SYMBOL_NAMESPACE, this->m_input);
View::confirmButtons("hex.builtin.common.set"_lang, "hex.builtin.common.cancel"_lang,
ImGuiExt::ConfirmButtons("hex.builtin.common.set"_lang, "hex.builtin.common.cancel"_lang,
[&, this] {
fill(this->m_address, this->m_size, this->m_input);
editor->closePopup();
@ -552,7 +552,7 @@ namespace hex::plugin::builtin {
/* Hex Editor */
ViewHexEditor::ViewHexEditor() : View("hex.builtin.view.hex_editor.name") {
ViewHexEditor::ViewHexEditor() : View::Window("hex.builtin.view.hex_editor.name") {
this->m_hexEditor.setForegroundHighlightCallback([this](u64 address, const u8 *data, size_t size) -> std::optional<color_t> {
if (auto highlight = this->m_foregroundHighlights->find(address); highlight != this->m_foregroundHighlights->end())
return highlight->second;
@ -675,15 +675,12 @@ namespace hex::plugin::builtin {
}
void ViewHexEditor::drawContent() {
if (ImGui::Begin(View::toWindowName(this->getUnlocalizedName()).c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoNavInputs | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) {
this->m_hexEditor.setProvider(ImHexApi::Provider::get());
this->m_hexEditor.draw();
this->drawPopup();
}
ImGui::End();
}
static void save() {
ImHexApi::Provider::get()->save();

View File

@ -20,7 +20,7 @@ namespace hex::plugin::builtin {
using namespace hex::literals;
ViewInformation::ViewInformation() : View("hex.builtin.view.information.name") {
ViewInformation::ViewInformation() : View::Window("hex.builtin.view.information.name") {
EventManager::subscribe<EventDataChanged>(this, [this] {
this->m_dataValid = false;
this->m_plainTextCharacterPercentage = -1.0;
@ -136,7 +136,6 @@ namespace hex::plugin::builtin {
}
void ViewInformation::drawContent() {
if (ImGui::Begin(View::toWindowName("hex.builtin.view.information.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
if (ImGui::BeginChild("##scrolling", ImVec2(0, 0), false, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoNav)) {
auto provider = ImHexApi::Provider::get();
@ -361,7 +360,5 @@ namespace hex::plugin::builtin {
}
ImGui::EndChild();
}
ImGui::End();
}
}

View File

@ -5,9 +5,8 @@
namespace hex::plugin::builtin {
ViewLogs::ViewLogs() : View("hex.builtin.view.logs.name") {
ViewLogs::ViewLogs() : View::Floating("hex.builtin.view.logs.name") {
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.extras", "hex.builtin.view.logs.name" }, 2500, Shortcut::None, [&, this] {
this->m_viewOpen = true;
this->getWindowOpenState() = true;
});
}
@ -41,8 +40,6 @@ namespace hex::plugin::builtin {
}
void ViewLogs::drawContent() {
if (ImGui::Begin(View::toWindowName("hex.builtin.view.logs.name").c_str(), &this->m_viewOpen, ImGuiWindowFlags_NoCollapse)) {
ImGui::Combo("hex.builtin.view.logs.log_level"_lang, &this->m_logLevel, "DEBUG\0INFO\0WARNING\0ERROR\0FATAL\0");
if (ImGui::BeginTable("##logs", 2, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_ScrollY)) {
@ -80,9 +77,5 @@ namespace hex::plugin::builtin {
ImGui::EndTable();
}
}
ImGui::End();
this->getWindowOpenState() = this->m_viewOpen;
}
}

View File

@ -11,7 +11,7 @@ using namespace std::literals::string_literals;
namespace hex::plugin::builtin {
ViewPatches::ViewPatches() : View("hex.builtin.view.patches.name") {
ViewPatches::ViewPatches() : View::Window("hex.builtin.view.patches.name") {
ProjectFile::registerPerProviderHandler({
.basePath = "patches.json",
@ -54,7 +54,6 @@ namespace hex::plugin::builtin {
}
void ViewPatches::drawContent() {
if (ImGui::Begin(View::toWindowName("hex.builtin.view.patches.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
auto provider = ImHexApi::Provider::get();
if (ImHexApi::Provider::isValid() && provider->isReadable()) {
@ -118,10 +117,8 @@ namespace hex::plugin::builtin {
}
}
}
ImGui::End();
}
void ViewPatches::drawAlwaysVisible() {
void ViewPatches::drawAlwaysVisibleContent() {
if (auto provider = ImHexApi::Provider::get(); provider != nullptr) {
const auto &patches = provider->getPatches();
if (this->m_numPatches.get(provider) != patches.size()) {

View File

@ -8,7 +8,7 @@
namespace hex::plugin::builtin {
ViewPatternData::ViewPatternData() : View("hex.builtin.view.pattern_data.name") {
ViewPatternData::ViewPatternData() : View::Window("hex.builtin.view.pattern_data.name") {
this->m_patternDrawer = std::make_unique<ui::PatternDrawer>();
// Handle tree style setting changes
@ -42,7 +42,6 @@ namespace hex::plugin::builtin {
}
void ViewPatternData::drawContent() {
if (ImGui::Begin(View::toWindowName("hex.builtin.view.pattern_data.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
// Draw the pattern tree if the provider is valid
if (ImHexApi::Provider::isValid()) {
// Make sure the runtime has finished evaluating and produced valid patterns
@ -57,7 +56,5 @@ namespace hex::plugin::builtin {
}
}
}
ImGui::End();
}
}

View File

@ -122,7 +122,7 @@ namespace hex::plugin::builtin {
return langDef;
}
ViewPatternEditor::ViewPatternEditor() : View("hex.builtin.view.pattern_editor.name") {
ViewPatternEditor::ViewPatternEditor() : View::Window("hex.builtin.view.pattern_editor.name") {
this->m_parserRuntime = std::make_unique<pl::PatternLanguage>();
ContentRegistry::PatternLanguage::configureRuntime(*this->m_parserRuntime, nullptr);
@ -148,7 +148,6 @@ namespace hex::plugin::builtin {
}
void ViewPatternEditor::drawContent() {
if (ImGui::Begin(View::toWindowName("hex.builtin.view.pattern_editor.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_None | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) {
auto provider = ImHexApi::Provider::get();
if (ImHexApi::Provider::isValid() && provider->isAvailable()) {
@ -343,8 +342,6 @@ namespace hex::plugin::builtin {
View::discardNavigationRequests();
}
ImGui::End();
}
void ViewPatternEditor::drawConsole(ImVec2 size) {
if (this->m_consoleNeedsUpdate) {
@ -689,7 +686,7 @@ namespace hex::plugin::builtin {
ImGui::EndChild();
}
void ViewPatternEditor::drawAlwaysVisible() {
void ViewPatternEditor::drawAlwaysVisibleContent() {
auto provider = ImHexApi::Provider::get();
auto open = this->m_sectionWindowDrawer.contains(provider);

View File

@ -5,7 +5,7 @@
namespace hex::plugin::builtin {
ViewProviderSettings::ViewProviderSettings() : hex::View("hex.builtin.view.provider_settings.name") {
ViewProviderSettings::ViewProviderSettings() : View::Modal("hex.builtin.view.provider_settings.name") {
EventManager::subscribe<EventProviderCreated>(this, [](const hex::prv::Provider *provider) {
if (provider->hasLoadInterface() && !provider->shouldSkipLoadInterface())
EventManager::post<RequestOpenPopup>(View::toWindowName("hex.builtin.view.provider_settings.load_popup"));
@ -29,13 +29,6 @@ namespace hex::plugin::builtin {
}
void ViewProviderSettings::drawContent() {
}
void ViewProviderSettings::drawAlwaysVisible() {
ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_Appearing, ImVec2(0.5F, 0.5F));
if (ImGui::BeginPopupModal(View::toWindowName("hex.builtin.view.provider_settings.load_popup").c_str(), nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
auto provider = hex::ImHexApi::Provider::get();
if (provider != nullptr) {
bool settingsValid = provider->drawLoadInterface();
@ -69,17 +62,10 @@ namespace hex::plugin::builtin {
TaskManager::doLater([=] { ImHexApi::Provider::remove(provider); });
}
}
ImGui::EndPopup();
}
}
bool ViewProviderSettings::hasViewMenuItemEntry() const {
return false;
}
bool ViewProviderSettings::isAvailable() const {
return false;
}
}

View File

@ -10,12 +10,12 @@
namespace hex::plugin::builtin {
ViewSettings::ViewSettings() : View("hex.builtin.view.settings.name") {
ViewSettings::ViewSettings() : View::Floating("hex.builtin.view.settings.name") {
// Handle window open requests
EventManager::subscribe<RequestOpenWindow>(this, [this](const std::string &name) {
if (name == "Settings") {
TaskManager::doLater([this] {
ImGui::OpenPopup(View::toWindowName("hex.builtin.view.settings.name").c_str());
ImGui::OpenPopup(View::toWindowName(this->getUnlocalizedName()).c_str());
this->getWindowOpenState() = true;
});
}
@ -24,7 +24,7 @@ namespace hex::plugin::builtin {
// Add the settings menu item to the Extras menu
ContentRegistry::Interface::addMenuItemSeparator({ "hex.builtin.menu.extras" }, 3000);
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.extras", "hex.builtin.view.settings.name"_lang }, 4000, Shortcut::None, [&, this] {
TaskManager::doLater([] { ImGui::OpenPopup(View::toWindowName("hex.builtin.view.settings.name").c_str()); });
TaskManager::doLater([this] { ImGui::OpenPopup(View::toWindowName(this->getUnlocalizedName()).c_str()); });
this->getWindowOpenState() = true;
});
}
@ -33,9 +33,8 @@ namespace hex::plugin::builtin {
EventManager::unsubscribe<RequestOpenWindow>(this);
}
void ViewSettings::drawContent() {
if (ImGui::BeginPopupModal(View::toWindowName("hex.builtin.view.settings.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoResize)) {
void ViewSettings::drawAlwaysVisibleContent() {
if (ImGui::BeginPopupModal(View::toWindowName(this->getUnlocalizedName()).c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoResize)) {
if (ImGui::BeginTabBar("settings")) {
auto &categories = ContentRegistry::Settings::impl::getSettings();

View File

@ -27,11 +27,11 @@ namespace hex::plugin::builtin {
using namespace std::literals::string_literals;
using namespace std::literals::chrono_literals;
ViewStore::ViewStore() : View("hex.builtin.view.store.name") {
ViewStore::ViewStore() : View::Floating("hex.builtin.view.store.name") {
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.extras", "hex.builtin.view.store.name" }, 1000, Shortcut::None, [&, this] {
if (this->m_requestStatus == RequestStatus::NotAttempted)
this->refresh();
TaskManager::doLater([] { ImGui::OpenPopup(View::toWindowName("hex.builtin.view.store.name").c_str()); });
TaskManager::doLater([this] { ImGui::OpenPopup(View::toWindowName(this->getUnlocalizedName()).c_str()); });
this->getWindowOpenState() = true;
});
@ -278,16 +278,10 @@ namespace hex::plugin::builtin {
}
void ViewStore::drawContent() {
if (ImGui::BeginPopupModal(View::toWindowName("hex.builtin.view.store.name").c_str(), &this->getWindowOpenState())) {
if (this->m_requestStatus == RequestStatus::Failed)
ImGuiExt::TextFormattedColored(ImGuiExt::GetCustomColorVec4(ImGuiCustomCol_ToolbarRed), "hex.builtin.view.store.netfailed"_lang);
this->drawStore();
ImGui::EndPopup();
} else {
this->getWindowOpenState() = false;
}
}
bool ViewStore::download(fs::ImHexPath pathType, const std::string &fileName, const std::string &url, bool update) {

View File

@ -7,15 +7,13 @@
namespace hex::plugin::builtin {
ViewThemeManager::ViewThemeManager() : View("hex.builtin.view.theme_manager.name") {
ViewThemeManager::ViewThemeManager() : View::Floating("hex.builtin.view.theme_manager.name") {
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.extras", "hex.builtin.view.theme_manager.name" }, 2000, Shortcut::None, [&, this] {
this->m_viewOpen = true;
this->getWindowOpenState() = true;
});
}
void ViewThemeManager::drawContent() {
if (ImGui::Begin(View::toWindowName("hex.builtin.view.theme_manager.name").c_str(), &this->m_viewOpen, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoDocking)) {
ImGuiExt::Header("hex.builtin.view.theme_manager.colors"_lang, true);
// Draw theme handlers
@ -125,11 +123,6 @@ namespace hex::plugin::builtin {
outputFile.writeString(json.dump(4));
});
}
}
ImGui::End();
this->getWindowOpenState() = this->m_viewOpen;
}
}

View File

@ -5,15 +5,13 @@
namespace hex::plugin::builtin {
ViewTools::ViewTools() : View("hex.builtin.view.tools.name") {
ViewTools::ViewTools() : View::Window("hex.builtin.view.tools.name") {
this->m_dragStartIterator = ContentRegistry::Tools::impl::getEntries().end();
}
void ViewTools::drawContent() {
auto &tools = ContentRegistry::Tools::impl::getEntries();
if (ImGui::Begin(View::toWindowName("hex.builtin.view.tools.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
// Draw all tools
for (auto iter = tools.begin(); iter != tools.end(); ++iter) {
auto &[name, function, detached] = *iter;
@ -44,10 +42,8 @@ namespace hex::plugin::builtin {
}
}
}
ImGui::End();
}
void ViewTools::drawAlwaysVisible() {
void ViewTools::drawAlwaysVisibleContent() {
// Make sure the tool windows never get drawn over the welcome screen
if (!ImHexApi::Provider::isValid())
return;

View File

@ -27,7 +27,7 @@ namespace hex::plugin::builtin {
using namespace wolv::literals;
ViewYara::ViewYara() : View("hex.builtin.view.yara.name") {
ViewYara::ViewYara() : View::Window("hex.builtin.view.yara.name") {
yr_initialize();
ContentRegistry::FileHandler::add({ ".yar", ".yara" }, [](const auto &path) {
@ -99,8 +99,6 @@ namespace hex::plugin::builtin {
}
void ViewYara::drawContent() {
if (ImGui::Begin(View::toWindowName("hex.builtin.view.yara.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
ImGuiExt::Header("hex.builtin.view.yara.header.rules"_lang, true);
if (ImGui::BeginListBox("##rules", ImVec2(-FLT_MIN, ImGui::GetTextLineHeightWithSpacing() * 5))) {
@ -245,8 +243,6 @@ namespace hex::plugin::builtin {
}
ImGui::EndChild();
}
ImGui::End();
}
void ViewYara::clearResult() {
for (const auto &match : *this->m_matches) {

View File

@ -11,7 +11,7 @@
namespace hex::plugin::windows {
class ViewTTYConsole : public View {
class ViewTTYConsole : public View::Window {
public:
ViewTTYConsole();
~ViewTTYConsole() override = default;

View File

@ -9,7 +9,7 @@
namespace hex::plugin::windows {
ViewTTYConsole::ViewTTYConsole() : View("hex.windows.view.tty_console.name") {
ViewTTYConsole::ViewTTYConsole() : View::Window("hex.windows.view.tty_console.name") {
this->m_comPorts = getAvailablePorts();
this->m_transmitDataBuffer.resize(0xFFF, 0x00);
this->m_receiveDataBuffer.reserve(0xFFF);
@ -17,8 +17,6 @@ namespace hex::plugin::windows {
}
void ViewTTYConsole::drawContent() {
if (ImGui::Begin(View::toWindowName("hex.windows.view.tty_console.name").c_str(), &this->getWindowOpenState())) {
ImGuiExt::Header("hex.windows.view.tty_console.config"_lang, true);
bool connected = this->m_portHandle != INVALID_HANDLE_VALUE;
@ -166,8 +164,6 @@ namespace hex::plugin::windows {
ImGui::EndPopup();
}
}
ImGui::End();
}
std::vector<std::pair<std::string, std::string>> ViewTTYConsole::getAvailablePorts() const {
std::vector<std::pair<std::string, std::string>> result;