site  contact  subhomenews

gintro GUI toolkit for Nim

August 31, 2022 — BarryK

I am new to Nim, and only started looking for a GUI toolkit a few days ago. Posted about the 'ui' toolkit:

ui GUI toolkit for Nim — August 30, 2022

...which is just about a dead project. Checked out several others, all in an immature state, few or none recent commits, or dead projects.

One exception though, is the 'gintro' toolkit. Very active, looks fairly feature-complete. For gtk3 and gtk4, so although can be made to work on Windows and MacOS, it really is for Linux only. Which is fine with me. Project page:

I have Nim installed, which has the 'nimble' executable, which is the Nim package manager. This is how to install gintro:

# nimble install gintro

Nimble, amazingly, knows where to find gintro, on github, and downloads it. The default install location is ~/.nimble/pkgs

Note, you can alternatively not use nimble, just download the gintro project anywhere, from github. Then put in a path to it when compiling, like this (the path can be absolute or relative):

# nim c --path:<path to gintro>/gintro app0.nim

...a clarification. Download the project, tagged release version 0.9.9, expand it and you will have folder "gintro-0.9.9" and inside that another folder "gintro" -- that latter folder is what you have got to specify a path to.

I looked at the examples. Firstly, to create a window only; 'app0.nim'. I created a working folder, and copied 'app0.nim' to it, then created 'nim.cfg' in that folder:

The system-wide nim.cfg is at /etc/nim/nim.cfg, and you must have that -- if you don't have it, download nim from github, and you will find config/nim.cfg. Copy to /etc/nim

The 'nim.cfg' in my working-folder adds extra settings for my project. What is allowed in nim.cfg is not very well documented. One thing I discovered is the "-flto" must be in quotes. I have selected these settings for creating a small executable. Note, "--d:" and "--define:" are equivalent.

Here is 'app0.nim', with comments inserted:


Very simple! Compiling:

# nim c app0.nim
# strip app0

...results in a 27KB binary!

These examples are also in the readme front page of the gintro github site linked-to above, with explanations.

Adding a button, example 'button.nim':


Again, very simple. But where are these functions documented?

That "utf8Strreverse" is a glib function, I found it documented here:

Functions "newApplication", "newButton" and "newApplicationWindow" are high-level bindings provided by gintro.

Compiling, the binary is just 27KB again! Displays a window with a button, click on the button reverses the text that is displayed in the button.

The gintro github site readme goes on with more examples. Enough for this blog post. Very impressed so far.

Dr Salewski has also written a book, focusing on gintro with gtk4:

Well, EasyOS only has gtk2 and gtk3, which is not likely to change for a very long time. Possibly though, the book will be still useful if only have gtk3. Interesting to read Dr Salewski's comments about the state of gtk development.

I have started a thread on the forum for further information and discussion about GUI toolkits for Nim:         

Tags: easy