pekim / gobbi

gobbi is a set of generated Go bindings for gtk et al.
MIT License
28 stars 3 forks source link

missing api gtk_text_buffer_create_tag() #2

Closed rythmkraze closed 5 years ago

rythmkraze commented 5 years ago

gtk_text_buffer_create_tag() is missing from the api. Is this unimplemented because of varargs?

pekim commented 5 years ago

Yes, cgo does not support calling variadic C functions.

In some cases, where the variadic arguments are to support printf-like functionality, gobbi does provide support. It does this by using fmt.Sprintf to format a string from the arguments, and then calls the C function with the formatted string. However it gets trickier for other types of function.

In many cases there are alternative functions that can be used. And I think that gtk_text_buffer_create_tag is one such case.

Something like this will probably work.

    tag := gtk.TextTagNew("my_tag_name")

    editable := gobject.ValueNew(gobject.TYPE_BOOLEAN)
    editable.SetBoolean(false)
    tag.Object().SetProperty("property-name", editable)

    indent := gobject.ValueNew(gobject.TYPE_INT)
    indent.SetInt(4)
    tag.Object().SetProperty("indent", indent)

    tagTable := gtk.TextTagTableNew()
    tagTable.Add(tag)
    buffer := gtk.TextBufferNew(tagTable)
pekim commented 5 years ago

I'll see about writing a documentation page describing this sort of problem and workaround.

rythmkraze commented 5 years ago

Thanks for the workaround.

pekim commented 5 years ago

https://pekim.github.io/gobbi/variadic-functions/ now contains some general notes about variadic function support in gobbi.

ec4437f7