TyomaVader / ImGuiNotify

A (very) simple notification wrapper for Dear ImGui
MIT License
88 stars 11 forks source link
cpp dear-imgui glfw imgui imgui-glfw notifications opengl vulkan

ImGuiNotify

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

Latest changes (v0.0.1, v0.0.2 & v0.0.3)

Added

Fixed

Changed

FULL CHANGELOG

Usage

Include

#include "ImGuiNotify.hpp"
#include "IconsFontAwesome6.h"
#include "fa-solid-900.h"

Initialisation (after impl call: ImGui_ImplDX12_Init, ImGui_ImplVulkan_Init, etc.)

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);

Create notifications

Rendering

// 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);

Showcase

[!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

License

MIT license