Browse Source

Focus, InputText: fixed an issue where SetKeyboardFocusHere() did not work on InputTextMultiline() with ImGuiInputTextFlags_AllowTabInput. (#8928)

ocornut 1 ngày trước cách đây
mục cha
commit
2f1d1c8b2f
4 tập tin đã thay đổi với 9 bổ sung3 xóa
  1. 3 0
      docs/CHANGELOG.txt
  2. 2 0
      imgui.cpp
  3. 2 1
      imgui_internal.h
  4. 2 2
      imgui_widgets.cpp

+ 3 - 0
docs/CHANGELOG.txt

@@ -69,6 +69,9 @@ Other Changes:
 - InputText: revert a change in 1.79 where pressing Down or PageDown on the last line
 - InputText: revert a change in 1.79 where pressing Down or PageDown on the last line
   of a multi-line buffer without a trailing carriage return would keep the cursor
   of a multi-line buffer without a trailing carriage return would keep the cursor
   unmoved. We revert back to move to the end of line in this situation.
   unmoved. We revert back to move to the end of line in this situation.
+- Focus, InputText: fixed an issue where SetKeyboardFocusHere() did not work
+  on InputTextMultiline() fields with ImGuiInputTextFlags_AllowTabInput, since
+  they normally inhibit activation to allow tabbing through multiple items. (#8928)
 - Selectable: added ImGuiSelectableFlags_SelectOnNav to auto-select an item when
 - Selectable: added ImGuiSelectableFlags_SelectOnNav to auto-select an item when
   moved into (automatic when in a BeginMultiSelect() block).
   moved into (automatic when in a BeginMultiSelect() block).
 - TabBar: fixed an issue were forcefully selecting a tab using internal API would
 - TabBar: fixed an issue were forcefully selecting a tab using internal API would

+ 2 - 0
imgui.cpp

@@ -13932,6 +13932,8 @@ void ImGui::NavMoveRequestApplyResult()
     {
     {
         g.NavNextActivateId = result->ID;
         g.NavNextActivateId = result->ID;
         g.NavNextActivateFlags = ImGuiActivateFlags_None;
         g.NavNextActivateFlags = ImGuiActivateFlags_None;
+        if (g.NavMoveFlags & ImGuiNavMoveFlags_FocusApi)
+            g.NavNextActivateFlags |= ImGuiActivateFlags_FromFocusApi;
         if (g.NavMoveFlags & ImGuiNavMoveFlags_IsTabbing)
         if (g.NavMoveFlags & ImGuiNavMoveFlags_IsTabbing)
             g.NavNextActivateFlags |= ImGuiActivateFlags_PreferInput | ImGuiActivateFlags_TryToPreserveState | ImGuiActivateFlags_FromTabbing;
             g.NavNextActivateFlags |= ImGuiActivateFlags_PreferInput | ImGuiActivateFlags_TryToPreserveState | ImGuiActivateFlags_FromTabbing;
     }
     }

+ 2 - 1
imgui_internal.h

@@ -1679,8 +1679,9 @@ enum ImGuiActivateFlags_
     ImGuiActivateFlags_PreferInput          = 1 << 0,       // Favor activation that requires keyboard text input (e.g. for Slider/Drag). Default for Enter key.
     ImGuiActivateFlags_PreferInput          = 1 << 0,       // Favor activation that requires keyboard text input (e.g. for Slider/Drag). Default for Enter key.
     ImGuiActivateFlags_PreferTweak          = 1 << 1,       // Favor activation for tweaking with arrows or gamepad (e.g. for Slider/Drag). Default for Space key and if keyboard is not used.
     ImGuiActivateFlags_PreferTweak          = 1 << 1,       // Favor activation for tweaking with arrows or gamepad (e.g. for Slider/Drag). Default for Space key and if keyboard is not used.
     ImGuiActivateFlags_TryToPreserveState   = 1 << 2,       // Request widget to preserve state if it can (e.g. InputText will try to preserve cursor/selection)
     ImGuiActivateFlags_TryToPreserveState   = 1 << 2,       // Request widget to preserve state if it can (e.g. InputText will try to preserve cursor/selection)
-    ImGuiActivateFlags_FromTabbing          = 1 << 3,       // Activation requested by a tabbing request
+    ImGuiActivateFlags_FromTabbing          = 1 << 3,       // Activation requested by a tabbing request (ImGuiNavMoveFlags_IsTabbing)
     ImGuiActivateFlags_FromShortcut         = 1 << 4,       // Activation requested by an item shortcut via SetNextItemShortcut() function.
     ImGuiActivateFlags_FromShortcut         = 1 << 4,       // Activation requested by an item shortcut via SetNextItemShortcut() function.
+    ImGuiActivateFlags_FromFocusApi         = 1 << 5,       // Activation requested by an api request (ImGuiNavMoveFlags_FocusApi)
 };
 };
 
 
 // Early work-in-progress API for ScrollToItem()
 // Early work-in-progress API for ScrollToItem()

+ 2 - 2
imgui_widgets.cpp

@@ -4607,8 +4607,8 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
         item_data_backup = g.LastItemData;
         item_data_backup = g.LastItemData;
         window->DC.CursorPos = backup_pos;
         window->DC.CursorPos = backup_pos;
 
 
-        // Prevent NavActivation from Tabbing when our widget accepts Tab inputs: this allows cycling through widgets without stopping.
-        if (g.NavActivateId == id && (g.NavActivateFlags & ImGuiActivateFlags_FromTabbing) && (flags & ImGuiInputTextFlags_AllowTabInput))
+        // Prevent NavActivation from explicit Tabbing when our widget accepts Tab inputs: this allows cycling through widgets without stopping.
+        if (g.NavActivateId == id && (g.NavActivateFlags & ImGuiActivateFlags_FromTabbing) && !(g.NavActivateFlags & ImGuiActivateFlags_FromFocusApi) && (flags & ImGuiInputTextFlags_AllowTabInput))
             g.NavActivateId = 0;
             g.NavActivateId = 0;
 
 
         // Prevent NavActivate reactivating in BeginChild() when we are already active.
         // Prevent NavActivate reactivating in BeginChild() when we are already active.