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

Add option to TreeNode to enable button behaviour with key modifiers enabled. #2886

Closed
AlvaroBarua opened this issue Nov 7, 2019 · 3 comments
Labels
tree tree nodes

Comments

@AlvaroBarua
Copy link

Hi, I am working on a multiselection tree hierarchy and using LCTRL as the modifier to select multiple items. My idea is to be able to while holding down the LCTRL key, open a tree node if I click on the arrow. Right now, the default behaviour of the button behaviour inside the TreeNode is to include the ImGuiButtonFlags_NoKeyModifiers flag which prevents me from doing so.

I have manually removed the default flag, but I guess having a proper way of disabling this behaviour would be the ideal solution.

Thanks.

\\Won't change state when LCTRL is held
bool treeNodeOpen = ImGui::TreeNodeEx(name, treeNodeFlasg);
bool clickedOnArrow = (ImGui::GetMousePos().x - ImGui::GetItemRectMin().x) < ImGui::GetTreeNodeToLabelSpacing();

if (ImGui::IsItemClicked())
{
    if (Input::GetKey(KeyCode::LCTRL) && !clickedOnArrow)
   {
       //Add item to list
   }
}

if (treeNodeOpen)
    RecursiveBuild(...);

@ocornut ocornut added the tree tree nodes label Nov 8, 2019
@ocornut
Copy link
Owner

ocornut commented Nov 8, 2019

Which tree node flags are you using? Are you using ImGuiTreeNodeFlags_OpenOnArrow, or are not your using it and expecting a different behavior based on whether CTRL and click are happening over the arrow or before/after ?

My gut feeling is that for tree node it would make sense to allow toggling the node open state with modifiers when clicking specifically on the arrow, so we could alter the behavior based on mouse position. I'll have to check with features/range_select and think about other side-effects or doing this.

Potential fix would be to move the arrow_x1/arrow_x2 declaration higher in the function and alter the button flags based on io.MousePos.x.

(Also need to consider ImGuiTreeNodeFlags_SpanFullWidth being used which mean we can click before the arrow.)

Also consider looking at #1861 and the features/range_select branch.

(PS: Please fill the issue template as requested when creating a new issue.)

ocornut added a commit that referenced this issue Nov 8, 2019
… 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. (#2886)
ocornut added a commit that referenced this issue Nov 8, 2019
…e being held, facilitating interactions with multi-select patterns. (#2886, #1896, #1861)
@ocornut
Copy link
Owner

ocornut commented Nov 8, 2019

I applied the change described above now.

In addition, I have added IsItemToggledOpen() to explicitely query if the node was just open/closed which is required to fully handle #1896.

@AlvaroBarua
Copy link
Author

AlvaroBarua commented Nov 8, 2019

Thank you for the quick fix, it is exactly what I needed.

I was using ImGuiTreeNodeFlags_SpanFullWidth and doing a range check to see if the mouse was in the arrow area when clicked using the TreeDepth, but with IsItemToggledOpen() should be way easier and cleaner.

And sorry for the template, I must have cleared the text and forgot about it completely.

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

No branches or pull requests

2 participants