Skip to content

Commit 4c1f281

Browse files
docking feature + example (#6)
* feat: docking feature + example imgui = { version, features = ["docking"] }: - sources switch to upstream's docking tag (compat.imgui 1.92.8-docking, a superset — identical behavior with the feature off; default build/tests unchanged). - core exports the Dock* surface gated by MCPP_FEATURE_DOCKING (DockSpace/DockSpaceOverViewport/SetNextWindowDockID/GetWindowDockID/ IsWindowDocked + ConfigFlags_DockingEnable/Cond_FirstUseEver constants; plain-int typedefs intentionally not re-aliased — GMF typedef name clash). - imgui.app facade auto-enables ImGuiConfigFlags_DockingEnable. - examples/docking: pre-docked Toolbox/Inspector via DockSpaceOverViewport (verified rendering: docked tab bar). CI builds it (needs mcpp >= 0.0.47 for features; CI installs latest). * ci: bootstrap mcpp 0.0.48 (features mechanism required by docking example) --------- Co-authored-by: sunrisepeak <x.d2learn.org@gmail.com>
1 parent 2f30040 commit 4c1f281

8 files changed

Lines changed: 89 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,9 @@ jobs:
102102
run: |
103103
cd examples/glfw_opengl3
104104
mcpp build
105+
106+
- name: Build docking example (features=["docking"])
107+
shell: bash
108+
run: |
109+
cd examples/docking
110+
mcpp build

.xlings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"workspace": {
3-
"xim:mcpp": "0.0.44"
3+
"xim:mcpp": "0.0.48"
44
}
55
}

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,21 @@ alias — the rest of the consumer code is identical. Cross-platform GL/GLSL
4141
configuration (incl. macOS forward-compat) is handled by `RecommendedGlConfig()`,
4242
which `CreateWindow`/`Init` use by default.
4343

44+
## Features
45+
46+
- `docking` — 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+
See `examples/docking/`. Sources come from upstream's docking tag
56+
(`compat.imgui 1.92.8-docking`, a superset of mainline — identical behavior
57+
while the feature is off).
58+
4459
## Dependencies
4560

4661
The root package depends on:

examples/docking/mcpp.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "imgui-docking"
3+
version = "0.1.0"
4+
description = "Dockable-windows demo using the imgui `docking` feature"
5+
license = "MIT"
6+
7+
[dependencies]
8+
imgui = { path = "../..", features = ["docking"] }

examples/docking/src/main.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Docking demo — `imgui = { ..., features = ["docking"] }`.
2+
// The imgui.app facade auto-enables ImGuiConfigFlags_DockingEnable when the
3+
// feature is active; DockSpaceOverViewport turns the whole window into a
4+
// dock host, so the two panels below can be dragged into / split around it.
5+
import imgui.core;
6+
import imgui.app;
7+
8+
int main() {
9+
return ImGui::App::run({.title = "mcpp imgui docking demo"}, [] {
10+
const auto dockspace = ImGui::DockSpaceOverViewport();
11+
12+
// Pre-dock both panels into the dockspace on first run; they remain
13+
// freely draggable/splittable afterwards.
14+
ImGui::SetNextWindowDockID(dockspace, ImGui::Cond_FirstUseEver);
15+
ImGui::Begin("Toolbox");
16+
ImGui::TextUnformatted("Drag this panel onto the dockspace.");
17+
ImGui::TextUnformatted("Docked: ");
18+
ImGui::TextUnformatted(ImGui::IsWindowDocked() ? "yes" : "no");
19+
ImGui::End();
20+
21+
ImGui::SetNextWindowDockID(dockspace, ImGui::Cond_FirstUseEver);
22+
ImGui::Begin("Inspector");
23+
ImGui::TextUnformatted("Split me against the Toolbox.");
24+
ImGui::End();
25+
});
26+
}

mcpp.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,14 @@ sources = [
2222
"src/backends/opengl3_impl.cpp",
2323
]
2424

25+
[features]
26+
default = []
27+
# docking: export the Dock* API surface and auto-enable
28+
# ImGuiConfigFlags_DockingEnable in the imgui.app facade.
29+
docking = []
30+
2531
[dependencies]
26-
compat.imgui = "1.92.8"
32+
compat.imgui = "1.92.8-docking"
2733
compat.glfw = "3.4"
2834
compat.opengl = "2026.05.31"
2935

src/app.cppm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ export namespace ImGui::App {
5353

5454
ImGuiContext* context = ImGui::CreateContext();
5555
ImGui::SetCurrentContext(context);
56+
#ifdef MCPP_FEATURE_DOCKING
57+
// `docking` feature: enable dockable windows out of the box.
58+
ImGui::GetIO().ConfigFlags |= ImGui::ConfigFlags_DockingEnable;
59+
#endif
5660

5761
if (!Backend::Init(window)) {
5862
const auto error = Backend::LastError();

src/core.cppm

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,25 @@ export namespace ImGui {
2626
using ::ImGui::SetCurrentContext;
2727
using ::ImGui::TextUnformatted;
2828
}
29+
30+
// Docking surface — gated by the `docking` feature
31+
// (`imgui = { ..., features = ["docking"] }`). Requires the upstream docking
32+
// sources (compat.imgui 1.92.8-docking); with the feature off, the docking
33+
// sources behave exactly like mainline.
34+
#ifdef MCPP_FEATURE_DOCKING
35+
// (ImGuiID / ImGuiDockNodeFlags are plain-integer typedefs; GMF typedefs
36+
// cannot be re-aliased under the same global name in a module. Consumers
37+
// take DockSpace* return values with `auto`.)
38+
export namespace ImGui {
39+
using ::ImGui::DockSpace;
40+
using ::ImGui::DockSpaceOverViewport;
41+
using ::ImGui::SetNextWindowDockID;
42+
using ::ImGui::GetWindowDockID;
43+
using ::ImGui::IsWindowDocked;
44+
45+
// Unscoped global enumerators, re-exported as namespaced constants for
46+
// module consumers.
47+
inline constexpr int ConfigFlags_DockingEnable = ::ImGuiConfigFlags_DockingEnable;
48+
inline constexpr int Cond_FirstUseEver = ::ImGuiCond_FirstUseEver;
49+
}
50+
#endif

0 commit comments

Comments
 (0)