|
1 | 1 | # imgui |
2 | 2 |
|
3 | | -C++23 module package for Dear ImGui on mcpp. |
4 | | - |
5 | | -This package uses `compat.imgui` for upstream Dear ImGui sources and provides |
6 | | -module interfaces for the core API plus GLFW/OpenGL3 backend entry points. |
7 | | - |
8 | | -## Modules |
9 | | - |
10 | | -Three tiers of consumer UX: |
11 | | - |
12 | | -- **Tier-0** `imgui.app` — the convenience facade. Owns the whole window/context |
13 | | - lifecycle; you supply only a per-frame UI callback. |
14 | | -- **Tier-1** automatic via the `imgui.backend` contract — write backend-agnostic |
15 | | - code against the `BackendApi` concept and shared types. |
16 | | -- **Tier-2** explicit `imgui.backend.<impl>` — import a concrete backend module |
17 | | - and alias it (`using Backend = ...;`); swap backend with one import + alias. |
18 | | - |
19 | | -- `imgui.app` |
20 | | - - Tier-0 facade. `ImGui::App::run(opts, ui)` / `ImGui::App::run(ui)` drive the |
21 | | - full GLFW/OpenGL3 lifecycle using the default backend. `export import`s |
22 | | - `imgui.core` so a consumer gets the `ImGui::*` surface for free. |
23 | | -- `imgui.core` |
24 | | - - Core Dear ImGui context, frame, widget, and draw-data APIs. |
25 | | -- `imgui.backend` |
26 | | - - Generic backend abstraction layer: shared value types (`GlConfig`, `Error`, |
27 | | - `FbSize`), `RecommendedGlConfig()` cross-platform defaults, and the |
28 | | - compile-time `BackendApi` contract every backend satisfies. No platform code. |
29 | | -- `imgui.backend.platform.glfw` |
30 | | - - GLFW platform piece: window/event management + `ImGui_ImplGlfw_*` binding. |
31 | | -- `imgui.backend.renderer.opengl3` |
32 | | - - OpenGL3 renderer piece: GL framebuffer ops + `ImGui_ImplOpenGL3_*` binding. |
33 | | -- `imgui.backend.glfw_opengl3` |
34 | | - - Concrete backend: assembles the GLFW platform and OpenGL3 renderer pieces |
35 | | - into a single `ImGui::Backend::GlfwOpenGL3` type satisfying `BackendApi`. |
36 | | - Re-exports `imgui.backend` (shared types) but **not** `imgui.core`. |
37 | | - |
38 | | -Backends expose one `Backend` type with a uniform static API, so swapping |
39 | | -backend is just a different `import` plus a one-line `using Backend = ...;` |
40 | | -alias — the rest of the consumer code is identical. Cross-platform GL/GLSL |
41 | | -configuration (incl. macOS forward-compat) is handled by `RecommendedGlConfig()`, |
42 | | -which `CreateWindow`/`Init` use by default. |
| 3 | +> Dear ImGui 的 C++23 模块化封装 — `import` 即用 · 跨平台 · 特性可插拔 |
43 | 4 |
|
44 | | -## Features |
45 | | - |
46 | | -- `docking` — dockable panels inside the main window (Wayland-safe). Exports the Dock* API surface (`DockSpace`, `DockSpaceOverViewport`, |
47 | | - `SetNextWindowDockID`, `IsWindowDocked`, ...) and makes the `imgui.app` facade |
48 | | - enable `ImGuiConfigFlags_DockingEnable` automatically: |
49 | | - |
50 | | - ```toml |
51 | | - [dependencies] |
52 | | - imgui = { version = "0.0.4", features = ["docking"] } |
53 | | - ``` |
54 | | - |
55 | | -- `viewports` — panels dragged (or positioned) outside the main window detach |
56 | | - into real OS windows (multi-viewport). X11/Windows/macOS; note GLFW/Wayland |
57 | | - does not support it upstream. |
58 | | -- `docking-full = ["docking", "viewports"]` — convenience bundle: the full |
59 | | - docking experience. |
60 | | - |
61 | | - ```toml |
62 | | - [dependencies] |
63 | | - imgui = { version = "0.0.5", features = ["docking-full"] } |
64 | | - ``` |
| 5 | +[](https://github.com/mcpplibs/imgui-m/releases) |
| 6 | +[](https://en.cppreference.com/w/cpp/23) |
| 7 | +[](https://en.cppreference.com/w/cpp/language/modules) |
| 8 | +[](LICENSE) |
65 | 9 |
|
66 | | - See `examples/docking/`. Sources come from upstream's docking tag |
67 | | - (`compat.imgui 1.92.8-docking`, a superset of mainline — identical behavior |
68 | | - while the features are off). |
| 10 | +| [mcpp 构建工具](https://github.com/mcpp-community/mcpp) · [包索引 mcpp-index](https://github.com/mcpp-community/mcpp-index) · [Dear ImGui 上游](https://github.com/ocornut/imgui) · [Issues](https://github.com/mcpplibs/imgui-m/issues) · [Releases](https://github.com/mcpplibs/imgui-m/releases) | |
| 11 | +|:---:| |
| 12 | +| [](https://github.com/mcpplibs/imgui-m/actions/workflows/ci.yml) | |
69 | 13 |
|
70 | | -## Dependencies |
| 14 | +## 核心特性 |
71 | 15 |
|
72 | | -The root package depends on: |
| 16 | +- **纯模块导入** — `import imgui.core;`,消费者代码零 `#include` |
| 17 | +- **三档使用体验** — `imgui.app` 一行出窗口(默认档)/ `imgui.backend` 编译期契约(自动档)/ `imgui.backend.<impl>` 显式选后端(专家档),换后端 = 改一行 import + alias |
| 18 | +- **特性可插拔** — `features = ["docking-full"]` 解锁面板停靠 + 拖出主窗口变独立 OS 窗口 |
| 19 | +- **不绑定工具链、不打包 GL 驱动** — Linux / macOS / Windows 三平台 CI;GL 运行时由 mcpp 生态自动闭合 |
73 | 20 |
|
74 | | -- `compat.imgui = "1.92.8"` |
75 | | -- `compat.glfw = "3.4"` |
76 | | -- `compat.opengl = "2026.05.31"` |
77 | | - |
78 | | -The repository does not vendor Dear ImGui sources. Source and header files come |
79 | | -from compat packages through mcpp dependency metadata. |
80 | | - |
81 | | -### Toolchain and GL runtime |
82 | | - |
83 | | -The package does not pin a toolchain; mcpp resolves the environment/default |
84 | | -toolchain. The GL runtime is closed by mcpp/mcpp-index (`compat.glx-runtime`, |
85 | | -pulled in transitively by `compat.glfw` on Linux), not bundled by this package. |
86 | | - |
87 | | -## Quick Start |
| 21 | +## 快速开始 |
88 | 22 |
|
89 | 23 | ```bash |
90 | | -mcpp build |
91 | | -mcpp test |
92 | | -cd examples/basic |
93 | | -mcpp run |
| 24 | +mcpp new myapp --template gui && cd myapp && mcpp run # 窗口直接出现 |
94 | 25 | ``` |
95 | 26 |
|
96 | | -Expected headless example output: |
97 | | - |
98 | | -```text |
99 | | -Dear ImGui 1.92.8 module frame ok |
100 | | -``` |
101 | | - |
102 | | -## Backend Example |
103 | | - |
104 | | -The minimal GLFW/OpenGL3 window example uses the combined backend module and |
105 | | -does not use `#include` in consumer code: |
106 | | - |
107 | | -```bash |
108 | | -cd examples/minimal_window |
109 | | -mcpp build |
110 | | -mcpp run |
111 | | -``` |
112 | | - |
113 | | -It requires an OpenGL runtime that is visible to the mcpp/xlings runtime. If |
114 | | -GLFW cannot create the window, the example prints the GLFW error text. The |
115 | | -`compat.opengl` package supplies OpenGL registry/header content; it does not |
116 | | -bundle a platform `libGL`/GLX runtime. |
117 | | - |
118 | | -The larger GLFW/OpenGL3 example builds on CI but should be run only in an |
119 | | -environment with a working display and OpenGL context: |
120 | | - |
121 | | -```bash |
122 | | -cd examples/glfw_opengl3 |
123 | | -mcpp build |
124 | | -mcpp run |
125 | | -``` |
126 | | - |
127 | | -## Consumer Usage |
| 27 | +或在已有项目中手动接入: |
128 | 28 |
|
129 | 29 | ```toml |
130 | 30 | [dependencies] |
131 | | -imgui = "0.0.1" |
| 31 | +imgui = "0.0.5" |
132 | 32 | ``` |
133 | 33 |
|
134 | | -Then import the modules you need. |
135 | | - |
136 | | -Tier-0 (`imgui.app` facade — least code): |
137 | | - |
138 | 34 | ```cpp |
139 | 35 | import imgui.core; |
140 | 36 | import imgui.app; |
141 | 37 |
|
142 | 38 | int main() { |
143 | 39 | return ImGui::App::run([] { |
144 | | - ImGui::Begin("hi"); |
145 | | - ImGui::TextUnformatted("imgui.app facade"); |
| 40 | + ImGui::Begin("hello"); |
| 41 | + ImGui::TextUnformatted("mcpp + imgui"); |
146 | 42 | ImGui::End(); |
147 | 43 | }); |
148 | 44 | } |
149 | 45 | ``` |
150 | 46 |
|
151 | | -Tier-2 (explicit backend module + alias — full control): |
| 47 | +## 模块一览 |
152 | 48 |
|
153 | | -```cpp |
154 | | -import imgui.core; |
155 | | -import imgui.backend.glfw_opengl3; |
156 | | -using Backend = ImGui::Backend::GlfwOpenGL3; // swap import + alias to switch backends |
| 49 | +| 模块 | 说明 | |
| 50 | +|---|---| |
| 51 | +| `imgui.core` | Dear ImGui 核心:context / frame / widgets / draw-data | |
| 52 | +| `imgui.app` | Tier-0 facade:平台默认后端 + 一行帧循环 | |
| 53 | +| `imgui.backend` | 后端契约:`BackendApi` concept + 共享类型(`GlConfig`/`Error`/`FbSize`) | |
| 54 | +| `imgui.backend.glfw_opengl3` | GLFW + OpenGL3 窗口后端(单一 `Backend` 类型) | |
| 55 | +| `imgui.backend.headless` | 无显示后端:同一业务循环跑 CI / 逻辑测试 | |
157 | 56 |
|
158 | | -int main() { |
159 | | - Backend::InitGlfw(); |
160 | | - auto* window = Backend::CreateWindow(960, 540, "demo"); // cross-platform GL hints |
161 | | - Backend::MakeContextCurrent(window); |
162 | | - |
163 | | - ImGuiContext* context = ImGui::CreateContext(); |
164 | | - ImGui::SetCurrentContext(context); |
165 | | - Backend::Init(window); // RecommendedGlConfig() default |
166 | | - // ... frame loop: Backend::NewFrame / ImGui::* / Backend::RenderDrawData ... |
167 | | - Backend::Shutdown(); |
168 | | - ImGui::DestroyContext(context); |
169 | | - Backend::DestroyWindow(window); |
170 | | - Backend::TerminateGlfw(); |
171 | | -} |
172 | | -``` |
| 57 | +后端实现模块**不 re-export** `imgui.core`,消费者需各自显式 `import`;换后端只改 import 行与一行 `using Backend = ...;`。 |
173 | 58 |
|
174 | | -## Module Surface |
| 59 | +## Features |
175 | 60 |
|
176 | | -`src/core.cppm` wraps `imgui.h` through a global module fragment and exports a |
177 | | -tested core API surface: |
| 61 | +| Feature | 说明 | |
| 62 | +|---|---| |
| 63 | +| `docking` | 主窗口内面板停靠(Wayland 安全) | |
| 64 | +| `viewports` | 面板拖出主窗口分离为独立 OS 窗口(X11 / Windows / macOS) | |
| 65 | +| `docking-full` | 组合糖 = `["docking", "viewports"]`,完整 docking 体验 | |
178 | 66 |
|
179 | | -- Types: `ImGuiContext`, `ImFontAtlas`, `ImGuiIO`, `ImDrawData`, `ImVec2`, |
180 | | - `ImVec4`. |
181 | | -- Functions: context lifecycle, `GetIO`, `NewFrame`, `Begin`, `Button`, |
182 | | - `TextUnformatted`, `End`, `Render`, and `GetDrawData`. |
| 67 | +```toml |
| 68 | +[dependencies] |
| 69 | +imgui = { version = "0.0.5", features = ["docking-full"] } |
| 70 | +``` |
183 | 71 |
|
184 | | -`imgui.core` exports a curated core subset; for rarely used APIs not yet |
185 | | -exported, a consumer translation unit can still `#include <imgui.h>` directly |
186 | | -alongside the module imports. |
| 72 | +docking/viewports 源码来自上游 docking tag(`compat.imgui 1.92.8-docking`,主线超集——特性关闭时行为与主线一致)。需 mcpp ≥ 0.0.47。 |
187 | 73 |
|
188 | | -Backend modules adapt the official Dear ImGui backend headers internally and |
189 | | -expose a single `Backend` type per backend (uniform static API constrained by |
190 | | -`ImGui::Backend::BackendApi`). Consumer code only needs module imports for the |
191 | | -surfaces exposed by this package. |
| 74 | +## 示例 |
| 75 | + |
| 76 | +| 示例 | 内容 | |
| 77 | +|---|---| |
| 78 | +| [`examples/app_minimal`](examples/app_minimal) | facade 三行出窗口 | |
| 79 | +| [`examples/docking`](examples/docking) | IDE 式四分屏 + 面板分离为独立 OS 窗口 | |
| 80 | +| [`examples/minimal_window`](examples/minimal_window) | 显式后端 API 的最小窗口(带诊断) | |
| 81 | +| [`examples/glfw_opengl3`](examples/glfw_opengl3) | 显式后端的完整事件循环 | |
| 82 | +| [`examples/basic`](examples/basic) | headless 核心 API(CI 可跑) | |
| 83 | + |
| 84 | +```bash |
| 85 | +cd examples/docking && mcpp run |
| 86 | +``` |
192 | 87 |
|
193 | | -## Verification |
| 88 | +## 工具链与运行时 |
194 | 89 |
|
195 | | -The `0.0.1` release state is verified with mcpp `0.0.44`: |
| 90 | +包不固定工具链(mcpp 解析环境默认,如 Linux glibc gcc);GL/GLX 运行时由生态包 `compat.glx-runtime` 透传闭合,不打包驱动。解析结果可用 `mcpp why` / `mcpp self doctor` 查看。 |
196 | 91 |
|
197 | | -- `mcpp build` |
198 | | -- `mcpp test` |
199 | | -- `cd examples/basic && mcpp run` |
200 | | -- `cd examples/app_minimal && mcpp build` |
201 | | -- `cd examples/minimal_window && mcpp build` |
202 | | -- `cd examples/glfw_opengl3 && mcpp build` |
| 92 | +> [!NOTE] |
| 93 | +> 早期版本,接口可能调整。问题与想法欢迎提 [issue](https://github.com/mcpplibs/imgui-m/issues)。 |
203 | 94 |
|
204 | 95 | ## License |
205 | 96 |
|
206 | | -The wrapper code in this repository is MIT licensed. Dear ImGui is MIT licensed |
207 | | -and provided by the `compat.imgui` package. |
| 97 | +封装代码 MIT;Dear ImGui 本体 MIT(经 `compat.imgui` 提供)。 |
0 commit comments