FullscreenUI: Fix popup close resetting window scroll

This commit is contained in:
Stenzek
2024-08-13 17:48:31 +10:00
parent f99d5ff39d
commit 13a37418e6
3 changed files with 61 additions and 44 deletions

View File

@ -71,6 +71,7 @@ public:
#define FSUI_FSTR(str) fmt::runtime(Host::TranslateToStringView(TR_CONTEXT, str))
#define FSUI_NSTR(str) str
using ImGuiFullscreen::FocusResetType;
using ImGuiFullscreen::g_large_font;
using ImGuiFullscreen::g_layout_padding_left;
using ImGuiFullscreen::g_layout_padding_top;
@ -125,6 +126,7 @@ using ImGuiFullscreen::ForceKeyNavEnabled;
using ImGuiFullscreen::GetCachedTexture;
using ImGuiFullscreen::GetCachedTextureAsync;
using ImGuiFullscreen::GetPlaceholderTexture;
using ImGuiFullscreen::GetQueuedFocusResetType;
using ImGuiFullscreen::HorizontalMenuItem;
using ImGuiFullscreen::IsFocusResetQueued;
using ImGuiFullscreen::IsGamepadInputSource;
@ -636,7 +638,7 @@ void FullscreenUI::OnSystemStarted()
return;
s_current_main_window = MainWindowType::None;
QueueResetFocus();
QueueResetFocus(FocusResetType::WindowChanged);
}
void FullscreenUI::OnSystemPaused()
@ -695,7 +697,7 @@ void FullscreenUI::OpenPauseMenu()
PauseForMenuOpen(true);
s_current_main_window = MainWindowType::PauseMenu;
s_current_pause_submenu = PauseSubMenu::None;
QueueResetFocus();
QueueResetFocus(FocusResetType::WindowChanged);
ForceKeyNavEnabled();
FixStateIfPaused();
}
@ -730,7 +732,7 @@ void FullscreenUI::ClosePauseMenu()
s_current_main_window = MainWindowType::None;
s_current_pause_submenu = PauseSubMenu::None;
s_pause_menu_was_open = false;
QueueResetFocus();
QueueResetFocus(FocusResetType::WindowChanged);
FixStateIfPaused();
}
@ -738,7 +740,7 @@ void FullscreenUI::OpenPauseSubMenu(PauseSubMenu submenu)
{
s_current_main_window = MainWindowType::PauseMenu;
s_current_pause_submenu = submenu;
QueueResetFocus();
QueueResetFocus(FocusResetType::WindowChanged);
}
void FullscreenUI::Shutdown()
@ -876,7 +878,7 @@ void FullscreenUI::ReturnToPreviousWindow()
if (System::IsValid() && s_pause_menu_was_open)
{
s_current_main_window = MainWindowType::PauseMenu;
QueueResetFocus();
QueueResetFocus(FocusResetType::WindowChanged);
}
else
{
@ -976,7 +978,6 @@ void FullscreenUI::DoStartFile()
if (!path.empty())
DoStartPath(path);
QueueResetFocus();
CloseFileSelector();
};
@ -1040,7 +1041,6 @@ void FullscreenUI::DoStartDisc()
DoStartDisc(std::move(paths[index]));
CloseChoiceDialog();
QueueResetFocus();
});
}
@ -1117,7 +1117,6 @@ void FullscreenUI::DoChangeDiscFromFile()
}
}
QueueResetFocus();
CloseFileSelector();
ReturnToPreviousWindow();
};
@ -1153,7 +1152,6 @@ void FullscreenUI::DoChangeDisc()
System::SwitchMediaSubImage(static_cast<u32>(index - 1));
}
QueueResetFocus();
CloseChoiceDialog();
ReturnToPreviousWindow();
};
@ -1195,7 +1193,6 @@ void FullscreenUI::DoChangeDisc()
System::InsertMedia(paths[index - 1].c_str());
}
QueueResetFocus();
CloseChoiceDialog();
ReturnToMainWindow();
};
@ -1299,7 +1296,7 @@ void FullscreenUI::DoToggleFullscreen()
void FullscreenUI::SwitchToLanding()
{
s_current_main_window = MainWindowType::Landing;
QueueResetFocus();
QueueResetFocus(FocusResetType::WindowChanged);
}
void FullscreenUI::DrawLandingTemplate(ImVec2* menu_pos, ImVec2* menu_size)
@ -1396,7 +1393,7 @@ void FullscreenUI::DrawLandingWindow()
FSUI_CSTR("Launch a game from a file, disc, or starts the console without any disc inserted.")))
{
s_current_main_window = MainWindowType::StartGame;
QueueResetFocus();
QueueResetFocus(FocusResetType::WindowChanged);
}
if (HorizontalMenuItem(GetCachedTexture("fullscreenui/applications-system.png"), FSUI_CSTR("Settings"),
@ -1410,7 +1407,7 @@ void FullscreenUI::DrawLandingWindow()
(!AreAnyDialogsOpen() && WantsToCloseMenu()))
{
s_current_main_window = MainWindowType::Exit;
QueueResetFocus();
QueueResetFocus(FocusResetType::WindowChanged);
}
}
EndHorizontalMenu();
@ -1481,7 +1478,7 @@ void FullscreenUI::DrawStartGameWindow()
(!AreAnyDialogsOpen() && WantsToCloseMenu()))
{
s_current_main_window = MainWindowType::Landing;
QueueResetFocus();
QueueResetFocus(FocusResetType::WindowChanged);
}
}
EndHorizontalMenu();
@ -1527,7 +1524,7 @@ void FullscreenUI::DrawExitWindow()
WantsToCloseMenu())
{
s_current_main_window = MainWindowType::Landing;
QueueResetFocus();
QueueResetFocus(FocusResetType::WindowChanged);
}
if (HorizontalMenuItem(GetCachedTexture("fullscreenui/exit.png"), FSUI_CSTR("Exit DuckStation"),
@ -2742,7 +2739,7 @@ void FullscreenUI::SwitchToGameSettingsForSerial(std::string_view serial)
s_game_settings_interface->Load();
s_current_main_window = MainWindowType::Settings;
s_settings_page = SettingsPage::Summary;
QueueResetFocus();
QueueResetFocus(FocusResetType::WindowChanged);
}
void FullscreenUI::SwitchToGameSettings()
@ -2884,7 +2881,7 @@ void FullscreenUI::DrawSettingsWindow()
{
index = (index == 0) ? (count - 1) : (index - 1);
s_settings_page = pages[index];
QueueResetFocus();
QueueResetFocus(FocusResetType::WindowChanged);
}
else if (ImGui::IsKeyPressed(ImGuiKey_GamepadDpadRight, true) ||
ImGui::IsKeyPressed(ImGuiKey_NavGamepadTweakFast, true) ||
@ -2892,7 +2889,7 @@ void FullscreenUI::DrawSettingsWindow()
{
index = (index + 1) % count;
s_settings_page = pages[index];
QueueResetFocus();
QueueResetFocus(FocusResetType::WindowChanged);
}
}
@ -2911,6 +2908,7 @@ void FullscreenUI::DrawSettingsWindow()
if (NavButton(icons[i], i == index, true, ITEM_WIDTH, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY))
{
s_settings_page = pages[i];
QueueResetFocus(FocusResetType::WindowChanged);
}
}
@ -2920,8 +2918,13 @@ void FullscreenUI::DrawSettingsWindow()
EndFullscreenWindow();
// we have to do this here, because otherwise it uses target, and jumps a frame later.
if (IsFocusResetQueued())
// don't do it for popups opening/closing, otherwise we lose our position
if (FocusResetType focus_reset = GetQueuedFocusResetType(); focus_reset != FocusResetType::None &&
focus_reset != FocusResetType::PopupOpened &&
focus_reset != FocusResetType::PopupClosed)
{
ImGui::SetNextWindowScroll(ImVec2(0.0f, 0.0f));
}
if (BeginFullscreenWindow(
ImVec2(0.0f, heading_size.y),
@ -5836,7 +5839,7 @@ void FullscreenUI::DrawSaveStateSelector(bool is_loading)
{
s_save_state_selector_submenu_index = -1;
if (!closed)
QueueResetFocus();
QueueResetFocus(FocusResetType::WindowChanged);
}
ImGui::PopStyleColor(3);
@ -6280,7 +6283,7 @@ void FullscreenUI::DrawGameListWindow()
else if (ImGui::IsKeyPressed(ImGuiKey_GamepadStart, false) || ImGui::IsKeyPressed(ImGuiKey_F2))
{
s_current_main_window = MainWindowType::GameListSettings;
QueueResetFocus();
QueueResetFocus(FocusResetType::WindowChanged);
}
switch (s_game_list_view)
@ -6785,7 +6788,7 @@ void FullscreenUI::DrawGameListSettingsWindow()
if (NavButton(ICON_FA_BACKWARD, true, true))
{
s_current_main_window = MainWindowType::GameList;
QueueResetFocus();
QueueResetFocus(FocusResetType::WindowChanged);
}
NavTitle(FSUI_CSTR("Game List Settings"));
@ -6806,7 +6809,7 @@ void FullscreenUI::DrawGameListSettingsWindow()
if (ImGui::IsWindowFocused() && WantsToCloseMenu())
{
s_current_main_window = MainWindowType::GameList;
QueueResetFocus();
QueueResetFocus(FocusResetType::WindowChanged);
}
auto lock = Host::GetSettingsLock();
@ -6960,7 +6963,7 @@ void FullscreenUI::SwitchToGameList()
auto lock = Host::GetSettingsLock();
PopulateGameListDirectoryCache(Host::Internal::GetBaseSettingsLayer());
}
QueueResetFocus();
QueueResetFocus(FocusResetType::WindowChanged);
}
GPUTexture* FullscreenUI::GetGameListCover(const GameList::Entry* entry)
@ -7114,7 +7117,7 @@ void FullscreenUI::OpenAchievementsWindow()
}
s_current_main_window = MainWindowType::Achievements;
QueueResetFocus();
QueueResetFocus(FocusResetType::WindowChanged);
FixStateIfPaused();
}
@ -7148,7 +7151,7 @@ void FullscreenUI::OpenLeaderboardsWindow()
}
s_current_main_window = MainWindowType::Leaderboards;
QueueResetFocus();
QueueResetFocus(FocusResetType::WindowChanged);
FixStateIfPaused();
}