Skip to content

Commit 037126e

Browse files
committed
TreeNode: Reworded code for ImGuiTreeNodeFlags_OpenOnArrow (follow up to f79b2d6) to make it lightweight. Should be a no-op from user's point of view. Will facilitate using the arrow hovering information in the hot path. (ocornut#2886)
1 parent d003674 commit 037126e

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

imgui_widgets.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5287,13 +5287,15 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l
52875287
{
52885288
if (pressed)
52895289
{
5290-
const float arrow_x1 = text_pos.x - text_offset_x;
5291-
const float arrow_x2 = arrow_x1 + g.FontSize + padding.x * 2.0f;
5292-
toggled = !(flags & (ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick)) || (g.NavActivateId == id);
5290+
const float hit_padding_x = style.TouchExtraPadding.x;
5291+
const float arrow_hit_x1 = (text_pos.x - text_offset_x) - hit_padding_x;
5292+
const float arrow_hit_x2 = (text_pos.x - text_offset_x) + (g.FontSize + padding.x * 2.0f) + hit_padding_x;
52935293
if (flags & ImGuiTreeNodeFlags_OpenOnArrow)
5294-
toggled |= IsMouseHoveringRect(ImVec2(arrow_x1, interact_bb.Min.y), ImVec2(arrow_x2, interact_bb.Max.y)) && (!g.NavDisableMouseHover);
5295-
if (flags & ImGuiTreeNodeFlags_OpenOnDoubleClick)
5296-
toggled |= g.IO.MouseDoubleClicked[0];
5294+
toggled |= (g.IO.MousePos.x >= arrow_hit_x1 && g.IO.MousePos.x < arrow_hit_x2) && (!g.NavDisableMouseHover); // Lightweight equivalent of IsMouseHoveringRect() since ButtonBehavior() already did the job
5295+
if ((flags & (ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick)) == 0 || (g.NavActivateId == id))
5296+
toggled = true;
5297+
if ((flags & ImGuiTreeNodeFlags_OpenOnDoubleClick) && g.IO.MouseDoubleClicked[0])
5298+
toggled = true;
52975299
if (g.DragDropActive && is_open) // When using Drag and Drop "hold to open" we keep the node highlighted after opening, but never close it again.
52985300
toggled = false;
52995301
}

0 commit comments

Comments
 (0)