Skip to content

Commit e9082ed

Browse files
docs: concise README (mcpp-style) (#9)
Badge header + nav table, core features, quick start, compact tables for modules / features / examples, toolchain & runtime note. Replaces the accumulated long-form sections; field-level reference stays in docs/architecture.md and the design docs. Co-authored-by: sunrisepeak <x.d2learn.org@gmail.com>
1 parent 87bd8ec commit e9082ed

1 file changed

Lines changed: 57 additions & 167 deletions

File tree

README.md

Lines changed: 57 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -1,207 +1,97 @@
11
# imgui
22

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` 即用 · 跨平台 · 特性可插拔
434
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+
[![Release](https://img.shields.io/github/v/release/mcpplibs/imgui-m)](https://github.com/mcpplibs/imgui-m/releases)
6+
[![C++23](https://img.shields.io/badge/C%2B%2B-23-blue.svg)](https://en.cppreference.com/w/cpp/23)
7+
[![Module](https://img.shields.io/badge/module-ok-green.svg)](https://en.cppreference.com/w/cpp/language/modules)
8+
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
659

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+
| [![CI](https://github.com/mcpplibs/imgui-m/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/mcpplibs/imgui-m/actions/workflows/ci.yml) |
6913

70-
## Dependencies
14+
## 核心特性
7115

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 生态自动闭合
7320

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+
## 快速开始
8822

8923
```bash
90-
mcpp build
91-
mcpp test
92-
cd examples/basic
93-
mcpp run
24+
mcpp new myapp --template gui && cd myapp && mcpp run # 窗口直接出现
9425
```
9526

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+
或在已有项目中手动接入:
12828

12929
```toml
13030
[dependencies]
131-
imgui = "0.0.1"
31+
imgui = "0.0.5"
13232
```
13333

134-
Then import the modules you need.
135-
136-
Tier-0 (`imgui.app` facade — least code):
137-
13834
```cpp
13935
import imgui.core;
14036
import imgui.app;
14137

14238
int main() {
14339
return ImGui::App::run([] {
144-
ImGui::Begin("hi");
145-
ImGui::TextUnformatted("imgui.app facade");
40+
ImGui::Begin("hello");
41+
ImGui::TextUnformatted("mcpp + imgui");
14642
ImGui::End();
14743
});
14844
}
14945
```
15046

151-
Tier-2 (explicit backend module + alias — full control):
47+
## 模块一览
15248

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 / 逻辑测试 |
15756

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 = ...;`
17358

174-
## Module Surface
59+
## Features
17560

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 体验 |
17866

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+
```
18371

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。
18773

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+
```
19287

193-
## Verification
88+
## 工具链与运行时
19489

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` 查看。
19691

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)
20394
20495
## License
20596

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

Comments
 (0)