仅对TyomaVader版本的ImGui弹窗源码添加设置图标字体功能, 使弹窗标题及内容可以用其他字体显示
(只改了win32里的文件, unix里面的文件和win32原版内容一样懒得再传一遍了)
初始化图标字体:
#include "ImGui/fa_solid_900.h"
#include "ImGui/ImGuiNotify.hpp"
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
static const ImWchar iconsRanges[] = { ICON_MIN_FA, ICON_MAX_16_FA, 0 };
ImFontConfig iconsConfig;
iconsConfig.MergeMode = true;
iconsConfig.PixelSnapH = true;
iconsConfig.GlyphMinAdvanceX = iconFontSize;
ImFont* font_ImGuiNotify_Icon = io.Fonts->AddFontFromMemoryTTF((void*)fa_solid_900, sizeof(fa_solid_900), iconFontSize, &iconsConfig, iconsRanges);
ImGui::SetNotificationIconFont(font_ImGuiNotify_Icon);
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.
- 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
- 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
- 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
#include "ImGuiNotify.hpp"
#include "IconsFontAwesome6.h"
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.
- 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
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.F, 0.F, 0.F, 0.F)); // Button 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(2);
Note
The following preview uses an Embrace The Darkness theme by @janekb04. It can be found in the main.cpp
.