diff --git a/lib/libimhex/include/hex/ui/view.hpp b/lib/libimhex/include/hex/ui/view.hpp index 0fb435d5a..bfa1e07c3 100644 --- a/lib/libimhex/include/hex/ui/view.hpp +++ b/lib/libimhex/include/hex/ui/view.hpp @@ -14,7 +14,6 @@ #include #include -#include namespace hex { @@ -27,7 +26,7 @@ namespace hex { * @brief Draws the view * @note Do not override this method. Override drawContent() instead */ - virtual void draw() = 0; + virtual void draw(ImGuiWindowFlags extraFlags = ImGuiWindowFlags_None) = 0; /** * @brief Draws the content of the view @@ -126,6 +125,7 @@ namespace hex { class Window; class Special; class Floating; + class Scrolling; class Modal; class FullScreen; @@ -153,16 +153,10 @@ namespace hex { */ virtual void drawHelpText() = 0; - void draw() final { - if (this->shouldDraw()) { - ImGui::SetNextWindowSizeConstraints(this->getMinSize(), this->getMaxSize()); - const auto title = fmt::format("{} {}", this->getIcon(), View::toWindowName(this->getUnlocalizedName())); - if (ImGui::Begin(title.c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse | this->getWindowFlags())) { - TutorialManager::setLastItemInteractiveHelpPopup([this]{ this->drawHelpText(); }); - this->drawContent(); - } - ImGui::End(); - } + void draw(ImGuiWindowFlags extraFlags = ImGuiWindowFlags_None) override; + + virtual bool allowScroll() const { + return false; } }; @@ -174,12 +168,7 @@ namespace hex { public: explicit Special(UnlocalizedString unlocalizedName) : View(std::move(unlocalizedName), "") {} - void draw() final { - if (this->shouldDraw()) { - ImGui::SetNextWindowSizeConstraints(this->getMinSize(), this->getMaxSize()); - this->drawContent(); - } - } + void draw(ImGuiWindowFlags extraFlags = ImGuiWindowFlags_None) final; }; /** @@ -189,7 +178,24 @@ namespace hex { public: explicit Floating(UnlocalizedString unlocalizedName, const char *icon) : Window(std::move(unlocalizedName), icon) {} - [[nodiscard]] ImGuiWindowFlags getWindowFlags() const override { return ImGuiWindowFlags_NoDocking; } + void draw(ImGuiWindowFlags extraFlags = ImGuiWindowFlags_None) final; + + [[nodiscard]] bool shouldStoreWindowState() const override { return false; } + }; + + /** + * @brief A view that draws all its content at once without any scrolling being done by the window itself + */ + class View::Scrolling : public View::Window { + public: + explicit Scrolling(UnlocalizedString unlocalizedName, const char *icon) : Window(std::move(unlocalizedName), icon) {} + + void draw(ImGuiWindowFlags extraFlags = ImGuiWindowFlags_None) final; + + bool allowScroll() const final { + return true; + } + [[nodiscard]] bool shouldStoreWindowState() const override { return false; } }; @@ -200,24 +206,7 @@ namespace hex { public: explicit Modal(UnlocalizedString unlocalizedName, const char *icon) : View(std::move(unlocalizedName), icon) {} - void draw() final { - if (this->shouldDraw()) { - if (this->getWindowOpenState()) - ImGui::OpenPopup(View::toWindowName(this->getUnlocalizedName()).c_str()); - - ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_Appearing, ImVec2(0.5F, 0.5F)); - ImGui::SetNextWindowSizeConstraints(this->getMinSize(), this->getMaxSize()); - const auto title = fmt::format("{} {}", this->getIcon(), View::toWindowName(this->getUnlocalizedName())); - if (ImGui::BeginPopupModal(title.c_str(), this->hasCloseButton() ? &this->getWindowOpenState() : nullptr, ImGuiWindowFlags_NoCollapse | this->getWindowFlags())) { - this->drawContent(); - - ImGui::EndPopup(); - } - - if (ImGui::IsKeyPressed(ImGuiKey_Escape)) - this->getWindowOpenState() = false; - } - } + void draw(ImGuiWindowFlags extraFlags = ImGuiWindowFlags_None) final; [[nodiscard]] virtual bool hasCloseButton() const { return true; } [[nodiscard]] bool shouldStoreWindowState() const override { return false; } @@ -227,10 +216,7 @@ namespace hex { public: explicit FullScreen() : View("FullScreen", "") {} - void draw() final { - this->drawContent(); - this->drawAlwaysVisibleContent(); - } + void draw(ImGuiWindowFlags extraFlags = ImGuiWindowFlags_None) final; }; } diff --git a/lib/libimhex/source/ui/view.cpp b/lib/libimhex/source/ui/view.cpp index 8bdc3cb97..b524c953b 100644 --- a/lib/libimhex/source/ui/view.cpp +++ b/lib/libimhex/source/ui/view.cpp @@ -1,8 +1,10 @@ #include -#include #include #include +#include +#include + #include #include @@ -116,4 +118,63 @@ namespace hex { } + void View::Window::draw(ImGuiWindowFlags extraFlags) { + if (this->shouldDraw()) { + if (!allowScroll()) + extraFlags |= ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse; + + ImGui::SetNextWindowSizeConstraints(this->getMinSize(), this->getMaxSize()); + const auto title = fmt::format("{} {}", this->getIcon(), View::toWindowName(this->getUnlocalizedName())); + if (ImGui::Begin(title.c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse | extraFlags | this->getWindowFlags())) { + TutorialManager::setLastItemInteractiveHelpPopup([this]{ this->drawHelpText(); }); + this->drawContent(); + } + ImGui::End(); + } + } + + void View::Special::draw(ImGuiWindowFlags extraFlags) { + std::ignore = extraFlags; + + if (this->shouldDraw()) { + ImGui::SetNextWindowSizeConstraints(this->getMinSize(), this->getMaxSize()); + this->drawContent(); + } + } + + void View::Floating::draw(ImGuiWindowFlags extraFlags) { + Window::draw(extraFlags | ImGuiWindowFlags_NoDocking); + } + + void View::Scrolling::draw(ImGuiWindowFlags extraFlags) { + Window::draw(extraFlags); + } + + void View::Modal::draw(ImGuiWindowFlags extraFlags) { + if (this->shouldDraw()) { + if (this->getWindowOpenState()) + ImGui::OpenPopup(View::toWindowName(this->getUnlocalizedName()).c_str()); + + ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_Appearing, ImVec2(0.5F, 0.5F)); + ImGui::SetNextWindowSizeConstraints(this->getMinSize(), this->getMaxSize()); + const auto title = fmt::format("{} {}", this->getIcon(), View::toWindowName(this->getUnlocalizedName())); + if (ImGui::BeginPopupModal(title.c_str(), this->hasCloseButton() ? &this->getWindowOpenState() : nullptr, ImGuiWindowFlags_NoCollapse | extraFlags | this->getWindowFlags())) { + this->drawContent(); + + ImGui::EndPopup(); + } + + if (ImGui::IsKeyPressed(ImGuiKey_Escape)) + this->getWindowOpenState() = false; + } + } + + void View::FullScreen::draw(ImGuiWindowFlags extraFlags) { + std::ignore = extraFlags; + + this->drawContent(); + this->drawAlwaysVisibleContent(); + } + + } \ No newline at end of file diff --git a/plugins/builtin/include/content/views/view_data_processor.hpp b/plugins/builtin/include/content/views/view_data_processor.hpp index f47d6e6ab..a84e42127 100644 --- a/plugins/builtin/include/content/views/view_data_processor.hpp +++ b/plugins/builtin/include/content/views/view_data_processor.hpp @@ -57,10 +57,6 @@ namespace hex::plugin::builtin { void reloadCustomNodes(); void updateNodePositions(); - [[nodiscard]] ImGuiWindowFlags getWindowFlags() const override { - return ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse; - } - std::vector &getWorkspaceStack() { return *m_workspaceStack; } private: diff --git a/plugins/builtin/include/content/views/view_hex_editor.hpp b/plugins/builtin/include/content/views/view_hex_editor.hpp index 1776961f9..f1e1b7959 100644 --- a/plugins/builtin/include/content/views/view_hex_editor.hpp +++ b/plugins/builtin/include/content/views/view_hex_editor.hpp @@ -13,7 +13,7 @@ namespace hex::plugin::builtin { void drawContent() override; [[nodiscard]] ImGuiWindowFlags getWindowFlags() const override { - return ImGuiWindowFlags_NoNavInputs | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse; + return ImGuiWindowFlags_NoNavInputs; } bool shouldDefaultFocus() const override { return true; } diff --git a/plugins/builtin/include/content/views/view_highlight_rules.hpp b/plugins/builtin/include/content/views/view_highlight_rules.hpp index 045fb9954..4195d372e 100644 --- a/plugins/builtin/include/content/views/view_highlight_rules.hpp +++ b/plugins/builtin/include/content/views/view_highlight_rules.hpp @@ -27,7 +27,7 @@ namespace hex::plugin::builtin { } ImGuiWindowFlags getWindowFlags() const override { - return View::Floating::getWindowFlags() | ImGuiWindowFlags_NoResize; + return ImGuiWindowFlags_NoResize; } private: diff --git a/plugins/builtin/include/content/views/view_information.hpp b/plugins/builtin/include/content/views/view_information.hpp index 692794934..7b6cd013e 100644 --- a/plugins/builtin/include/content/views/view_information.hpp +++ b/plugins/builtin/include/content/views/view_information.hpp @@ -7,7 +7,7 @@ namespace hex::plugin::builtin { - class ViewInformation : public View::Window { + class ViewInformation : public View::Scrolling { public: explicit ViewInformation(); ~ViewInformation() override = default; diff --git a/plugins/builtin/include/content/views/view_pattern_editor.hpp b/plugins/builtin/include/content/views/view_pattern_editor.hpp index 21d53a6ef..f0a899bb6 100644 --- a/plugins/builtin/include/content/views/view_pattern_editor.hpp +++ b/plugins/builtin/include/content/views/view_pattern_editor.hpp @@ -66,9 +66,6 @@ namespace hex::plugin::builtin { } void drawContent() override; - [[nodiscard]] ImGuiWindowFlags getWindowFlags() const override { - return ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse; - } void setPopupWindowHeight(u32 height) { m_popupWindowHeight = height; } u32 getPopupWindowHeight() const { return m_popupWindowHeight; } diff --git a/plugins/builtin/include/content/views/view_tools.hpp b/plugins/builtin/include/content/views/view_tools.hpp index 024c130f0..083e7e4f2 100644 --- a/plugins/builtin/include/content/views/view_tools.hpp +++ b/plugins/builtin/include/content/views/view_tools.hpp @@ -7,7 +7,7 @@ namespace hex::plugin::builtin { - class ViewTools : public View::Window { + class ViewTools : public View::Scrolling { public: ViewTools(); ~ViewTools() override = default; diff --git a/plugins/builtin/include/content/views/view_tutorials.hpp b/plugins/builtin/include/content/views/view_tutorials.hpp index 76fc3e413..678ec436d 100644 --- a/plugins/builtin/include/content/views/view_tutorials.hpp +++ b/plugins/builtin/include/content/views/view_tutorials.hpp @@ -26,7 +26,7 @@ namespace hex::plugin::builtin { } ImGuiWindowFlags getWindowFlags() const override { - return Floating::getWindowFlags() | ImGuiWindowFlags_NoResize; + return ImGuiWindowFlags_NoResize; } private: diff --git a/plugins/builtin/source/content/ui_items.cpp b/plugins/builtin/source/content/ui_items.cpp index 9d77886f5..1ccce8d72 100644 --- a/plugins/builtin/source/content/ui_items.cpp +++ b/plugins/builtin/source/content/ui_items.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include diff --git a/plugins/builtin/source/content/views/view_information.cpp b/plugins/builtin/source/content/views/view_information.cpp index ed4c68c8d..00e04938c 100644 --- a/plugins/builtin/source/content/views/view_information.cpp +++ b/plugins/builtin/source/content/views/view_information.cpp @@ -15,7 +15,7 @@ namespace hex::plugin::builtin { using namespace hex::literals; - ViewInformation::ViewInformation() : View::Window("hex.builtin.view.information.name", ICON_VS_GRAPH_LINE) { + ViewInformation::ViewInformation() : View::Scrolling("hex.builtin.view.information.name", ICON_VS_GRAPH_LINE) { m_analysisData.setOnCreateCallback([](const prv::Provider *provider, AnalysisData &data) { data.analyzedProvider = provider; diff --git a/plugins/builtin/source/content/views/view_tools.cpp b/plugins/builtin/source/content/views/view_tools.cpp index b28a1cdff..bdeb90579 100644 --- a/plugins/builtin/source/content/views/view_tools.cpp +++ b/plugins/builtin/source/content/views/view_tools.cpp @@ -8,7 +8,7 @@ namespace hex::plugin::builtin { - ViewTools::ViewTools() : View::Window("hex.builtin.view.tools.name", ICON_VS_TOOLS) { + ViewTools::ViewTools() : View::Scrolling("hex.builtin.view.tools.name", ICON_VS_TOOLS) { m_dragStartIterator = ContentRegistry::Tools::impl::getEntries().end(); LayoutManager::registerLoadCallback([this](std::string_view line) { diff --git a/plugins/diffing/include/content/views/view_diff.hpp b/plugins/diffing/include/content/views/view_diff.hpp index afbf08fe8..993818f98 100644 --- a/plugins/diffing/include/content/views/view_diff.hpp +++ b/plugins/diffing/include/content/views/view_diff.hpp @@ -21,7 +21,6 @@ namespace hex::plugin::diffing { void drawContent() override; void drawAlwaysVisibleContent() override; void drawHelpText() override; - ImGuiWindowFlags getWindowFlags() const override { return ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse; } public: struct Column {