From 04fdd09d1e1786a8523c0dee57be21b842e234b3 Mon Sep 17 00:00:00 2001 From: KamFretoZ <14798312+kamfretoz@users.noreply.github.com> Date: Sun, 18 Aug 2024 22:31:28 +0700 Subject: [PATCH] ImGuiFullscreen: Display checkmark on right of choice dialog Backport from: https://github.com/stenzek/duckstation/commit/f5815f3183a5c99b974e66ff9f39dae54f17cbff --- pcsx2/ImGui/ImGuiFullscreen.cpp | 30 ++++++++++++++++++++++++------ pcsx2/ImGui/ImGuiFullscreen.h | 2 ++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/pcsx2/ImGui/ImGuiFullscreen.cpp b/pcsx2/ImGui/ImGuiFullscreen.cpp index 8c29d149ed848..d3f92d26d96c8 100644 --- a/pcsx2/ImGui/ImGuiFullscreen.cpp +++ b/pcsx2/ImGui/ImGuiFullscreen.cpp @@ -1088,10 +1088,16 @@ bool ImGuiFullscreen::MenuHeadingButton( } bool ImGuiFullscreen::ActiveButton(const char* title, bool is_active, bool enabled, float height, ImFont* font) +{ + return ActiveButtonWithRightText(title, nullptr, is_active, enabled, height, font); +} + +bool ImGuiFullscreen::ActiveButtonWithRightText(const char* title, const char* right_title, bool is_active, + bool enabled, float height, ImFont* font) { if (is_active) { - // don't draw over a prerendered border + // don't draw over a prerendered border const float border_size = ImGui::GetStyle().FrameBorderSize; const ImVec2 border_size_v = ImVec2(border_size, border_size); ImVec2 pos, size; @@ -1112,6 +1118,16 @@ bool ImGuiFullscreen::ActiveButton(const char* title, bool is_active, bool enabl ImGui::PushFont(font); ImGui::RenderTextClipped(title_bb.Min, title_bb.Max, title, nullptr, nullptr, ImVec2(0.0f, 0.0f), &title_bb); + + + if (right_title && *right_title) + { + const ImVec2 right_text_size = font->CalcTextSizeA(font->FontSize, title_bb.GetWidth(), 0.0f, right_title); + const ImVec2 right_text_start = ImVec2(title_bb.Max.x - right_text_size.x, title_bb.Min.y); + ImGui::RenderTextClipped(right_text_start, title_bb.Max, right_title, nullptr, &right_text_size, ImVec2(0.0f, 0.0f), + &title_bb); + } + ImGui::PopFont(); if (!enabled) @@ -1983,8 +1999,8 @@ void ImGuiFullscreen::DrawFileSelector() if (!s_file_selector_current_directory.empty()) { - MenuButton(fmt::format(ICON_FA_FOLDER_OPEN " {}", s_file_selector_current_directory).c_str(), nullptr, false, - LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY); + MenuButton(SmallString::from_format(ICON_FA_FOLDER_OPEN " {}", s_file_selector_current_directory).c_str(), + nullptr, false, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY); } if (s_file_selector_directory && !s_file_selector_current_directory.empty()) @@ -2124,7 +2140,8 @@ void ImGuiFullscreen::DrawChoiceDialog() { auto& option = s_choice_dialog_options[i]; - const std::string title(fmt::format("{0} {1}", option.second ? ICON_FA_CHECK_SQUARE : ICON_FA_SQUARE, option.first)); + const SmallString title = + SmallString::from_format("{0} {1}", option.second ? ICON_FA_CHECK_SQUARE : ICON_FA_SQUARE, option.first); if (MenuButton(title.c_str(), nullptr, true, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY)) { choice = i; @@ -2142,7 +2159,8 @@ void ImGuiFullscreen::DrawChoiceDialog() title += ICON_FA_CHECK " "; title += option.first; - if (ActiveButton(title.c_str(), option.second, true, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY)) + if (ActiveButtonWithRightText(option.first.c_str(), option.second ? ICON_FA_CHECK : nullptr, option.second, + true, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY)) { choice = i; for (s32 j = 0; j < static_cast(s_choice_dialog_options.size()); j++) @@ -2307,7 +2325,7 @@ void ImGuiFullscreen::OpenConfirmMessageDialog( s_message_dialog_callback = std::move(callback); s_message_dialog_buttons[0] = std::move(yes_button_text); s_message_dialog_buttons[1] = std::move(no_button_text); - QueueResetFocus(FocusResetType::PopupOpened); + QueueResetFocus(FocusResetType::PopupOpened); } void ImGuiFullscreen::OpenInfoMessageDialog( diff --git a/pcsx2/ImGui/ImGuiFullscreen.h b/pcsx2/ImGui/ImGuiFullscreen.h index 5289230229cae..8dd73311b550a 100644 --- a/pcsx2/ImGui/ImGuiFullscreen.h +++ b/pcsx2/ImGui/ImGuiFullscreen.h @@ -167,6 +167,8 @@ namespace ImGuiFullscreen bool MenuHeadingButton(const char* title, const char* value = nullptr, bool enabled = true, bool draw_line = true); bool ActiveButton(const char* title, bool is_active, bool enabled = true, float height = LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, ImFont* font = g_large_font); + bool ActiveButtonWithRightText(const char* title, const char* right_title, bool is_active, bool enabled = true, + float height = LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, ImFont* font = g_large_font); bool MenuButton(const char* title, const char* summary, bool enabled = true, float height = LAYOUT_MENU_BUTTON_HEIGHT, ImFont* font = g_large_font, ImFont* summary_font = g_medium_font); bool MenuButtonWithoutSummary(const char* title, bool enabled = true, float height = LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY,