Hey, I am quite new to OCaml and I was wondering what the popular UI frameworks are.
The general space of UI has some interesting retained mode libraries like Libadwaita / GTK, Slint, Kirigami2 / QT and Cosmic / Iced.
Are there any (active) efforts in OCaml to conveniently create native UIs?
I think the biggest one is Lablgtk. It’s used by the Coq theorem prover. See Trying the 7GUIs with LablGTK3/OCaml
Sanette’s Bogue also seems to be actively maintained.
And of those two, Bogue is the only one that has some support on native Windows.
opam install bogue on Windows, I have
tsdl < 0.9.9 not available because the package is pinned to version 0.9.9.
Lablgtk can be installed on Windows (Diskuv OCaml), but the process is rather complex.
I’m not sure what this means. Bogue install does not perform any pinning. What happens if you simply try
opam install tsdl.0.9.8?
tsdl.0.9.9is pinned by something else… I can’t figure out why.
did you try
opam unpin tsdl?
It is pinned by DkML. You can unpin but you might miss DkML patches for Windows, or sometimes you get broken versions that have had no testing on Windows.
So … try out unpinning first. If that doesn’t work you can file a feature request at DkML / Distributions / DkML · GitLab because I do intend to have at least minimal support for Bogue in DkML. Include the output of
opam list and also a two-line use case (sufficient for me to know what packages will be needed in the future).
on the other hand, I am planning quite soon a new release of Bogue using
tsdl 1.0.0, so this problem should disappear
in fact, if you want to try it right away:
opam pin firstname.lastname@example.org:sanette/bogue.git#power_saving
Regarding native UIs in OCaml, it seems to me that lablqml by @Kakadu is also a long-maintained library, that relies on a historical library (Qt/QML) with a sane approach to UI (QML, a.k.a. HTML/CSS-ish). I haven’t used it though so I can’t vouch for it.
Why is this? In python, tkinter is a solid choice for cross-platform UIs. Does labltk not work in Windows?
I have made Lablgtk3 working on Windows.
Either DiskuvML (MSVC based) or opam.2.2.0~beta1 (MSVC or MinGW). Opam/MSVC not tested however.
I have an hard time getting a compiled Gtk library. But vcpkg should help (I have been informed of this source afterward). Note: the DiskuvML compiler is too old and doesn’t compile Gtk because of huge strings containing ressources. A recent Visual Studio Community is ok.
The Lablgtk3 package must be patched to be compiled by MSVC (some options unsupported by the C compiler). The original Lablgtk3 has worked well in a MinGW environment. But MinGW search libname.lib file and not plain name.lib. Some symlinks are needed.
Looks like tcl/tk is more readily available for Windows Thomas Perschak / tcltk · GitLab
I’m using python’s tkinter bindings at work and it’s very easy to knock out an application quickly, so it would be nice if it worked similarly for OCaml.
The 7guis benchmark has been ported to Lablgtk3.
The short answer is that I only support what I use and what my private customers use. I’m not opposed to tkinter it is just that I don’t have anybody who needs it today. So for now I’m sticking with SDL/Bogue, and I’m quite happy to see the 7GUIs response to your 5yr question at Library for GUI? - #50 by Idara_Nabuk.
Aside: The tcltk Windows link you gave looks like someone built binaries without publishing the source or build logic. Other people may be comfortable with that, but as a vendor I’m not. I’m only comfortable with auditable code that has an active maintainer.
I wish there was a UI library which wasn’t object oriented and written in C, so it can be bound to a lot of languages. One could write an Elm style framework on top, while keeping the core portable.
@sanette their library looks really great nice! How does using SDL as a base work for you? this link states that GLFW and SDL wouldn’t suffice for it.
Another thing I went looking for is a GObject introspection library like Haskell-GI. This would allow for using OCaml to write GTK4 apps and Adwaita GNOME apps, too.
It looks like tcl/tk is a very old-school kind of framework. Its source code is published here. See also this for more background.
Having had a good recent experience making a working gui app in a day or so (chatgpt also seems to be quite familiar with tk), I think it would be good to have cross-platform support for labltk.
SDL is a nice “windows library” (creating system windows, drawing pixels on them, handling events) for ocaml because:
- they work very hard to make it run on every device available on earth
- there are good bindings for ocaml (I first used
ocamlsdl and then switched to
However I can understand why one could say it’s not sufficient, because it is very low level. You have to do all the rest by yourself (and this is precisely what I found fun to do when I started the project: code the text entry widget, the audio mixer, the compositing, the threading model, etc — there is even an ocaml version of the Bresenham’s circle drawing algorithm somewhere in Bogue’s code )
But from the wider perspective, Bogue is a very modest project, still under construction. if you are after a complete GUI with accessibility toolkit, multi-dir text, speech synthesis, access to system menus in Mac OS, connection to the Desktop compositing for embedding videos, etc. Then Bogue is not for you! (or, maybe, not yet haha), and you should look after QT or GTK4 or Web, probably.