ImGuiFullscreen: Fix whole menu being unscrollable

If the first/last menu items were not enabled, e.g. settings pages
This commit is contained in:
Stenzek 2024-09-09 21:37:52 +10:00
parent 15d26c976d
commit 18f2f7512e
No known key found for this signature in database
1 changed files with 25 additions and 0 deletions

View File

@ -89,6 +89,7 @@ ImVec4 UISecondaryTextColor;
static u32 s_menu_button_index = 0; static u32 s_menu_button_index = 0;
static u32 s_close_button_state = 0; static u32 s_close_button_state = 0;
static ImGuiDir s_has_pending_nav_move = ImGuiDir_None;
static FocusResetType s_focus_reset_queued = FocusResetType::None; static FocusResetType s_focus_reset_queued = FocusResetType::None;
static bool s_light_theme = false; static bool s_light_theme = false;
static bool s_smooth_scrolling = false; static bool s_smooth_scrolling = false;
@ -898,6 +899,30 @@ void ImGuiFullscreen::BeginMenuButtons(u32 num_items, float y_align, float x_pad
{ {
s_menu_button_index = 0; s_menu_button_index = 0;
// If we're scrolling up and down, it's possible that the first menu item won't be enabled.
// If so, track when the scroll happens, and if we moved to a new ID. If not, scroll the parent window.
if (GImGui->NavMoveDir != ImGuiDir_None)
{
s_has_pending_nav_move = GImGui->NavMoveDir;
}
else if (s_has_pending_nav_move != ImGuiDir_None)
{
if (GImGui->NavJustMovedToId == 0)
{
switch (s_has_pending_nav_move)
{
case ImGuiDir_Up:
ImGui::SetScrollY(std::max(ImGui::GetScrollY() - item_height, 0.0f));
break;
case ImGuiDir_Down:
ImGui::SetScrollY(std::min(ImGui::GetScrollY() + item_height, ImGui::GetScrollMaxY()));
break;
}
}
s_has_pending_nav_move = ImGuiDir_None;
}
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, LayoutScale(x_padding, y_padding)); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, LayoutScale(x_padding, y_padding));
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 0.0f); ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, LayoutScale(1.0f)); ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, LayoutScale(1.0f));