37#include <imgui_includes.h>
39#define NOTIFY_MAX_TOASTS 10
40#define NOTIFY_MAX_MSG_LENGTH 4096
41#define NOTIFY_PADDING_X 20.f
42#define NOTIFY_PADDING_Y 20.f
43#define NOTIFY_PADDING_MESSAGE_Y 10.f
44#define NOTIFY_FADE_IN_OUT_TIME 150
45#define NOTIFY_DEFAULT_DISMISS 3000
46#define NOTIFY_OPACITY 1.0f
47#define NOTIFY_TOAST_FLAGS ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoFocusOnAppearing
49#define NOTIFY_USE_SEPARATOR
51#define NOTIFY_INLINE inline
52#define NOTIFY_NULL_OR_EMPTY(str) (!str ||! strlen(str))
53#define NOTIFY_FORMAT(fn, format, ...) if (format) { va_list args; va_start(args, format); fn(format, args, ##__VA_ARGS__); va_end(args); }
104 uint64_t creation_time = 0;
109 NOTIFY_INLINE auto set_title(
const char* format, va_list args) { vsnprintf(this->title,
sizeof(this->title), format, args); }
111 NOTIFY_INLINE auto set_content(
const char* format, va_list args) { vsnprintf(this->content,
sizeof(this->content), format, args); }
131 if (!strlen(this->title))
161 return { 255, 255, 255, 255 };
163 return { 0, 255, 0, 255 };
165 return { 255, 255, 0, 255 };
167 return { 255, 0, 0, 255 };
169 return { 255, 255, 255, 255 };
171 return { 255, 255, 255, 255 };
253 using namespace std::chrono;
254 return duration_cast<milliseconds>(steady_clock::now().time_since_epoch()).count();
267 this->dismiss_time = dismiss_time;
270 memset(this->title, 0,
sizeof(this->title));
271 memset(this->content, 0,
sizeof(this->content));
282 this->draw_callback = callback;
295 if(toast.unique_id == unique_id)
324 auto current_phase = notification->get_phase();
325 auto current_elapsed = notification->get_elapsed_time();
328 *notification = toast;
335 notification->set_creation_time(
static_cast<uint64_t
>(-
static_cast<int64_t
>(current_elapsed)));
345 notification->set_creation_time(0);
369 const auto vp_pos = GetMainViewport()->Pos;
370 const auto vp_size = GetMainViewport()->Size;
386 const auto icon = current_toast->get_icon();
387 const auto title = current_toast->get_title();
388 const auto content = current_toast->get_content();
389 const auto default_title = current_toast->get_default_title();
390 const auto opacity = current_toast->get_fade_percent();
393 auto text_color = current_toast->get_color();
394 text_color.w = opacity;
397 char window_name[50]{};
398 snprintf(window_name,
sizeof(window_name),
"##TOAST%d", i);
401 SetNextWindowBgAlpha(opacity);
404 SetNextWindowPos(window_pos, ImGuiCond_Always, ImVec2(1.0f, 1.0f));
409 PushTextWrapPos(vp_size.x / 3.f);
411 bool was_title_rendered =
false;
417 TextColored(text_color,
"%s",
icon);
418 was_title_rendered =
true;
429 was_title_rendered =
true;
436 Text(
"%s", default_title);
437 was_title_rendered =
true;
443 SetCursorPosY(GetCursorPosY() + 5.f);
449 if (was_title_rendered)
451#ifdef NOTIFY_USE_SEPARATOR
460 if (current_toast->has_draw_callback())
463 current_toast->get_draw_callback()(*current_toast, opacity, text_color);
NOTIFY_INLINE auto get_phase() -> const ImGuiToastPhase
NOTIFY_INLINE auto get_color() -> const ImVec4
NOTIFY_INLINE auto get_elapsed_time()
ImGuiToast(ImGuiToastType type, const char *format,...)
static NOTIFY_INLINE auto get_tick_count() -> const unsigned long long
NOTIFY_INLINE auto set_creation_time(uint64_t offset) -> const uint64_t
NOTIFY_INLINE auto get_type() -> const ImGuiToastType &
NOTIFY_INLINE auto get_content() -> char *
static NOTIFY_INLINE auto get_icon(ImGuiToastType type) -> const char *
NOTIFY_INLINE auto get_draw_callback() -> const ImGuiToastDrawCallback &
NOTIFY_INLINE auto get_fade_percent() -> const float
NOTIFY_INLINE auto set_content(const char *format,...) -> void
NOTIFY_INLINE auto get_icon() -> const char *
NOTIFY_INLINE auto get_default_title() -> const char *
static NOTIFY_INLINE auto get_color(ImGuiToastType type) -> const ImVec4
NOTIFY_INLINE auto set_title(const char *format,...) -> void
ImGuiToast(ImGuiToastType type, int dismiss_time, const char *format,...)
NOTIFY_INLINE auto set_type(const ImGuiToastType &type) -> void
NOTIFY_INLINE auto has_draw_callback() -> bool
NOTIFY_INLINE auto set_draw_callback(const ImGuiToastDrawCallback &callback) -> void
ImGuiToast(ImGuiToastType type, const ImGuiToastDrawCallback &callback, int dismiss_time=NOTIFY_DEFAULT_DISMISS)
NOTIFY_INLINE auto get_title() -> char *
ImGuiToast(ImGuiToastType type, int dismiss_time=NOTIFY_DEFAULT_DISMISS)
#define ICON_MDI_ALERT_BOX
#define ICON_MDI_ALERT_CIRCLE
#define ICON_MDI_CHECK_CIRCLE
#define ICON_MDI_INFORMATION
#define NOTIFY_MAX_MSG_LENGTH
@ ImGuiToastPhase_Expired
@ ImGuiToastPhase_FadeOut
#define NOTIFY_FADE_IN_OUT_TIME
#define NOTIFY_MAX_TOASTS
#define NOTIFY_PADDING_MESSAGE_Y
#define NOTIFY_DEFAULT_DISMISS
#define NOTIFY_TOAST_FLAGS
#define NOTIFY_NULL_OR_EMPTY(str)
#define NOTIFY_FORMAT(fn, format,...)
@ ImGuiToastPos_BottomCenter
@ ImGuiToastPos_BottomLeft
@ ImGuiToastPos_BottomRight
@ ImGuiToastPos_TopCenter
std::function< void(const ImGuiToast &, float, const ImVec4 &)> ImGuiToastDrawCallback
NOTIFY_INLINE void PushNotification(const ImGuiToast &toast)
Insert a new toast in the list.
NOTIFY_INLINE void RemoveNotification(int index)
Remove a toast from the list by its index.
NOTIFY_INLINE ImGuiToast * GetNotification(uint64_t unique_id)
NOTIFY_INLINE void RenderNotifications()
Render toasts, call at the end of your rendering!
NOTIFY_INLINE std::vector< ImGuiToast > notifications