feat: Added a much more flexible popup system
This commit is contained in:
parent
51e615095e
commit
9c9ac23818
@ -5,37 +5,38 @@ set(CMAKE_CXX_STANDARD 23)
|
||||
set(CMAKE_SHARED_LIBRARY_PREFIX "")
|
||||
|
||||
set(LIBIMHEX_SOURCES
|
||||
source/api/event.cpp
|
||||
source/api/imhex_api.cpp
|
||||
source/api/content_registry.cpp
|
||||
source/api/task.cpp
|
||||
source/api/keybinding.cpp
|
||||
source/api/plugin_manager.cpp
|
||||
source/api/localization.cpp
|
||||
source/api/project_file_manager.cpp
|
||||
source/api/theme_manager.cpp
|
||||
source/api/event.cpp
|
||||
source/api/imhex_api.cpp
|
||||
source/api/content_registry.cpp
|
||||
source/api/task.cpp
|
||||
source/api/keybinding.cpp
|
||||
source/api/plugin_manager.cpp
|
||||
source/api/localization.cpp
|
||||
source/api/project_file_manager.cpp
|
||||
source/api/theme_manager.cpp
|
||||
|
||||
source/data_processor/attribute.cpp
|
||||
source/data_processor/link.cpp
|
||||
source/data_processor/node.cpp
|
||||
source/data_processor/attribute.cpp
|
||||
source/data_processor/link.cpp
|
||||
source/data_processor/node.cpp
|
||||
|
||||
source/helpers/utils.cpp
|
||||
source/helpers/fs.cpp
|
||||
source/helpers/magic.cpp
|
||||
source/helpers/crypto.cpp
|
||||
source/helpers/http_requests.cpp
|
||||
source/helpers/opengl.cpp
|
||||
source/helpers/patches.cpp
|
||||
source/helpers/encoding_file.cpp
|
||||
source/helpers/logger.cpp
|
||||
source/helpers/stacktrace.cpp
|
||||
source/helpers/tar.cpp
|
||||
source/helpers/utils.cpp
|
||||
source/helpers/fs.cpp
|
||||
source/helpers/magic.cpp
|
||||
source/helpers/crypto.cpp
|
||||
source/helpers/http_requests.cpp
|
||||
source/helpers/opengl.cpp
|
||||
source/helpers/patches.cpp
|
||||
source/helpers/encoding_file.cpp
|
||||
source/helpers/logger.cpp
|
||||
source/helpers/stacktrace.cpp
|
||||
source/helpers/tar.cpp
|
||||
|
||||
source/providers/provider.cpp
|
||||
source/providers/provider.cpp
|
||||
|
||||
source/ui/imgui_imhex_extensions.cpp
|
||||
source/ui/view.cpp
|
||||
)
|
||||
source/ui/imgui_imhex_extensions.cpp
|
||||
source/ui/view.cpp
|
||||
source/ui/popup.cpp
|
||||
)
|
||||
|
||||
if (APPLE)
|
||||
set(OSX_11_0_SDK_PATH /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.0.sdk)
|
||||
|
66
lib/libimhex/include/hex/ui/popup.hpp
Normal file
66
lib/libimhex/include/hex/ui/popup.hpp
Normal file
@ -0,0 +1,66 @@
|
||||
#pragma once
|
||||
|
||||
#include <hex.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
namespace hex {
|
||||
|
||||
class PopupBase {
|
||||
public:
|
||||
explicit PopupBase(std::string unlocalizedName, bool closeButton = true)
|
||||
: m_unlocalizedName(std::move(unlocalizedName)), m_closeButton(closeButton) { }
|
||||
|
||||
virtual ~PopupBase() = default;
|
||||
|
||||
virtual void drawContent() = 0;
|
||||
[[nodiscard]] virtual ImGuiPopupFlags getFlags() const { return ImGuiPopupFlags_None; }
|
||||
|
||||
|
||||
[[nodiscard]] static std::vector<std::unique_ptr<PopupBase>> &getOpenPopups() {
|
||||
return s_openPopups;
|
||||
}
|
||||
|
||||
[[nodiscard]] const std::string &getUnlocalizedName() const {
|
||||
return this->m_unlocalizedName;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool hasCloseButton() const {
|
||||
return this->m_closeButton;
|
||||
}
|
||||
|
||||
protected:
|
||||
static void close() {
|
||||
ImGui::CloseCurrentPopup();
|
||||
s_openPopups.pop_back();
|
||||
}
|
||||
|
||||
static std::vector<std::unique_ptr<PopupBase>> s_openPopups;
|
||||
private:
|
||||
|
||||
std::string m_unlocalizedName;
|
||||
bool m_closeButton;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class Popup : public PopupBase {
|
||||
protected:
|
||||
explicit Popup(std::string unlocalizedName, bool closeButton = true) : PopupBase(std::move(unlocalizedName), closeButton) { }
|
||||
|
||||
public:
|
||||
virtual ~Popup() = default;
|
||||
|
||||
template<typename ...Args>
|
||||
static void open(Args && ... args) {
|
||||
auto popup = std::make_unique<T>(std::forward<Args>(args)...);
|
||||
|
||||
s_openPopups.emplace_back(std::move(popup));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
7
lib/libimhex/source/ui/popup.cpp
Normal file
7
lib/libimhex/source/ui/popup.cpp
Normal file
@ -0,0 +1,7 @@
|
||||
#include <hex/ui/popup.hpp>
|
||||
|
||||
namespace hex {
|
||||
|
||||
std::vector<std::unique_ptr<PopupBase>> PopupBase::s_openPopups;
|
||||
|
||||
}
|
@ -11,6 +11,9 @@
|
||||
#include <hex/helpers/logger.hpp>
|
||||
#include <hex/helpers/stacktrace.hpp>
|
||||
|
||||
#include <hex/ui/view.hpp>
|
||||
#include <hex/ui/popup.hpp>
|
||||
|
||||
#include <chrono>
|
||||
#include <csignal>
|
||||
#include <set>
|
||||
@ -520,6 +523,27 @@ namespace hex {
|
||||
});
|
||||
}
|
||||
|
||||
// Draw popup stack
|
||||
{
|
||||
if (auto &popups = PopupBase::getOpenPopups(); !popups.empty()) {
|
||||
auto &currPopup = popups.back();
|
||||
const auto &name = LangEntry(currPopup->getUnlocalizedName());
|
||||
|
||||
if (!ImGui::IsPopupOpen(ImGuiID(0), ImGuiPopupFlags_AnyPopupId))
|
||||
ImGui::OpenPopup(name);
|
||||
|
||||
bool open = true;
|
||||
if (ImGui::BeginPopupModal(name, currPopup->hasCloseButton() ? &open : nullptr, currPopup->getFlags())) {
|
||||
currPopup->drawContent();
|
||||
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
if (!open)
|
||||
popups.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
// Run all deferred calls
|
||||
TaskManager::runDeferredCalls();
|
||||
|
||||
|
@ -774,7 +774,7 @@
|
||||
"hex.builtin.view.patches.remove": "Remove patch",
|
||||
"hex.builtin.view.pattern_data.name": "Pattern Data",
|
||||
"hex.builtin.view.pattern_editor.accept_pattern": "Accept pattern",
|
||||
"hex.builtin.view.pattern_editor.accept_pattern.desc": "One or more pattern_language compatible with this data type has been found",
|
||||
"hex.builtin.view.pattern_editor.accept_pattern.desc": "One or more Patterns compatible with this data type has been found",
|
||||
"hex.builtin.view.pattern_editor.accept_pattern.pattern_language": "Patterns",
|
||||
"hex.builtin.view.pattern_editor.accept_pattern.question": "Do you want to apply the selected pattern?",
|
||||
"hex.builtin.view.pattern_editor.auto": "Auto evaluate",
|
||||
|
@ -767,7 +767,7 @@
|
||||
"hex.builtin.view.patches.remove": "パッチを削除",
|
||||
"hex.builtin.view.pattern_data.name": "パターンデータ",
|
||||
"hex.builtin.view.pattern_editor.accept_pattern": "使用できるパターン",
|
||||
"hex.builtin.view.pattern_editor.accept_pattern.desc": "このデータ型と互換性のある pattern_language が1つ以上見つかりました",
|
||||
"hex.builtin.view.pattern_editor.accept_pattern.desc": "このデータ型と互換性のある Patterns が1つ以上見つかりました",
|
||||
"hex.builtin.view.pattern_editor.accept_pattern.pattern_language": "パターン",
|
||||
"hex.builtin.view.pattern_editor.accept_pattern.question": "選択したパターンを反映してよろしいですか?",
|
||||
"hex.builtin.view.pattern_editor.auto": "常に実行",
|
||||
|
@ -767,7 +767,7 @@
|
||||
"hex.builtin.view.patches.remove": "Remove patch",
|
||||
"hex.builtin.view.pattern_data.name": "模式資料",
|
||||
"hex.builtin.view.pattern_editor.accept_pattern": "接受模式",
|
||||
"hex.builtin.view.pattern_editor.accept_pattern.desc": "已找到一或多個與此資料類型相容的 pattern_language",
|
||||
"hex.builtin.view.pattern_editor.accept_pattern.desc": "已找到一或多個與此資料類型相容的 Patterns",
|
||||
"hex.builtin.view.pattern_editor.accept_pattern.pattern_language": "模式",
|
||||
"hex.builtin.view.pattern_editor.accept_pattern.question": "您要套用所選的模式嗎?",
|
||||
"hex.builtin.view.pattern_editor.auto": "自動評估",
|
||||
|
Loading…
Reference in New Issue
Block a user