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

Missing bindings for GLib.Variant #843

Closed
cameronwhite opened this issue Apr 1, 2023 · 5 comments
Closed

Missing bindings for GLib.Variant #843

cameronwhite opened this issue Apr 1, 2023 · 5 comments
Milestone

Comments

@cameronwhite
Copy link
Contributor

A full sweep is probably needed to make sure there are bindings for all the variant types, but the ones I found porting Pinta were:

  • bool types: need Variant.Create(bool) and bool GetBool()
  • more predefined VariantType constants would be convenient, currently only "s" and "v" have named constants
  • dictionary types: the "a{sv}" variant type mapping strings to variants. It's only possible currently to construct an empty one via Variant.CreateEmptyDictionary()
@badcel badcel added this to the 0.8.0 milestone Apr 1, 2023
@badcel badcel modified the milestones: 0.8.0, 0.5.0 Sep 12, 2023
@badcel
Copy link
Member

badcel commented Sep 12, 2023

@cameronwhite: I wonder if there should be more VariantType constants or if they should be removed altogether as those are only convenience. If the API is getting generated a user can create every type he wants to via a string. E.g.: VariantType.New("i");

Or if they should be static methods instead to avoid unnecessary memory allocation.

@cameronwhite
Copy link
Contributor Author

I think at least some sort of constant is useful so that it's more discoverable - otherwise you have to look up the GTK docs to find the right string to use and might make a typo

@badcel
Copy link
Member

badcel commented Sep 15, 2023

With constant you mean a string constant?

So you write: VariantType.New(VariantType.String)?

We could have a static method instead:
VariantType.GetString() or VariantType.CreateString()

Or a static property:
VariantType.String

I think I would avoid caching a lot of instances. As new instances are created in all 3 scenarios I would probably not use the static property as it is not obvious that a new instance is created on every call.

What do you think of implementing a custom equality so that two VariantTypes are equal if they represent the same type (e.g. via type_equal)?

This should probably be a separate PR and not be part of #942.


Edit: the more i think about it the more I think having helper for the types is not useful as it is possible to create arbitrary complex types and the helpers would never cover all cases. This is probably the reason why there are no helpers in c, too. It is probably best to add extensive documentation to the class.

I think I would prefer a builder class (see #954).

@cameronwhite
Copy link
Contributor Author

I think a separate build class is probably fine too, that also makes it more clearly separated as a convenience on top of the actual GTK API

@badcel
Copy link
Member

badcel commented Oct 25, 2023

A boolean variant can now be created:

public void CanCreateBool(bool value)

In regard to VariantType #954 supersedes this.

@badcel badcel closed this as completed Oct 25, 2023
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