packages feed

nano-ui-rgfw-bindings-0.2.0.0: README.md

# nano-ui-rgfw-bindings

Haskell bindings to [RGFW](https://github.com/ColleagueRiley/RGFW), a single-header C library for native windows, input handling, and OpenGL contexts. The C source is bundled and compiled directly with this package.

`RGFW` provides the higher-level wrapper used by `nano-ui-rgfw`, covering OpenGL windows, events, geometry, display scale, cursors, and clipboard access. `RGFW.Raw` exposes the direct C FFI.

## Window lifetime

Create, drive, and close each `Window` on the same bound OS thread (where `createWindowGL` makes the OpenGL context current). `Window` values have no GC finalizers: close every window once and do not use it afterward.

```haskell
import Control.Concurrent (runInBoundThread)
import Control.Exception (bracket)
import RGFW

main :: IO ()
main = runInBoundThread $
  bracket (createWindowGL "RGFW" 0 0 640 480 0 3 2)
    (maybe (pure ()) closeWindow) $ \window ->
      case window of
        Nothing -> ioError (userError "Could not create an OpenGL window")
        Just w -> withEventBuffer $ \events -> loop w events
  where
    loop w events = do
      event <- pollEvent w events
      case event of
        EventWindowClose -> pure ()
        EventNone -> waitForEvent 16 >> loop w events
        _ -> loop w events
```

`withEventBuffer` allocates temporary storage valid only inside its callback. Drain `pollEvent` until `EventNone`, then wait or render and call `swapBuffersGL`.

## Linked system libraries

- **Linux:** X11, Xcursor, Xrandr, Xi
- **macOS:** Cocoa, CoreVideo, IOKit, OpenGL
- **Windows:** `gdi32`, `user32`, `shell32`

## License

MIT, except the bundled RGFW header, which is under the zlib license (`LICENSE-RGFW`).