diamondburned / gotk4

Autogenerated GTK4 bindings for Go
GNU Affero General Public License v3.0
525 stars 20 forks source link

Help Needed: Accessing Child Widget from gtk.FlowBoxChild Causes Panic #153

Closed itsManjeet closed 3 months ago

itsManjeet commented 3 months ago

Description:

I'm working with GTK4 bindings in Go and have encountered a panic when trying to access a custom child widget from gtk.FlowBoxChild.

I created a subclass as per the instructions in Subclassing with the following structure:

type ChildWidget struct {
    gtk.Widget
    // Other fields...
}

var childWidgetType = glib.RegisterSubclass[*ChildWidget]()

I attempted to access this ChildWidget within a FlowBox like so:

flowBox.ConnectChildActivated(func(child *gtk.FlowBoxChild) {
    childWidget := child.Child().(*ChildWidget)
})

However, I encountered the following panic:

panic: interface conversion: gtk.Widgetter is *gtk.Widget, not *disk_card.DiskCard [recovered]
        panic: closure error: unexpected panic caught: interface conversion: gtk.Widgetter is *gtk.Widget, not *disk_card.DiskCard

Expected Behavior:

I expected to successfully cast child.Child() to my custom ChildWidget type without causing a panic.

Actual Behavior:

The application panics with the error mentioned above, indicating a type mismatch during the conversion.

Steps to Reproduce:

  1. Create a subclass of gtk.Widget as shown.
  2. Add instances of this subclass to a FlowBox.
  3. Attempt to access and cast the child widget within the ConnectChildActivated callback.

Environment:

Additional Information:

Any guidance on correctly accessing the child widget in this context would be greatly appreciated!

diamondburned commented 3 months ago

Subclassing currently barely works and will very likely be removed in the future in order to allow development on dynamic runtime linking. Sorry about this.