From 49ee151ed6ce9b8043542ae5b1e2472e5bfa4bad Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 13 Mar 2026 15:01:10 +0100 Subject: [PATCH] Nav: pressing gamepad north button activates context menus. + update ShowUserGuide(). --- docs/CHANGELOG.txt | 1 + imgui.cpp | 7 +++++-- imgui.h | 6 +++--- imgui_demo.cpp | 11 ++++++++++- imgui_internal.h | 4 ++-- 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index df0f2bf5e..acc3965ab 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -103,6 +103,7 @@ Other Changes: - Popups: Shift+F10 or Menu key can now open popups menus when using BeginPopupContextItem(), BeginPopupContextWindow() or OpenPopupOnItemClick(). (#8803, #9270) [@exelix11, @ocornut] + - Popups: pressing North button (PS4/PS5 triangle, SwitchX, Xbox Y) also open popups menus. - Clipper: - Clear `DisplayStart`/`DisplayEnd` fields when `Step()` returns false. - Added `UserIndex` helper storage. This is solely a convenience for cases where diff --git a/imgui.cpp b/imgui.cpp index 61a6456bc..b7c5d1b22 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -14252,10 +14252,13 @@ static void ImGui::NavUpdateContextMenuRequest() ImGuiContext& g = *GImGui; g.NavOpenContextMenuItemId = g.NavOpenContextMenuWindowId = 0; const bool nav_keyboard_active = (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) != 0; - if (!nav_keyboard_active || g.NavWindow == NULL) + const bool nav_gamepad_active = (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) != 0; + if ((!nav_keyboard_active && !nav_gamepad_active) || g.NavWindow == NULL) return; - const bool request = IsKeyReleased(ImGuiKey_Menu, ImGuiKeyOwner_NoOwner) || (IsKeyPressed(ImGuiKey_F10, ImGuiInputFlags_None, ImGuiKeyOwner_NoOwner) && g.IO.KeyMods == ImGuiMod_Shift); + bool request = false; + request |= nav_keyboard_active && (IsKeyReleased(ImGuiKey_Menu, ImGuiKeyOwner_NoOwner) || (IsKeyPressed(ImGuiKey_F10, ImGuiInputFlags_None, ImGuiKeyOwner_NoOwner) && g.IO.KeyMods == ImGuiMod_Shift)); + request |= nav_gamepad_active && IsKeyPressed(ImGuiKey_NavGamepadContextMenu, ImGuiInputFlags_None, ImGuiKeyOwner_NoOwner); if (!request) return; g.NavOpenContextMenuItemId = g.NavId; diff --git a/imgui.h b/imgui.h index 349c31040..b69a9b563 100644 --- a/imgui.h +++ b/imgui.h @@ -1618,10 +1618,10 @@ enum ImGuiKey : int // // XBOX | SWITCH | PLAYSTA. | -> ACTION ImGuiKey_GamepadStart, // Menu | + | Options | ImGuiKey_GamepadBack, // View | - | Share | - ImGuiKey_GamepadFaceLeft, // X | Y | Square | Tap: Toggle Menu. Hold: Windowing mode (Focus/Move/Resize windows) + ImGuiKey_GamepadFaceLeft, // X | Y | Square | Toggle Menu. Hold for Windowing mode (Focus/Move/Resize windows) ImGuiKey_GamepadFaceRight, // B | A | Circle | Cancel / Close / Exit - ImGuiKey_GamepadFaceUp, // Y | X | Triangle | - ImGuiKey_GamepadFaceDown, // A | B | Cross | Activate / Open / Toggle / Tweak. Hold for 0.60f to Activate in Text Input mode (e.g. wired to an on-screen keyboard). + ImGuiKey_GamepadFaceUp, // Y | X | Triangle | Open Context Menu + ImGuiKey_GamepadFaceDown, // A | B | Cross | Activate / Open / Toggle. Hold for 0.60f to Activate in Text Input mode (e.g. wired to an on-screen keyboard). ImGuiKey_GamepadDpadLeft, // D-pad Left | " | " | Move / Tweak / Resize Window (in Windowing mode) ImGuiKey_GamepadDpadRight, // D-pad Right | " | " | Move / Tweak / Resize Window (in Windowing mode) ImGuiKey_GamepadDpadUp, // D-pad Up | " | " | Move / Tweak / Resize Window (in Windowing mode) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index e8a43924c..738096c57 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -8731,7 +8731,7 @@ void ImGui::ShowUserGuide() BulletText("Ctrl+Z to undo, Ctrl+Y/Ctrl+Shift+Z to redo."); BulletText("Escape to revert."); Unindent(); - BulletText("With keyboard navigation enabled:"); + BulletText("With Keyboard controls enabled:"); Indent(); BulletText("Arrow keys or Home/End/PageUp/PageDown to navigate."); BulletText("Space to activate a widget."); @@ -8740,6 +8740,15 @@ void ImGui::ShowUserGuide() BulletText("Alt to jump to the menu layer of a window."); BulletText("Menu or Shift+F10 to open a context menu."); Unindent(); + BulletText("With Gamepad controls enabled:"); + Indent(); + BulletText("D-Pad: Navigate / Tweak / Resize (in Windowing mode)."); + BulletText("%s Face button: Activate / Open / Toggle. Hold: activate with text input.", io.ConfigNavSwapGamepadButtons ? "East" : "South"); + BulletText("%s Face button: Cancel / Close / Exit.", io.ConfigNavSwapGamepadButtons ? "South" : "East"); + BulletText("West Face button: Toggle Menu. Hold for Windowing mode (Focus/Move/Resize windows)."); + BulletText("North Face button: Open Context Menu."); + BulletText("L1/R1: Tweak Slower/Faster, Focus Previous/Next (in Windowing Mode)."); + Unindent(); } //----------------------------------------------------------------------------- diff --git a/imgui_internal.h b/imgui_internal.h index e9eded337..cb5e4e1c0 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1508,8 +1508,8 @@ typedef ImBitArray ImBitAr #define ImGuiKey_NavGamepadTweakFast ImGuiKey_GamepadR1 #define ImGuiKey_NavGamepadActivate (g.IO.ConfigNavSwapGamepadButtons ? ImGuiKey_GamepadFaceRight : ImGuiKey_GamepadFaceDown) #define ImGuiKey_NavGamepadCancel (g.IO.ConfigNavSwapGamepadButtons ? ImGuiKey_GamepadFaceDown : ImGuiKey_GamepadFaceRight) -#define ImGuiKey_NavGamepadMenu ImGuiKey_GamepadFaceLeft -//#define ImGuiKey_NavGamepadInput ImGuiKey_GamepadFaceUp +#define ImGuiKey_NavGamepadMenu ImGuiKey_GamepadFaceLeft // Toggle menu layer. Hold to enable Windowing. +#define ImGuiKey_NavGamepadContextMenu ImGuiKey_GamepadFaceUp // Open context menu (same as Shift+F10) enum ImGuiInputEventType {