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!
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:
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
Most helpful comment
I don't have a solution for it other than a workaround testing the X coordinates.
Or using
imgui_internal.h:I'll keep this open because it's an interesting issue I would like to solve along with #1861.