FullscreenUI: Remove redundant ActiveButton() and friends

This commit is contained in:
Stenzek 2025-03-28 19:45:52 +10:00
parent f80a77fa27
commit 6f2225fb61
No known key found for this signature in database
3 changed files with 88 additions and 163 deletions

View File

@ -91,7 +91,6 @@ using ImGuiFullscreen::LAYOUT_SCREEN_HEIGHT;
using ImGuiFullscreen::LAYOUT_SCREEN_WIDTH; using ImGuiFullscreen::LAYOUT_SCREEN_WIDTH;
using ImGuiFullscreen::UIStyle; using ImGuiFullscreen::UIStyle;
using ImGuiFullscreen::ActiveButton;
using ImGuiFullscreen::AddNotification; using ImGuiFullscreen::AddNotification;
using ImGuiFullscreen::BeginFixedPopupModal; using ImGuiFullscreen::BeginFixedPopupModal;
using ImGuiFullscreen::BeginFullscreenColumns; using ImGuiFullscreen::BeginFullscreenColumns;
@ -103,7 +102,6 @@ using ImGuiFullscreen::BeginNavBar;
using ImGuiFullscreen::CancelPendingMenuClose; using ImGuiFullscreen::CancelPendingMenuClose;
using ImGuiFullscreen::CenterImage; using ImGuiFullscreen::CenterImage;
using ImGuiFullscreen::DarkerColor; using ImGuiFullscreen::DarkerColor;
using ImGuiFullscreen::DefaultActiveButton;
using ImGuiFullscreen::EndFixedPopupModal; using ImGuiFullscreen::EndFixedPopupModal;
using ImGuiFullscreen::EndFullscreenColumns; using ImGuiFullscreen::EndFullscreenColumns;
using ImGuiFullscreen::EndFullscreenColumnWindow; using ImGuiFullscreen::EndFullscreenColumnWindow;
@ -4347,7 +4345,7 @@ void FullscreenUI::DrawEmulationSettingsPage()
"system requirements."); "system requirements.");
} }
ActiveButton(rewind_summary, false, false, ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, UIStyle.LargeFont); MenuButtonWithoutSummary(rewind_summary, false);
EndMenuButtons(); EndMenuButtons();
} }
@ -5937,10 +5935,10 @@ void FullscreenUI::DrawAchievementsSettingsPage()
if (Achievements::IsUsingRAIntegration()) if (Achievements::IsUsingRAIntegration())
{ {
BeginMenuButtons(); BeginMenuButtons();
ActiveButton( MenuButtonWithoutSummary(
FSUI_ICONSTR(ICON_FA_BAN, FSUI_ICONSTR(ICON_FA_BAN,
FSUI_CSTR("RAIntegration is being used instead of the built-in achievements implementation.")), FSUI_CSTR("RAIntegration is being used instead of the built-in achievements implementation.")),
false, false, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY); false);
EndMenuButtons(); EndMenuButtons();
return; return;
} }
@ -6000,18 +5998,18 @@ void FullscreenUI::DrawAchievementsSettingsPage()
if (bsi->ContainsValue("Cheevos", "Token")) if (bsi->ContainsValue("Cheevos", "Token"))
{ {
ImGui::PushStyleColor(ImGuiCol_TextDisabled, ImGui::GetStyle().Colors[ImGuiCol_Text]); ImGui::PushStyleColor(ImGuiCol_TextDisabled, ImGui::GetStyle().Colors[ImGuiCol_Text]);
ActiveButton(SmallString::from_format(fmt::runtime(FSUI_ICONSTR(ICON_FA_USER, "Username: {}")), MenuButtonWithoutSummary(SmallString::from_format(fmt::runtime(FSUI_ICONSTR(ICON_FA_USER, "Username: {}")),
bsi->GetTinyStringValue("Cheevos", "Username")), bsi->GetTinyStringValue("Cheevos", "Username")),
false, false, ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY); false);
TinyString ts_string; TinyString ts_string;
ts_string.format( ts_string.format(
FSUI_FSTR("{:%Y-%m-%d %H:%M:%S}"), FSUI_FSTR("{:%Y-%m-%d %H:%M:%S}"),
fmt::localtime( fmt::localtime(
StringUtil::FromChars<u64>(bsi->GetTinyStringValue("Cheevos", "LoginTimestamp", "0")).value_or(0))); StringUtil::FromChars<u64>(bsi->GetTinyStringValue("Cheevos", "LoginTimestamp", "0")).value_or(0)));
ActiveButton( MenuButtonWithoutSummary(
SmallString::from_format(fmt::runtime(FSUI_ICONSTR(ICON_FA_CLOCK, "Login token generated on {}")), ts_string), SmallString::from_format(fmt::runtime(FSUI_ICONSTR(ICON_FA_CLOCK, "Login token generated on {}")), ts_string),
false, false, ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY); false);
ImGui::PopStyleColor(); ImGui::PopStyleColor();
if (MenuButton(FSUI_ICONSTR(ICON_FA_KEY, "Logout"), FSUI_CSTR("Logs out of RetroAchievements."))) if (MenuButton(FSUI_ICONSTR(ICON_FA_KEY, "Logout"), FSUI_CSTR("Logs out of RetroAchievements.")))
@ -6021,8 +6019,7 @@ void FullscreenUI::DrawAchievementsSettingsPage()
} }
else else
{ {
ActiveButton(FSUI_ICONSTR(ICON_FA_USER, "Not Logged In"), false, false, MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_USER, "Not Logged In"), false);
ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY);
if (MenuButton(FSUI_ICONSTR(ICON_FA_KEY, "Login"), FSUI_CSTR("Logs in to RetroAchievements."))) if (MenuButton(FSUI_ICONSTR(ICON_FA_KEY, "Login"), FSUI_CSTR("Logs in to RetroAchievements.")))
{ {
@ -6040,28 +6037,21 @@ void FullscreenUI::DrawAchievementsSettingsPage()
const auto lock = Achievements::GetLock(); const auto lock = Achievements::GetLock();
ImGui::PushStyleColor(ImGuiCol_TextDisabled, ImGui::GetStyle().Colors[ImGuiCol_Text]); ImGui::PushStyleColor(ImGuiCol_TextDisabled, ImGui::GetStyle().Colors[ImGuiCol_Text]);
ActiveButton(SmallString::from_format(fmt::runtime(FSUI_ICONSTR(ICON_FA_BOOKMARK, "Game: {} ({})")), MenuButtonWithoutSummary(SmallString::from_format(fmt::runtime(FSUI_ICONSTR(ICON_FA_BOOKMARK, "Game: {} ({})")),
Achievements::GetGameID(), Achievements::GetGameTitle()), Achievements::GetGameID(), Achievements::GetGameTitle()),
false, false, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY); false);
const std::string& rich_presence_string = Achievements::GetRichPresenceString(); const std::string& rich_presence_string = Achievements::GetRichPresenceString();
if (!rich_presence_string.empty()) if (!rich_presence_string.empty())
{ MenuButtonWithoutSummary(SmallString::from_format(ICON_FA_MAP "{}", rich_presence_string), false);
ActiveButton(SmallString::from_format(ICON_FA_MAP "{}", rich_presence_string), false, false,
LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY);
}
else else
{ MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_MAP, "Rich presence inactive or unsupported."), false);
ActiveButton(FSUI_ICONSTR(ICON_FA_MAP, "Rich presence inactive or unsupported."), false, false,
LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY);
}
ImGui::PopStyleColor(); ImGui::PopStyleColor();
} }
else else
{ {
ActiveButton(FSUI_ICONSTR(ICON_FA_BAN, "Game not loaded or no RetroAchievements available."), false, false, MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_BAN, "Game not loaded or no RetroAchievements available."), false);
LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY);
} }
} }
@ -6120,7 +6110,7 @@ void FullscreenUI::DrawAchievementsLoginWindow()
const bool login_enabled = (std::strlen(username) > 0 && std::strlen(password) > 0 && !is_logging_in); const bool login_enabled = (std::strlen(username) > 0 && std::strlen(password) > 0 && !is_logging_in);
if (ActiveButton(FSUI_ICONSTR(ICON_FA_KEY, "Login"), false, login_enabled)) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_KEY, "Login"), login_enabled))
{ {
ImGuiFullscreen::OpenBackgroundProgressDialog(LOGIN_PROGRESS_NAME, FSUI_STR("Logging in to RetroAchievements..."), ImGuiFullscreen::OpenBackgroundProgressDialog(LOGIN_PROGRESS_NAME, FSUI_STR("Logging in to RetroAchievements..."),
0, 0, 0); 0, 0, 0);
@ -6153,7 +6143,7 @@ void FullscreenUI::DrawAchievementsLoginWindow()
}); });
} }
if (ActiveButton(FSUI_ICONSTR(ICON_FA_TIMES, "Cancel"), false, !is_logging_in)) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_TIMES, "Cancel"), !is_logging_in))
popup_closed = true; popup_closed = true;
popup_closed = popup_closed || (!is_logging_in && WantsToCloseMenu()); popup_closed = popup_closed || (!is_logging_in && WantsToCloseMenu());
@ -6439,11 +6429,11 @@ void FullscreenUI::DrawPatchesOrCheatsSettingsPage(bool cheats)
if (cheats) if (cheats)
{ {
ActiveButton( MenuButtonWithoutSummary(
FSUI_ICONSTR( FSUI_ICONSTR(
ICON_EMOJI_WARNING, ICON_EMOJI_WARNING,
"WARNING: Activating cheats can cause unpredictable behavior, crashing, soft-locks, or broken saved games."), "WARNING: Activating cheats can cause unpredictable behavior, crashing, soft-locks, or broken saved games."),
false, false, ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY); false);
MenuHeading(FSUI_CSTR("Settings")); MenuHeading(FSUI_CSTR("Settings"));
@ -6486,8 +6476,7 @@ void FullscreenUI::DrawPatchesOrCheatsSettingsPage(bool cheats)
if (code_list.empty()) if (code_list.empty())
{ {
ActiveButton(FSUI_ICONSTR(ICON_FA_STORE_ALT_SLASH, "No cheats are available for this game."), false, false, MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_STORE_ALT_SLASH, "No cheats are available for this game."), false);
ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY);
} }
else else
{ {
@ -6510,16 +6499,15 @@ void FullscreenUI::DrawPatchesOrCheatsSettingsPage(bool cheats)
} }
else else
{ {
ActiveButton( MenuButtonWithoutSummary(
FSUI_ICONSTR(ICON_EMOJI_WARNING, FSUI_ICONSTR(ICON_EMOJI_WARNING,
"WARNING: Activating game patches can cause unpredictable behavior, crashing, soft-locks, or broken " "WARNING: Activating game patches can cause unpredictable behavior, crashing, soft-locks, or broken "
"saved games."), "saved games."),
false, false, ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY); false);
if (code_list.empty()) if (code_list.empty())
{ {
ActiveButton(FSUI_ICONSTR(ICON_FA_STORE_ALT_SLASH, "No patches are available for this game."), false, false, MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_STORE_ALT_SLASH, "No patches are available for this game."), false);
ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY);
} }
else else
{ {
@ -6652,34 +6640,36 @@ void FullscreenUI::DrawPauseMenu()
// NOTE: Menu close must come first, because otherwise VM destruction options will race. // NOTE: Menu close must come first, because otherwise VM destruction options will race.
const bool has_game = GPUThread::HasGPUBackend(); const bool has_game = GPUThread::HasGPUBackend();
if (DefaultActiveButton(FSUI_ICONSTR(ICON_FA_PLAY, "Resume Game"), false) || WantsToCloseMenu()) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_PLAY, "Resume Game")) || WantsToCloseMenu())
ClosePauseMenu(); ClosePauseMenu();
else
ImGui::SetItemDefaultFocus();
if (ActiveButton(FSUI_ICONSTR(ICON_FA_FAST_FORWARD, "Toggle Fast Forward"), false)) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_FAST_FORWARD, "Toggle Fast Forward"), false))
{ {
ClosePauseMenu(); ClosePauseMenu();
DoToggleFastForward(); DoToggleFastForward();
} }
if (ActiveButton(FSUI_ICONSTR(ICON_FA_UNDO, "Load State"), false, has_game)) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_UNDO, "Load State"), has_game))
OpenSaveStateSelector(s_state.current_game_serial, s_state.current_game_path, true); OpenSaveStateSelector(s_state.current_game_serial, s_state.current_game_path, true);
if (ActiveButton(FSUI_ICONSTR(ICON_FA_DOWNLOAD, "Save State"), false, has_game)) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_DOWNLOAD, "Save State"), has_game))
OpenSaveStateSelector(s_state.current_game_serial, s_state.current_game_path, false); OpenSaveStateSelector(s_state.current_game_serial, s_state.current_game_path, false);
if (ActiveButton(FSUI_ICONSTR(ICON_FA_GAMEPAD, "Toggle Analog"), false)) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_GAMEPAD, "Toggle Analog")))
{ {
ClosePauseMenu(); ClosePauseMenu();
DoToggleAnalogMode(); DoToggleAnalogMode();
} }
if (ActiveButton(FSUI_ICONSTR(ICON_FA_WRENCH, "Game Properties"), false, has_game)) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_WRENCH, "Game Properties"), has_game))
{ {
SwitchToGameSettings(); SwitchToGameSettings();
} }
if (ActiveButton(FSUI_ICONSTR(ICON_FA_TROPHY, "Achievements"), false, if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_TROPHY, "Achievements"),
Achievements::HasAchievementsOrLeaderboards())) Achievements::HasAchievementsOrLeaderboards()))
{ {
// skip second menu and go straight to cheevos if there's no lbs // skip second menu and go straight to cheevos if there's no lbs
if (!Achievements::HasLeaderboards()) if (!Achievements::HasLeaderboards())
@ -6688,22 +6678,22 @@ void FullscreenUI::DrawPauseMenu()
OpenPauseSubMenu(PauseSubMenu::Achievements); OpenPauseSubMenu(PauseSubMenu::Achievements);
} }
if (ActiveButton(FSUI_ICONSTR(ICON_FA_CAMERA, "Save Screenshot"), false)) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_CAMERA, "Save Screenshot")))
{ {
Host::RunOnCPUThread([]() { System::SaveScreenshot(); }); Host::RunOnCPUThread([]() { System::SaveScreenshot(); });
ClosePauseMenu(); ClosePauseMenu();
} }
if (ActiveButton(FSUI_ICONSTR(ICON_FA_COMPACT_DISC, "Change Disc"), false)) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_COMPACT_DISC, "Change Disc")))
{ {
s_state.current_main_window = MainWindowType::None; s_state.current_main_window = MainWindowType::None;
Host::RunOnCPUThread([]() { BeginChangeDiscOnCPUThread(false); }); Host::RunOnCPUThread([]() { BeginChangeDiscOnCPUThread(false); });
} }
if (ActiveButton(FSUI_ICONSTR(ICON_FA_SLIDERS_H, "Settings"), false)) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_SLIDERS_H, "Settings")))
SwitchToSettings(); SwitchToSettings();
if (ActiveButton(FSUI_ICONSTR(ICON_FA_POWER_OFF, "Close Game"), false)) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_POWER_OFF, "Close Game")))
{ {
// skip submenu when we can't save anyway // skip submenu when we can't save anyway
if (!has_game) if (!has_game)
@ -6716,29 +6706,33 @@ void FullscreenUI::DrawPauseMenu()
case PauseSubMenu::Exit: case PauseSubMenu::Exit:
{ {
if (ActiveButton(FSUI_ICONSTR(ICON_PF_NAVIGATION_BACK, "Back To Pause Menu"), false) || WantsToCloseMenu()) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_PF_NAVIGATION_BACK, "Back To Pause Menu")) || WantsToCloseMenu())
OpenPauseSubMenu(PauseSubMenu::None); OpenPauseSubMenu(PauseSubMenu::None);
else
ImGui::SetItemDefaultFocus();
if (ActiveButton(FSUI_ICONSTR(ICON_FA_SYNC, "Reset System"), false)) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_SYNC, "Reset System")))
RequestReset(); RequestReset();
if (ActiveButton(FSUI_ICONSTR(ICON_FA_SAVE, "Exit And Save State"), false)) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_SAVE, "Exit And Save State")))
RequestShutdown(true); RequestShutdown(true);
if (DefaultActiveButton(FSUI_ICONSTR(ICON_FA_POWER_OFF, "Exit Without Saving"), false)) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_POWER_OFF, "Exit Without Saving")))
RequestShutdown(false); RequestShutdown(false);
} }
break; break;
case PauseSubMenu::Achievements: case PauseSubMenu::Achievements:
{ {
if (ActiveButton(FSUI_ICONSTR(ICON_PF_NAVIGATION_BACK, "Back To Pause Menu"), false) || WantsToCloseMenu()) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_PF_NAVIGATION_BACK, "Back To Pause Menu")) || WantsToCloseMenu())
OpenPauseSubMenu(PauseSubMenu::None); OpenPauseSubMenu(PauseSubMenu::None);
else
ImGui::SetItemDefaultFocus();
if (DefaultActiveButton(FSUI_ICONSTR(ICON_FA_TROPHY, "Achievements"), false)) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_TROPHY, "Achievements")))
OpenAchievementsWindow(); OpenAchievementsWindow();
if (ActiveButton(FSUI_ICONSTR(ICON_FA_STOPWATCH, "Leaderboards"), false)) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_STOPWATCH, "Leaderboards")))
OpenLeaderboardsWindow(); OpenLeaderboardsWindow();
} }
break; break;
@ -7042,9 +7036,8 @@ void FullscreenUI::DrawSaveStateSelector(bool is_loading)
BeginMenuButtons(); BeginMenuButtons();
if (ActiveButton(is_loading ? FSUI_ICONSTR(ICON_FA_FOLDER_OPEN, "Load State") : if (MenuButtonWithoutSummary(is_loading ? FSUI_ICONSTR(ICON_FA_FOLDER_OPEN, "Load State") :
FSUI_ICONSTR(ICON_FA_FOLDER_OPEN, "Save State"), FSUI_ICONSTR(ICON_FA_FOLDER_OPEN, "Save State")))
false, true, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY))
{ {
if (is_loading) if (is_loading)
DoLoadState(std::move(entry.path)); DoLoadState(std::move(entry.path));
@ -7055,8 +7048,7 @@ void FullscreenUI::DrawSaveStateSelector(bool is_loading)
was_close_not_back = true; was_close_not_back = true;
} }
if (!entry.path.empty() && ActiveButton(FSUI_ICONSTR(ICON_FA_FOLDER_MINUS, "Delete Save"), false, true, if (!entry.path.empty() && MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_FOLDER_MINUS, "Delete Save")))
LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY))
{ {
if (!FileSystem::FileExists(entry.path.c_str())) if (!FileSystem::FileExists(entry.path.c_str()))
{ {
@ -7090,9 +7082,7 @@ void FullscreenUI::DrawSaveStateSelector(bool is_loading)
} }
} }
if (ActiveButton(FSUI_ICONSTR(ICON_FA_WINDOW_CLOSE, "Close Menu"), false, true, if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_WINDOW_CLOSE, "Close Menu")) || WantsToCloseMenu())
LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY) ||
WantsToCloseMenu())
{ {
is_open = false; is_open = false;
ignore_close_request = true; ignore_close_request = true;
@ -7296,19 +7286,19 @@ void FullscreenUI::DrawResumeStateSelector()
ResetFocusHere(); ResetFocusHere();
BeginMenuButtons(); BeginMenuButtons();
if (ActiveButton(FSUI_ICONSTR(ICON_FA_PLAY, "Load State"), false)) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_PLAY, "Load State")))
{ {
DoStartPath(s_state.save_state_selector_game_path, std::move(entry.path)); DoStartPath(s_state.save_state_selector_game_path, std::move(entry.path));
is_open = false; is_open = false;
} }
if (ActiveButton(FSUI_ICONSTR(ICON_FA_LIGHTBULB, "Clean Boot"), false)) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_LIGHTBULB, "Clean Boot")))
{ {
DoStartPath(s_state.save_state_selector_game_path); DoStartPath(s_state.save_state_selector_game_path);
is_open = false; is_open = false;
} }
if (ActiveButton(FSUI_ICONSTR(ICON_FA_FOLDER_MINUS, "Delete State"), false)) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_FOLDER_MINUS, "Delete State")))
{ {
if (FileSystem::DeleteFile(entry.path.c_str())) if (FileSystem::DeleteFile(entry.path.c_str()))
{ {
@ -7321,7 +7311,7 @@ void FullscreenUI::DrawResumeStateSelector()
} }
} }
if (ActiveButton(FSUI_ICONSTR(ICON_FA_WINDOW_CLOSE, "Cancel"), false) || WantsToCloseMenu()) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_WINDOW_CLOSE, "Cancel")) || WantsToCloseMenu())
{ {
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();
is_open = false; is_open = false;
@ -8473,14 +8463,14 @@ void FullscreenUI::DrawAboutWindow()
ImGui::NewLine(); ImGui::NewLine();
BeginMenuButtons(); BeginMenuButtons();
if (ActiveButton(FSUI_ICONSTR(ICON_FA_GLOBE, "GitHub Repository"), false)) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_GLOBE, "GitHub Repository")))
ExitFullscreenAndOpenURL("https://github.com/stenzek/duckstation/"); ExitFullscreenAndOpenURL("https://github.com/stenzek/duckstation/");
if (ActiveButton(FSUI_ICONSTR(ICON_FA_COMMENT, "Discord Server"), false)) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_COMMENT, "Discord Server")))
ExitFullscreenAndOpenURL("https://www.duckstation.org/discord.html"); ExitFullscreenAndOpenURL("https://www.duckstation.org/discord.html");
if (ActiveButton(FSUI_ICONSTR(ICON_FA_PEOPLE_CARRY, "Contributor List"), false)) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_PEOPLE_CARRY, "Contributor List")))
ExitFullscreenAndOpenURL("https://github.com/stenzek/duckstation/blob/master/CONTRIBUTORS.md"); ExitFullscreenAndOpenURL("https://github.com/stenzek/duckstation/blob/master/CONTRIBUTORS.md");
if (ActiveButton(FSUI_ICONSTR(ICON_FA_WINDOW_CLOSE, "Close"), false) || WantsToCloseMenu()) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_WINDOW_CLOSE, "Close")) || WantsToCloseMenu())
{ {
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();
s_state.about_window_open = false; s_state.about_window_open = false;

View File

@ -1520,59 +1520,8 @@ bool ImGuiFullscreen::MenuHeadingButton(const char* title, const char* value /*=
return pressed; return pressed;
} }
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::DefaultActiveButton(const char* title, bool is_active, bool enabled /* = true */,
float height /* = LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY */,
ImFont* font /* = g_large_font */)
{
const bool result = ActiveButtonWithRightText(title, nullptr, is_active, enabled, height, font);
ImGui::SetItemDefaultFocus();
return result;
}
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
const float border_size = ImGui::GetStyle().FrameBorderSize;
const ImVec2 border_size_v = ImVec2(border_size, border_size);
ImVec2 pos, size;
GetMenuButtonFrameBounds(height, &pos, &size);
ImGui::RenderFrame(pos + border_size_v, pos + size - border_size_v, ImGui::GetColorU32(UIStyle.PrimaryColor), false,
LayoutScale(MENU_ITEM_BORDER_ROUNDING));
}
ImRect bb;
bool visible, hovered;
bool pressed = MenuButtonFrame(title, enabled, height, &visible, &hovered, &bb);
if (!visible)
return false;
const ImRect title_bb(bb.GetTL(), bb.GetBR());
const u32 text_color = ImGui::GetColorU32(enabled ? ImGuiCol_Text : ImGuiCol_TextDisabled);
RenderShadowedTextClipped(font, title_bb.Min, title_bb.Max, text_color, title, nullptr, nullptr, ImVec2(0.0f, 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);
RenderShadowedTextClipped(font, right_text_start, title_bb.Max, text_color, right_title, nullptr, &right_text_size,
ImVec2(0.0f, 0.0f), 0.0f, &title_bb);
}
s_state.menu_button_index++;
return pressed;
}
bool ImGuiFullscreen::MenuButton(const char* title, const char* summary, bool enabled, float height, ImFont* font, bool ImGuiFullscreen::MenuButton(const char* title, const char* summary, bool enabled, float height, ImFont* font,
ImFont* summary_font) ImFont* summary_font, const ImVec2& text_align /*= ImVec2(0.0f, 0.0f)*/)
{ {
ImRect bb; ImRect bb;
bool visible, hovered; bool visible, hovered;
@ -1582,41 +1531,29 @@ bool ImGuiFullscreen::MenuButton(const char* title, const char* summary, bool en
const float midpoint = bb.Min.y + font->FontSize + LayoutScale(4.0f); const float midpoint = bb.Min.y + font->FontSize + LayoutScale(4.0f);
const ImRect title_bb(bb.Min, ImVec2(bb.Max.x, midpoint)); const ImRect title_bb(bb.Min, ImVec2(bb.Max.x, midpoint));
const ImRect summary_bb(ImVec2(bb.Min.x, midpoint), bb.Max);
const ImVec4& color = ImGui::GetStyle().Colors[enabled ? ImGuiCol_Text : ImGuiCol_TextDisabled];
RenderShadowedTextClipped(font, title_bb.Min, title_bb.Max, ImGui::GetColorU32(color), title, nullptr, nullptr,
ImVec2(0.0f, 0.0f), 0.0f, &title_bb);
if (summary)
{
RenderShadowedTextClipped(summary_font, summary_bb.Min, summary_bb.Max, ImGui::GetColorU32(DarkerColor(color)),
summary, nullptr, nullptr, ImVec2(0.0f, 0.0f), 0.0f, &summary_bb);
}
s_state.menu_button_index++;
return pressed;
}
bool ImGuiFullscreen::MenuButtonWithoutSummary(const char* title, bool enabled, float height, ImFont* font,
const ImVec2& text_align)
{
ImRect bb;
bool visible, hovered;
bool pressed = MenuButtonFrame(title, enabled, height, &visible, &hovered, &bb);
if (!visible)
return false;
const float midpoint = bb.Min.y + font->FontSize + LayoutScale(4.0f);
const ImRect title_bb(bb.Min, ImVec2(bb.Max.x, midpoint));
const ImRect summary_bb(ImVec2(bb.Min.x, midpoint), bb.Max);
const ImVec4& color = ImGui::GetStyle().Colors[enabled ? ImGuiCol_Text : ImGuiCol_TextDisabled]; const ImVec4& color = ImGui::GetStyle().Colors[enabled ? ImGuiCol_Text : ImGuiCol_TextDisabled];
RenderShadowedTextClipped(font, title_bb.Min, title_bb.Max, ImGui::GetColorU32(color), title, nullptr, nullptr, RenderShadowedTextClipped(font, title_bb.Min, title_bb.Max, ImGui::GetColorU32(color), title, nullptr, nullptr,
text_align, 0.0f, &title_bb); text_align, 0.0f, &title_bb);
if (summary)
{
const ImRect summary_bb(ImVec2(bb.Min.x, midpoint), bb.Max);
RenderShadowedTextClipped(summary_font, summary_bb.Min, summary_bb.Max, ImGui::GetColorU32(DarkerColor(color)),
summary, nullptr, nullptr, text_align, 0.0f, &summary_bb);
}
s_state.menu_button_index++; s_state.menu_button_index++;
return pressed; return pressed;
} }
bool ImGuiFullscreen::MenuButtonWithoutSummary(const char* title, bool enabled /*= true*/,
float height /*= LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY*/,
ImFont* font /*= UIStyle.LargeFont*/,
const ImVec2& text_align /*= ImVec2(0.0f, 0.0f)*/)
{
return MenuButton(title, nullptr, enabled, height, font, nullptr, text_align);
}
bool ImGuiFullscreen::MenuImageButton(const char* title, const char* summary, ImTextureID user_texture_id, bool ImGuiFullscreen::MenuImageButton(const char* title, const char* summary, ImTextureID user_texture_id,
const ImVec2& image_size, bool enabled, float height, const ImVec2& uv0, const ImVec2& image_size, bool enabled, float height, const ImVec2& uv0,
const ImVec2& uv1, ImFont* title_font, ImFont* summary_font) const ImVec2& uv1, ImFont* title_font, ImFont* summary_font)
@ -1920,7 +1857,9 @@ bool ImGuiFullscreen::RangeButton(const char* title, const char* summary, s32* v
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + LayoutScale(10.0f)); ImGui::SetCursorPosY(ImGui::GetCursorPosY() + LayoutScale(10.0f));
if (MenuButtonWithoutSummary(ok_text, true, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, UIStyle.LargeFont, if (MenuButtonWithoutSummary(ok_text, true, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, UIStyle.LargeFont,
ImVec2(0.5f, 0.0f))) ImVec2(0.5f, 0.0f)))
{
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();
}
EndMenuButtons(); EndMenuButtons();
EndFixedPopupModal(); EndFixedPopupModal();
@ -2001,7 +1940,6 @@ bool ImGuiFullscreen::MenuButtonWithValue(const char* title, const char* summary
const float midpoint = bb.Min.y + font->FontSize + LayoutScale(4.0f); const float midpoint = bb.Min.y + font->FontSize + LayoutScale(4.0f);
const float text_end = bb.Max.x - value_size.x; const float text_end = bb.Max.x - value_size.x;
const ImRect title_bb(bb.Min, ImVec2(text_end, midpoint)); const ImRect title_bb(bb.Min, ImVec2(text_end, midpoint));
const ImRect summary_bb(ImVec2(bb.Min.x, midpoint), ImVec2(text_end, bb.Max.y));
const ImVec4& color = ImGui::GetStyle().Colors[enabled ? ImGuiCol_Text : ImGuiCol_TextDisabled]; const ImVec4& color = ImGui::GetStyle().Colors[enabled ? ImGuiCol_Text : ImGuiCol_TextDisabled];
RenderShadowedTextClipped(font, title_bb.Min, title_bb.Max, ImGui::GetColorU32(color), title, nullptr, nullptr, RenderShadowedTextClipped(font, title_bb.Min, title_bb.Max, ImGui::GetColorU32(color), title, nullptr, nullptr,
ImVec2(0.0f, 0.0f), 0.0f, &title_bb); ImVec2(0.0f, 0.0f), 0.0f, &title_bb);
@ -2010,6 +1948,7 @@ bool ImGuiFullscreen::MenuButtonWithValue(const char* title, const char* summary
if (summary) if (summary)
{ {
const ImRect summary_bb(ImVec2(bb.Min.x, midpoint), ImVec2(text_end, bb.Max.y));
RenderShadowedTextClipped(summary_font, summary_bb.Min, summary_bb.Max, ImGui::GetColorU32(DarkerColor(color)), RenderShadowedTextClipped(summary_font, summary_bb.Min, summary_bb.Max, ImGui::GetColorU32(DarkerColor(color)),
summary, nullptr, nullptr, ImVec2(0.0f, 0.0f), 0.0f, &summary_bb); summary, nullptr, nullptr, ImVec2(0.0f, 0.0f), 0.0f, &summary_bb);
} }
@ -2665,7 +2604,7 @@ void ImGuiFullscreen::DrawChoiceDialog()
// draw background first, because otherwise it'll obscure the frame border // draw background first, because otherwise it'll obscure the frame border
for (s32 i = 0; i < static_cast<s32>(s_state.choice_dialog_options.size()); i++) for (s32 i = 0; i < static_cast<s32>(s_state.choice_dialog_options.size()); i++)
{ {
auto& option = s_state.choice_dialog_options[i]; const auto& option = s_state.choice_dialog_options[i];
if (!option.second) if (!option.second)
continue; continue;
@ -2681,8 +2620,9 @@ void ImGuiFullscreen::DrawChoiceDialog()
for (s32 i = 0; i < static_cast<s32>(s_state.choice_dialog_options.size()); i++) for (s32 i = 0; i < static_cast<s32>(s_state.choice_dialog_options.size()); i++)
{ {
auto& option = s_state.choice_dialog_options[i]; auto& option = s_state.choice_dialog_options[i];
if (ActiveButtonWithRightText(option.first.c_str(), option.second ? ICON_FA_CHECK : nullptr, false, true, if (option.second ? MenuButtonWithValue(option.first.c_str(), nullptr, ICON_FA_CHECK, true,
LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY)) LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY) :
MenuButtonWithoutSummary(option.first.c_str()))
{ {
choice = i; choice = i;
for (s32 j = 0; j < static_cast<s32>(s_state.choice_dialog_options.size()); j++) for (s32 j = 0; j < static_cast<s32>(s_state.choice_dialog_options.size()); j++)
@ -2790,7 +2730,7 @@ void ImGuiFullscreen::DrawInputDialog()
const bool ok_enabled = !s_state.input_dialog_text.empty(); const bool ok_enabled = !s_state.input_dialog_text.empty();
if (ActiveButton(s_state.input_dialog_ok_text.c_str(), false, ok_enabled) && ok_enabled) if (MenuButtonWithoutSummary(s_state.input_dialog_ok_text.c_str(), ok_enabled) && ok_enabled)
{ {
// have to move out in case they open another dialog in the callback // have to move out in case they open another dialog in the callback
InputStringDialogCallback cb(std::move(s_state.input_dialog_callback)); InputStringDialogCallback cb(std::move(s_state.input_dialog_callback));
@ -2800,7 +2740,7 @@ void ImGuiFullscreen::DrawInputDialog()
cb(std::move(text)); cb(std::move(text));
} }
if (ActiveButton(ICON_FA_TIMES " Cancel", false)) if (MenuButtonWithoutSummary(ICON_FA_TIMES " Cancel"))
{ {
CloseInputDialog(); CloseInputDialog();
@ -2938,7 +2878,7 @@ void ImGuiFullscreen::DrawMessageDialog()
for (s32 button_index = 0; button_index < static_cast<s32>(s_state.message_dialog_buttons.size()); button_index++) for (s32 button_index = 0; button_index < static_cast<s32>(s_state.message_dialog_buttons.size()); button_index++)
{ {
if (!s_state.message_dialog_buttons[button_index].empty() && if (!s_state.message_dialog_buttons[button_index].empty() &&
ActiveButton(s_state.message_dialog_buttons[button_index].c_str(), false)) MenuButtonWithoutSummary(s_state.message_dialog_buttons[button_index].c_str()))
{ {
result = button_index; result = button_index;
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();

View File

@ -265,14 +265,9 @@ void RenderShadowedTextClipped(ImDrawList* draw_list, ImFont* font, const ImVec2
const ImVec2& align, float wrap_width, const ImRect* clip_rect, float shadow_offset); const ImVec2& align, float wrap_width, const ImRect* clip_rect, float shadow_offset);
void MenuHeading(const char* title, bool draw_line = true); void MenuHeading(const char* title, bool draw_line = true);
bool MenuHeadingButton(const char* title, const char* value = nullptr, bool enabled = true, bool draw_line = true); 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 = UIStyle.LargeFont);
bool DefaultActiveButton(const char* title, bool is_active, bool enabled = true,
float height = LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, ImFont* font = UIStyle.LargeFont);
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 = UIStyle.LargeFont);
bool MenuButton(const char* title, const char* summary, bool enabled = true, float height = LAYOUT_MENU_BUTTON_HEIGHT, bool MenuButton(const char* title, const char* summary, bool enabled = true, float height = LAYOUT_MENU_BUTTON_HEIGHT,
ImFont* font = UIStyle.LargeFont, ImFont* summary_font = UIStyle.MediumFont); ImFont* font = UIStyle.LargeFont, ImFont* summary_font = UIStyle.MediumFont,
const ImVec2& text_align = ImVec2(0.0f, 0.0f));
bool MenuButtonWithoutSummary(const char* title, bool enabled = true, bool MenuButtonWithoutSummary(const char* title, bool enabled = true,
float height = LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, ImFont* font = UIStyle.LargeFont, float height = LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, ImFont* font = UIStyle.LargeFont,
const ImVec2& text_align = ImVec2(0.0f, 0.0f)); const ImVec2& text_align = ImVec2(0.0f, 0.0f));