Skip to content

TyomaVader/ImGuiNotify

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

  • CMake support, see CMakeLists.txt for details
  • Dismiss button for notifications (optional)
  • Optional button in the notification that executes a user-defined function
  • GitHub Actions for Linux and Windows builds
  • Documentation examples
  • Linux support
  • Documentation
  • Optional notifications rendering relative to the monitor size (See NOTIFY_RENDER_OUTSIDE_MAIN_WINDOW) (#7)
  • Simultanious notification rendering limit (See NOTIFY_RENDER_LIMIT)
  • MacOS support (2199194 & a3eb32b)
    Thanks to @sjy0727 and @starlight-traveler

Fixed

  • Notifications now render above all other windows
  • Notifications now render in the correct position when the main window is moved
  • Compilation warnings about incorrect usage of ImGui::Text()
  • Documentation fixes
  • Removed unnecessary files. (#5)
  • Warnings fixed in Windows example.

Changed

  • Code readability improved
  • Switched to Font Awesome 6 icons
  • Visual changes to the notifications (can be customized in the main.cpp file)
  • Default Dear ImGui theme changed to Embrace The Darkness by janekb04
  • Switched from classic enums to scoped enums
  • README clarifications. (#5)
  • Upgraded Dear ImGui version used in example to v1.91.2
  • Upgraded Font Awesome version
  • Switched to compressed fonts (#14) Thanks to OlegSirenko

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

  • Success
ImGui::InsertNotification({ImGuiToastType::Success, 3000, "That is a success! %s", "(Format here)"});

success

  • Warning
ImGui::InsertNotification({ImGuiToastType::Warning, 3000, "Hello World! This is a warning! %d", 0x1337});

warning

  • Error
ImGui::InsertNotification({ImGuiToastType::Error, 3000, "Hello World! This is an error! 0x%X", 0xDEADBEEF});

error

  • Info
ImGui::InsertNotification({ImGuiToastType::Info, 3000, "Hello World! This is an info!"});

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."});

longInfo

  • Error with button
ImGui::InsertNotification({ImGuiToastType::Error, 3000, "Click me!", [](){ImGui::InsertNotification({ImGuiToastType::Success, 3000, "Thanks for clicking!"});}, "Notification content"});

withButton

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

customTitle

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.

Untitled.mp4

License

MIT license

Packages

No packages published

Languages

  • C++ 77.5%
  • C 22.5%