Skip to content

Commit

Permalink
auto-size about dialog for small screens
Browse files Browse the repository at this point in the history
  • Loading branch information
wkjarosz committed Jan 4, 2024
1 parent 5b15eeb commit f4a6905
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,17 @@ void SampleViewer::draw_about_dialog()
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
ImGui::SetNextWindowFocus();
const float2 col_width = {11 * HelloImGui::EmSize(), 32 * HelloImGui::EmSize()};
ImGui::SetNextWindowContentSize(float2{col_width[0] + col_width[1], 0});
constexpr float icon_size = 128.f;
float2 col_width = {icon_size + HelloImGui::EmSize(), 32 * HelloImGui::EmSize()};
float2 display_size = ImGui::GetIO().DisplaySize;
#ifdef __EMSCRIPTEN__
display_size = float2{window_width(), window_height()};
#endif
col_width[1] = clamp(col_width[1], 5 * HelloImGui::EmSize(),
display_size.x - ImGui::GetStyle().WindowPadding.x - 2 * ImGui::GetStyle().ItemSpacing.x -
ImGui::GetStyle().ScrollbarSize - col_width[0]);

ImGui::SetNextWindowContentSize(float2{col_width[0] + col_width[1] + ImGui::GetStyle().ItemSpacing.x, 0});

bool about_open = true;
if (ImGui::BeginPopupModal("About", &about_open,
Expand All @@ -473,12 +482,12 @@ void SampleViewer::draw_about_dialog()
ImGui::TableNextColumn();
// right align the image
{
auto posX = (ImGui::GetCursorPosX() + ImGui::GetColumnWidth() - 128.f - ImGui::GetScrollX() -
auto posX = (ImGui::GetCursorPosX() + ImGui::GetColumnWidth() - icon_size -
2 * ImGui::GetStyle().ItemSpacing.x);
if (posX > ImGui::GetCursorPosX())
ImGui::SetCursorPosX(posX);
}
HelloImGui::ImageFromAsset("app_settings/icon.png", {128, 128}); // show the app icon
HelloImGui::ImageFromAsset("app_settings/icon.png", {icon_size, icon_size}); // show the app icon

ImGui::TableNextColumn();
ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + col_width[1]);
Expand Down Expand Up @@ -635,7 +644,7 @@ void SampleViewer::draw_about_dialog()
ImGui::CloseCurrentPopup();
g_dismissed_version = version_combined();
}
ImGui::SetItemDefaultFocus();
// ImGui::SetItemDefaultFocus();

ImGui::EndPopup();
g_open_help = false;
Expand Down

0 comments on commit f4a6905

Please sign in to comment.