Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

newBuilderListItemFactoryFromBytes template instantiation error #129

Open
gavr123456789 opened this issue May 23, 2021 · 3 comments
Open

Comments

@gavr123456789
Copy link

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
Copy link
Owner

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
Copy link
Owner

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
Copy link
Owner

Well and you can compile your example with

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants