garrigue / lablgtk

LablGTK 2 and 3: an interface to the GIMP Tool Kit
https://garrigue.github.io/lablgtk
Other
89 stars 40 forks source link

Add bindings for GtkStack and GtkStackSwitcher #122

Closed hugrs closed 3 years ago

hugrs commented 3 years ago

Hi,

I'm an OCaml beginner and I wanted to use the GtkStack widget from GTK 3.10+ in a small project.

I added bindings for GtkStack and GtkStackSwitcher, along with an example for the Stack widget. The bindings are very naive, I only added enough to make the examples compile with dune build @all.

Also I would like to ask for advice regarding some points:

The StackSwitcher has a "stack" property where you can get/set the GtkStack widget associated to it. As you can see in the stackswitcher.ml example, I am trying to use the set_stack method. However, it expects a Gtk.stack Gtk.obj and my variable is a GPack.stack. I don't know if I'm just missing an OCaml concept or that the type declarations in the binding are wrong, but I cannot figure out how to convert from one to the other.

My other concern is that GtkStack and StackSwitcher have only been introduced in 3.10, and I'm not sure how to handle backwards-compatibility with older versions. I have noticed the HASGTK* macros in C, should I do the same and define a HASGTK310 macro ?

garrigue commented 3 years ago

Thanks for your contribution. This looks fine. Concerning your two questions:

hugrs commented 3 years ago

Thank you for your quick reply. I added as_stack as a method in the stack class and it perfectly solved the type mismatch for stack_switcher. I completed the example as well so that both widgets have a working example.

Regarding the gtk3 version, I had a quick look in repology to see which versions of gtk are supported by mainstream distributions. Debian stable provides 3.24, and very few of them provide a version inferior to that. I think it's safe to assume that adding functionality from 3.22 and earlier without any extra checks should be fine. Let me know what you think.

garrigue commented 3 years ago

Actually, the README.md file states explicitly that lablgtk3 requires gtk+-3.18 or better. So GtkStack is already covered. We might raise the requirement in the future, rather than introducing conditional compilation.

Let me known when this is ready for inclusion.

hugrs commented 3 years ago

Ok then let's follow the requirements in the readme. There is just the icon-size property of stack_switcher that was added later in 3.20, so i've documented that. Now the PR is ready for review.