From 86f92fe75605021a7440d72131a6aa7e27ca13a9 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 2 May 2019 20:19:53 +0200 Subject: [PATCH] Demo: Improved trees in columns demo. (#2136) --- docs/CHANGELOG.txt | 1 + imgui_demo.cpp | 39 +++++++++++++++++++++++++++++++-------- imgui_internal.h | 2 +- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 86fd1a90..d808f4c2 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -89,6 +89,7 @@ Other Changes: - Misc: Added IM_MALLOC/IM_FREE macros mimicking IM_NEW/IM_DELETE so user doesn't need to revert to using the ImGui::MemAlloc()/MemFree() calls directly. - Metrics: Added "Show windows rectangles" tool to visualize the different rectangles. +- Demo: Improved trees in columns demo. - Examples: OpenGL: Added a dummy GL call + comments in ImGui_ImplOpenGL3_Init() to detect uninitialized GL function loaders early, and help users understand what they are missing. (#2421) - Examples: Emscripten: Added Emscripten+SDL+GLES2 example. (#2494, #2492, #2351, #336) [@nicolasnoble, @redblobgames] diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 75f690ce..0d9c50a1 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -2545,16 +2545,39 @@ static void ShowDemoWindowColumns() ImGui::TreePop(); } - bool node_open = ImGui::TreeNode("Tree within single cell"); - ImGui::SameLine(); HelpMarker("NB: Tree node must be poped before ending the cell. There's no storage of state per-cell."); - if (node_open) + if (ImGui::TreeNode("Tree")) { - ImGui::Columns(2, "tree items"); - ImGui::Separator(); - if (ImGui::TreeNode("Hello")) { ImGui::BulletText("Sailor"); ImGui::TreePop(); } ImGui::NextColumn(); - if (ImGui::TreeNode("Bonjour")) { ImGui::BulletText("Marin"); ImGui::TreePop(); } ImGui::NextColumn(); + ImGui::Columns(2, "tree", true); + for (int x = 0; x < 3; x++) + { + bool open1 = ImGui::TreeNode((void*)(intptr_t)x, "Node%d", x); + ImGui::NextColumn(); + ImGui::Text("Node contents"); + ImGui::NextColumn(); + if (open1) + { + for (int y = 0; y < 5; y++) + { + bool open2 = ImGui::TreeNode((void*)(intptr_t)y, "Node%d.%d", x, y); + ImGui::NextColumn(); + ImGui::Text("Node contents"); + if (open2) + { + ImGui::Text("Even more contents"); + if (ImGui::TreeNode("Tree in column")) + { + ImGui::Text("The quick brown fox jumps over the lazy dog"); + ImGui::TreePop(); + } + } + ImGui::NextColumn(); + if (open2) + ImGui::TreePop(); + } + ImGui::TreePop(); + } + } ImGui::Columns(1); - ImGui::Separator(); ImGui::TreePop(); } diff --git a/imgui_internal.h b/imgui_internal.h index 0aacd0fd..4130ab8a 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -346,7 +346,7 @@ enum ImGuiSelectableFlagsPrivate_ ImGuiSelectableFlags_NoHoldingActiveID = 1 << 10, ImGuiSelectableFlags_PressedOnClick = 1 << 11, ImGuiSelectableFlags_PressedOnRelease = 1 << 12, - ImGuiSelectableFlags_DrawFillAvailWidth = 1 << 13, + ImGuiSelectableFlags_DrawFillAvailWidth = 1 << 13, // FIXME: We may be able to remove this (added in 6251d379 for menus) ImGuiSelectableFlags_AllowItemOverlap = 1 << 14 };