@@ -33,7 +33,7 @@ namespace SmartPeak
3333 if (reset_layout_)
3434 {
3535 current_layout_.clear ();
36- current_layout_ = new_layout ;
36+ current_layout_ = new_layout_ ;
3737 }
3838 const auto & top_windows_ = current_layout_.at (" top" );
3939 const auto & bottom_windows_ = current_layout_.at (" bottom" );
@@ -70,6 +70,18 @@ namespace SmartPeak
7070 }
7171 }
7272
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+
7385 void SplitWindow::draw ()
7486 {
7587 ImGuiIO& io = ImGui::GetIO ();
@@ -85,12 +97,12 @@ namespace SmartPeak
8597 if (reset_layout_)
8698 {
8799 current_layout_.clear ();
88- current_layout_ = new_layout ;
100+ current_layout_ = new_layout_ ;
89101 }
90102
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" );
94106
95107 // Build default docking
96108 ImGuiID dockspace_id = ImGui::GetID (" MyDockSpace" );
@@ -103,31 +115,37 @@ namespace SmartPeak
103115 ImGui::DockBuilderSetNodeSize (dockspace_id, ImVec2 (io.DisplaySize .x , io.DisplaySize .y - menu_height));
104116 ImGui::DockBuilderSplitNode (dockspace_id, ImGuiDir_Left, 0.3 , &left_node, ¢er_node); // The second parameter defines the direction of the split
105117 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 )
107119 {
108120 widget->visible_ = visible;
109121 ImGui::DockBuilderDockWindow (widget->title_ .c_str () , left_node);
110122 }
111- for (auto & [widget, visible] : top_windows_ )
123+ for (auto & [widget, visible] : top_windows )
112124 {
113125 widget->visible_ = visible;
114126 ImGui::DockBuilderDockWindow (widget->title_ .c_str (), center_node);
115127 }
116- for (auto & [widget, visible] : bottom_windows_ )
128+ for (auto & [widget, visible] : bottom_windows )
117129 {
118130 widget->visible_ = visible;
119131 ImGui::DockBuilderDockWindow (widget->title_ .c_str (), bottom_node);
120132 }
121133 ImGui::DockBuilderFinish (dockspace_id);
122- reset_layout_ = false ;
123134 }
124135
125136 ImGui::DockSpace (dockspace_id, ImVec2 (0 .0f , 0 .0f ), ImGuiDockNodeFlags_None);
126137
127138 // 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 ;
131149 }
132150 ImGui::End ();
133151 ImGui::PopStyleVar ();
@@ -136,7 +154,7 @@ namespace SmartPeak
136154
137155 void SplitWindow::resetLayout (const std::map<std::string, std::vector<std::tuple<std::shared_ptr<Widget>, bool >>>& layout)
138156 {
139- new_layout = layout;
157+ new_layout_ = layout;
140158 // complete with the default layout
141159 for (const auto & default_entry : default_layout_)
142160 {
@@ -160,7 +178,7 @@ namespace SmartPeak
160178 }
161179 if (!found)
162180 {
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
164182 }
165183 }
166184 }
0 commit comments