@@ -33,7 +33,7 @@ namespace SmartPeak
33
33
if (reset_layout_)
34
34
{
35
35
current_layout_.clear ();
36
- current_layout_ = new_layout ;
36
+ current_layout_ = new_layout_ ;
37
37
}
38
38
const auto & top_windows_ = current_layout_.at (" top" );
39
39
const auto & bottom_windows_ = current_layout_.at (" bottom" );
@@ -70,6 +70,18 @@ namespace SmartPeak
70
70
}
71
71
}
72
72
73
+ void SplitWindow::focusFirstWindow (const std::vector<std::tuple<std::shared_ptr<Widget>, bool >>& windows)
74
+ {
75
+ for (auto & [widget, visible] : windows)
76
+ {
77
+ if (widget->visible_ )
78
+ {
79
+ ImGui::SetWindowFocus (widget->title_ .c_str ());
80
+ break ;
81
+ }
82
+ }
83
+ }
84
+
73
85
void SplitWindow::draw ()
74
86
{
75
87
ImGuiIO& io = ImGui::GetIO ();
@@ -85,12 +97,12 @@ namespace SmartPeak
85
97
if (reset_layout_)
86
98
{
87
99
current_layout_.clear ();
88
- current_layout_ = new_layout ;
100
+ current_layout_ = new_layout_ ;
89
101
}
90
102
91
- const auto & top_windows_ = current_layout_.at (" top" );
92
- const auto & bottom_windows_ = current_layout_.at (" bottom" );
93
- const auto & left_windows_ = current_layout_.at (" left" );
103
+ const auto & top_windows = current_layout_.at (" top" );
104
+ const auto & bottom_windows = current_layout_.at (" bottom" );
105
+ const auto & left_windows = current_layout_.at (" left" );
94
106
95
107
// Build default docking
96
108
ImGuiID dockspace_id = ImGui::GetID (" MyDockSpace" );
@@ -103,31 +115,37 @@ namespace SmartPeak
103
115
ImGui::DockBuilderSetNodeSize (dockspace_id, ImVec2 (io.DisplaySize .x , io.DisplaySize .y - menu_height));
104
116
ImGui::DockBuilderSplitNode (dockspace_id, ImGuiDir_Left, 0.3 , &left_node, ¢er_node); // The second parameter defines the direction of the split
105
117
ImGui::DockBuilderSplitNode (center_node, ImGuiDir_Down, 0.5 , &bottom_node, ¢er_node); // The second parameter defines the direction of the split
106
- for (auto & [widget, visible] : left_windows_ )
118
+ for (auto & [widget, visible] : left_windows )
107
119
{
108
120
widget->visible_ = visible;
109
121
ImGui::DockBuilderDockWindow (widget->title_ .c_str () , left_node);
110
122
}
111
- for (auto & [widget, visible] : top_windows_ )
123
+ for (auto & [widget, visible] : top_windows )
112
124
{
113
125
widget->visible_ = visible;
114
126
ImGui::DockBuilderDockWindow (widget->title_ .c_str (), center_node);
115
127
}
116
- for (auto & [widget, visible] : bottom_windows_ )
128
+ for (auto & [widget, visible] : bottom_windows )
117
129
{
118
130
widget->visible_ = visible;
119
131
ImGui::DockBuilderDockWindow (widget->title_ .c_str (), bottom_node);
120
132
}
121
133
ImGui::DockBuilderFinish (dockspace_id);
122
- reset_layout_ = false ;
123
134
}
124
135
125
136
ImGui::DockSpace (dockspace_id, ImVec2 (0 .0f , 0 .0f ), ImGuiDockNodeFlags_None);
126
137
127
138
// Instanciate windows
128
- showWindows (left_windows_);
129
- showWindows (top_windows_);
130
- showWindows (bottom_windows_);
139
+ showWindows (left_windows);
140
+ showWindows (top_windows);
141
+ showWindows (bottom_windows);
142
+ if (reset_layout_)
143
+ {
144
+ focusFirstWindow (left_windows);
145
+ focusFirstWindow (top_windows);
146
+ focusFirstWindow (bottom_windows);
147
+ }
148
+ reset_layout_ = false ;
131
149
}
132
150
ImGui::End ();
133
151
ImGui::PopStyleVar ();
@@ -136,7 +154,7 @@ namespace SmartPeak
136
154
137
155
void SplitWindow::resetLayout (const std::map<std::string, std::vector<std::tuple<std::shared_ptr<Widget>, bool >>>& layout)
138
156
{
139
- new_layout = layout;
157
+ new_layout_ = layout;
140
158
// complete with the default layout
141
159
for (const auto & default_entry : default_layout_)
142
160
{
@@ -160,7 +178,7 @@ namespace SmartPeak
160
178
}
161
179
if (!found)
162
180
{
163
- new_layout [default_entry.first ].push_back (std::make_tuple (default_widget, false )); // default is not found, add it but invisible
181
+ new_layout_ [default_entry.first ].push_back (std::make_tuple (default_widget, false )); // default is not found, add it but invisible
164
182
}
165
183
}
166
184
}
0 commit comments