TreeNode double clicked #1872

Closed
opened 2018-06-09 15:29:12 +00:00 by devkaiwang · 4 comments
devkaiwang commented 2018-06-09 15:29:12 +00:00 (Migrated from github.com)

I found we can use ImGui::IsItemClicked() to handle tree node clicked event. Can we handle mouse double click event on the tree node? (e.g double click on the tree node to open the file related to it)

Edit: should we have ImGui::IsItemDoubleClicked() function?

I found we can use `ImGui::IsItemClicked()` to handle tree node clicked event. Can we handle mouse double click event on the tree node? (e.g double click on the tree node to open the file related to it) Edit: should we have `ImGui::IsItemDoubleClicked()` function?
ocornut commented 2018-06-09 16:04:12 +00:00 (Migrated from github.com)

This is IsItemClicked():

bool ImGui::IsItemClicked(int mouse_button)
{
    return IsMouseClicked(mouse_button) && IsItemHovered(ImGuiHoveredFlags_Default);
}

Therefore you can easily call IsMouseDoubleClicked() && IsItemHovered().
The problem is that as is, a tree node will unfold on the first click unless you use the ImGuiTreeNodeFlags_OpenOnDoubleClick or ImGuiTreeNodeFlags_OpenOnArrow flag.

This is IsItemClicked(): ``` bool ImGui::IsItemClicked(int mouse_button) { return IsMouseClicked(mouse_button) && IsItemHovered(ImGuiHoveredFlags_Default); } ``` Therefore you can easily call IsMouseDoubleClicked() && IsItemHovered(). The problem is that as is, a tree node will unfold on the first click unless you use the `ImGuiTreeNodeFlags_OpenOnDoubleClick` or `ImGuiTreeNodeFlags_OpenOnArrow` flag.
devkaiwang commented 2018-06-10 02:37:53 +00:00 (Migrated from github.com)

Thanks, that solves my problem. IMHO, I still think we can have IsItemDoubleClicked. It will be IsItemDoubleClicked returns true and also the tree node toggled. There is still no logic confliction.

Thanks, that solves my problem. IMHO, I still think we can have IsItemDoubleClicked. It will be IsItemDoubleClicked returns true and also the tree node toggled. There is still no logic confliction.
devkaiwang commented 2018-06-11 02:01:11 +00:00 (Migrated from github.com)

Since there is a solution I would like to close this issue.

Since there is a solution I would like to close this issue.
ocornut commented 2018-06-11 15:44:04 +00:00 (Migrated from github.com)

IMHO, I still think we can have IsItemDoubleClicked.

Hmm, at the moment I'd prefer to resist adding many extra API entry points. We have reusable and combinable blocks so that may be enough for now? May reconsider this later. For now I'll add a comment to IsItemClicked() in the header file to suggest that it is no other than a shortcut to IsMouseClicked() && IsItemHovered() so it would be more understandable that you could dig one level lower (and merely 2 obvious calls instead of 1) to get extra flexibility.

> IMHO, I still think we can have IsItemDoubleClicked. Hmm, at the moment I'd prefer to resist adding many extra API entry points. We have reusable and combinable blocks so that may be enough for now? May reconsider this later. For now I'll add a comment to `IsItemClicked()` in the header file to suggest that it is no other than a shortcut to `IsMouseClicked() && IsItemHovered()` so it would be more understandable that you could dig one level lower (and merely 2 obvious calls instead of 1) to get extra flexibility.
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#1872
No description provided.