Skip to content

Commit f4a6905

Browse files
committed
auto-size about dialog for small screens
1 parent 5b15eeb commit f4a6905

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/app.cpp

+14-5
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,17 @@ void SampleViewer::draw_about_dialog()
453453
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
454454
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
455455
ImGui::SetNextWindowFocus();
456-
const float2 col_width = {11 * HelloImGui::EmSize(), 32 * HelloImGui::EmSize()};
457-
ImGui::SetNextWindowContentSize(float2{col_width[0] + col_width[1], 0});
456+
constexpr float icon_size = 128.f;
457+
float2 col_width = {icon_size + HelloImGui::EmSize(), 32 * HelloImGui::EmSize()};
458+
float2 display_size = ImGui::GetIO().DisplaySize;
459+
#ifdef __EMSCRIPTEN__
460+
display_size = float2{window_width(), window_height()};
461+
#endif
462+
col_width[1] = clamp(col_width[1], 5 * HelloImGui::EmSize(),
463+
display_size.x - ImGui::GetStyle().WindowPadding.x - 2 * ImGui::GetStyle().ItemSpacing.x -
464+
ImGui::GetStyle().ScrollbarSize - col_width[0]);
465+
466+
ImGui::SetNextWindowContentSize(float2{col_width[0] + col_width[1] + ImGui::GetStyle().ItemSpacing.x, 0});
458467

459468
bool about_open = true;
460469
if (ImGui::BeginPopupModal("About", &about_open,
@@ -473,12 +482,12 @@ void SampleViewer::draw_about_dialog()
473482
ImGui::TableNextColumn();
474483
// right align the image
475484
{
476-
auto posX = (ImGui::GetCursorPosX() + ImGui::GetColumnWidth() - 128.f - ImGui::GetScrollX() -
485+
auto posX = (ImGui::GetCursorPosX() + ImGui::GetColumnWidth() - icon_size -
477486
2 * ImGui::GetStyle().ItemSpacing.x);
478487
if (posX > ImGui::GetCursorPosX())
479488
ImGui::SetCursorPosX(posX);
480489
}
481-
HelloImGui::ImageFromAsset("app_settings/icon.png", {128, 128}); // show the app icon
490+
HelloImGui::ImageFromAsset("app_settings/icon.png", {icon_size, icon_size}); // show the app icon
482491

483492
ImGui::TableNextColumn();
484493
ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + col_width[1]);
@@ -635,7 +644,7 @@ void SampleViewer::draw_about_dialog()
635644
ImGui::CloseCurrentPopup();
636645
g_dismissed_version = version_combined();
637646
}
638-
ImGui::SetItemDefaultFocus();
647+
// ImGui::SetItemDefaultFocus();
639648

640649
ImGui::EndPopup();
641650
g_open_help = false;

0 commit comments

Comments
 (0)