ImGuiNotify 项目使用教程
1. 项目的目录结构及介绍
ImGuiNotify 是一个用于 Dear ImGui 的简单通知包装库。以下是其目录结构和各部分的简要介绍:
imgui-notify/
├── example/
│ ├── example.cpp
│ ├── example.sln
│ └── gitignore
├── LICENSE
├── README.md
└── src/
└── imgui_notify.h
- example/: 包含示例代码和解决方案文件。
- example.cpp: 示例代码文件,展示了如何使用 ImGuiNotify。
- example.sln: Visual Studio 解决方案文件。
- gitignore: Git 忽略文件。
- LICENSE: 项目许可证文件,采用 MIT 许可证。
- README.md: 项目说明文档。
- src/: 源代码目录。
- imgui_notify.h: 主要头文件,包含了通知系统的实现。
2. 项目的启动文件介绍
项目的启动文件是 example/example.cpp
。这个文件包含了如何初始化和使用 ImGuiNotify 的示例代码。以下是该文件的关键部分:
#include "src/imgui_notify.h"
#include "tahoma.h" // 必需的字体
// 初始化 ImGui 和 ImGuiNotify
ImGuiIO* io = &ImGui::GetIO();
ImFontConfig font_cfg;
font_cfg.FontDataOwnedByAtlas = false;
io->Fonts->AddFontFromMemoryTTF((void*)tahoma, sizeof(tahoma), 17.0f, &font_cfg);
// 创建通知
ImGuiToast toast(ImGuiToastType::Success, 3000);
toast.setTitle("This is a %s title", "wonderful");
toast.setContent("Lorem ipsum dolor sit amet");
ImGui::InsertNotification(toast);
// 渲染通知
ImGui::RenderNotifications();
3. 项目的配置文件介绍
ImGuiNotify 项目没有专门的配置文件,其配置主要通过代码进行。以下是一些关键的配置步骤:
-
字体配置:
ImFontConfig font_cfg; font_cfg.FontDataOwnedByAtlas = false; io->Fonts->AddFontFromMemoryTTF((void*)tahoma, sizeof(tahoma), 17.0f, &font_cfg);
-
通知样式配置:
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); // 禁用圆角边框 ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); // 禁用边框 ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.10f, 0.10f, 0.10f, 1.00f)); // 背景颜色
-
渲染通知:
ImGui::RenderNotifications();
通过以上步骤,您可以配置和使用 ImGuiNotify 来创建和管理通知。