Giter Club home page Giter Club logo

imguinotify's Introduction

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.

Latest changes (v0.0.1 & v0.0.2)

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

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

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
  • Upgraded Dear ImGui version used in example to v1.89.9 WIP

Usage

Include

#include "ImGuiNotify.hpp"
#include "IconsFontAwesome6.h"

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

io.Fonts->AddFontDefault();

float baseFontSize = 16.0f; // Default font size
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

// Check if FONT_ICON_FILE_NAME_FAS is a valid path
std::ifstream fontAwesomeFile(FONT_ICON_FILE_NAME_FAS);

if (!fontAwesomeFile.good())
{
    // If it's not good, then we can't find the font and should abort
    std::cerr << "Could not find the FontAwesome font file." << std::endl;
    abort();
}

static const ImWchar iconsRanges[] = {ICON_MIN_FA, ICON_MAX_16_FA, 0};
ImFontConfig iconsConfig;
iconsConfig.MergeMode = true;
iconsConfig.PixelSnapH = true;
iconsConfig.GlyphMinAdvanceX = iconFontSize;
io.Fonts->AddFontFromFileTTF(FONT_ICON_FILE_NAME_FAS, iconFontSize, &iconsConfig, iconsRanges);

Warning

FONT_ICON_FILE_NAME_FAS may require a different path depending on your project structure, see IconsFontAwesome6.h for details. Incorrect path will result in a runtime error.

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

imguinotify's People

Contributors

tyomavader avatar patrickcjk avatar im-rises avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.