Thursday, November 26, 2015

A starter kit for IUP, lightweight and cross-platform user interface library for C and Lua

Some months ago I wrote a post about the NW.js runtime, a framework to develop desktop applications using web languages and technologies, which is, in my opinion, a very interesting platform but has an annoying problem: the only user-friendly way to ship your applications is to merge the NW.js runtime files with your application, resulting in an overhead of about 90 MBs for each NW-based application the users install on their machines. To get around this problem, I'm interested to develop a small tool to manage a global, system-wide, installation of the NW runtime files on users' computers (in different versions if necessary); this program should be GUI-based, as lightweight as possible, and cross-platform (Windows and Linux for now).
After reading information about various GUI toolkits, I found the IUP user interface toolkit to be the most suitable for my program. It can be used as a small (~1 MB) library (.dll on Windows or .so on Linux) which can be shipped with the application; you can use it in plain C programs or in Lua scripts (I choose C since Lua is interpreted and I don't want to increase the size of the program by embedding the interpreter into it).
IUP also has a custom language, LED, that can be used to define the layout of each application's window. LED files can either be loaded at runtime or compiled into a C file which you can then compile and link together with other source files of the application.
In my opinion, the main advantage of IUP against other well-known cross-platform frameworks like Qt is that it doesn't define its own controls, but instead it provides an abstraction layer over the platform's native controls, resulting in smaller binaries. IUP provides drivers for the native Win32 API (which is part of Windows), GTK (which, as far as I know, is actually installed by default on the majority of desktop Linux distributions) and Motif (a GUI toolkit used in other Unix-based systems).
A similar approach is used by wxWidgets, which is however available for C++ only and not for C.
To begin using IUP, I set up a starter kit to compile IUP-based applications on Linux for Linux itself and for Windows (using the mingw-w64 cross compiler); you can find it here: https://github.com/gianluca-nitti/iup-cp-boilerplate. This repository contains shell scripts and a Makefile to compile an example IUP application to three target platforms: linux64, linux32 and win32. Actually I didn't add the win64 target since (correct me if I'm wrong) thanks to WoW64, on 64-bit Windows installations 32-bit applications run out-of-the-box, and I don't plan to develop performance-critical applications (this target should be easy to add, though). This boilerplate is tested to compile out-of-the-box on Ubuntu 14.04, which is also the OS used by the Travis-CI continuous integration service (the repository, in fact, also includes a .travis.yml that allows the code to be automatically built by that service); for other distributions you may need to edit the get-packages.sh script to change the package names and/or the package manager command. In detail, this boilerplate contains:
  • C and LED source files for a minimal IUP application (two windows: a main dialog and an about dialog);
  • A shell script (get-packages.sh) that installs the required packages to compile the application for the three targets;
  • A shell script (get-libs.sh) that downloads the IUP library for the three targets to allow linking the application with it, and the LEDC compiler for LED interface definition files (which is used in the Makefile)
  • A Makefile that builds the binaries, using the tools downloaded from the scripts.
Here are some screenshots of the example application:
On Ubuntu 12.04 (64-bit)
On Windows 8.1 (64-bit)

On Fedora (32-bit)


You can find more information about how to use this boilerplate to build your cross-platform GUI application based on IUP in the README file of the repository.