StefanSalewski / gintro

High level GObject-Introspection based GTK3/GTK4 bindings for Nim language
MIT License
298 stars 20 forks source link

newBuilderListItemFactoryFromBytes template instantiation error #129

Open gavr123456789 opened 3 years ago

gavr123456789 commented 3 years ago
import gintro/[gtk4, gobject, gio, glib]
import std/with

const ui_string = """<interface>
  <template class="GtkListItem">
    <property name="child">
      <object class="GtkLabel">
        <binding name="label">
          <lookup name="string" type="GtkStringObject">
            <lookup name="item">GtkListItem</lookup>
          </lookup>
        </binding>
      </object>
    </property>
  </template>
</interface>"""

proc activate(app: gtk4.Application) =
  let
    window = newApplicationWindow(app)
    scr = newScrolledWindow()

    sl = gtk4.newStringList("Nim", "Vala", "Rust", "Zig")
    ls = cast[ListModel](sl)
    ss = gtk4.newSingleSelection(ls)
    bytes = glib.newBytesTake(ui_string)
    # builder = gtk4.newBuilderFromString(ui_string)
    factory = gtk4.newBuilderListItemFactoryFromBytes(nil, bytes) # .nimble/pkgs/gintro-#head/gintro/gtk4.nim(42107, 115) Error: undeclared field: 'impl' 
    # factory3 = gtk4.newSignalListItemFactory()
    lv = newListView(ss, factory)

  scr.setChild lv

  with window:
    defaultSize = (600, 400)
    title = "Nim ListView"
    setChild scr
    show

proc main =
  let app = newApplication("org.gtk.example")
  app.connect("activate", activate)
  discard run(app)

main()

Error on factory = gtk4.newBuilderListItemFactoryFromBytes(nil, bytes) line

StefanSalewski commented 3 years ago

Thanks for reporting.

I just had a short look at the problematic proc:

proc newBuilderListItemFactoryFromBytes*(scope: BuilderScope | BuilderCScope = nil;
    bytes: glib.Bytes): BuilderListItemFactory =
  let gobj = gtk_builder_list_item_factory_new_from_bytes(if scope.isNil: nil else: cast[ptr BuilderScope00](scope.impl), cast[ptr glib.Bytes00](bytes.impl))

The parameter list looks strange indeed. Do you think it is valid? Is the default nil only applied to BuilderCScope or also to BuilderScope? And does it work at all when first parameter has a default, so is optional, but second parameter is not optional?

I think I have to consult the manual and do a few tests. Will try in the next days...

StefanSalewski commented 3 years ago

It is really a funny issue. This one compiles

proc newBuilderListItemFactoryFromBytes*(scope: BuilderScope;# | BuilderCScope;
    bytes: glib.Bytes): BuilderListItemFactory =
  echo scope.impl == nil
  echo bytes.impl == nil

So how can dispatch for or types work when we pass value nil?

StefanSalewski commented 3 years ago

Well and you can compile your example with

factory = gtk4.newBuilderListItemFactoryFromBytes(BuilderScope(nil), bytes)