diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7bcd830..8f47b13 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -102,3 +102,9 @@ jobs: run: | cd examples/glfw_opengl3 mcpp build + + - name: Build docking example (features=["docking"]) + shell: bash + run: | + cd examples/docking + mcpp build diff --git a/.xlings.json b/.xlings.json index e2f6cb5..f4a5155 100644 --- a/.xlings.json +++ b/.xlings.json @@ -1,5 +1,5 @@ { "workspace": { - "xim:mcpp": "0.0.44" + "xim:mcpp": "0.0.48" } } diff --git a/README.md b/README.md index e95c39d..ae8abf7 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,21 @@ alias — the rest of the consumer code is identical. Cross-platform GL/GLSL configuration (incl. macOS forward-compat) is handled by `RecommendedGlConfig()`, which `CreateWindow`/`Init` use by default. +## Features + +- `docking` — exports the Dock* API surface (`DockSpace`, `DockSpaceOverViewport`, + `SetNextWindowDockID`, `IsWindowDocked`, ...) and makes the `imgui.app` facade + enable `ImGuiConfigFlags_DockingEnable` automatically: + + ```toml + [dependencies] + imgui = { version = "0.0.4", features = ["docking"] } + ``` + + See `examples/docking/`. Sources come from upstream's docking tag + (`compat.imgui 1.92.8-docking`, a superset of mainline — identical behavior + while the feature is off). + ## Dependencies The root package depends on: diff --git a/examples/docking/mcpp.toml b/examples/docking/mcpp.toml new file mode 100644 index 0000000..92859bb --- /dev/null +++ b/examples/docking/mcpp.toml @@ -0,0 +1,8 @@ +[package] +name = "imgui-docking" +version = "0.1.0" +description = "Dockable-windows demo using the imgui `docking` feature" +license = "MIT" + +[dependencies] +imgui = { path = "../..", features = ["docking"] } diff --git a/examples/docking/src/main.cpp b/examples/docking/src/main.cpp new file mode 100644 index 0000000..e6fa048 --- /dev/null +++ b/examples/docking/src/main.cpp @@ -0,0 +1,26 @@ +// Docking demo — `imgui = { ..., features = ["docking"] }`. +// The imgui.app facade auto-enables ImGuiConfigFlags_DockingEnable when the +// feature is active; DockSpaceOverViewport turns the whole window into a +// dock host, so the two panels below can be dragged into / split around it. +import imgui.core; +import imgui.app; + +int main() { + return ImGui::App::run({.title = "mcpp imgui docking demo"}, [] { + const auto dockspace = ImGui::DockSpaceOverViewport(); + + // Pre-dock both panels into the dockspace on first run; they remain + // freely draggable/splittable afterwards. + ImGui::SetNextWindowDockID(dockspace, ImGui::Cond_FirstUseEver); + ImGui::Begin("Toolbox"); + ImGui::TextUnformatted("Drag this panel onto the dockspace."); + ImGui::TextUnformatted("Docked: "); + ImGui::TextUnformatted(ImGui::IsWindowDocked() ? "yes" : "no"); + ImGui::End(); + + ImGui::SetNextWindowDockID(dockspace, ImGui::Cond_FirstUseEver); + ImGui::Begin("Inspector"); + ImGui::TextUnformatted("Split me against the Toolbox."); + ImGui::End(); + }); +} diff --git a/mcpp.toml b/mcpp.toml index 857bdf9..f47cf24 100644 --- a/mcpp.toml +++ b/mcpp.toml @@ -22,8 +22,14 @@ sources = [ "src/backends/opengl3_impl.cpp", ] +[features] +default = [] +# docking: export the Dock* API surface and auto-enable +# ImGuiConfigFlags_DockingEnable in the imgui.app facade. +docking = [] + [dependencies] -compat.imgui = "1.92.8" +compat.imgui = "1.92.8-docking" compat.glfw = "3.4" compat.opengl = "2026.05.31" diff --git a/src/app.cppm b/src/app.cppm index c4100b6..3d5d55c 100644 --- a/src/app.cppm +++ b/src/app.cppm @@ -53,6 +53,10 @@ export namespace ImGui::App { ImGuiContext* context = ImGui::CreateContext(); ImGui::SetCurrentContext(context); +#ifdef MCPP_FEATURE_DOCKING + // `docking` feature: enable dockable windows out of the box. + ImGui::GetIO().ConfigFlags |= ImGui::ConfigFlags_DockingEnable; +#endif if (!Backend::Init(window)) { const auto error = Backend::LastError(); diff --git a/src/core.cppm b/src/core.cppm index 5a443ed..d4d1edc 100644 --- a/src/core.cppm +++ b/src/core.cppm @@ -26,3 +26,25 @@ export namespace ImGui { using ::ImGui::SetCurrentContext; using ::ImGui::TextUnformatted; } + +// Docking surface — gated by the `docking` feature +// (`imgui = { ..., features = ["docking"] }`). Requires the upstream docking +// sources (compat.imgui 1.92.8-docking); with the feature off, the docking +// sources behave exactly like mainline. +#ifdef MCPP_FEATURE_DOCKING +// (ImGuiID / ImGuiDockNodeFlags are plain-integer typedefs; GMF typedefs +// cannot be re-aliased under the same global name in a module. Consumers +// take DockSpace* return values with `auto`.) +export namespace ImGui { + using ::ImGui::DockSpace; + using ::ImGui::DockSpaceOverViewport; + using ::ImGui::SetNextWindowDockID; + using ::ImGui::GetWindowDockID; + using ::ImGui::IsWindowDocked; + + // Unscoped global enumerators, re-exported as namespaced constants for + // module consumers. + inline constexpr int ConfigFlags_DockingEnable = ::ImGuiConfigFlags_DockingEnable; + inline constexpr int Cond_FirstUseEver = ::ImGuiCond_FirstUseEver; +} +#endif