TreeNode should keep selection state when arrow clicked #1896

Closed
opened 2018-06-23 15:28:32 +00:00 by devkaiwang · 7 comments
devkaiwang commented 2018-06-23 15:28:32 +00:00 (Migrated from github.com)

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!

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 commented 2018-06-23 16:09:30 +00:00 (Migrated from github.com)

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

I am not sure what you mean by selection state, TreeNode currently don’t hold any selection state. Please provide more details.
devkaiwang commented 2018-06-23 16:40:38 +00:00 (Migrated from github.com)

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.

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 commented 2018-06-23 17:24:37 +00:00 (Migrated from github.com)

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.

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.
devkaiwang commented 2018-06-23 17:40:32 +00:00 (Migrated from github.com)

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

X coord approach appearly solves my problem. Cheers! :)
geneotech commented 2018-10-09 19:25:14 +00:00 (Migrated from github.com)

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

Yeah, it works for me as well! Would be nice to have a built-in for this.
Folling commented 2019-10-17 16:27:42 +00:00 (Migrated from github.com)

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.

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 commented 2019-11-08 14:37:49 +00:00 (Migrated from github.com)

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

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
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ocornut/imgui#1896
No description provided.