Is a header-only wrapper made to create notifications with Dear ImGui. Fork of imgui-notify by patrickcjk.
[!IMPORTANT] Requires Font Awesome 6 for icons (Setup example).
[!IMPORTANT] Requires C++17 or later.
[!IMPORTANT] Requires Dear ImGui docking branch with multi-viewport enabled for rendering outside the main viewport
NOTIFY_RENDER_OUTSIDE_MAIN_WINDOW
) (#7)NOTIFY_RENDER_LIMIT
)ImGui::Text()
main.cpp
file)#include "ImGuiNotify.hpp"
#include "IconsFontAwesome6.h"
#include "fa-solid-900.h"
io.Fonts->AddFontDefault();
float baseFontSize = 16.0f;
float iconFontSize = baseFontSize * 2.0f / 3.0f; // FontAwesome fonts need to have their sizes reduced by 2.0f/3.0f in order to align correctly
static constexpr ImWchar iconsRanges[] = {ICON_MIN_FA, ICON_MAX_16_FA, 0};
ImFontConfig iconsConfig;
iconsConfig.MergeMode = true;
iconsConfig.PixelSnapH = true;
iconsConfig.GlyphMinAdvanceX = iconFontSize;
io.Fonts->AddFontFromMemoryCompressedTTF(fa_solid_900_compressed_data, fa_solid_900_compressed_size, iconFontSize, &iconsConfig, iconsRanges);
Success
ImGui::InsertNotification({ImGuiToastType::Success, 3000, "That is a success! %s", "(Format here)"});
Warning
ImGui::InsertNotification({ImGuiToastType::Warning, 3000, "Hello World! This is a warning! %d", 0x1337});
Error
ImGui::InsertNotification({ImGuiToastType::Error, 3000, "Hello World! This is an error! 0x%X", 0xDEADBEEF});
Info
ImGui::InsertNotification({ImGuiToastType::Info, 3000, "Hello World! This is an info!"});
Long info
ImGui::InsertNotification({ImGuiToastType::Info, 3000, "Hi, I'm a long notification. I'm here to show you that you can write a lot of text in me. I'm also here to show you that I can wrap text, so you don't have to worry about that."});
Error with button
ImGui::InsertNotification({ImGuiToastType::Error, 3000, "Click me!", [](){ImGui::InsertNotification({ImGuiToastType::Success, 3000, "Thanks for clicking!"});}, "Notification content"});
Now using a custom title...
ImGuiToast toast(ImGuiToastType::Success, 3000); // <-- content can also be passed here as above
toast.setTitle("This is a %s title", "wonderful");
toast.setContent("Lorem ipsum dolor sit amet");
ImGui::InsertNotification(toast);
// Notifications style setup
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.f); // Disable round borders
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.f); // Disable borders
// Notifications color setup
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.10f, 0.10f, 0.10f, 1.00f)); // Background color
// Main rendering function
ImGui::RenderNotifications();
//——————————————————————————————— WARNING ———————————————————————————————
// Argument MUST match the amount of ImGui::PushStyleVar() calls
ImGui::PopStyleVar(2);
// Argument MUST match the amount of ImGui::PushStyleColor() calls
ImGui::PopStyleColor(1);
[!NOTE] The following preview uses an Embrace The Darkness theme by @janekb04. It can be found in the
main.cpp
.
https://github.com/TyomaVader/ImGuiNotify/assets/67346255/c4d9ee3c-5725-4d8d-89ee-670d9ecd3378