mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 21:47:40 -05:00
impr: Update all of ImHex to the new popup system
This commit is contained in:
@@ -183,10 +183,7 @@ namespace hex {
|
||||
EVENT_DEF(RequestCreateProvider, std::string, bool, hex::prv::Provider **);
|
||||
EVENT_DEF(RequestInitThemeHandlers);
|
||||
|
||||
EVENT_DEF(RequestShowInfoPopup, std::string);
|
||||
EVENT_DEF(RequestShowErrorPopup, std::string);
|
||||
EVENT_DEF(RequestShowFatalErrorPopup, std::string);
|
||||
EVENT_DEF(RequestShowYesNoQuestionPopup, std::string, std::function<void()>, std::function<void()>);
|
||||
EVENT_DEF(RequestShowFileChooserPopup, std::vector<std::fs::path>, std::vector<nfdfilteritem_t>, std::function<void(std::fs::path)>, bool);
|
||||
|
||||
EVENT_DEF(RequestOpenInfoPopup, const std::string);
|
||||
EVENT_DEF(RequestOpenErrorPopup, const std::string);
|
||||
EVENT_DEF(RequestOpenFatalPopup, const std::string);
|
||||
}
|
||||
@@ -108,6 +108,8 @@ namespace hex {
|
||||
[[nodiscard]] bool wasInterrupted() const;
|
||||
[[nodiscard]] bool shouldInterrupt() const;
|
||||
|
||||
[[nodiscard]] u32 getProgress() const;
|
||||
|
||||
void interrupt();
|
||||
private:
|
||||
std::weak_ptr<Task> m_task;
|
||||
|
||||
@@ -7,55 +7,88 @@
|
||||
#include <vector>
|
||||
|
||||
#include <imgui.h>
|
||||
#include <hex/ui/imgui_imhex_extensions.h>
|
||||
#include <hex/helpers/utils.hpp>
|
||||
|
||||
#include <hex/api/task.hpp>
|
||||
|
||||
namespace hex {
|
||||
|
||||
class PopupBase {
|
||||
public:
|
||||
explicit PopupBase(std::string unlocalizedName, bool closeButton = true)
|
||||
: m_unlocalizedName(std::move(unlocalizedName)), m_closeButton(closeButton) { }
|
||||
namespace impl {
|
||||
|
||||
virtual ~PopupBase() = default;
|
||||
class PopupBase {
|
||||
public:
|
||||
explicit PopupBase(std::string unlocalizedName, bool closeButton, bool modal)
|
||||
: m_unlocalizedName(std::move(unlocalizedName)), m_closeButton(closeButton), m_modal(modal) { }
|
||||
|
||||
virtual void drawContent() = 0;
|
||||
[[nodiscard]] virtual ImGuiPopupFlags getFlags() const { return ImGuiPopupFlags_None; }
|
||||
virtual ~PopupBase() = default;
|
||||
|
||||
virtual void drawContent() = 0;
|
||||
[[nodiscard]] virtual ImGuiWindowFlags getFlags() const { return ImGuiWindowFlags_None; }
|
||||
|
||||
[[nodiscard]] static std::vector<std::unique_ptr<PopupBase>> &getOpenPopups() {
|
||||
return s_openPopups;
|
||||
}
|
||||
[[nodiscard]] virtual ImVec2 getMinSize() const {
|
||||
return { 0, 0 };
|
||||
}
|
||||
|
||||
[[nodiscard]] const std::string &getUnlocalizedName() const {
|
||||
return this->m_unlocalizedName;
|
||||
}
|
||||
[[nodiscard]] virtual ImVec2 getMaxSize() const {
|
||||
return { FLT_MAX, FLT_MAX };
|
||||
}
|
||||
|
||||
[[nodiscard]] bool hasCloseButton() const {
|
||||
return this->m_closeButton;
|
||||
}
|
||||
[[nodiscard]] static std::vector<std::unique_ptr<PopupBase>> &getOpenPopups() {
|
||||
return s_openPopups;
|
||||
}
|
||||
|
||||
protected:
|
||||
static void close() {
|
||||
ImGui::CloseCurrentPopup();
|
||||
s_openPopups.pop_back();
|
||||
}
|
||||
[[nodiscard]] const std::string &getUnlocalizedName() const {
|
||||
return this->m_unlocalizedName;
|
||||
}
|
||||
|
||||
static std::vector<std::unique_ptr<PopupBase>> s_openPopups;
|
||||
private:
|
||||
[[nodiscard]] bool hasCloseButton() const {
|
||||
return this->m_closeButton;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool isModal() const {
|
||||
return this->m_modal;
|
||||
}
|
||||
|
||||
static void close() {
|
||||
if (s_openPopups.empty())
|
||||
return;
|
||||
|
||||
TaskManager::doLater([]{
|
||||
std::lock_guard lock(s_mutex);
|
||||
|
||||
ImGui::CloseCurrentPopup();
|
||||
s_openPopups.pop_back();
|
||||
});
|
||||
}
|
||||
|
||||
static std::mutex& getMutex() {
|
||||
return s_mutex;
|
||||
}
|
||||
|
||||
protected:
|
||||
static std::vector<std::unique_ptr<PopupBase>> s_openPopups;
|
||||
static std::mutex s_mutex;
|
||||
|
||||
private:
|
||||
|
||||
std::string m_unlocalizedName;
|
||||
bool m_closeButton, m_modal;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
std::string m_unlocalizedName;
|
||||
bool m_closeButton;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class Popup : public PopupBase {
|
||||
class Popup : public impl::PopupBase {
|
||||
protected:
|
||||
explicit Popup(std::string unlocalizedName, bool closeButton = true) : PopupBase(std::move(unlocalizedName), closeButton) { }
|
||||
explicit Popup(std::string unlocalizedName, bool closeButton = true, bool modal = true) : PopupBase(std::move(unlocalizedName), closeButton, modal) { }
|
||||
|
||||
public:
|
||||
virtual ~Popup() = default;
|
||||
|
||||
template<typename ...Args>
|
||||
static void open(Args && ... args) {
|
||||
std::lock_guard lock(s_mutex);
|
||||
|
||||
auto popup = std::make_unique<T>(std::forward<Args>(args)...);
|
||||
|
||||
s_openPopups.emplace_back(std::move(popup));
|
||||
|
||||
@@ -34,13 +34,6 @@ namespace hex {
|
||||
[[nodiscard]] virtual bool isAvailable() const;
|
||||
[[nodiscard]] virtual bool shouldProcess() const { return this->isAvailable() && this->getWindowOpenState(); }
|
||||
|
||||
static void showInfoPopup(const std::string &message);
|
||||
static void showErrorPopup(const std::string &message);
|
||||
static void showFatalPopup(const std::string &message);
|
||||
static void showYesNoQuestionPopup(const std::string &message, const std::function<void()> &yesCallback, const std::function<void()> &noCallback);
|
||||
|
||||
static void showFileChooserPopup(const std::vector<std::fs::path> &paths, const std::vector<nfdfilteritem_t> &validExtensions, bool multiple, const std::function<void(std::fs::path)> &callback);
|
||||
|
||||
[[nodiscard]] virtual bool hasViewMenuItemEntry() const;
|
||||
[[nodiscard]] virtual ImVec2 getMinSize() const;
|
||||
[[nodiscard]] virtual ImVec2 getMaxSize() const;
|
||||
|
||||
Reference in New Issue
Block a user