GtkCClosureExpression is really a C convenience API to create a GtkExpression that calls a function when the expression is evaluated, wrapped in a GClosure.
Language bindings should use GtkClosureExpression and GClosure directly, though, especially because bindings should already have some wrappers that turn the arguments of a closure into native types, as they are the same mechanism used to handle GObject signals.
I wounder how the callback get_family_name got it’s parameter item , although only the return type G_TYPE_STRING was defined in the closure creation and all other parameters are null?
The item parameter is passed by the expression to the closure. It’s a generic “instance” parameter taken from the list model, which requires it to be a GObject. You could have written get_family_name() as:
@ebassi Thanks for the explanation.
Nevertheless, I’ve a hard time transferring this concept in vala. All I get are segfaults
I’ve started a repository with the code here.
I appreciate your help if you could sacrifice a few minutes of your time and review the code to point out what I’m doing wrong.
Needless to say that in the moment there are no other code in vala that use the new Gtk.Expression anywhere.
I’m just trying to think loudly why my example don’t work
I need to create a GLib.ListStore to hold the data that I want to display, in this example a list of all fonts in the system. I’ve successfully done that. fonts_list = new GLib.ListStore (typeof (Pango.FontFamily));.
Create a new Gtk.DropDown var button = new Gtk.DropDown ();.
Attach the model to the dropdown, button.set_model (fonts_list);
Create a Gtk.CClosureExpression which got evaluated every time dropdown wants to display an item. This item got passed automatically form the model to the callback as @ebassi explained above .
@ebassi Shouldn’t the API pass a pointer to the sender as a first argument - like in Signals - because depending on first position makes it difficult for language bindings. The static wasn’t so obvious at first. What do you think?