@@ -118,14 +118,6 @@ namespace {
118118 ImGui::PopTextWrapPos ();
119119 }
120120
121- std::string backend_combo_label (const BackendInfo& info)
122- {
123- std::string label = std::string (backend_display_name (info.kind ));
124- if (!info.compiled )
125- label += " (not built)" ;
126- return label;
127- }
128-
129121 bool input_text_string (const char * label, std::string& value)
130122 {
131123 char buffer[4096 ];
@@ -277,52 +269,85 @@ draw_preferences_window(PlaceholderUiState& ui, bool& show_window,
277269 ImGui::Checkbox (" Generate mipmaps (requires restart)" , &ui.auto_mipmap );
278270
279271 ImGui::Spacing ();
280- const BackendKind requested_backend = sanitize_backend_kind (
272+ BackendKind requested_backend = sanitize_backend_kind (
281273 ui.renderer_backend );
274+ const float spacing = ImGui::GetStyle ().ItemSpacing .x ;
275+ const float row_width = ImGui::GetContentRegionAvail ().x ;
276+ const float button_width = std::max (
277+ 1 .0f , (row_width - spacing * 2 .0f ) / 3 .0f );
278+ bool have_backend_row_rect = false ;
279+ ImVec2 backend_row_min (0 .0f , 0 .0f );
280+ ImVec2 backend_row_max (0 .0f , 0 .0f );
281+ int backend_button_index = 0 ;
282+ for (const BackendInfo& info : compiled_backend_info ()) {
283+ const bool selected = requested_backend == info.kind ;
284+ if (backend_button_index > 0 )
285+ ImGui::SameLine (0 .0f , spacing);
286+ ImGui::PushID (static_cast <int >(info.kind ));
287+ if (!info.compiled )
288+ ImGui::BeginDisabled ();
289+ push_preview_active_button_style (selected);
290+ if (ImGui::Button (backend_display_name (info.kind ),
291+ ImVec2 (button_width, 0 .0f ))
292+ && info.compiled ) {
293+ ui.renderer_backend = static_cast <int >(info.kind );
294+ }
295+ pop_preview_active_button_style (selected);
296+ if (!info.compiled )
297+ ImGui::EndDisabled ();
298+ register_layout_dump_synthetic_item (" button" ,
299+ backend_display_name (info.kind ));
300+ const ImVec2 item_min = ImGui::GetItemRectMin ();
301+ const ImVec2 item_max = ImGui::GetItemRectMax ();
302+ if (!have_backend_row_rect) {
303+ backend_row_min = item_min;
304+ backend_row_max = item_max;
305+ have_backend_row_rect = true ;
306+ } else {
307+ backend_row_min.x = std::min (backend_row_min.x , item_min.x );
308+ backend_row_min.y = std::min (backend_row_min.y , item_min.y );
309+ backend_row_max.x = std::max (backend_row_max.x , item_max.x );
310+ backend_row_max.y = std::max (backend_row_max.y , item_max.y );
311+ }
312+ ImGui::PopID ();
313+ ++backend_button_index;
314+ }
315+ if (have_backend_row_rect) {
316+ register_layout_dump_synthetic_rect (" button" , " Renderer backend" ,
317+ backend_row_min,
318+ backend_row_max);
319+ }
320+
321+ requested_backend = sanitize_backend_kind (ui.renderer_backend );
282322 const BackendKind next_launch_backend = resolve_backend_request (
283323 requested_backend);
284324 const bool requested_backend_compiled
285325 = requested_backend == BackendKind::Auto
286326 || backend_kind_is_compiled (requested_backend);
287- std::string backend_label
288- = std::string (backend_display_name (requested_backend));
289- if (requested_backend != BackendKind::Auto
290- && !requested_backend_compiled) {
291- backend_label += " (not built)" ;
292- }
293- if (ImGui::BeginCombo (" Renderer backend" , backend_label.c_str ())) {
294- register_test_engine_item_label (" Renderer backend" , true );
295- const bool auto_selected = requested_backend == BackendKind::Auto;
296- if (ImGui::Selectable (" Auto" , auto_selected)) {
297- ui.renderer_backend = static_cast <int >(BackendKind::Auto);
298- }
299- if (auto_selected)
300- ImGui::SetItemDefaultFocus ();
301- for (const BackendInfo& info : compiled_backend_info ()) {
302- const bool selected = requested_backend == info.kind ;
303- const std::string label = backend_combo_label (info);
304- if (!info.compiled )
305- ImGui::BeginDisabled ();
306- if (ImGui::Selectable (label.c_str (), selected)
307- && info.compiled ) {
308- ui.renderer_backend = static_cast <int >(info.kind );
309- }
310- if (!info.compiled )
311- ImGui::EndDisabled ();
312- if (selected)
313- ImGui::SetItemDefaultFocus ();
314- }
315- ImGui::EndCombo ();
316- } else {
317- register_test_engine_item_label (" Renderer backend" , true );
318- }
327+ const bool invalid_requested_backend = requested_backend != BackendKind::Auto
328+ && !requested_backend_compiled;
329+ if (requested_backend == BackendKind::Auto)
330+ ImGui::TextUnformatted (" Stored preference: Auto" );
331+ else
332+ ImGui::Text (" Stored preference: %s" ,
333+ backend_display_name (requested_backend));
334+ ImGui::SameLine ();
335+ if (requested_backend == BackendKind::Auto)
336+ ImGui::BeginDisabled ();
337+ if (ImGui::SmallButton (" Reset to Auto" ))
338+ ui.renderer_backend = static_cast <int >(BackendKind::Auto);
339+ register_layout_dump_synthetic_item (" button" , " Reset to Auto" );
340+ if (requested_backend == BackendKind::Auto)
341+ ImGui::EndDisabled ();
319342 ImGui::TextUnformatted (" Current backend" );
320343 ImGui::SameLine ();
321344 ImGui::TextUnformatted (backend_display_name (active_backend));
322- if (requested_backend != BackendKind::Auto
323- && !requested_backend_compiled) {
345+ ImGui::Text (" Next launch backend: %s" ,
346+ backend_display_name (resolve_backend_request (
347+ sanitize_backend_kind (ui.renderer_backend ))));
348+ if (invalid_requested_backend) {
324349 ImGui::TextUnformatted (
325- " Requested backend is not built into this binary." );
350+ " Requested backend is not built in this binary and will be ignored when Preferences closes ." );
326351 } else if (next_launch_backend != active_backend) {
327352 ImGui::TextUnformatted (" Backend change requires restart." );
328353 }
@@ -422,6 +447,11 @@ draw_preferences_window(PlaceholderUiState& ui, bool& show_window,
422447 }
423448 ImGui::End ();
424449 ImGui::PopStyleVar ();
450+ const BackendKind close_backend = sanitize_backend_kind (ui.renderer_backend );
451+ if (!show_window && close_backend != BackendKind::Auto
452+ && !backend_kind_is_compiled (close_backend)) {
453+ ui.renderer_backend = static_cast <int >(BackendKind::Auto);
454+ }
425455}
426456
427457void
0 commit comments