Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

nano-ui

An immediate-mode GUI toolkit for Haskell.

In an immediate-mode GUI, your UI code runs again on every frame. Drawing a button and checking whether it was clicked is one function call, and the application keeps no tree of widget objects to update. In Haskell this makes the interface a function of state, written with ordinary functions, do notation, and if/case/for_, with no callbacks to register.

You describe the whole window as one NanoUI () action, and the backend runs that action again on every frame. The rest of this book calls that action the view. Widgets return values directly (button returns Bool), input widgets take a mutable Var holding their state, and layout is a composable modifier argument.

counter :: NanoUI ()
counter = row $ do
  n <- useVar (0 :: Int)
  whenM (button "-") (modifyVar n (subtract 1))
  label . T.pack . show =<< readVar n
  whenM (button "+") (modifyVar n (+ 1))

Code samples assume import NanoUI and OverloadedStrings. The runnable source for each tutorial is in packages/nano-ui-demo/examples.

Packages in the monorepo

PackageWhat it isRead
packages/nano-uiCore toolkit: widgets, layout, input, theming, draw list, text arena.State, Layout, Widget Gallery
packages/nano-ui-sdlSDL3 backend: TrueType fonts via HarfBuzz, system font search, native non-blocking file dialogs, custom title bars.Ecosystem Packages, Desktop Windows
packages/nano-ui-rgfwRGFW + OpenGL 3.2 backend with a bundled bitmap font and no system dependencies.Ecosystem Packages
packages/nano-ui-emitElm-style typed messages and update reducers (NanoUIE msg a).Elm-Style State
packages/nano-ui-diagramsLine, bar, scatter, and area charts (NanoUI.Plot) with diagrams-lib integration.Ecosystem Packages
packages/nano-ui-formValidated applicative forms built on ditto.Ecosystem Packages
packages/nano-ui-markdownMarkdown rendering, incrementally appendable for streamed replies.Ecosystem Packages
packages/nano-ui-svgHeadless DrawOp-to-SVG export and visual regression testing.Ecosystem Packages
packages/nano-ui-demoRunnable example applications and single-topic tutorials.Tutorials

Styling workbenches

The styling chapters embed live specimens. Toggle modifiers, themes, and interaction states: