Skip to content

Commit

Permalink
FullscreenUI: Fix popup close resetting window scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Aug 13, 2024
1 parent f99d5ff commit 13a3741
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 44 deletions.
55 changes: 29 additions & 26 deletions src/core/fullscreen_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class IconStackString : public SmallStackString<L>
#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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -636,7 +638,7 @@ void FullscreenUI::OnSystemStarted()
return;

s_current_main_window = MainWindowType::None;
QueueResetFocus();
QueueResetFocus(FocusResetType::WindowChanged);
}

void FullscreenUI::OnSystemPaused()
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -730,15 +732,15 @@ 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();
}

void FullscreenUI::OpenPauseSubMenu(PauseSubMenu submenu)
{
s_current_main_window = MainWindowType::PauseMenu;
s_current_pause_submenu = submenu;
QueueResetFocus();
QueueResetFocus(FocusResetType::WindowChanged);
}

void FullscreenUI::Shutdown()
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -976,7 +978,6 @@ void FullscreenUI::DoStartFile()
if (!path.empty())
DoStartPath(path);

QueueResetFocus();
CloseFileSelector();
};

Expand Down Expand Up @@ -1040,7 +1041,6 @@ void FullscreenUI::DoStartDisc()

DoStartDisc(std::move(paths[index]));
CloseChoiceDialog();
QueueResetFocus();
});
}

Expand Down Expand Up @@ -1117,7 +1117,6 @@ void FullscreenUI::DoChangeDiscFromFile()
}
}

QueueResetFocus();
CloseFileSelector();
ReturnToPreviousWindow();
};
Expand Down Expand Up @@ -1153,7 +1152,6 @@ void FullscreenUI::DoChangeDisc()
System::SwitchMediaSubImage(static_cast<u32>(index - 1));
}

QueueResetFocus();
CloseChoiceDialog();
ReturnToPreviousWindow();
};
Expand Down Expand Up @@ -1195,7 +1193,6 @@ void FullscreenUI::DoChangeDisc()
System::InsertMedia(paths[index - 1].c_str());
}

QueueResetFocus();
CloseChoiceDialog();
ReturnToMainWindow();
};
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"),
Expand All @@ -1410,7 +1407,7 @@ void FullscreenUI::DrawLandingWindow()
(!AreAnyDialogsOpen() && WantsToCloseMenu()))
{
s_current_main_window = MainWindowType::Exit;
QueueResetFocus();
QueueResetFocus(FocusResetType::WindowChanged);
}
}
EndHorizontalMenu();
Expand Down Expand Up @@ -1481,7 +1478,7 @@ void FullscreenUI::DrawStartGameWindow()
(!AreAnyDialogsOpen() && WantsToCloseMenu()))
{
s_current_main_window = MainWindowType::Landing;
QueueResetFocus();
QueueResetFocus(FocusResetType::WindowChanged);
}
}
EndHorizontalMenu();
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -2884,15 +2881,15 @@ 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) ||
ImGui::IsKeyPressed(ImGuiKey_RightArrow, true))
{
index = (index + 1) % count;
s_settings_page = pages[index];
QueueResetFocus();
QueueResetFocus(FocusResetType::WindowChanged);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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),
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"));
Expand All @@ -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();
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -7114,7 +7117,7 @@ void FullscreenUI::OpenAchievementsWindow()
}

s_current_main_window = MainWindowType::Achievements;
QueueResetFocus();
QueueResetFocus(FocusResetType::WindowChanged);
FixStateIfPaused();
}

Expand Down Expand Up @@ -7148,7 +7151,7 @@ void FullscreenUI::OpenLeaderboardsWindow()
}

s_current_main_window = MainWindowType::Leaderboards;
QueueResetFocus();
QueueResetFocus(FocusResetType::WindowChanged);
FixStateIfPaused();
}

Expand Down
Loading

0 comments on commit 13a3741

Please sign in to comment.