Git Product home page Git Product logo

imgui-notify's Introduction

Warning

This project is not maintained be me anymore. Please use TyomaVader's fork ImGuiNotify. Thanks for his hard work!

imgui-notify

Is a header-only wrapper made to create notifications with Dear ImGui. As I couldn't find any library for this I just decided to create my own. We will use Font Awesome 5 for icons.

forthebadge forthebadge

Requirements

  • You must use a font other than the default one. Font-Awesome icons used in this library cannot be merged with default font. You can use Tahoma (provided in the example project).
  • If you load the font using AddFontFromMemoryTTF (from memory, instead of from a file on disk) and memory is read-only as in the example, you must pass a ImFontConfig structure with FontDataOwnedByAtlas = false to prevent imgui from attempting to free the buffer (which will lead into a crash).

Changes in version 2

  • Toast now contains a title. If no title is provided, a default one is used (ImGuiToastType_Success will result in "Success")
  • Added getters and setters to get/set private properties
  • Added assertions
  • Constructors will only accept a content (formatting is possible), title must be set with ImGuiToast::set_title() (see example)
  • "notify" namespace was removed, we now use "ImGui" namespace for a better implementation
  • "notify::init" was removed, you must now call "ImGui::MergeIconsWithLatestFont" after EACH loaded font in your initialisation (see example)
  • "notify::render" was renamed to "ImGui::RenderNotifications()"
  • By default, NOTIFY_USE_SEPARATOR is defined which will add a separator (horizontal line) between the title and the content.
  • Now supporting multiline content (1/3 of the total view port width as max-width)

Usage

Include

#include "src/imgui_notify.h"
#include "tahoma.h" // <-- Required font!

Initialisation (after impl call, e.g ImGui_ImplDX12_Init)

ImGuiIO* io = &ImGui::GetIO();

ImFontConfig font_cfg;
font_cfg.FontDataOwnedByAtlas = false;
io->Fonts->AddFontFromMemoryTTF((void*)tahoma, sizeof(tahoma), 17.f, &font_cfg);

// Initialize notify
ImGui::MergeIconsWithLatestFont(16.f, false);

// If you use multiple fonts, repeat the same thing!
// io->Fonts->AddFontFromMemoryTTF((void*)another_font, sizeof(another_font), 17.f, &font_cfg);
// ImGui::MergeIconsWithLatestFont(16.f, false);

Create notifications

// A few examples... (no title provided, default one used!)
ImGui::InsertNotification({ ImGuiToastType_Success, 3000, "Hello World! This is a success! %s", "We can also format here:)" });
ImGui::InsertNotification({ ImGuiToastType_Warning, 3000, "Hello World! This is a warning! %d", 0x1337 });
ImGui::InsertNotification({ ImGuiToastType_Error, 3000, "Hello World! This is an error! 0x%X", 0xDEADBEEF });
ImGui::InsertNotification({ ImGuiToastType_Info, 3000, "Hello World! This is an info!" });
ImGui::InsertNotification({ ImGuiToastType_Info, 3000, "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation" });

// Now using a custom title...
ImGuiToast toast(ImGuiToastType_Success, 3000); // <-- content can also be passed here as above
toast.set_title("This is a %s title", "wonderful");
toast.set_content("Lorem ipsum dolor sit amet");
ImGui::InsertNotification(toast);

Rendering

// Render toasts on top of everything, at the end of your code!
// You should push style vars here
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 5.f); // Round borders
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(43.f / 255.f, 43.f / 255.f, 43.f / 255.f, 100.f / 255.f)); // Background color
ImGui::RenderNotifications(); // <-- Here we render all notifications
ImGui::PopStyleVar(1); // Don't forget to Pop()
ImGui::PopStyleColor(1);

Showcase

Showcase

License

MIT license

imgui-notify's People

Contributors

hellohackynow avatar mixaill avatar patrickcjk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

imgui-notify's Issues

Do you have the TTF version of the tahoma.h?

Hello @patrickcjk ,
thanks for that repo, it looks cute.

I have the code almost working in an openFrameworks environment, but I am having problems to "unlock" draw the icons.

On the ImGui add-on for oF,
it's implemented only the AddFontFromFileTTF method...
not the one you used 'AddFontFromMemoryTTF'.

I tried to make it work, but no success. Fonts look broke as white squares and I am getting exceptions.

Do you have the TTF version for the tahoma font?

Thanks

Do you know if it requires C++17?

Hey @patrickcjk , thanks for sharing this.

I am trying to use it in an openFrameworks project without success...
I am on VS 2017, and OF is bundled with C++ 11/14.

After getting these errors:

Severity	Code	Description	Project	File	Line	Suppression State
Error	C7525	inline variables require at least '/std:c++17' (compiling source file src\main.cpp)	1_7_Notify	f:\openframeworks\addons\ofxsurfingimgui\1_widgets\1_7_notify\src\imgui_notify.h	220	

I "forced" the VS project to C++17. But I am getting OF related errors like:

Severity	Code	Description	Project	File	Line	Suppression State
Error	C2757	'filesystem': a symbol with this name already exists and therefore this name cannot be used as a namespace name (compiling source file src\main.cpp)	1_7_Notify	c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\fstream	24	

Any idea?

https://github.com/moebiussurfing/ofxSurfingImGui/tree/master/1_Widgets/1_7_Notify/src

Icons aren't working

Hey, I followed your instructions and everything works fine except the Icons.
I tried it with different fonts, but instead of an Icon it shows a colored Question mark "?".
The font applys tho as the text changes the font style based on the Font that I use.

I use the following code after the Init:

writefont = io.Fonts->AddFontFromMemoryCompressedTTF(Font_Font_data, Font_Font_size, 16.f);
ImFontConfig font_cfg;
font_cfg.FontDataOwnedByAtlas = false;
io.Fonts->AddFontFromMemoryCompressedTTF(Font_Font_data, Font_Font_size, 16.f, &font_cfg);
ImGui::MergeIconsWithLatestFont(16.f, false);

To use the font I do:

ImGui::PushFont(writefont); //apply font
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 5.f);
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(43.f / 255.f, 43.f / 255.f, 43.f / 255.f, 255.f / 255.f));
ImGui::RenderNotifications();
ImGui::PopStyleVar(1);
ImGui::PopStyleColor(1);
ImGui::PopFont();

Runtime error

I get the following error when I try to call notify::init() after ImGui_ImplDX12_Init()

image

I included all the files correctly and am doing exactly as the instructions stated. It seems its failing to initialize the font... What is going on here?

NOTIFY_FORMAT doesn't compile

i.e.

imgui_notify.h:205:83: error: expected expression
    ImGuiToast(ImGuiToastType type, const char* format, ...) : ImGuiToast(type) { NOTIFY_FORMAT(this->set_content, format); }

imgui_notify.h:23:120: note: expanded from macro 'NOTIFY_FORMAT'
#define NOTIFY_FORMAT(fn, format, ...)  if (format) { va_list args; va_start(args, format); fn(format, args, __VA_ARGS__); va_end(args); }

That's what my clangd 14.0.0 says
image

Clangd config: -Wno-unused-variable,-Wno-infinite-recursion,-Werror=implicit-function-declaration,-Wshadow,-Wno-shadow-field-in-constructor-modified,-Wno-shadow-ivar,-Wuninitialized,-Wunused-label,-Wunused-lambda-capture, ,--target=aarch64

sprintf_s in code

line about 260-270

char window_name[50];
sprintf_s(window_name, "##TOAST%d", i);

I'd suggest to replace it with ImFormat cuz not everyone has sprintf_s function

error: expected expression

NOTIFY_INLINE auto set_title(const char* format, ...) -> void { NOTIFY_FORMAT(this->set_title, format); }

	NOTIFY_INLINE auto set_content(const char* format, ...) -> void { NOTIFY_FORMAT(this->set_content, format); }

	NOTIFY_INLINE auto set_type(const ImGuiToastType& type) -> void { IM_ASSERT(type < ImGuiToastType_COUNT); this->type = type; };

imgui_notify.h:81:66: error: expected expression

this NOTIFY_FORMAT

linux support ?

my lib crash when i port this library to linux, anyway to fix ?

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.