From 349af8766cbb6ea7e56b242b18be8476bebbe977 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 14 Oct 2024 13:52:40 +0200 Subject: [PATCH] InputText: ensure mouse cursor is set regardless of whether keyboard mode is enabled or not. (#6417) + Nav comments (#8059) --- docs/CHANGELOG.txt | 2 ++ imgui.cpp | 5 ++++- imgui_internal.h | 1 + imgui_widgets.cpp | 6 +++++- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 977db92e6..a01d5d6bc 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -73,6 +73,8 @@ Other changes: - Tables: fixed initial auto-sizing issue with synched-instances. (#8045, #7218) - InputText: fixed an issue with not declaring ownership of Delete/Backspace/Arrow keys, preventing use of external shortcuts not guarded by an ActiveId check. (#8048) [@geertbleyen] +- InputText: ensure mouse cursor shape is set regardless of whether keyboard mode is + enabled or not. (#6417) - Backends: DX11, DX12, SDLRenderer2/3. Vulkan, WGPU: expose selected state in ImGui_ImplXXXX_RenderState structures during render loop. (#6969, #5834, #7468, #3590) - Backends: DX9, DX10, DX11, DX12, OpenGL, Vulkan, WGPU: Changed default texture sampler diff --git a/imgui.cpp b/imgui.cpp index 3bd7a473a..971f48f16 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4606,7 +4606,7 @@ bool ImGui::ItemHoverable(const ImRect& bb, ImGuiID id, ImGuiItemFlags item_flag } #endif - if (g.NavDisableMouseHover) + if (g.NavDisableMouseHover && (item_flags & ImGuiItemFlags_NoNavDisableMouseHover) == 0) return false; return true; @@ -13340,8 +13340,11 @@ static void ImGui::NavUpdateCancelRequest() else { // Clear NavLastId for popups but keep it for regular child window so we can leave one and come back where we were + // FIXME-NAV: This should happen on window appearing. if (g.NavWindow && ((g.NavWindow->Flags & ImGuiWindowFlags_Popup) || !(g.NavWindow->Flags & ImGuiWindowFlags_ChildWindow))) g.NavWindow->NavLastIds[0] = 0; + + // Clear nav focus g.NavId = 0; } } diff --git a/imgui_internal.h b/imgui_internal.h index 05378c3d9..5722291af 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -833,6 +833,7 @@ enum ImGuiItemFlagsPrivate_ ImGuiItemFlags_MixedValue = 1 << 12, // false // [BETA] Represent a mixed/indeterminate value, generally multi-selection where values differ. Currently only supported by Checkbox() (later should support all sorts of widgets) ImGuiItemFlags_NoWindowHoverableCheck = 1 << 13, // false // Disable hoverable check in ItemHoverable() ImGuiItemFlags_AllowOverlap = 1 << 14, // false // Allow being overlapped by another widget. Not-hovered to Hovered transition deferred by a frame. + ImGuiItemFlags_NoNavDisableMouseHover = 1 << 15, // false // Nav keyboard/gamepad mode doesn't disable hover. // Controlled by widget code ImGuiItemFlags_Inputable = 1 << 20, // false // [WIP] Auto-activate input mode when tab focused. Currently only used and supported by a few items before it becomes a generic feature. diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 9d4ef66da..aac7383b1 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -4462,9 +4462,13 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ if (!ItemAdd(total_bb, id, &frame_bb, ImGuiItemFlags_Inputable)) return false; } - const bool hovered = ItemHoverable(frame_bb, id, g.LastItemData.InFlags); + + // Ensure mouse cursor is set even after switching to keyboard/gamepad mode. May generalize further? (#6417) + bool hovered = ItemHoverable(frame_bb, id, g.LastItemData.InFlags | ImGuiItemFlags_NoNavDisableMouseHover); if (hovered) SetMouseCursor(ImGuiMouseCursor_TextInput); + if (hovered && g.NavDisableMouseHover) + hovered = false; // We are only allowed to access the state if we are already the active widget. ImGuiInputTextState* state = GetInputTextState(id);