Closed pdf closed 10 months ago
Thanks! The reason I didn't do this is because I wasn't sure that this would break things. But it seems like gotk4 also does this so I have merged this. I converted my own codebase to this too and I saw no issues.
nice work btw, makes things very neat
Thank you. It wasn't really trivial to implement tbh (especially with all the interfaces and stuff), but it's a neat design I would say. Note that casting is a bit awkward right now, ideally we want to do (like gotk4):
value.Cast().(type)
This is possible to implement but will take some effort
See the current readme example, we have to do
window.SetChild(&label.Widget)
which is okay and exactly what you stated, what gotk4 allows is pretty neat though:
we will also have to look at this maybe
Currently working with the lib is a bit awkward due to the dance required by constructors returning unexpected types, in particular widget constructors returning
*gtk.Widget
instead of the type the constructor is named for.For example in the current API:
If instead we return the expected type, because it already embeds gtk.Widget, this is much cleaner:
Drastically friendlier to work with, and because class types already embed their ancestors, the returned object provides access to all methods from the composed types on one object, and the ancestor types can be passed to any function that needs them by virtue of the pointer being set on the earliest ancestor (nice work btw, makes things very neat).
Obviously this would be a breaking change, but I think the usability benefits are well worth it.
As a quick hack to test I made the change in this PR, which unless I'm missing something ought be valid for all class constructors, and have been testing locally with no issues after migrating my consumer code to use the new API. With the change to make this work seeming so trivial though, I wonder if there was a reaon I'm not grokking that the current API was left standing.