From 4d67f71217ee38155978a44595bae88255979764 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Wed, 15 May 2024 07:18:39 +1000 Subject: [PATCH] FullscreenUI: Add horizontal padding to menu windows Backport of https://github.com/stenzek/duckstation/commit/37a76a020aa67e534425e5b1717587f5899f774f --- pcsx2/Achievements.cpp | 17 +++++++++-------- pcsx2/ImGui/FullscreenUI.cpp | 9 +++++---- pcsx2/ImGui/ImGuiFullscreen.cpp | 12 ++++++------ pcsx2/ImGui/ImGuiFullscreen.h | 7 +++++-- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/pcsx2/Achievements.cpp b/pcsx2/Achievements.cpp index 602ab5c325..ef99c10d43 100644 --- a/pcsx2/Achievements.cpp +++ b/pcsx2/Achievements.cpp @@ -618,7 +618,7 @@ uint32_t Achievements::ClientReadMemory(uint32_t address, uint8_t* buffer, uint3 // Fast paths for known data sizes. switch (num_bytes) { - // clang-format off + // clang-format off case 1: std::memcpy(buffer, ptr, 1); break; case 2: std::memcpy(buffer, ptr, 2); break; case 4: std::memcpy(buffer, ptr, 4); break; @@ -2163,7 +2163,7 @@ void Achievements::DrawAchievementsWindow() const float heading_height = ImGuiFullscreen::LayoutScale(heading_height_unscaled); if (ImGuiFullscreen::BeginFullscreenWindow(ImVec2(0.0f, 0.0f), ImVec2(display_size.x, heading_height), "achievements_heading", - heading_background, 0.0f, 0.0f, ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoScrollWithMouse)) + heading_background, 0.0f, ImVec2(), ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoScrollWithMouse)) { ImRect bb; bool visible, hovered; @@ -2267,7 +2267,7 @@ void Achievements::DrawAchievementsWindow() if (ImGuiFullscreen::BeginFullscreenWindow( ImVec2(0.0f, heading_height), ImVec2(display_size.x, display_size.y - heading_height - LayoutScale(ImGuiFullscreen::LAYOUT_FOOTER_HEIGHT)), - "achievements", background, 0.0f, 0.0f, 0)) + "achievements", background, 0.0f, ImVec2(ImGuiFullscreen::LAYOUT_MENU_WINDOW_X_PADDING, 0.0f), 0)) { static bool buckets_collapsed[NUM_RC_CLIENT_ACHIEVEMENT_BUCKETS] = {}; static const char* bucket_names[NUM_RC_CLIENT_ACHIEVEMENT_BUCKETS] = { @@ -2339,7 +2339,7 @@ void Achievements::DrawAchievement(const rc_client_achievement_t* cheevo) LayoutScale(ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT + 30.0f) - points_template_size.x); const ImVec2 summary_text_size(g_medium_font->CalcTextSizeA(g_medium_font->FontSize, FLT_MAX, summary_wrap_width, cheevo->description, cheevo->description + summary_length)); - + // Messy, but need to undo LayoutScale in MenuButtonFrame()... const float extra_summary_height = LayoutUnscale(std::max(summary_text_size.y - g_medium_font->FontSize, 0.0f)); @@ -2522,8 +2522,9 @@ void Achievements::DrawLeaderboardsWindow() g_large_font->CalcTextSizeA(g_large_font->FontSize, std::numeric_limits::max(), -1.0f, "WWWWWWWWWWW").x; const float column_spacing = spacing * 2.0f; - if (ImGuiFullscreen::BeginFullscreenWindow(ImVec2(0.0f, 0.0f), ImVec2(display_size.x, heading_height), "leaderboards_heading", - heading_background, 0.0f, 0.0f, ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoScrollWithMouse)) + if (ImGuiFullscreen::BeginFullscreenWindow(ImVec2(), ImVec2(display_size.x, heading_height), "leaderboards_heading", + heading_background, 0.0f, ImVec2(), + ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoScrollWithMouse)) { bool visible, hovered; ImGuiFullscreen::MenuButtonFrame( @@ -2697,7 +2698,7 @@ void Achievements::DrawLeaderboardsWindow() if (ImGuiFullscreen::BeginFullscreenWindow( ImVec2(0.0f, heading_height), ImVec2(display_size.x, display_size.y - heading_height - LayoutScale(ImGuiFullscreen::LAYOUT_FOOTER_HEIGHT)), - "leaderboards", background, 0.0f, 0.0f, 0)) + "leaderboards", background, 0.0f, ImVec2(ImGuiFullscreen::LAYOUT_MENU_WINDOW_X_PADDING, 0.0f), 0)) { ImGuiFullscreen::BeginMenuButtons(); @@ -2717,7 +2718,7 @@ void Achievements::DrawLeaderboardsWindow() if (ImGuiFullscreen::BeginFullscreenWindow( ImVec2(0.0f, heading_height), ImVec2(display_size.x, display_size.y - heading_height - LayoutScale(ImGuiFullscreen::LAYOUT_FOOTER_HEIGHT)), - "leaderboard", background, 0.0f, 0.0f, 0)) + "leaderboard", background, 0.0f, ImVec2(ImGuiFullscreen::LAYOUT_MENU_WINDOW_X_PADDING, 0.0f), 0)) { ImGuiFullscreen::BeginMenuButtons(); diff --git a/pcsx2/ImGui/FullscreenUI.cpp b/pcsx2/ImGui/FullscreenUI.cpp index a4ec6891c3..befec14cb6 100644 --- a/pcsx2/ImGui/FullscreenUI.cpp +++ b/pcsx2/ImGui/FullscreenUI.cpp @@ -2906,7 +2906,8 @@ void FullscreenUI::DrawSettingsWindow() ImVec2(0.0f, heading_size.y), ImVec2(io.DisplaySize.x, io.DisplaySize.y - heading_size.y - LayoutScale(LAYOUT_FOOTER_HEIGHT)), TinyString::from_format("settings_page_{}", static_cast(s_settings_page)).c_str(), - ImVec4(UIBackgroundColor.x, UIBackgroundColor.y, UIBackgroundColor.z, bg_alpha))) + ImVec4(UIBackgroundColor.x, UIBackgroundColor.y, UIBackgroundColor.z, bg_alpha), 0.0f, + ImVec2(ImGuiFullscreen::LAYOUT_MENU_WINDOW_X_PADDING, 0.0f))) { ResetFocusHere(); @@ -5039,8 +5040,8 @@ void FullscreenUI::DrawPauseMenu(MainWindowType type) const ImVec2 window_size(LayoutScale(500.0f, LAYOUT_SCREEN_HEIGHT)); const ImVec2 window_pos(0.0f, display_size.y - LayoutScale(LAYOUT_FOOTER_HEIGHT) - window_size.y); - if (BeginFullscreenWindow( - window_pos, window_size, "pause_menu", ImVec4(0.0f, 0.0f, 0.0f, 0.0f), 0.0f, 10.0f, ImGuiWindowFlags_NoBackground)) + if (BeginFullscreenWindow(window_pos, window_size, "pause_menu", ImVec4(0.0f, 0.0f, 0.0f, 0.0f), 0.0f, + ImVec2(10.0f, 10.0f), ImGuiWindowFlags_NoBackground)) { static constexpr u32 submenu_item_count[] = { 11, // None @@ -6310,7 +6311,7 @@ void FullscreenUI::DrawGameListSettingsWindow() if (!BeginFullscreenWindow( ImVec2(0.0f, heading_size.y), ImVec2(io.DisplaySize.x, io.DisplaySize.y - heading_size.y - LayoutScale(LAYOUT_FOOTER_HEIGHT)), - "settings_parent", UIBackgroundColor)) + "settings_parent", UIBackgroundColor, 0.0f, ImVec2(ImGuiFullscreen::LAYOUT_MENU_WINDOW_X_PADDING, 0.0f))) { EndFullscreenWindow(); return; diff --git a/pcsx2/ImGui/ImGuiFullscreen.cpp b/pcsx2/ImGui/ImGuiFullscreen.cpp index e1c491bddb..77f3fbb853 100644 --- a/pcsx2/ImGui/ImGuiFullscreen.cpp +++ b/pcsx2/ImGui/ImGuiFullscreen.cpp @@ -688,8 +688,8 @@ void ImGuiFullscreen::EndFullscreenColumnWindow() } bool ImGuiFullscreen::BeginFullscreenWindow(float left, float top, float width, float height, const char* name, - const ImVec4& background /* = HEX_TO_IMVEC4(0x212121, 0xFF) */, float rounding /*= 0.0f*/, float padding /*= 0.0f*/, - ImGuiWindowFlags flags /*= 0*/) + const ImVec4& background /* = HEX_TO_IMVEC4(0x212121, 0xFF) */, float rounding /*= 0.0f*/, + const ImVec2& padding /*= 0.0f*/, ImGuiWindowFlags flags /*= 0*/) { if (left < 0.0f) left = (LAYOUT_SCREEN_WIDTH - width) * -left; @@ -702,14 +702,14 @@ bool ImGuiFullscreen::BeginFullscreenWindow(float left, float top, float width, } bool ImGuiFullscreen::BeginFullscreenWindow(const ImVec2& position, const ImVec2& size, const char* name, - const ImVec4& background /* = HEX_TO_IMVEC4(0x212121, 0xFF) */, float rounding /*= 0.0f*/, float padding /*= 0.0f*/, - ImGuiWindowFlags flags /*= 0*/) + const ImVec4& background /* = HEX_TO_IMVEC4(0x212121, 0xFF) */, float rounding /*= 0.0f*/, + const ImVec2& padding /*= 0.0f*/, ImGuiWindowFlags flags /*= 0*/) { ImGui::SetNextWindowPos(position); ImGui::SetNextWindowSize(size); ImGui::PushStyleColor(ImGuiCol_WindowBg, background); - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, LayoutScale(padding, padding)); + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, LayoutScale(padding)); ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(rounding)); @@ -1740,7 +1740,7 @@ bool ImGuiFullscreen::BeginHorizontalMenu(const char* name, const ImVec2& positi ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, LayoutScale(1.0f)); ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(item_spacing, 0.0f)); - if (!BeginFullscreenWindow(position, size, name, UIBackgroundColor, 0.0f, 0.0f)) + if (!BeginFullscreenWindow(position, size, name, UIBackgroundColor, 0.0f, ImVec2())) return false; ImGui::SetCursorPos(ImVec2((size.x - menu_width) * 0.5f, (size.y - menu_height) * 0.5f)); diff --git a/pcsx2/ImGui/ImGuiFullscreen.h b/pcsx2/ImGui/ImGuiFullscreen.h index 7b058df6bf..7c7ec85f71 100644 --- a/pcsx2/ImGui/ImGuiFullscreen.h +++ b/pcsx2/ImGui/ImGuiFullscreen.h @@ -34,6 +34,7 @@ namespace ImGuiFullscreen 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_WINDOW_X_PADDING = 12.0f; static constexpr float LAYOUT_FOOTER_PADDING = 10.0f; static constexpr float LAYOUT_FOOTER_HEIGHT = LAYOUT_MEDIUM_FONT_SIZE + LAYOUT_FOOTER_PADDING * 2.0f; static constexpr float LAYOUT_HORIZONTAL_MENU_HEIGHT = 320.0f; @@ -131,9 +132,11 @@ namespace ImGuiFullscreen void EndFullscreenColumnWindow(); bool BeginFullscreenWindow(float left, float top, float width, float height, const char* name, - const ImVec4& background = HEX_TO_IMVEC4(0x212121, 0xFF), float rounding = 0.0f, float padding = 0.0f, ImGuiWindowFlags flags = 0); + const ImVec4& background = HEX_TO_IMVEC4(0x212121, 0xFF), float rounding = 0.0f, const ImVec2& padding = ImVec2(), + ImGuiWindowFlags flags = 0); bool BeginFullscreenWindow(const ImVec2& position, const ImVec2& size, const char* name, - const ImVec4& background = HEX_TO_IMVEC4(0x212121, 0xFF), float rounding = 0.0f, float padding = 0.0f, ImGuiWindowFlags flags = 0); + const ImVec4& background = HEX_TO_IMVEC4(0x212121, 0xFF), float rounding = 0.0f, const ImVec2& padding = ImVec2(), + ImGuiWindowFlags flags = 0); void EndFullscreenWindow(); bool IsGamepadInputSource();