From 7b03b54539d8456b47b25224f0b63e24186c4314 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 21 Jun 2025 21:11:15 +1000 Subject: [PATCH] FullscreenUI: Eliminate last of layout height constants --- src/core/fullscreen_ui.cpp | 56 ++++++++++++----------------------- src/util/imgui_fullscreen.cpp | 36 ++++------------------ src/util/imgui_fullscreen.h | 6 +--- 3 files changed, 25 insertions(+), 73 deletions(-) diff --git a/src/core/fullscreen_ui.cpp b/src/core/fullscreen_ui.cpp index 46e84f7ab..36bddbfce 100644 --- a/src/core/fullscreen_ui.cpp +++ b/src/core/fullscreen_ui.cpp @@ -90,8 +90,6 @@ using ImGuiFullscreen::LAYOUT_LARGE_FONT_SIZE; using ImGuiFullscreen::LAYOUT_LARGE_POPUP_PADDING; using ImGuiFullscreen::LAYOUT_LARGE_POPUP_ROUNDING; using ImGuiFullscreen::LAYOUT_MEDIUM_FONT_SIZE; -using ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT; -using ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY; using ImGuiFullscreen::LAYOUT_MENU_BUTTON_SPACING; using ImGuiFullscreen::LAYOUT_MENU_BUTTON_X_PADDING; using ImGuiFullscreen::LAYOUT_MENU_BUTTON_Y_PADDING; @@ -2107,9 +2105,8 @@ bool FullscreenUI::ShouldOpenToGameList() void FullscreenUI::DrawLandingTemplate(ImVec2* menu_pos, ImVec2* menu_size) { const ImGuiIO& io = ImGui::GetIO(); - const ImVec2 heading_size = - ImVec2(io.DisplaySize.x, LayoutScale(LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY) + - (LayoutScale(LAYOUT_MENU_BUTTON_Y_PADDING) * 2.0f) + LayoutScale(2.0f)); + const ImVec2 heading_size = ImVec2( + io.DisplaySize.x, UIStyle.LargeFontSize + (LayoutScale(LAYOUT_MENU_BUTTON_Y_PADDING) * 2.0f) + LayoutScale(2.0f)); *menu_pos = ImVec2(0.0f, heading_size.y); *menu_size = ImVec2(io.DisplaySize.x, io.DisplaySize.y - heading_size.y - LayoutScale(LAYOUT_FOOTER_HEIGHT)); @@ -2127,7 +2124,7 @@ void FullscreenUI::DrawLandingTemplate(ImVec2* menu_pos, ImVec2* menu_size) // draw branding { const ImVec2 logo_pos = LayoutScale(LAYOUT_MENU_BUTTON_X_PADDING, LAYOUT_MENU_BUTTON_Y_PADDING); - const ImVec2 logo_size = LayoutScale(LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY); + const ImVec2 logo_size = ImVec2(UIStyle.LargeFontSize, UIStyle.LargeFontSize); dl->AddImage(s_state.app_icon_texture.get(), logo_pos, logo_pos + logo_size); const std::string_view heading_text = "DuckStation"; @@ -2169,8 +2166,7 @@ void FullscreenUI::DrawLandingTemplate(ImVec2* menu_pos, ImVec2* menu_size) s_state.achievements_user_badge_path = Achievements::GetLoggedInUserBadgePath(); if (!s_state.achievements_user_badge_path.empty()) [[likely]] { - const ImVec2 badge_size = - LayoutScale(LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY); + const ImVec2 badge_size = ImVec2(UIStyle.LargeFontSize, UIStyle.LargeFontSize); const ImVec2 badge_pos = ImVec2(name_pos.x - badge_size.x - LayoutScale(LAYOUT_MENU_BUTTON_X_PADDING), time_pos.y); @@ -3283,9 +3279,7 @@ void FullscreenUI::DrawIntSpinBoxSetting(SettingsInterface* bsi, std::string_vie ImVec2 button_pos(ImGui::GetCursorPos()); // Align value text in middle. - ImGui::SetCursorPosY( - button_pos.y + - ((LayoutScale(LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY) + padding.y * 2.0f) - UIStyle.LargeFontSize) * 0.5f); + ImGui::SetCursorPosY(button_pos.y + ((UIStyle.LargeFontSize + padding.y * 2.0f) - UIStyle.LargeFontSize) * 0.5f); ImGui::TextUnformatted(str_value); s32 step = 0; @@ -3314,7 +3308,7 @@ void FullscreenUI::DrawIntSpinBoxSetting(SettingsInterface* bsi, std::string_vie dlg_value_changed = true; } - ImGui::SetCursorPosY(button_pos.y + (padding.y * 2.0f) + LayoutScale(LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY + 10.0f)); + ImGui::SetCursorPosY(button_pos.y + (padding.y * 2.0f) + UIStyle.LargeFontSize + LayoutScale(10.0f)); } if (dlg_value_changed) @@ -3795,9 +3789,8 @@ void FullscreenUI::DoClearGameSettings() void FullscreenUI::DrawSettingsWindow() { ImGuiIO& io = ImGui::GetIO(); - const ImVec2 heading_size = - ImVec2(io.DisplaySize.x, LayoutScale(LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY) + - (LayoutScale(LAYOUT_MENU_BUTTON_Y_PADDING) * 2.0f) + LayoutScale(2.0f)); + const ImVec2 heading_size = ImVec2( + io.DisplaySize.x, UIStyle.LargeFontSize + (LayoutScale(LAYOUT_MENU_BUTTON_Y_PADDING) * 2.0f) + LayoutScale(2.0f)); const float target_bg_alpha = GetBackgroundAlpha(); s_state.settings_last_bg_alpha = (target_bg_alpha < s_state.settings_last_bg_alpha) ? @@ -5845,17 +5838,10 @@ void FullscreenUI::DrawPostProcessingSettingsPage() { if (!opt.help_text.empty()) { - const float width = ImGui::GetCurrentWindow()->WorkRect.GetWidth(); - const ImVec2 text_size = UIStyle.Font->CalcTextSizeA(UIStyle.MediumFontSize, UIStyle.NormalFontWeight, FLT_MAX, - width, IMSTR_START_END(opt.help_text)); - ImVec2 pos, size; - ImGuiFullscreen::GetMenuButtonFrameBounds(LayoutUnscale(text_size.y), &pos, &size); - const ImVec2& frame_padding = ImGui::GetStyle().FramePadding; - const ImRect rect = ImRect(pos + frame_padding, pos + size - frame_padding); - ImGui::ItemSize(size); - RenderShadowedTextClipped(UIStyle.Font, UIStyle.MediumFontSize, UIStyle.NormalFontWeight, rect.Min, rect.Max, - ImGui::GetColorU32(ImGuiCol_TextDisabled), opt.help_text, &text_size, - ImVec2(0.0f, 0.0f), width, &rect); + str.format("##help_{}{}", stage_index, opt.name); + ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyle().Colors[ImGuiCol_TextDisabled]); + MenuButton(str, opt.help_text, false); + ImGui::PopStyleColor(); } if (opt.ShouldHide()) @@ -6636,9 +6622,8 @@ void FullscreenUI::DrawPatchesOrCheatsSettingsPage(bool cheats) ImVec2 button_pos(ImGui::GetCursorPos()); // Align value text in middle. - ImGui::SetCursorPosY( - button_pos.y + - ((LayoutScale(LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY) + padding.y * 2.0f) - UIStyle.LargeFontSize) * 0.5f); + ImGui::SetCursorPosY(button_pos.y + + ((UIStyle.LargeFontSize + padding.y * 2.0f) - UIStyle.LargeFontSize) * 0.5f); ImGui::TextUnformatted(visible_value.c_str(), visible_value.end_ptr()); s32 step = 0; @@ -6663,8 +6648,7 @@ void FullscreenUI::DrawPatchesOrCheatsSettingsPage(bool cheats) range_value_changed = true; } - ImGui::SetCursorPosY(button_pos.y + (padding.y * 2.0f) + - LayoutScale(LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY + 10.0f)); + ImGui::SetCursorPosY(button_pos.y + (padding.y * 2.0f) + UIStyle.LargeFontSize + LayoutScale(10.0f)); if (range_value_changed) { @@ -7253,9 +7237,8 @@ void FullscreenUI::DrawSaveStateSelector() }; ImGuiIO& io = ImGui::GetIO(); - const ImVec2 heading_size = - ImVec2(io.DisplaySize.x, LayoutScale(LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY) + - (LayoutScale(LAYOUT_MENU_BUTTON_Y_PADDING) * 2.0f) + LayoutScale(2.0f)); + const ImVec2 heading_size = ImVec2( + io.DisplaySize.x, UIStyle.LargeFontSize + (LayoutScale(LAYOUT_MENU_BUTTON_Y_PADDING) * 2.0f) + LayoutScale(2.0f)); bool closed = false; @@ -7712,9 +7695,8 @@ void FullscreenUI::DrawGameListWindow() PopulateGameListEntryList(); ImGuiIO& io = ImGui::GetIO(); - const ImVec2 heading_size = - ImVec2(io.DisplaySize.x, LayoutScale(LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY) + - (LayoutScale(LAYOUT_MENU_BUTTON_Y_PADDING) * 2.0f) + LayoutScale(2.0f)); + const ImVec2 heading_size = ImVec2( + io.DisplaySize.x, UIStyle.LargeFontSize + (LayoutScale(LAYOUT_MENU_BUTTON_Y_PADDING) * 2.0f) + LayoutScale(2.0f)); if (BeginFullscreenWindow(ImVec2(0.0f, 0.0f), heading_size, "gamelist_view", MulAlpha(UIStyle.PrimaryColor, GetBackgroundAlpha()))) diff --git a/src/util/imgui_fullscreen.cpp b/src/util/imgui_fullscreen.cpp index 79589a601..2341e0f0b 100644 --- a/src/util/imgui_fullscreen.cpp +++ b/src/util/imgui_fullscreen.cpp @@ -1363,26 +1363,6 @@ float ImGuiFullscreen::GetMenuButtonAvailableWidth() return MenuButtonBounds::CalcAvailWidth(); } -bool ImGuiFullscreen::IsNextMenuButtonClipped(std::string_view str_id, bool has_summary, - float y_padding /*= LAYOUT_MENU_BUTTON_Y_PADDING*/) -{ - ImGuiWindow* window = ImGui::GetCurrentWindow(); - const ImGuiID id = window->GetID(IMSTR_START_END(str_id)); - const ImGuiStyle& style = ImGui::GetStyle(); - const ImVec2 guessed_pos = window->DC.CursorPos; - const ImRect gussed_bb = - ImRect(guessed_pos, guessed_pos + ImVec2(style.FramePadding.x * 2.0f, - style.FramePadding.y * 2.0f + - (has_summary ? MenuButtonBounds::GetSummaryLineHeight(y_padding) : - MenuButtonBounds::GetSingleLineHeight(y_padding)))); - if (!ImGui::IsClippedEx(gussed_bb, id)) - return false; - - // still record it - ImGui::ItemSize(gussed_bb.GetSize()); - return ImGui::ItemAdd(gussed_bb, id); -} - bool ImGuiFullscreen::MenuButtonFrame(std::string_view str_id, float height, bool enabled, ImRect* item_bb, bool* visible, bool* hovered, ImGuiButtonFlags flags /*= 0*/, float alpha /*= 1.0f*/) @@ -1419,13 +1399,6 @@ void ImGuiFullscreen::DrawWindowTitle(std::string_view title) dl->AddLine(line_start, line_end, IM_COL32(255, 255, 255, 255), line_thickness); } -void ImGuiFullscreen::GetMenuButtonFrameBounds(float height, ImVec2* pos, ImVec2* size) -{ - ImGuiWindow* window = ImGui::GetCurrentWindowRead(); - *pos = window->DC.CursorPos; - *size = ImVec2(window->WorkRect.GetWidth(), LayoutScale(height) + ImGui::GetStyle().FramePadding.y * 2.0f); -} - bool ImGuiFullscreen::MenuButtonFrame(std::string_view str_id, bool enabled, const ImRect& bb, bool* visible, bool* hovered, ImGuiButtonFlags flags, float hover_alpha) { @@ -1548,9 +1521,10 @@ void ImGuiFullscreen::MenuButtonBounds::SetValueSize(const ImVec2& size) void ImGuiFullscreen::MenuButtonBounds::CalcTitleSize(const std::string_view& title) { - title_size = title.empty() ? ImVec2() : - UIStyle.Font->CalcTextSizeA(UIStyle.LargeFontSize, UIStyle.BoldFontWeight, FLT_MAX, - available_non_value_width, IMSTR_START_END(title)); + const std::string_view real_title = ImGuiFullscreen::RemoveHash(title); + title_size = real_title.empty() ? ImVec2() : + UIStyle.Font->CalcTextSizeA(UIStyle.LargeFontSize, UIStyle.BoldFontWeight, FLT_MAX, + available_non_value_width, IMSTR_START_END(real_title)); } void ImGuiFullscreen::MenuButtonBounds::CalcSummarySize(const std::string_view& summary) @@ -1831,7 +1805,7 @@ bool ImGuiFullscreen::MenuHeadingButton(std::string_view title, std::string_view const MenuButtonBounds bb(title, value, {}); bool visible, hovered; - const bool pressed = MenuButtonFrame(title, false, bb.frame_bb, &visible, &hovered); + const bool pressed = MenuButtonFrame(title, enabled, bb.frame_bb, &visible, &hovered); if (!visible) return false; diff --git a/src/util/imgui_fullscreen.h b/src/util/imgui_fullscreen.h index 6d6b7d7dd..a402eab08 100644 --- a/src/util/imgui_fullscreen.h +++ b/src/util/imgui_fullscreen.h @@ -36,8 +36,6 @@ static constexpr float LAYOUT_SCREEN_HEIGHT = 720.0f; static constexpr float LAYOUT_LARGE_FONT_SIZE = 26.0f; static constexpr float LAYOUT_MEDIUM_FONT_SIZE = 16.0f; static constexpr float LAYOUT_SMALL_FONT_SIZE = 10.0f; -static constexpr float LAYOUT_MENU_BUTTON_HEIGHT = 50.0f; -static constexpr float LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY = 26.0f; static constexpr float LAYOUT_MENU_BUTTON_X_PADDING = 15.0f; static constexpr float LAYOUT_MENU_BUTTON_Y_PADDING = 10.0f; static constexpr float LAYOUT_MENU_BUTTON_SPACING = 6.0f; @@ -167,7 +165,7 @@ ALWAYS_INLINE static u32 MulAlpha(u32 col32, u32 a) ALWAYS_INLINE static std::string_view RemoveHash(std::string_view s) { - const std::string_view::size_type pos = s.find('#'); + const std::string_view::size_type pos = s.find("##"); return (pos != std::string_view::npos) ? s.substr(0, pos) : s; } @@ -281,8 +279,6 @@ void BeginMenuButtons(u32 num_items = 0, float y_align = 0.0f, float x_padding = float y_spacing = LAYOUT_MENU_BUTTON_SPACING, bool prerender_frame = true); void EndMenuButtons(); float GetMenuButtonAvailableWidth(); -bool IsNextMenuButtonClipped(std::string_view str_id, bool has_summary, float y_padding = LAYOUT_MENU_BUTTON_Y_PADDING); -void GetMenuButtonFrameBounds(float height, ImVec2* pos, ImVec2* size); bool MenuButtonFrame(std::string_view str_id, float height, bool enabled, ImRect* item_bb, bool* visible, bool* hovered, ImGuiButtonFlags flags = 0, float alpha = 1.0f); void DrawMenuButtonFrame(const ImVec2& p_min, const ImVec2& p_max, ImU32 fill_col, bool border = true);