mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 13:37:42 -05:00
feat: Added basic toast popups
This commit is contained in:
@@ -56,8 +56,9 @@ namespace hex {
|
||||
return m_close;
|
||||
}
|
||||
|
||||
protected:
|
||||
static std::mutex& getMutex();
|
||||
private:
|
||||
|
||||
UnlocalizedString m_unlocalizedName;
|
||||
bool m_closeButton, m_modal;
|
||||
std::atomic<bool> m_close = false;
|
||||
@@ -74,8 +75,7 @@ namespace hex {
|
||||
public:
|
||||
template<typename ...Args>
|
||||
static void open(Args && ... args) {
|
||||
static std::mutex mutex;
|
||||
std::lock_guard lock(mutex);
|
||||
std::lock_guard lock(getMutex());
|
||||
|
||||
auto popup = std::make_unique<T>(std::forward<Args>(args)...);
|
||||
|
||||
|
||||
60
lib/libimhex/include/hex/ui/toast.hpp
Normal file
60
lib/libimhex/include/hex/ui/toast.hpp
Normal file
@@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
|
||||
#include <hex.hpp>
|
||||
#include <imgui.h>
|
||||
|
||||
#include <list>
|
||||
#include <memory>
|
||||
|
||||
namespace hex {
|
||||
|
||||
namespace impl {
|
||||
|
||||
class ToastBase {
|
||||
public:
|
||||
ToastBase(ImColor color) : m_color(color) {}
|
||||
virtual ~ToastBase() = default;
|
||||
|
||||
virtual void draw() { drawContent(); }
|
||||
virtual void drawContent() = 0;
|
||||
|
||||
[[nodiscard]] static std::list<std::unique_ptr<ToastBase>> &getQueuedToasts();
|
||||
|
||||
[[nodiscard]] const ImColor& getColor() const {
|
||||
return m_color;
|
||||
}
|
||||
|
||||
void setAppearTime(double appearTime) {
|
||||
m_appearTime = appearTime;
|
||||
}
|
||||
|
||||
[[nodiscard]] double getAppearTime() const {
|
||||
return m_appearTime;
|
||||
}
|
||||
|
||||
constexpr static double VisibilityTime = 4.0;
|
||||
|
||||
protected:
|
||||
static std::mutex& getMutex();
|
||||
|
||||
double m_appearTime = 0;
|
||||
ImColor m_color;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
class Toast : public impl::ToastBase {
|
||||
public:
|
||||
using impl::ToastBase::ToastBase;
|
||||
|
||||
template<typename ...Args>
|
||||
static void open(Args && ... args) {
|
||||
std::lock_guard lock(getMutex());
|
||||
|
||||
auto toast = std::make_unique<T>(std::forward<Args>(args)...);
|
||||
getQueuedToasts().emplace_back(std::move(toast));
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user