-
Notifications
You must be signed in to change notification settings - Fork 21
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
Support subclassing and interfaces #22
Comments
Generate these:
To implement a new widget, the user can do this to subclass a widget:
And they can use it like so:
Or they can do this to implement an abstract class or interface:
It might be worth it to make glib.Object work for both C and Go objects, If this is the case (and the examples are already applied as such), then It is important to note that the Object's implementation for Go It might be quite troublesome for a Go GObject class to extend another Go class, Since GTK4 is shifting from the inheritance paradigm to a more composition-like For example, if someone makes a The code will look roughly like this: type OtherWidget struct {
Widget
box *gtk.Box
}
func NewOtherWidget() *OtherWidget {
w := OtherWidget{
Widget: NewWidget("Hello, world!"),
box: gtk.NewBox(),
}
w.Widget.Widget = gtk.OverrideWidget(&w)
return &w
} The only quirk with this method is that it requires the caller to manually dive Maybe There's also the issue of registering for signals. As for properties, it can // NewOtherWidget...
w.AddProperties(map[string]interface{}{
"fold": false,
}) Old Draft: Note that for all types that the user can override/implement, the methods Also note that there's no need for the user to implement Init, Dispose and Also note that NewClass will basically register a new GType, and that's it. The map will probably be a reflect.Type to a GType map. It'll basically The Register function will definitely need a valid GoObject instance, though |
Created the |
This API doesn't work. The properties have to be set during construction of the Perhaps this might: func OverrideWidget(w gtk.WidgetOverrider, opts ...glib.ObjectOptions)
gtk.OverrideWidget(w, glib.WithProperties{
"fold": false,
}) |
See |
New proposal: type Gadget struct {
gtk.Widget
Child gtk.Widgetter `glib:"child,Construct,ConstructOnly"`
}
var gadgetType = glib.RegisterSubclass[*Gadget](
glib.WithParamSpecs([]glib.ParamSpec{
// TODO
}),
)
func NewGadget(child gtk.Widgetter) *Gadget {
return gadgetType.NewWithProperties(map[string]any{
"child": child,
})
} |
Update: subclassing is now on the main branch. Things might be very unstable; please report bugs and crashes to issues. A release will be made that points to the last working pre-subclassing commit, just to mitigate this potential instability. |
Crashing with
This could be gotk4 not calling parent class initializers. |
This issue tracks gotk4's subclass and interface support. The goal is to make Go structs accessible and callable from C's side through the use of interfaces, as well as overriding and/or extending certain methods, similar to subclassing.
Relevant resources:
The text was updated successfully, but these errors were encountered: