Portable GUI-programming in C?

Is there a way to create a Linux and Haiku app, with GUI, written in C? With minimal porting coding! Ideally with Gtk. Afaik if I stick to C, I could only use Xlib-API (shudder) and no other toolkit because native Haiku-GUI must be coded with C++ or Yab.

Or maybe Tk/Tcl?

If you want plain C as opposed to C++, then you just said it: Gtk. Otherwise, a search for “GUI programming” on the forum mostly results in suggestions to use C++. There’s FLTK, Qt, and wxWidgets: a much wider selection. PyQt 5 and 6 are there too.

And sure, Tcl/Tk is also an option.

2 Likes

Thanks for the answer. That’s great to hear. I wasn’t aware that all the C toolkits you mentioned are usable on Haiku. (Gtk is my favorite, I’ll try that.) I thought: Haiku-GUI = C++.

Edit: I reread your answer and see you meant that FLTK, wxWidgets etc are C++ not C, right?

Yes, that’s right. Though FLTK only uses very light C++ features, nothing newer than the ‘98 standard, and you never need to declare a single class in your code.

For Qt there are C bindings: GitHub - rcalixte/libqt6c: Qt 6 for C
While Qt itself is still C++, that allows you to write your own applications in C and still use Qt with it.
Qt has the advantage on Haiku that it’s perfectly integrated and looks almost like a native application, so that’s what I’d strongly recommend for a multiplatform app if you also want to target Haiku.
While GTK technically works on Haiku, it does so only using a massive amount of compatibility layers (Wayland and all) and doesn’t integrate at all UI-wise.
Whenever I have other choices, I avoid using GTK stuff on Haiku.

2 Likes

A few years ago I had started porting IUP. It is a wrapper above other GUI toolkits (a bit like wxWidgets), and so you could use that to have GTK on Linux, and native widgets on Haiku (and also win32 standard widgets on Windows and a few other things).

Its API is a bit strange as it’s mainly designed to work with Lua, but it’s the least bad thing I’ve used for GUIs in C. However, Haiku port is not maintained, and I have no plans to resume it as Cosmoe may soon be usable to port my Haiku apps to Linux, making my life a lot simpler.

5 Likes

I wonder why IUP still isn’t in the repos of any Linux distribution, and especially Debian (which otherwise has everything under the sun). Doubly so as the long-abandoned XForms is still widely packaged.

1 Like

I’m currently considering Gtk, Nuklear, and the IUP (of which I never had hear before).

  • Nuklear: simple, but you have to edit the include file, and it’s based on xlib which is probably bad performance
  • Gtk: xlib based, so similar
  • IUP: Something completely new for me, the Notepad-example in the documentation looks good

@nosycat Indeed XForms is ooold and long gone.

Nuklear is also immediate mode, rather than retained mode, so that’s something to consider if that matters to you.

You could try and see how libAgar works. It’s a retained-mode GUI library, and while it doesn’t have a Haiku port, it does have an SDL2 backend, so you could test that out and see if that’ll work.

Another thought is Luigi, which also doesn’t have a Haiku port, but it’s very tiny, albeit barebones, so it shouldn’t be too difficult to bring over. I recommend this fork of it if you decide to try it: GitHub - miEsMar/luigi: A barebones single-header GUI library for Win32, X11 and Essence.

2 Likes

These are not that small but usable.

@theokeist , those are for C++, not C. XTC seems not to support and API lower than C++20? and GacUI also has no C exporter.

1 Like