FullscreenUI: Allow using right mouse button for 'back'

This commit is contained in:
Stenzek 2025-01-27 14:00:10 +10:00
parent 224cb6ac8e
commit 1b678d0ebc
No known key found for this signature in database
3 changed files with 40 additions and 15 deletions

View File

@ -97,6 +97,7 @@ using ImGuiFullscreen::BeginFullscreenWindow;
using ImGuiFullscreen::BeginHorizontalMenu;
using ImGuiFullscreen::BeginMenuButtons;
using ImGuiFullscreen::BeginNavBar;
using ImGuiFullscreen::CancelPendingMenuClose;
using ImGuiFullscreen::CenterImage;
using ImGuiFullscreen::DefaultActiveButton;
using ImGuiFullscreen::DrawShadowedText;
@ -2192,6 +2193,7 @@ void FullscreenUI::DrawInputBindingButton(SettingsInterface* bsi, InputBindingIn
}
else if (ImGui::IsItemClicked(ImGuiMouseButton_Right) || ImGui::IsKeyPressed(ImGuiKey_NavGamepadMenu, false))
{
CancelPendingMenuClose();
bsi->DeleteValue(section, name);
SetSettingsChanged(bsi);
}
@ -7149,6 +7151,7 @@ void FullscreenUI::DrawSaveStateSelector(bool is_loading)
(ImGui::IsItemClicked(ImGuiMouseButton_Right) ||
ImGui::IsKeyPressed(ImGuiKey_NavGamepadInput, false) || ImGui::IsKeyPressed(ImGuiKey_F1, false)))
{
CancelPendingMenuClose();
s_state.save_state_selector_submenu_index = static_cast<s32>(i);
}
}
@ -7665,6 +7668,7 @@ void FullscreenUI::DrawGameList(const ImVec2& heading_size)
(ImGui::IsItemClicked(ImGuiMouseButton_Right) || ImGui::IsKeyPressed(ImGuiKey_NavGamepadInput, false) ||
ImGui::IsKeyPressed(ImGuiKey_F3, false)))
{
CancelPendingMenuClose();
HandleGameListOptions(selected_entry);
}
}
@ -7927,6 +7931,7 @@ void FullscreenUI::DrawGameGrid(const ImVec2& heading_size)
(ImGui::IsItemClicked(ImGuiMouseButton_Right) || ImGui::IsKeyPressed(ImGuiKey_NavGamepadInput, false) ||
ImGui::IsKeyPressed(ImGuiKey_F3, false)))
{
CancelPendingMenuClose();
HandleGameListOptions(entry);
}
}

View File

@ -63,6 +63,16 @@ static ImGuiID GetBackgroundProgressID(const char* str_id);
namespace {
enum class CloseButtonState
{
None,
KeyboardPressed,
MousePressed,
GamepadPressed,
AnyReleased,
Cancelled,
};
struct FileSelectorItem
{
FileSelectorItem() = default;
@ -109,7 +119,7 @@ struct ALIGN_TO_CACHE_LINE UIState
std::recursive_mutex shared_state_mutex;
u32 menu_button_index = 0;
u32 close_button_state = 0;
CloseButtonState close_button_state = CloseButtonState::None;
ImGuiDir has_pending_nav_move = ImGuiDir_None;
FocusResetType focus_reset_queued = FocusResetType::None;
bool initialized = false;
@ -199,7 +209,7 @@ bool ImGuiFullscreen::Initialize(const char* placeholder_image_path)
std::unique_lock lock(s_state.shared_state_mutex);
s_state.focus_reset_queued = FocusResetType::ViewChanged;
s_state.close_button_state = 0;
s_state.close_button_state = CloseButtonState::None;
s_state.placeholder_texture = LoadTexture(placeholder_image_path);
if (!s_state.placeholder_texture)
@ -661,7 +671,8 @@ void ImGuiFullscreen::PopResetLayout()
void ImGuiFullscreen::QueueResetFocus(FocusResetType type)
{
s_state.focus_reset_queued = type;
s_state.close_button_state = 0;
s_state.close_button_state =
(s_state.close_button_state != CloseButtonState::Cancelled) ? CloseButtonState::None : CloseButtonState::Cancelled;
}
bool ImGuiFullscreen::ResetFocusHere()
@ -728,29 +739,37 @@ bool ImGuiFullscreen::WantsToCloseMenu()
{
ImGuiContext& g = *GImGui;
// Wait for the Close button to be released, THEN pressed
if (s_state.close_button_state == 0)
// Wait for the Close button to be pressed, THEN released
if (s_state.close_button_state == CloseButtonState::None)
{
if (ImGui::IsKeyPressed(ImGuiKey_Escape, false))
s_state.close_button_state = 1;
s_state.close_button_state = CloseButtonState::KeyboardPressed;
else if (ImGui::IsKeyPressed(ImGuiKey_MouseRight, false))
s_state.close_button_state = CloseButtonState::MousePressed;
else if (ImGui::IsKeyPressed(ImGuiKey_NavGamepadCancel, false))
s_state.close_button_state = 2;
s_state.close_button_state = CloseButtonState::GamepadPressed;
}
else if ((s_state.close_button_state == 1 && ImGui::IsKeyReleased(ImGuiKey_Escape)) ||
(s_state.close_button_state == 2 && ImGui::IsKeyReleased(ImGuiKey_NavGamepadCancel)))
else if ((s_state.close_button_state == CloseButtonState::KeyboardPressed && ImGui::IsKeyReleased(ImGuiKey_Escape)) ||
(s_state.close_button_state == CloseButtonState::MousePressed &&
ImGui::IsKeyReleased(ImGuiKey_MouseRight)) ||
(s_state.close_button_state == CloseButtonState::GamepadPressed &&
ImGui::IsKeyReleased(ImGuiKey_NavGamepadCancel)))
{
s_state.close_button_state = 3;
s_state.close_button_state = CloseButtonState::AnyReleased;
}
return s_state.close_button_state > 1;
return (s_state.close_button_state == CloseButtonState::AnyReleased);
}
void ImGuiFullscreen::ResetCloseMenuIfNeeded()
{
// If s_close_button_state reached the "Released" state, reset it after the tick
if (s_state.close_button_state > 1)
{
s_state.close_button_state = 0;
}
s_state.close_button_state =
(s_state.close_button_state >= CloseButtonState::AnyReleased) ? CloseButtonState::None : s_state.close_button_state;
}
void ImGuiFullscreen::CancelPendingMenuClose()
{
s_state.close_button_state = CloseButtonState::Cancelled;
}
void ImGuiFullscreen::PushPrimaryColor()

View File

@ -171,6 +171,7 @@ void ForceKeyNavEnabled();
bool WantsToCloseMenu();
void ResetCloseMenuIfNeeded();
void CancelPendingMenuClose();
void PushPrimaryColor();
void PopPrimaryColor();