-
-
Notifications
You must be signed in to change notification settings - Fork 74
Missing documentation/examples for subclassing & few questions #279
Description
I started to play with subclassing gtk-rs widgets. It took me a while, to understand few basic things. In my opinion we need more examples, or at least a more basic one with more explanations.
As a starter I had following questions:
- Why we need a
ExampleObjectPrivate
and aExampleObject
struct - What does the
glib_wrapper!
macro - How I can access from the
ExampleObject
struct stuff from theExampleObjectPrivate
struct
Now I managed to subclass my first widget. It resulted into this:
https://gitlab.gnome.org/World/Shortwave/commit/4a4e2442f9c15f92b5a2ea32c5eb0d874496793f
Now I wonder...
- I know, the
glib_wrapper!
macro turns it into a gtk-rs like usable object. But what's the object, before I wrap it? Is it a FFI-like object? - Is there a more elegant way as using
OnceCell
s? Since I cannot initialize mySongRow
directly anymore, so I have to use a Cell or something as placeholder. The annoying thing is now, that I have to use.get().unwrap()
everytime, if I want to access one of the struct variables. I wonder if something likeOption
exists, but without having tounwrap()
it every time.
https://gitlab.gnome.org/World/Shortwave/blob/master/src/ui/song_row.rs#L15 - Is it possible to use composite templates (
<template class="ExampleBox" parent="GtkBox">
) with subclassing (like as it is possible in Vala)? Example of composite template #275 - Is there any elegant way to pass values with
new()
, so I can initialize my struct directly? Like I have done it before: https://gitlab.gnome.org/World/Shortwave/blob/bf8e4a7d2bad3ec1412f0b2c4968f291bfe4a536/src/ui/song_row.rs#L30 - What does the
SongRowClass
field? It seems that I can enter here whatever I want.
https://gitlab.gnome.org/World/Shortwave/blob/master/src/ui/song_row.rs#L50
I'm refering to this example:
https://github.com/gtk-rs/examples/blob/master/src/bin/basic_subclass.rs
And BTW, there's an issue with it:
Shouldn't be it SimpleWindow
instead of the SimpleWindowPrivate
in the inspector?
To be fair, I should admit that I have no knowledge with handling gobject boilerplate manually (Thanks Vala 😄 ), so I might missing few bits.
As soon as I understand everything correctly, I want to submit one more basic example for subclassing (like just subclassing a simple gtk::Box
with more explanations)