Mandelbrot with gtk-rs

In this tutorial we show how gtk-rs, the rust version of the gnome toolkit, can be used to make a user interface to show the Mandelbrot figure. We use gtk4.

The gtk-rs website contains a nice book that explains many things. This tutorial aims to be complementary to this book. Although self contained, it pays less attention to things that are treated well there. Don't see this tutorial as an advice on how things should look. I am the last person you should hire if you want that kind of expertise.

This tutorial is accompanied by a github repository. The different stages of the application, treated here in one chapter per stage, correspond to a branch in the repository.

The stages are:

  1. The base. A window that shows the Mandelbrot figure, without any interaction. We use a DrawingArea and an ImageSurface.
  2. The first interaction: respond to resize signals.
  3. Add user interface elements to change the viewing parameters. Zoom in on a point and adapt the amount of detail shown. Uses the widgets Label, Entry, Scale and SpinButton and Box.
  4. Change the focus point by clicking. Uses GestureClick.
  5. Let the user select a coloring scheme. Uses DropDown.
  6. Present presets to the user, a way to set viewing parameters to an interesting region. Uses a modal Window, Button, ListItem, ListView, SignalListItemFactory, SingleSelection and StringObject.
  7. Develop an alternative for ImageSurface, necessary for the next stage. Uses the function create_for_data_unsafe.
  8. Stop freezing the user interface during computation of the Mandelbrot figure. Uses the functions spawn_blocking and spawn_future_local.
  9. Use threads to speed up the computation. Not a user interface thing, but definitely nicer for the user.