mirror of https://github.com/PCSX2/pcsx2.git
FullscreenUI: Fix popup close resetting window scroll
Backport from 13a37418e6
This commit is contained in:
parent
4f405adea9
commit
c72d98d4cd
|
@ -81,6 +81,7 @@ namespace
|
|||
#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;
|
||||
|
@ -134,6 +135,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;
|
||||
|
@ -655,7 +657,7 @@ void FullscreenUI::OnVMStarted()
|
|||
return;
|
||||
|
||||
s_current_main_window = MainWindowType::None;
|
||||
QueueResetFocus();
|
||||
QueueResetFocus(FocusResetType::WindowChanged);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -723,7 +725,7 @@ void FullscreenUI::OpenPauseMenu()
|
|||
ForceKeyNavEnabled();
|
||||
s_current_main_window = MainWindowType::PauseMenu;
|
||||
s_current_pause_submenu = PauseSubMenu::None;
|
||||
QueueResetFocus();
|
||||
QueueResetFocus(FocusResetType::WindowChanged);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -738,14 +740,14 @@ 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);
|
||||
}
|
||||
|
||||
void FullscreenUI::OpenPauseSubMenu(PauseSubMenu submenu)
|
||||
{
|
||||
s_current_main_window = MainWindowType::PauseMenu;
|
||||
s_current_pause_submenu = submenu;
|
||||
QueueResetFocus();
|
||||
QueueResetFocus(FocusResetType::WindowChanged);
|
||||
}
|
||||
|
||||
void FullscreenUI::Shutdown(bool clear_state)
|
||||
|
@ -901,7 +903,7 @@ void FullscreenUI::ReturnToPreviousWindow()
|
|||
if (VMManager::HasValidVM() && 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()
|
|||
FSUI_ICONSTR(ICON_FA_COMPACT_DISC, "Select Disc Drive"), false, std::move(options), [](s32, const std::string& path, bool) {
|
||||
DoStartDisc(path);
|
||||
CloseChoiceDialog();
|
||||
QueueResetFocus();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1115,7 +1115,6 @@ void FullscreenUI::DoChangeDiscFromFile()
|
|||
}
|
||||
}
|
||||
|
||||
QueueResetFocus();
|
||||
CloseFileSelector();
|
||||
ReturnToPreviousWindow();
|
||||
ClosePauseMenu();
|
||||
|
@ -1170,7 +1169,7 @@ void FullscreenUI::ConfirmShutdownIfMemcardBusy(std::function<void(bool)> callba
|
|||
void FullscreenUI::SwitchToLanding()
|
||||
{
|
||||
s_current_main_window = MainWindowType::Landing;
|
||||
QueueResetFocus();
|
||||
QueueResetFocus(FocusResetType::WindowChanged);
|
||||
}
|
||||
|
||||
void FullscreenUI::DrawLandingTemplate(ImVec2* menu_pos, ImVec2* menu_size)
|
||||
|
@ -1267,7 +1266,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"),
|
||||
|
@ -1281,7 +1280,7 @@ void FullscreenUI::DrawLandingWindow()
|
|||
(!AreAnyDialogsOpen() && WantsToCloseMenu()))
|
||||
{
|
||||
s_current_main_window = MainWindowType::Exit;
|
||||
QueueResetFocus();
|
||||
QueueResetFocus(FocusResetType::WindowChanged);
|
||||
}
|
||||
}
|
||||
EndHorizontalMenu();
|
||||
|
@ -1349,7 +1348,7 @@ void FullscreenUI::DrawStartGameWindow()
|
|||
(!AreAnyDialogsOpen() && WantsToCloseMenu()))
|
||||
{
|
||||
s_current_main_window = MainWindowType::Landing;
|
||||
QueueResetFocus();
|
||||
QueueResetFocus(FocusResetType::WindowChanged);
|
||||
}
|
||||
}
|
||||
EndHorizontalMenu();
|
||||
|
@ -1395,7 +1394,7 @@ void FullscreenUI::DrawExitWindow()
|
|||
WantsToCloseMenu())
|
||||
{
|
||||
s_current_main_window = MainWindowType::Landing;
|
||||
QueueResetFocus();
|
||||
QueueResetFocus(FocusResetType::WindowChanged);
|
||||
}
|
||||
|
||||
if (HorizontalMenuItem(GetCachedTexture("fullscreenui/exit.png"), FSUI_CSTR("Exit PCSX2"),
|
||||
|
@ -2701,7 +2700,7 @@ void FullscreenUI::SwitchToGameSettings(const std::string_view serial, u32 crc)
|
|||
PopulatePatchesAndCheatsList(serial, crc);
|
||||
s_current_main_window = MainWindowType::Settings;
|
||||
s_settings_page = SettingsPage::Summary;
|
||||
QueueResetFocus();
|
||||
QueueResetFocus(FocusResetType::WindowChanged);
|
||||
}
|
||||
|
||||
void FullscreenUI::SwitchToGameSettings()
|
||||
|
@ -2844,7 +2843,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) ||
|
||||
|
@ -2852,7 +2851,7 @@ void FullscreenUI::DrawSettingsWindow()
|
|||
{
|
||||
index = (index + 1) % count;
|
||||
s_settings_page = pages[index];
|
||||
QueueResetFocus();
|
||||
QueueResetFocus(FocusResetType::WindowChanged);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2876,6 +2875,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2886,7 +2886,12 @@ void FullscreenUI::DrawSettingsWindow()
|
|||
|
||||
// we have to do this here, because otherwise it uses target, and jumps a frame later.
|
||||
if (IsFocusResetQueued())
|
||||
ImGui::SetNextWindowScroll(ImVec2(0.0f, 0.0f));
|
||||
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),
|
||||
|
@ -3046,7 +3051,7 @@ void FullscreenUI::DrawSummarySettingsPage()
|
|||
}
|
||||
}
|
||||
|
||||
QueueResetFocus();
|
||||
QueueResetFocus(FocusResetType::PopupClosed);
|
||||
CloseFileSelector();
|
||||
};
|
||||
|
||||
|
@ -5517,7 +5522,7 @@ void FullscreenUI::DrawSaveStateSelector(bool is_loading)
|
|||
{
|
||||
s_save_state_selector_submenu_index = -1;
|
||||
if (!closed)
|
||||
QueueResetFocus();
|
||||
QueueResetFocus(FocusResetType::WindowChanged);
|
||||
}
|
||||
|
||||
ImGui::PopStyleColor(4);
|
||||
|
@ -5900,7 +5905,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)
|
||||
|
@ -6318,7 +6323,7 @@ void FullscreenUI::DrawGameListSettingsWindow()
|
|||
if (NavButton(ICON_PF_BACKWARD, true, true))
|
||||
{
|
||||
s_current_main_window = MainWindowType::GameList;
|
||||
QueueResetFocus();
|
||||
QueueResetFocus(FocusResetType::WindowChanged);
|
||||
}
|
||||
|
||||
NavTitle(FSUI_CSTR("Game List Settings"));
|
||||
|
@ -6339,7 +6344,7 @@ void FullscreenUI::DrawGameListSettingsWindow()
|
|||
if (ImGui::IsWindowFocused() && WantsToCloseMenu())
|
||||
{
|
||||
s_current_main_window = MainWindowType::GameList;
|
||||
QueueResetFocus();
|
||||
QueueResetFocus(FocusResetType::WindowChanged);
|
||||
}
|
||||
|
||||
auto lock = Host::GetSettingsLock();
|
||||
|
@ -6495,7 +6500,7 @@ void FullscreenUI::SwitchToGameList()
|
|||
auto lock = Host::GetSettingsLock();
|
||||
PopulateGameListDirectoryCache(Host::Internal::GetBaseSettingsLayer());
|
||||
}
|
||||
QueueResetFocus();
|
||||
QueueResetFocus(FocusResetType::WindowChanged);
|
||||
}
|
||||
|
||||
GSTexture* FullscreenUI::GetGameListCover(const GameList::Entry* entry)
|
||||
|
@ -6665,7 +6670,7 @@ void FullscreenUI::SwitchToAchievementsWindow()
|
|||
}
|
||||
|
||||
s_current_main_window = MainWindowType::Achievements;
|
||||
QueueResetFocus();
|
||||
QueueResetFocus(FocusResetType::WindowChanged);
|
||||
}
|
||||
|
||||
bool FullscreenUI::OpenLeaderboardsWindow()
|
||||
|
@ -6709,7 +6714,7 @@ void FullscreenUI::SwitchToLeaderboardsWindow()
|
|||
}
|
||||
|
||||
s_current_main_window = MainWindowType::Leaderboards;
|
||||
QueueResetFocus();
|
||||
QueueResetFocus(FocusResetType::WindowChanged);
|
||||
}
|
||||
|
||||
void FullscreenUI::DrawAchievementsSettingsPage(std::unique_lock<std::mutex>& settings_lock)
|
||||
|
|
|
@ -85,7 +85,7 @@ namespace ImGuiFullscreen
|
|||
|
||||
static u32 s_menu_button_index = 0;
|
||||
static u32 s_close_button_state = 0;
|
||||
static bool s_focus_reset_queued = false;
|
||||
static FocusResetType s_focus_reset_queued = FocusResetType::None;
|
||||
static bool s_light_theme = false;
|
||||
|
||||
static LRUCache<std::string, std::shared_ptr<GSTexture>> s_texture_cache(128, true);
|
||||
|
@ -204,7 +204,7 @@ void ImGuiFullscreen::SetFonts(ImFont* standard_font, ImFont* medium_font, ImFon
|
|||
|
||||
bool ImGuiFullscreen::Initialize(const char* placeholder_image_path)
|
||||
{
|
||||
s_focus_reset_queued = true;
|
||||
s_focus_reset_queued = FocusResetType::WindowChanged;
|
||||
s_close_button_state = 0;
|
||||
|
||||
s_placeholder_texture = LoadTexture(placeholder_image_path);
|
||||
|
@ -552,22 +552,22 @@ void ImGuiFullscreen::PopResetLayout()
|
|||
ImGui::PopStyleVar(12);
|
||||
}
|
||||
|
||||
void ImGuiFullscreen::QueueResetFocus()
|
||||
void ImGuiFullscreen::QueueResetFocus(FocusResetType type)
|
||||
{
|
||||
s_focus_reset_queued = true;
|
||||
s_focus_reset_queued = type;
|
||||
s_close_button_state = 0;
|
||||
}
|
||||
|
||||
bool ImGuiFullscreen::ResetFocusHere()
|
||||
{
|
||||
if (!s_focus_reset_queued)
|
||||
if (s_focus_reset_queued == FocusResetType::None)
|
||||
return false;
|
||||
|
||||
// don't take focus from dialogs
|
||||
if (ImGui::FindBlockingModal(ImGui::GetCurrentWindow()))
|
||||
return false;
|
||||
|
||||
s_focus_reset_queued = false;
|
||||
s_focus_reset_queued = FocusResetType::None;
|
||||
ImGui::SetWindowFocus();
|
||||
|
||||
// only do the active selection magic when we're using keyboard/gamepad
|
||||
|
@ -575,6 +575,11 @@ bool ImGuiFullscreen::ResetFocusHere()
|
|||
}
|
||||
|
||||
bool ImGuiFullscreen::IsFocusResetQueued()
|
||||
{
|
||||
return (s_focus_reset_queued != FocusResetType::None);
|
||||
}
|
||||
|
||||
ImGuiFullscreen::FocusResetType ImGuiFullscreen::GetQueuedFocusResetType()
|
||||
{
|
||||
return s_focus_reset_queued;
|
||||
}
|
||||
|
@ -1924,7 +1929,7 @@ void ImGuiFullscreen::OpenFileSelector(std::string_view title, bool select_direc
|
|||
s_file_selector_filters = std::move(filters);
|
||||
|
||||
SetFileSelectorDirectory(std::move(initial_directory));
|
||||
QueueResetFocus();
|
||||
QueueResetFocus(FocusResetType::PopupOpened);
|
||||
}
|
||||
|
||||
void ImGuiFullscreen::CloseFileSelector()
|
||||
|
@ -1940,7 +1945,7 @@ void ImGuiFullscreen::CloseFileSelector()
|
|||
std::string().swap(s_file_selector_current_directory);
|
||||
s_file_selector_items.clear();
|
||||
ImGui::CloseCurrentPopup();
|
||||
QueueResetFocus();
|
||||
QueueResetFocus(FocusResetType::PopupClosed);
|
||||
}
|
||||
|
||||
void ImGuiFullscreen::DrawFileSelector()
|
||||
|
@ -2014,7 +2019,7 @@ void ImGuiFullscreen::DrawFileSelector()
|
|||
if (selected->is_file)
|
||||
{
|
||||
s_file_selector_callback(selected->full_path);
|
||||
QueueResetFocus();
|
||||
QueueResetFocus(FocusResetType::Other);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -2039,7 +2044,7 @@ void ImGuiFullscreen::DrawFileSelector()
|
|||
" <Parent Directory>")
|
||||
{
|
||||
SetFileSelectorDirectory(std::move(s_file_selector_items.front().full_path));
|
||||
QueueResetFocus();
|
||||
QueueResetFocus(FocusResetType::Other);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2060,7 +2065,7 @@ void ImGuiFullscreen::OpenChoiceDialog(std::string_view title, bool checkable, C
|
|||
s_choice_dialog_title = fmt::format("{}##choice_dialog", title);
|
||||
s_choice_dialog_options = std::move(options);
|
||||
s_choice_dialog_callback = std::move(callback);
|
||||
QueueResetFocus();
|
||||
QueueResetFocus(FocusResetType::PopupOpened);
|
||||
}
|
||||
|
||||
void ImGuiFullscreen::CloseChoiceDialog()
|
||||
|
@ -2073,7 +2078,7 @@ void ImGuiFullscreen::CloseChoiceDialog()
|
|||
std::string().swap(s_choice_dialog_title);
|
||||
ChoiceDialogOptions().swap(s_choice_dialog_options);
|
||||
ChoiceDialogCallback().swap(s_choice_dialog_callback);
|
||||
QueueResetFocus();
|
||||
QueueResetFocus(FocusResetType::PopupClosed);
|
||||
}
|
||||
|
||||
void ImGuiFullscreen::DrawChoiceDialog()
|
||||
|
@ -2190,7 +2195,7 @@ void ImGuiFullscreen::OpenInputStringDialog(
|
|||
s_input_dialog_caption = std::move(caption);
|
||||
s_input_dialog_ok_text = std::move(ok_button_text);
|
||||
s_input_dialog_callback = std::move(callback);
|
||||
QueueResetFocus();
|
||||
QueueResetFocus(FocusResetType::PopupOpened);
|
||||
}
|
||||
|
||||
void ImGuiFullscreen::DrawInputDialog()
|
||||
|
@ -2299,7 +2304,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();
|
||||
QueueResetFocus(FocusResetType::PopupOpened);
|
||||
}
|
||||
|
||||
void ImGuiFullscreen::OpenInfoMessageDialog(
|
||||
|
@ -2312,7 +2317,7 @@ void ImGuiFullscreen::OpenInfoMessageDialog(
|
|||
s_message_dialog_message = std::move(message);
|
||||
s_message_dialog_callback = std::move(callback);
|
||||
s_message_dialog_buttons[0] = std::move(button_text);
|
||||
QueueResetFocus();
|
||||
QueueResetFocus(FocusResetType::PopupOpened);
|
||||
}
|
||||
|
||||
void ImGuiFullscreen::OpenMessageDialog(std::string title, std::string message, MessageDialogCallback callback,
|
||||
|
@ -2327,7 +2332,7 @@ void ImGuiFullscreen::OpenMessageDialog(std::string title, std::string message,
|
|||
s_message_dialog_buttons[0] = std::move(first_button_text);
|
||||
s_message_dialog_buttons[1] = std::move(second_button_text);
|
||||
s_message_dialog_buttons[2] = std::move(third_button_text);
|
||||
QueueResetFocus();
|
||||
QueueResetFocus(FocusResetType::PopupOpened);
|
||||
}
|
||||
|
||||
void ImGuiFullscreen::CloseMessageDialog()
|
||||
|
@ -2340,7 +2345,7 @@ void ImGuiFullscreen::CloseMessageDialog()
|
|||
s_message_dialog_message = {};
|
||||
s_message_dialog_buttons = {};
|
||||
s_message_dialog_callback = {};
|
||||
QueueResetFocus();
|
||||
QueueResetFocus(FocusResetType::PopupClosed);
|
||||
}
|
||||
|
||||
void ImGuiFullscreen::DrawMessageDialog()
|
||||
|
|
|
@ -112,9 +112,18 @@ namespace ImGuiFullscreen
|
|||
void PushResetLayout();
|
||||
void PopResetLayout();
|
||||
|
||||
void QueueResetFocus();
|
||||
enum class FocusResetType : u8
|
||||
{
|
||||
None,
|
||||
PopupOpened,
|
||||
PopupClosed,
|
||||
WindowChanged,
|
||||
Other,
|
||||
};
|
||||
void QueueResetFocus(FocusResetType type);
|
||||
bool ResetFocusHere();
|
||||
bool IsFocusResetQueued();
|
||||
FocusResetType GetQueuedFocusResetType();
|
||||
void ForceKeyNavEnabled();
|
||||
|
||||
bool WantsToCloseMenu();
|
||||
|
|
Loading…
Reference in New Issue