For the purposes of owlkettle I'm currently trying to wrap GtkBuilder. For the 
purposes of that, I _need_ to figure out how to get GTK to instantiate a 
GTK_WIDGET and hand me a pointer to that via said GtkBuilder.

Now I have the necessary procs to instantiate a GtkBuilder, they can be easily 
bound. However, instantiating a 
[GTK_WIDGET](https://docs.gtk.org/gtk4/class.Widget.html) requires a piece of C 
syntax that I don't know how to replicate in nim.

Something like this (lifted from a [tutorial page for 
gtkbuilder](https://github.com/ToshioCP/Gtk4-tutorial/blob/main/gfm/sec9.md#gtkbuilder)
 with C code):
    
    
    build = gtk_builder_new_from_file ("tfe3.ui");
    win = GTK_WIDGET (gtk_builder_get_object (build, "win"));
    
    
    Run

"win" is some id defined on said tfe3.ui file, think HTML tag id, basically 
that.

I can replicate this _somewhat_ already, but the expression `GTK_WIDGET` I 
don't know how to replicate. It's not a proc I can bind and there are no 
bindable constructor procs, so what do I do to replicate instantiating a 
GTK_WIDGET?

This is basically what I already have bar the last line which obviously doesn't 
work
    
    
    type GtkWidget = distinct pointer
    type GtkBuilder = distinct pointer
    type GObject = distinct pointer
    
    proc buildWidgetFromUIString(uiString: string): GtkWidget
      let builder = newBuilderFromString(uiString) # this is a nim proc that 
creates a builder, it's already wrapped and works.
      let gObj: GObject = gtk_builder_get_object(builder, "someIdOnUiString")
      let widget: GtkWidget = GTK_WIDGET (gObj) # This line obviously doesn't 
work, but what to replace it with that does work?
    
    
    Run

Reply via email to