Skip to content

Commit c75f329

Browse files
tksuoranclaude
andcommitted
editor: dock new Hierarchy windows with the existing one (#258)
Extend the #258 new-window placement to scene Hierarchy windows: when Create Scene opens a new "Scene Hierarchy" window, dock (tab) it with an existing scene-hierarchy window instead of leaving it floating at ImGui's default cascade position; when none is docked, float it centered at 25% width x 50% height of the viewport. Item_tree_window is also used for the developer-only "Tools Library" tree, so match on an explicit is_scene_hierarchy() marker (set in Scene_root::make_browser_window) rather than the concrete type. Placement is applied in Scene_commands::create_new_scene, alongside the viewport placement; the startup default-scene browser and the scene-load path (which restores its own saved per-scene layout) are left untouched. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 01ec5f7 commit c75f329

6 files changed

Lines changed: 49 additions & 0 deletions

File tree

src/editor/scene/scene_commands.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,9 @@ auto Scene_commands::create_new_scene() -> std::shared_ptr<Scene_root>
568568
*m_context.app_settings
569569
);
570570
browser_window->show_window();
571+
// Dock (tab) the new scene's Hierarchy window with the existing one instead
572+
// of leaving it floating at ImGui's default cascade position (#258).
573+
apply_hierarchy_window_placement(*m_context.imgui_windows, *browser_window);
571574

572575
// A viewport window looking through the new camera. create_viewport_scene_view
573576
// is called directly (rather than open_new_viewport_scene_view) so the new

src/editor/scene/scene_root.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ auto Scene_root::make_browser_window(
301301
fmt::format("Scene Hierarchy [{}]", ++s_browser_window_count),
302302
""
303303
);
304+
m_node_tree_window->set_scene_hierarchy(true);
304305
m_node_tree_window->set_root(m_scene->get_root_node());
305306
// Show a selectable Scene item at the top of the Hierarchy window, with the
306307
// Content Library nested under it (issue #240). The scene root node's child

src/editor/windows/item_tree_window.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,6 +1748,16 @@ void Item_tree_window::on_end()
17481748
ImGui::PopStyleVar(2);
17491749
}
17501750

1751+
void Item_tree_window::set_scene_hierarchy(const bool value)
1752+
{
1753+
m_is_scene_hierarchy = value;
1754+
}
1755+
1756+
auto Item_tree_window::is_scene_hierarchy() const -> bool
1757+
{
1758+
return m_is_scene_hierarchy;
1759+
}
1760+
17511761
void Item_tree_window::hidden()
17521762
{
17531763
// Drop cached rows so a hidden tree does not keep deleted items alive

src/editor/windows/item_tree_window.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,21 @@ class Item_tree_window : public erhe::imgui::Imgui_window, public Item_tree
203203
std::string_view ini_label
204204
);
205205

206+
// Marks this tree window as a scene-hierarchy browser (as opposed to the
207+
// generic content-library / tools tree windows built from the same class).
208+
// Used by window placement (#258) to dock a new Hierarchy window with an
209+
// existing one.
210+
void set_scene_hierarchy(bool value);
211+
[[nodiscard]] auto is_scene_hierarchy() const -> bool;
212+
206213
// Implements Imgui_window
207214
void imgui () override;
208215
void on_begin() override;
209216
void on_end () override;
210217
void hidden () override;
218+
219+
private:
220+
bool m_is_scene_hierarchy{false};
211221
};
212222

213223
}

src/editor/windows/window_placement.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "geometry_graph/geometry_graph_window.hpp"
44
#include "texture_graph/texture_graph_window.hpp"
5+
#include "windows/item_tree_window.hpp"
56
#include "windows/properties.hpp"
67
#include "windows/viewport_window.hpp"
78

@@ -20,6 +21,8 @@ namespace {
2021
constexpr float c_editor_window_ratio = 0.66f;
2122
constexpr float c_properties_width_ratio = 0.33f;
2223
constexpr float c_properties_height_ratio = 0.66f;
24+
constexpr float c_hierarchy_width_ratio = 0.25f;
25+
constexpr float c_hierarchy_height_ratio = 0.50f;
2326

2427
auto is_editor_window(const erhe::imgui::Imgui_window* window) -> bool
2528
{
@@ -89,4 +92,21 @@ void apply_properties_window_placement(erhe::imgui::Imgui_windows& imgui_windows
8992
new_window.set_initial_placement(target, c_properties_width_ratio, c_properties_height_ratio);
9093
}
9194

95+
void apply_hierarchy_window_placement(erhe::imgui::Imgui_windows& imgui_windows, erhe::imgui::Imgui_window& new_window)
96+
{
97+
std::string target;
98+
const std::vector<erhe::imgui::Imgui_window*>& windows = imgui_windows.get_windows();
99+
for (const erhe::imgui::Imgui_window* window : windows) {
100+
if ((window == &new_window) || !window->is_window_visible()) {
101+
continue;
102+
}
103+
const Item_tree_window* tree_window = dynamic_cast<const Item_tree_window*>(window);
104+
if ((tree_window != nullptr) && tree_window->is_scene_hierarchy()) {
105+
target = window->get_title();
106+
break;
107+
}
108+
}
109+
new_window.set_initial_placement(target, c_hierarchy_width_ratio, c_hierarchy_height_ratio);
110+
}
111+
92112
} // namespace editor

src/editor/windows/window_placement.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@ namespace editor {
2121
// none is currently docked, show it floating, centered, at 33% width x 66%
2222
// height of the viewport.
2323
//
24+
// - Hierarchy windows: dock (tab) with an existing scene-hierarchy window. If
25+
// none is currently docked, show it floating, centered, at 25% width x 50%
26+
// height of the viewport.
27+
//
2428
// new_window must already be registered in imgui_windows.
2529

2630
void apply_editor_window_placement (erhe::imgui::Imgui_windows& imgui_windows, erhe::imgui::Imgui_window& new_window);
2731
void apply_properties_window_placement(erhe::imgui::Imgui_windows& imgui_windows, erhe::imgui::Imgui_window& new_window);
32+
void apply_hierarchy_window_placement (erhe::imgui::Imgui_windows& imgui_windows, erhe::imgui::Imgui_window& new_window);
2833

2934
} // namespace editor

0 commit comments

Comments
 (0)