Skip to content

Commit c5db276

Browse files
committed
InputText, Nav: fixed tabbing through InputTextMultiline(). (#4761, #3092)
Messy... Broken by 66f0fb9. Added ImGuiItemFlags_NoTabStop to EndGroup() ahead of time (not strictly needed here).
1 parent 9d704d9 commit c5db276

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

imgui.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -7942,7 +7942,7 @@ void ImGui::EndGroup()
79427942

79437943
window->DC.CurrLineTextBaseOffset = ImMax(window->DC.PrevLineTextBaseOffset, group_data.BackupCurrLineTextBaseOffset); // FIXME: Incorrect, we should grab the base offset from the *first line* of the group but it is hard to obtain now.
79447944
ItemSize(group_bb.GetSize());
7945-
ItemAdd(group_bb, 0);
7945+
ItemAdd(group_bb, 0, NULL, ImGuiItemFlags_NoTabStop);
79467946

79477947
// If the current ActiveId was declared within the boundary of our group, we copy it to LastItemId so IsItemActive(), IsItemDeactivated() etc. will be functional on the entire group.
79487948
// It would be be neater if we replaced window.DC.LastItemId by e.g. 'bool LastItemIsActive', but would put a little more burden on individual widgets.

imgui_demo.cpp

+11-10
Original file line numberDiff line numberDiff line change
@@ -2285,7 +2285,7 @@ static void ShowDemoWindowWidgets()
22852285
// Select an item type
22862286
const char* item_names[] =
22872287
{
2288-
"Text", "Button", "Button (w/ repeat)", "Checkbox", "SliderFloat", "InputText", "InputFloat",
2288+
"Text", "Button", "Button (w/ repeat)", "Checkbox", "SliderFloat", "InputText", "InputTextMultiline", "InputFloat",
22892289
"InputFloat3", "ColorEdit4", "Selectable", "MenuItem", "TreeNode", "TreeNode (w/ double-click)", "Combo", "ListBox"
22902290
};
22912291
static int item_type = 4;
@@ -2308,15 +2308,16 @@ static void ShowDemoWindowWidgets()
23082308
if (item_type == 3) { ret = ImGui::Checkbox("ITEM: Checkbox", &b); } // Testing checkbox
23092309
if (item_type == 4) { ret = ImGui::SliderFloat("ITEM: SliderFloat", &col4f[0], 0.0f, 1.0f); } // Testing basic item
23102310
if (item_type == 5) { ret = ImGui::InputText("ITEM: InputText", &str[0], IM_ARRAYSIZE(str)); } // Testing input text (which handles tabbing)
2311-
if (item_type == 6) { ret = ImGui::InputFloat("ITEM: InputFloat", col4f, 1.0f); } // Testing +/- buttons on scalar input
2312-
if (item_type == 7) { ret = ImGui::InputFloat3("ITEM: InputFloat3", col4f); } // Testing multi-component items (IsItemXXX flags are reported merged)
2313-
if (item_type == 8) { ret = ImGui::ColorEdit4("ITEM: ColorEdit4", col4f); } // Testing multi-component items (IsItemXXX flags are reported merged)
2314-
if (item_type == 9) { ret = ImGui::Selectable("ITEM: Selectable"); } // Testing selectable item
2315-
if (item_type == 10){ ret = ImGui::MenuItem("ITEM: MenuItem"); } // Testing menu item (they use ImGuiButtonFlags_PressedOnRelease button policy)
2316-
if (item_type == 11){ ret = ImGui::TreeNode("ITEM: TreeNode"); if (ret) ImGui::TreePop(); } // Testing tree node
2317-
if (item_type == 12){ ret = ImGui::TreeNodeEx("ITEM: TreeNode w/ ImGuiTreeNodeFlags_OpenOnDoubleClick", ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_NoTreePushOnOpen); } // Testing tree node with ImGuiButtonFlags_PressedOnDoubleClick button policy.
2318-
if (item_type == 13){ const char* items[] = { "Apple", "Banana", "Cherry", "Kiwi" }; static int current = 1; ret = ImGui::Combo("ITEM: Combo", &current, items, IM_ARRAYSIZE(items)); }
2319-
if (item_type == 14){ const char* items[] = { "Apple", "Banana", "Cherry", "Kiwi" }; static int current = 1; ret = ImGui::ListBox("ITEM: ListBox", &current, items, IM_ARRAYSIZE(items), IM_ARRAYSIZE(items)); }
2311+
if (item_type == 6) { ret = ImGui::InputTextMultiline("ITEM: InputTextMultiline", &str[0], IM_ARRAYSIZE(str)); } // Testing input text (which uses a child window)
2312+
if (item_type == 7) { ret = ImGui::InputFloat("ITEM: InputFloat", col4f, 1.0f); } // Testing +/- buttons on scalar input
2313+
if (item_type == 8) { ret = ImGui::InputFloat3("ITEM: InputFloat3", col4f); } // Testing multi-component items (IsItemXXX flags are reported merged)
2314+
if (item_type == 9) { ret = ImGui::ColorEdit4("ITEM: ColorEdit4", col4f); } // Testing multi-component items (IsItemXXX flags are reported merged)
2315+
if (item_type == 10){ ret = ImGui::Selectable("ITEM: Selectable"); } // Testing selectable item
2316+
if (item_type == 11){ ret = ImGui::MenuItem("ITEM: MenuItem"); } // Testing menu item (they use ImGuiButtonFlags_PressedOnRelease button policy)
2317+
if (item_type == 12){ ret = ImGui::TreeNode("ITEM: TreeNode"); if (ret) ImGui::TreePop(); } // Testing tree node
2318+
if (item_type == 13){ ret = ImGui::TreeNodeEx("ITEM: TreeNode w/ ImGuiTreeNodeFlags_OpenOnDoubleClick", ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_NoTreePushOnOpen); } // Testing tree node with ImGuiButtonFlags_PressedOnDoubleClick button policy.
2319+
if (item_type == 14){ const char* items[] = { "Apple", "Banana", "Cherry", "Kiwi" }; static int current = 1; ret = ImGui::Combo("ITEM: Combo", &current, items, IM_ARRAYSIZE(items)); }
2320+
if (item_type == 15){ const char* items[] = { "Apple", "Banana", "Cherry", "Kiwi" }; static int current = 1; ret = ImGui::ListBox("ITEM: ListBox", &current, items, IM_ARRAYSIZE(items), IM_ARRAYSIZE(items)); }
23202321

23212322
// Display the values of IsItemHovered() and other common item state functions.
23222323
// Note that the ImGuiHoveredFlags_XXX flags can be combined.

imgui_widgets.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -3979,6 +3979,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
39793979
ImGuiWindow* draw_window = window;
39803980
ImVec2 inner_size = frame_size;
39813981
ImGuiItemStatusFlags item_status_flags = 0;
3982+
ImGuiLastItemData item_data_backup;
39823983
if (is_multiline)
39833984
{
39843985
ImVec2 backup_pos = window->DC.CursorPos;
@@ -3989,6 +3990,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
39893990
return false;
39903991
}
39913992
item_status_flags = g.LastItemData.StatusFlags;
3993+
item_data_backup = g.LastItemData;
39923994
window->DC.CursorPos = backup_pos;
39933995

39943996
// We reproduce the contents of BeginChildFrame() in order to provide 'label' so our window internal data are easier to read/debug.
@@ -4773,18 +4775,19 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
47734775
// For focus requests to work on our multiline we need to ensure our child ItemAdd() call specifies the ImGuiItemFlags_Inputable (ref issue #4761)...
47744776
Dummy(ImVec2(text_size.x, text_size.y + style.FramePadding.y));
47754777
ImGuiItemFlags backup_item_flags = g.CurrentItemFlags;
4776-
g.CurrentItemFlags |= ImGuiItemFlags_Inputable;
4778+
g.CurrentItemFlags |= ImGuiItemFlags_Inputable | ImGuiItemFlags_NoTabStop;
47774779
EndChild();
4780+
item_data_backup.StatusFlags |= (g.LastItemData.StatusFlags & ImGuiItemStatusFlags_HoveredWindow);
47784781
g.CurrentItemFlags = backup_item_flags;
47794782

47804783
// ...and then we need to undo the group overriding last item data, which gets a bit messy as EndGroup() tries to forward scrollbar being active...
4781-
ImGuiLastItemData item_data = g.LastItemData;
4784+
// FIXME: This quite messy/tricky, should attempt to get rid of the child window.
47824785
EndGroup();
47834786
if (g.LastItemData.ID == 0)
47844787
{
47854788
g.LastItemData.ID = id;
4786-
g.LastItemData.InFlags = item_data.InFlags;
4787-
g.LastItemData.StatusFlags = item_data.StatusFlags;
4789+
g.LastItemData.InFlags = item_data_backup.InFlags;
4790+
g.LastItemData.StatusFlags = item_data_backup.StatusFlags;
47884791
}
47894792
}
47904793

0 commit comments

Comments
 (0)