32#include "imgui/imgui.h"
33#include "imgui/imgui_internal.h"
39#include <imgui_includes.h>
41#define NOTIFY_MAX_TOASTS 10
42#define NOTIFY_MAX_MSG_LENGTH 4096
43#define NOTIFY_PADDING_X 20.f
44#define NOTIFY_PADDING_Y 20.f
45#define NOTIFY_PADDING_MESSAGE_Y 10.f
46#define NOTIFY_FADE_IN_OUT_TIME 150
47#define NOTIFY_DEFAULT_DISMISS 3000
48#define NOTIFY_OPACITY 1.0f
49#define NOTIFY_TOAST_FLAGS ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoInputs
51#define NOTIFY_USE_SEPARATOR
52#define NOTIFY_USE_DISMISS_BUTTON false
53#define NOTIFY_RENDER_LIMIT 10
55#define NOTIFY_INLINE inline
56#define NOTIFY_NULL_OR_EMPTY(str) (!str ||! strlen(str))
57#define NOTIFY_FORMAT(fn, format, ...) if (format) { va_list args; va_start(args, format); fn(format, args, ##__VA_ARGS__); va_end(args); }
116 uint64_t creation_time = 0;
120 std::function<void()> on_dismiss =
nullptr;
122 ImVec2 frame_padding = ImVec2(20.0f, 20.0f);
128 NOTIFY_INLINE auto set_title(
const char*
format, va_list args) { vsnprintf(this->title,
sizeof(this->title),
format, args); }
130 NOTIFY_INLINE auto set_content(
const char*
format, va_list args) { vsnprintf(this->content,
sizeof(this->content),
format, args); }
208 return { 255, 255, 255, 255 };
210 return { 0, 255, 0, 255 };
212 return { 255, 255, 0, 255 };
214 return { 255, 0, 0, 255 };
216 return { 255, 255, 255, 255 };
218 return { 255, 255, 255, 255 };
304 using namespace std::chrono;
305 return duration_cast<milliseconds>(steady_clock::now().time_since_epoch()).count();
318 this->dismiss_time = dismiss_time;
321 memset(this->title, 0,
sizeof(this->title));
322 memset(this->content, 0,
sizeof(this->content));
333 this->draw_callback = callback;
346 if(toast.unique_id == unique_id)
375 auto current_phase = notification->get_phase();
376 auto current_elapsed = notification->get_elapsed_time();
379 *notification = toast;
386 notification->set_creation_time(
static_cast<uint64_t
>(-
static_cast<int64_t
>(current_elapsed)));
396 notification->set_creation_time(0);
420 ImGuiViewport* viewport = GetMainViewport();
421 const auto vp_pos = viewport->WorkPos;
422 const auto vp_size = viewport->WorkSize;
424 float height_left = 0.f;
425 float height_right = 0.f;
438 #if NOTIFY_RENDER_LIMIT > 0
446 const auto icon = current_toast->get_icon();
447 const auto title = current_toast->get_title();
448 const auto content = current_toast->get_content();
449 const auto default_title = current_toast->get_default_title();
450 const auto opacity = current_toast->get_fade_percent();
451 const auto horizontal_pos = current_toast->get_horizontal_pos();
454 auto text_color = current_toast->get_color();
455 text_color.w = opacity;
458 char window_name[50]{};
459 snprintf(window_name,
sizeof(window_name),
"##TOAST%d", i);
462 SetNextWindowBgAlpha(opacity);
468 float* current_height;
469 const ImVec2& toast_frame_padding = current_toast->get_frame_padding();
474 pivot = ImVec2(0.0f, 1.0f);
475 current_height = &height_left;
480 pivot = ImVec2(1.0f, 1.0f);
481 current_height = &height_right;
484 SetNextWindowPos(window_pos, ImGuiCond_Always, pivot);
486 auto flags = current_toast->get_window_flags();
488 if (current_toast->get_show_dismiss_button())
490 flags &= ~ImGuiWindowFlags_NoInputs;
491 flags &= ~ImGuiWindowFlags_NoBringToFrontOnFocus;
494 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, toast_frame_padding);
495 Begin(window_name,
nullptr, flags);
500 PushTextWrapPos(vp_size.x / 3.f);
502 bool was_title_rendered =
false;
508 ImGui::AlignTextToFramePadding();
509 TextColored(text_color,
"%s",
icon);
520 ImGui::AlignTextToFramePadding();
522 was_title_rendered =
true;
529 ImGui::AlignTextToFramePadding();
530 Text(
"%s", default_title);
531 was_title_rendered =
true;
538 SetCursorPosY(GetCursorPosY() + 5.f);
544 if (was_title_rendered)
546#ifdef NOTIFY_USE_SEPARATOR
551 ImGui::AlignTextToFramePadding();
556 if (current_toast->has_draw_callback())
558 if(!was_title_rendered)
565 current_toast->get_draw_callback()(*current_toast, opacity, text_color);
574 if (current_toast->get_show_dismiss_button())
584 if(current_toast->get_on_dismiss())
586 current_toast->get_on_dismiss()();
gfx::texture_format format
NOTIFY_INLINE auto get_title() -> const char *
NOTIFY_INLINE auto get_phase() -> const ImGuiToastPhase
NOTIFY_INLINE auto set_button_label(const char *format,...) -> void
Set the label for the button in the notification.
NOTIFY_INLINE auto get_show_dismiss_button() -> const bool
NOTIFY_INLINE auto get_color() -> const ImVec4
NOTIFY_INLINE auto get_on_dismiss() -> const std::function< void()> &
NOTIFY_INLINE auto get_elapsed_time()
NOTIFY_INLINE auto get_window_flags() -> const ImGuiWindowFlags &
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_horizontal_pos() -> const ImGuiToastHorizontalPos &
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 set_show_dismiss_button(const bool &show) -> void
NOTIFY_INLINE auto get_fade_percent() -> const float
NOTIFY_INLINE auto set_on_dismiss(const std::function< void()> &callback) -> void
NOTIFY_INLINE auto set_content(const char *format,...) -> void
NOTIFY_INLINE auto get_icon() -> const char *
NOTIFY_INLINE auto get_frame_padding() -> const ImVec2 &
NOTIFY_INLINE auto get_default_title() -> const char *
static NOTIFY_INLINE auto get_color(ImGuiToastType type) -> const ImVec4
NOTIFY_INLINE auto set_frame_padding(float x, float y) -> void
NOTIFY_INLINE auto set_title(const char *format,...) -> void
ImGuiToast(ImGuiToastType type, int dismiss_time, const char *format,...)
NOTIFY_INLINE auto set_horizontal_pos(const ImGuiToastHorizontalPos &pos) -> void
NOTIFY_INLINE auto set_window_flags(ImGuiWindowFlags flags) -> void
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)
ImGuiToast(ImGuiToastType type, int dismiss_time=NOTIFY_DEFAULT_DISMISS)
NOTIFY_INLINE auto set_frame_padding(const ImVec2 &frame_padding) -> void
#define ICON_MDI_ALERT_BOX
#define ICON_MDI_ALERT_CIRCLE
#define ICON_MDI_CHECK_CIRCLE
#define ICON_MDI_INFORMATION
#define NOTIFY_MAX_MSG_LENGTH
@ ImGuiToastHorizontalPos_Left
@ ImGuiToastHorizontalPos_COUNT
@ ImGuiToastHorizontalPos_Right
@ ImGuiToastPhase_Expired
@ ImGuiToastPhase_FadeOut
#define NOTIFY_RENDER_LIMIT
#define NOTIFY_FADE_IN_OUT_TIME
#define NOTIFY_MAX_TOASTS
#define NOTIFY_PADDING_MESSAGE_Y
#define NOTIFY_DEFAULT_DISMISS
int ImGuiToastHorizontalPos
#define NOTIFY_TOAST_FLAGS
#define NOTIFY_NULL_OR_EMPTY(str)
#define NOTIFY_FORMAT(fn, format,...)
@ ImGuiToastPos_BottomCenter
@ ImGuiToastPos_BottomLeft
@ ImGuiToastPos_BottomRight
@ ImGuiToastPos_TopCenter
#define NOTIFY_USE_DISMISS_BUTTON
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