FIGURE v0.8.0 is out: Dear ImGui and ImPlot for Fortran programs (beta, still an experiment)

FIGURE

Fortran Immediate-mode GUI for User interfaces, Rendering and Exploration

FIGURE gives a Fortran program interactive windows, widgets and plots: Dear ImGui, ImPlot and ImPlot3D on SDL3 and OpenGL 3, on Linux, macOS and Windows. It is immediate mode: no widget objects, no handles, no callbacks. The interface is declared every frame, and its state is your own variables. Plots read your arrays in place, without copies. v0.8.0 is the first release I announce here (written with the help of an AI assistant).

Disclaimer: beta, and still more an experiment than a mature library. FIGURE has had only eight minor releases; the API can and will change before v1.0. Few applications use it so far (my own tools for a CFD solver), so most of it has been exercised by its tests, not by users. The native layer carries a few patches to Dear ImGui and ImPlot that are not upstream yet, and the known issues page is not short. Try it, break it, tell me; do not build anything on it yet that you cannot afford to rewrite.

hello

figure_hello: a button, a frequency slider dragged by the mouse, and a sine wave that follows it.

What it does

  • Widgets and plots. Buttons, sliders, numeric and text fields, drop-down lists, tables, tabs, trees; lines, scatter, bars, shaded areas, histograms, heatmaps with colour bars, contours, pies and bubbles, subplots with linked axes, log axes, drag tools.
  • An application, not only a window. Menus and keyboard shortcuts, popups and modals, the system’s file dialogs, docking (layouts set by the program or arranged by the user, saved and loaded), seven built-in styles and theme files, notifications.
  • Lazy redraw. An idle window sleeps (about 0.4 % of a core); live data redraws only when it changes.
  • Long runs stay responsive. Background tasks run your work on another thread, with progress and cancel; external processes (a solver, mpirun) run with their output streamed into a log view.
  • Remote mode. app%init_remote() serves the same interface to a web browser, with an access token: no display or GPU on the program’s side, e.g. a cluster node through an SSH tunnel.
  • 3-D. Meshes coloured by fields, drawn by FIGURE’s own CPU rasterizer, with gizmos to move a clipping plane or a probe by hand (ImGuizmo); 3-D plots of trajectories and surfaces (ImPlot3D).
  • A code editor and Markdown. Input files highlighted, a validator’s findings marked on their lines, find and replace, a diff of two versions; help pages and release notes from Markdown.
  • Headless. app%init_headless() and the figure_testing module drive the interface with synthetic input (clicks, keys, typing) in CI without a display, and a CPU renderer draws every frame, so tests compare pictures with goldens.

mandelbrot

figure_mandelbrot: 60 wheel steps, about 175 times into the seahorse valley, then more iterations; every frame recomputed at the plot’s resolution and uploaded as a texture.

cb_trajectory

A Lorenz trajectory growing in an ImPlot3D plot, its newest point marked; a right drag turns the box.

cb_gizmo

FIGURE’s 3-D view: a slender body coloured by a field, cut by a plane moved and turned with a gizmo.

A taste

The whole of a program with a window, a slider and a plot that follows it:

program readme
use, intrinsic :: iso_fortran_env, only : int32, real64
use figure, only : app_object, ig_begin, ig_end, ig_set_next_window, ig_slider, ip_begin_plot, ip_end_plot, ip_line

implicit none
type(app_object) :: app
real(real64)     :: x(200)
real(real64)     :: frequency
integer(int32)   :: i

x = [(0.05_real64 * i, i = 0, 199)]
frequency = 1.0_real64
call app%init('FIGURE', 800, 500)
do while (app%next_frame())                 ! the interface is declared every frame
   call ig_set_next_window(20.0_real64, 20.0_real64, 760.0_real64, 460.0_real64)
   if (ig_begin('Wave')) then
      if (ig_slider('frequency', frequency, 0.1_real64, 5.0_real64)) continue
      if (ip_begin_plot('sin(f x)', height=-1.0_real64)) then
         call ip_line('y', x, sin(frequency * x))
         call ip_end_plot()
      endif
   endif
   call ig_end()
enddo
call app%destroy()
endprogram readme
curl -fsSL https://github.com/szaghi/figure/releases/latest/download/install.sh | bash -s -- --gnu
gfortran readme.F90 $(pkg-config --cflags --libs figure) -o readme

The one-line installer builds the latest release (--nvidia for nvfortran), installs it into ~/.local, compiles and runs a test program against it, and prints the line above.

The same kind of program grows into an application by adding windows: here they dock into one another.

cb_dock

A window dragged by its title bar onto the Log area docks there as a tab; then the frequency slider changes the plot.

Its appearance changes at runtime: app%set_style picks one of seven built-in styles, or combines a look (the geometry) with a palette (the colours); every colour and size of Dear ImGui and ImPlot can be set by name; and the style editor saves a theme file that the program loads back.

gallery-cycle

gallery: one program through the seven built-in styles (seal, seal-light, paper, high-contrast, and Dear ImGui’s dark, light, and classic), one and a half seconds each.

Built with it

The showcase is the application that drove the design: a run checker and two input editors for a CFD solver, in one window, with the solvers run from it.

showcase_xall_evol

xall_evol, the run checker: the residuals of six variables on a log axis follow a run’s history files as they grow; the summary table updates (synthetic files).

xall_gui: the mesh tool runs on 2 processes from the window; its output scrolls, with a notification when it finishes.

What v0.8.0 adds

  • New wrappers: a colour picker (ig_color_picker), pie charts and bubbles (ip_pie_chart, ip_bubbles), error bars along x; in ImPlot3D, colours and sizes per point, axis formats and ticks, its style by name.
  • Fixes: a 2-D plot item drawn outside a plot is now a usage error with a message, not a crash; a texture released from a task is refused.
  • The documentation, rewritten for a learner: a 26-chapter tutorial, from a first window to a solver studio built chapter by chapter; 87 recipes in the cookbook; the reference pages ordered by concept, use, errors, and advanced.

New in v0.8.0: pie charts and bubbles.

tut13_field

The tutorial’s solver studio, chapter 13: F5 runs the solver; when it has converged, the plate’s temperature is shown as a heatmap with labelled contour lines and a colour bar.

How it is checked

  • Tests: 42 headless test programs, run on every push on Linux (gfortran 16.2, with coverage), macOS (gfortran, Apple clang), Windows (MSYS2 gfortran), and Linux with nvfortran 26.9 and Intel ifx.
  • Pictures: the 104 pictures and videos of the documentation are recorded headless from the programs they show, and CI records them again on Linux, macOS, and Windows and compares each with the committed one (a few, such as the remote-mode ones, are skipped where a platform cannot record them).
  • Docs: every snippet and output in the documentation comes from a program that is compiled and run, and a script checks that every public procedure has a doc comment, a sentence on its page, and a compiled example that calls it. Nothing is typed by hand.
  • Honest limits: the known issues list what does not work (multi-viewports, ImPlot3D’s depth, a few platform quirks), each with what to do meanwhile.

FIGURE builds with FoBiS or fpm (a self-contained vX.Y.Z-fpm tag per release), its native layer with CMake; your own project finds an installed FIGURE with pkg-config or CMake’s find_package(figure). Only SDL3 comes from the system. It is released under the MIT licence; the native layer compiles Dear ImGui, ImPlot, cimgui and cimplot (MIT) and SDL3 (zlib).

Coming next: FIGURE’s patches to Dear ImGui and ImPlot reported upstream, and whatever the first users find.

Feedback, issues, and contributions are welcome, and in this phase, bug reports most of all.

Stefano

4 Likes