#pragma once #include #include #include #include #include #include #include #include namespace hex { namespace impl { class PopupBase { public: explicit PopupBase(UnlocalizedString unlocalizedName, bool closeButton, bool modal) : m_unlocalizedName(std::move(unlocalizedName)), m_closeButton(closeButton), m_modal(modal) { } virtual ~PopupBase() = default; virtual void drawContent() = 0; [[nodiscard]] virtual ImGuiWindowFlags getFlags() const { return ImGuiWindowFlags_None; } [[nodiscard]] virtual ImVec2 getMinSize() const { return { 0, 0 }; } [[nodiscard]] virtual ImVec2 getMaxSize() const { return { 0, 0 }; } [[nodiscard]] static std::vector> &getOpenPopups(); [[nodiscard]] const UnlocalizedString &getUnlocalizedName() const { return m_unlocalizedName; } [[nodiscard]] bool hasCloseButton() const { return m_closeButton; } [[nodiscard]] bool isModal() const { return m_modal; } void close() { m_close = true; } [[nodiscard]] bool shouldClose() const { return m_close; } protected: static std::mutex& getMutex(); private: UnlocalizedString m_unlocalizedName; bool m_closeButton, m_modal; std::atomic m_close = false; }; } template class Popup : public impl::PopupBase { protected: explicit Popup(UnlocalizedString unlocalizedName, bool closeButton = true, bool modal = true) : PopupBase(std::move(unlocalizedName), closeButton, modal) { } public: template static void open(Args && ... args) { std::lock_guard lock(getMutex()); auto popup = std::make_unique(std::forward(args)...); getOpenPopups().emplace_back(std::move(popup)); } }; }