Skip to content

Commit

Permalink
tree node: allow to pin Eventhandler to TreeNode
Browse files Browse the repository at this point in the history
This adds (*TreeNodeWidget).EventHandler(...) as an alternative
to (*TreeNodeWidget).Event (which is marked depecated btw).

fix #917
  • Loading branch information
gucio321 committed Nov 27, 2024
1 parent adf90ef commit 7835e3c
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions ClickableWidgets.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,8 @@ type TreeNodeWidget struct {
label string
flags TreeNodeFlags
layout Layout
eventHandler func()
event func()
eventHandler *EventHandler
}

// TreeNode creates a new tree node widget.
Expand All @@ -531,10 +532,16 @@ func (t *TreeNodeWidget) Flags(flags TreeNodeFlags) *TreeNodeWidget {
return t
}

// Event create TreeNode with eventHandler
// Event create TreeNode with event handling function.
// You could detect events (e.g. IsItemClicked IsMouseDoubleClicked etc...) and handle them for TreeNode inside eventHandler.
// Deprecated: Use EventHandler instead!
// Deprecated: Use (*TreeNodeWidget).EventHandler instead!
func (t *TreeNodeWidget) Event(handler func()) *TreeNodeWidget {
t.event = handler
return t
}

// EventHandler allows to set *EventHandler instance for the actual TreeNode.
func (t *TreeNodeWidget) EventHandler(handler *EventHandler) *TreeNodeWidget {
t.eventHandler = handler
return t
}
Expand All @@ -549,8 +556,12 @@ func (t *TreeNodeWidget) Layout(widgets ...Widget) *TreeNodeWidget {
func (t *TreeNodeWidget) Build() {
open := imgui.TreeNodeExStrV(t.label, imgui.TreeNodeFlags(t.flags))

if t.event != nil {
t.event()
}

if t.eventHandler != nil {
t.eventHandler()
t.eventHandler.Build()
}

if open {
Expand Down

0 comments on commit 7835e3c

Please sign in to comment.