# nano-ui-sdl
Desktop SDL3 backend for [nano-ui](https://github.com/goolord/nano-ui). Shapes TrueType text with SDL3_ttf and HarfBuzz using the bundled Inter font or installed system fonts (with script fallbacks), and provides non-blocking native file dialogs, custom title bars, and screenshots.
```haskell
{-# LANGUAGE OverloadedStrings #-}
import NanoUI
import NanoUI.Backend.Sdl (defaultSdlOptions, runSdlApp)
main :: IO ()
main = runSdlApp defaultSdlOptions (label "Hello")
```
For Elm-style views, `runSdlAppReduce` pairs a `model -> NanoUIE msg ()` view with `msg -> model -> model` (via `nano-ui-emit`). Configure initial window settings, fonts, base font size, theme, and vsync through `SdlOptions`.
SDL view helpers find the active session inside `NanoUI`, so you do not pass a backend handle through your views (and they become no-ops in headless tests):
```haskell
main :: IO ()
main = do
picker <- FilePicker <$> newVar Nothing
runSdlApp defaultSdlOptions (filePicker picker)
newtype FilePicker = FilePicker (Var (Maybe FileDialogId))
filePicker :: FilePicker -> NanoUI ()
filePicker (FilePicker pending) =
whenM (button "Open") $
writeVar pending . Just =<< askOpenFileDialog defaultFileDialogOptions
```
Check dialog completion with `pollFileDialogUi` (consumes the result and restores window focus) or `peekFileDialogUi`. When you need low-level `IO` operations (`saveScreenshot`, `setWindowChrome`, raw dialog calls), obtain the `SdlEnv` handle via `askSdlEnv` and call them on the display thread.
## Windows, fonts, and DPI
`sdlWindowSettings` takes core `WindowSettings` (shared with `nano-ui-rgfw`): title, logical size, position, min/max bounds, icon, window mode, transparency (`wsTransparent`), opacity, and close-request handling. Combine `sdlWindowDecorations` with `windowCaption` for frameless custom title bars, and use `captureScreenshot` or `saveScreenshot` to read back the last presented frame.
Set the starting font in `SdlOptions` or switch at runtime with `setSdlUiFont`. `NanoUIFont` supports the bundled Inter default and searching installed system families by name.
Views always work in logical pixels. macOS and Wayland scale per monitor automatically; on Windows, SDL reports density `1` by default, so set `sdlAppUiScale = 0` to follow the desktop scale. Recoverable render device resets rebuild textures automatically.
## System requirements
Requires SDL3, SDL3_ttf 3.2+, and `pkg-config`:
```sh
pkg-config --modversion sdl3 sdl3-ttf
```
Link executables with `-threaded` so background tasks keep running while the SDL event wait sleeps.
## Documentation
- [The nano-ui Book](https://goolord.github.io/nano-ui/book/): Tutorials, widget gallery, window management, and backend reference.
## License
MIT. The bundled Inter font ships through `nano-ui-ttf` under the SIL Open Font License 1.1 (`LICENSE-Inter`). Because binaries built with `nano-ui-sdl` embed Inter, include `LICENSE-Inter` alongside distributed applications.