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

[bug] TreeNode OnClick event doesn't run when closing the node. #917

Closed
araujoarthur opened this issue Nov 27, 2024 · 1 comment · Fixed by #918
Closed

[bug] TreeNode OnClick event doesn't run when closing the node. #917

araujoarthur opened this issue Nov 27, 2024 · 1 comment · Fixed by #918
Labels
bug Something isn't working

Comments

@araujoarthur
Copy link

What happend?

Hello! I was digging the example files and noticed the usage of a event handler as a chained method in the TreeNode. Since it's deprecated I switched to the new EvenHandler and it seems that the left button click isn't registered when closing the Node. I don't even know if it's the right place for this Issue because when tracking it down I found out that the one that's returning false is

func IsMouseClicked(button MouseButton) bool {
	return imgui.IsMouseClickedBool(imgui.MouseButton(button))
}

and it tracks down to C.wrap_igIsMouseClicked_Bool(C.ImGuiMouseButton(button)). Which ends up calling ImGui's IsMouseClicked. The issue didn't happen with the old Handler that used IsItemClickedV.

Code example

main.go
package main

import (
	"fmt"
	"github.com/AllenDang/giu"
)

func loopd() {
	giu.SingleWindowWithMenuBar().Layout(
		giu.TabBar().TabItems(
			giu.TabItem("Multiline Input").Layout(
				giu.Label("This is first tab with a multiline input text field"),
				giu.InputTextMultiline(&multiline).Size(giu.Auto, giu.Auto),
			),
			giu.TabItem("Tree").Layout(
				giu.TreeNode("TreeNode1").Flags(giu.TreeNodeFlagsCollapsingHeader|giu.TreeNodeFlagsDefaultOpen).Layout(
					giu.Custom(func() {
						if giu.IsItemActive() && giu.IsMouseClicked(giu.MouseButtonLeft) {
							fmt.Println("Tree node Clicked")
						}
					}),
					giu.Selectable("Tree Node 1").OnClick(func() {
						fmt.Println("Click Tree Node 1")
					}),
					giu.Label("Tree Node 2"),
					giu.Label("Tree Node 3"),
					giu.Button("Button Inside Tree"),
				),
				giu.TreeNode("TreeNode with event handler").Flags(giu.TreeNodeFlagsCollapsingHeader|giu.TreeNodeFlagsDefaultOpen).Layout(
					giu.Selectable("Selectable 1").OnClick(func() { fmt.Println(1) }),
					giu.Selectable("Selectable 2").OnClick(func() { fmt.Println(2) }),
				), /*.Event(func() {
					if giu.IsItemClicked(giu.MouseButtonLeft) {
						fmt.Println("Clicked")
					}
				}),*/
				giu.Event().OnClick(giu.MouseButtonLeft, TreeNodeEventHandlerClicked),
			),
			// End GIU TabItem
		),
		)
}
func main() {
	items = make([]string, 100)
	for i := range items {
		items[i] = fmt.Sprintf("Item %d", i)
	}
	wnd := giu.NewMasterWindow("Notification Services", 800, 800, 0)
	wnd.Run(loopd)
}

To Reproduce

  1. Run the provided minimal version of the Widgets demo, or the entire demo
  2. You should notice that when it closes the node the event callback is not triggered.

Version

master

OS

Windows11 23H2

@araujoarthur araujoarthur added the bug Something isn't working label Nov 27, 2024
@gucio321
Copy link
Collaborator

thank you for reporting!
Well, when I look at the code, it is quite obvious for me that putting EventHandler after TreeNode will not work (so idk Why did I suggest that in that comment).
I think TreeNodeWidget should have EventHandler() method that sets EventHandler that will be called after node createion but before layout.
funfact: examples/widgets still uses Event method 😄

@gucio321 gucio321 linked a pull request Nov 27, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants