Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TreeNode should keep selection state when arrow clicked #1896

Closed
SuperWangKai opened this issue Jun 23, 2018 · 7 comments
Closed

TreeNode should keep selection state when arrow clicked #1896

SuperWangKai opened this issue Jun 23, 2018 · 7 comments
Labels

Comments

@SuperWangKai
Copy link

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!

@ocornut
Copy link
Owner

ocornut commented Jun 23, 2018 via email

@SuperWangKai
Copy link
Author

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.

@ocornut ocornut added the tree tree nodes label Jun 23, 2018
@ocornut
Copy link
Owner

ocornut commented Jun 23, 2018

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.

@SuperWangKai
Copy link
Author

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

@geneotech
Copy link

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

@Folling
Copy link

Folling commented Oct 17, 2019

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.

ocornut added a commit that referenced this issue Nov 8, 2019
…e being held, facilitating interactions with multi-select patterns. (#2886, #1896, #1861)
ocornut added a commit that referenced this issue Nov 8, 2019
…ust open/closed, facilitating interactions with custom multi-selections patterns. (#1896, #1861)
@ocornut
Copy link
Owner

ocornut commented Nov 8, 2019

Hello,

I have made two changes:

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

-Omar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants