Skip to content

Commit 97ff9bd

Browse files
committed
Nav: fixed c licking window decorations (e.g. resize borders) from losing focused item when within a child window using ImGuiChildFlags_NavFlattened.
In essence, using ImGuiFocusRequestFlags_RestoreFocusedChild here is a way to reduce changes caused by FocusWindow(), but it could be done more neatly. See amended "nav_flattened" test.
1 parent c3dca77 commit 97ff9bd

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

docs/CHANGELOG.txt

+2
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ Other changes:
134134
- Multi-Select (checkboxes)
135135
- Multi-Select (multiple scopes)
136136
- Multi-Select (advanced)
137+
- Nav: fixed clicking window decorations (e.g. resize borders) from losing focused item when
138+
within a child window using ImGuiChildFlags_NavFlattened.
137139
- Clipper: added SeekCursorForItem() function. When using ImGuiListClipper::Begin(INT_MAX) you can
138140
can use the clipper without knowing the amount of items beforehand. (#1311)
139141
In this situation, call ImGuiListClipper::SeekCursorForItem(items_count) as the end of your iteration

imgui.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
// Library Version
2929
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM >= 12345')
3030
#define IMGUI_VERSION "1.91.0 WIP"
31-
#define IMGUI_VERSION_NUM 19097
31+
#define IMGUI_VERSION_NUM 19098
3232
#define IMGUI_HAS_TABLE
3333

3434
/*

imgui_widgets.cpp

+15-3
Original file line numberDiff line numberDiff line change
@@ -567,8 +567,14 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool
567567
SetActiveID(id, window);
568568
g.ActiveIdMouseButton = mouse_button_clicked;
569569
if (!(flags & ImGuiButtonFlags_NoNavFocus))
570+
{
570571
SetFocusID(id, window);
571-
FocusWindow(window);
572+
FocusWindow(window);
573+
}
574+
else
575+
{
576+
FocusWindow(window, ImGuiFocusRequestFlags_RestoreFocusedChild); // Still need to focus and bring to front, but try to avoid losing NavId when navigating a child
577+
}
572578
}
573579
if ((flags & ImGuiButtonFlags_PressedOnClick) || ((flags & ImGuiButtonFlags_PressedOnDoubleClick) && g.IO.MouseClickedCount[mouse_button_clicked] == 2))
574580
{
@@ -577,10 +583,16 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool
577583
ClearActiveID();
578584
else
579585
SetActiveID(id, window); // Hold on ID
586+
g.ActiveIdMouseButton = mouse_button_clicked;
580587
if (!(flags & ImGuiButtonFlags_NoNavFocus))
588+
{
581589
SetFocusID(id, window);
582-
g.ActiveIdMouseButton = mouse_button_clicked;
583-
FocusWindow(window);
590+
FocusWindow(window);
591+
}
592+
else
593+
{
594+
FocusWindow(window, ImGuiFocusRequestFlags_RestoreFocusedChild); // Still need to focus and bring to front, but try to avoid losing NavId when navigating a child
595+
}
584596
}
585597
}
586598
if (flags & ImGuiButtonFlags_PressedOnRelease)

0 commit comments

Comments
 (0)