Imgui: TreeNode should keep selection state when arrow clicked

Created on 23 Jun 2018  路  7Comments  路  Source: ocornut/imgui

TreeNode should allow user to expand or collapse and keep selection state not changed, when user clicking the arrow.

Correct me if I missed something.

Thanks very much!

tree

Most helpful comment

I don't have a solution for it other than a workaround testing the X coordinates.

if (ImGui::IsItemClicked() && (ImGui::GetMousePos().x - ImGui::GetItemRectMin().x) > ImGui::GetTreeNodeToLabelSpacing())
{
}

Or using imgui_internal.h:

ImGuiContext& g = *GImGui;
if (ImGui::IsItemClicked() && g.ActiveIdClickOffset.x > g.FontSize + g.FramePadding.x * 2)
{
}

I'll keep this open because it's an interesting issue I would like to solve along with #1861.

All 7 comments

I am not sure what you mean by selection state, TreeNode currently don鈥檛 hold any selection state. Please provide more details.

Oh, sorry.

Here is my issue: AFAIK, we use methods like ImGui::IsItemClicked() to trigger the selection (#1872). However, when user clicks on the arrow of the tree node, ImGui::IsItemClicked() also returns true. In this case, when a user intends to expand/collapse the node, the node will also be selected. This is not desired.

I don't have a solution for it other than a workaround testing the X coordinates.

if (ImGui::IsItemClicked() && (ImGui::GetMousePos().x - ImGui::GetItemRectMin().x) > ImGui::GetTreeNodeToLabelSpacing())
{
}

Or using imgui_internal.h:

ImGuiContext& g = *GImGui;
if (ImGui::IsItemClicked() && g.ActiveIdClickOffset.x > g.FontSize + g.FramePadding.x * 2)
{
}

I'll keep this open because it's an interesting issue I would like to solve along with #1861.

X coord approach appearly solves my problem. Cheers! :)

Yeah, it works for me as well! Would be nice to have a built-in for this.

You could split the TreeNodeBehaviour into two items, one button for the arrow, and one for the rest.
This should be toggeable with a ImGuiTreeNodeFlags_SeparateArrow flag (or something similar, in which case two button behaviours and ItemAdd's are used instead of just once.

Hello,

I have made two changes:

  • For #2886 made it that it is possible to ctrl-click the arrow, which should facilitate implementing multi-select patterns.
  • Added a IsItemToggledOpen() call to explicitely query if the node was just closed/open making it possible to differenciate this from e..g a simple click.

Both of those changes should normally answer the problem opened here now.

-Omar

Was this page helpful?
0 / 5 - 0 ratings

Related issues

KaungZawHtet picture KaungZawHtet  路  3Comments

ocornut picture ocornut  路  3Comments

bogdaNNNN1 picture bogdaNNNN1  路  3Comments

Folling picture Folling  路  3Comments

namuda picture namuda  路  3Comments