What is the right way to bind to a click on a Frame?

6 views
Skip to first unread message

Brian Stafford

unread,
Dec 2, 2020, 4:35:08 PM12/2/20
to GoKi-Gi
It's unclear how to do this right. My first guess was something like

```
wgt := gi.AddNewFrame(mainFrame, "wgt", gi.LayoutVert)
wgt.WidgetSig.Connect(view1, func(recv, send ki.Ki, iSig int64, data interface{}) {
    if gi.WidgetSignals(iSig) == gi.WidgetSelected {
        fmt.Println("--clicked")
    }
})
```
But that apparently doesn't work. So I thought I would bind the the `MouseEvent` directly, 

```
wgt.ConnectEvent(oswin.MouseEvent, gi.RegPri, func(_, _ ki.Ki, _ int64, ev interface{}) {
    ...
})
```

And that works until the widget is hidden and re-rendered, after which it does nothing. 

So what is the right way to bind to a click event on a `Frame`?

Brian Stafford

unread,
Dec 2, 2020, 4:50:52 PM12/2/20
to GoKi-Gi
Also had to do 

`wgt.Layout.Viewport = vp`

to make it work. 

Randall O'Reilly

unread,
Dec 3, 2020, 6:33:11 AM12/3/20
to Brian Stafford, GoKi-Gi
Yeah there is an optimization that connects to events for visible items and then disconnects when not visible -- the consequence is that you need to actually define event processing at a type level, so the proper methods are called (ConnectEvents2D() in particular needs to be defined specifically for a given type). Frame is designed to just be a layout with basic rendering, and not an event processor.. So you'd need to define your own new struct type that embeds Frame and defines ConnectEvents2D() to call your ConnectEvent method per your first attempt.

The signals in general are activated by the specific event processing methods, e.g., in button, so once you're dealing with something like that, it is easy to just add the closure callback on the signal.

WidgetSelected in particular is only sent for types that support a selection logic, which Frame does not..

So, a question here is: what kind of behavior are you trying to capture by clicking into a frame, and how does that correspond to some kind of standard GUI behavior? Is there some other more direct solution to what you're trying to achieve?

- Randy
> --
> You received this message because you are subscribed to the Google Groups "GoKi-Gi" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to goki-gi+u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/goki-gi/e118c867-6442-49c5-a3b5-d934e6f1dc69n%40googlegroups.com.

Brian Stafford

unread,
Dec 3, 2020, 9:00:50 AM12/3/20
to GoKi-Gi
I tried to do it with an embedded frame and overloaded ConnectEvents2D, but got 

panic: interface conversion: ki.Ki is nil, not *gi.NodeBase

goroutine 102 [running]:
/home/buck/programs/gi/gi/node.go:360
/home/buck/programs/gi/gi/widget.go:213 +0xb3b
/home/buck/programs/gi/gi/widget.go:321 +0xa7


Randall O'Reilly

unread,
Dec 3, 2020, 6:10:11 PM12/3/20
to Brian Stafford, GoKi-Gi
Hard to tell exactly from that but probably the new frame is the parent at that node.go:360 and it is not being initialized properly? Ki types require the "InitName" or equivalent method to be called, which sets their "This" member -- that is how we get proper virtual inheritance to work within Go..

Did you copy the paradigm of making an "AddNewX" method and use that to add the new type to the tree? just copy these lines and update to your type name, to register the type etc:

// Frame is a Layout that renders a background according to the
// background-color style setting, and optional striping for grid layouts
type Frame struct {
Layout
Stripes Stripes `desc:"options for striped backgrounds -- rendered as darker bands relative to background color"`
}

var KiT_Frame = kit.Types.AddType(&Frame{}, FrameProps)

// AddNewFrame adds a new frame to given parent node, with given name and layout
func AddNewFrame(parent ki.Ki, name string, layout Layouts) *Frame {
fr := parent.AddNewChild(KiT_Frame, name).(*Frame)
fr.Lay = layout
return fr
}


- Randy
> To view this discussion on the web visit https://groups.google.com/d/msgid/goki-gi/b7c71c44-77c8-4c72-88c3-cc46ad1bb019n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages