|
| 1 | +# Nuklear.Net |
| 2 | + |
| 3 | +.NET 10 bindings for [Nuklear](https://github.com/Immediate-Mode-UI/Nuklear), a single-header immediate-mode GUI library written in C. |
| 4 | + |
| 5 | +> **Status: incomplete.** Not all Nuklear widgets and API surface are wrapped. The high-level C# layer covers the core widget set and rendering pipeline, but several Nuklear features remain either unbound or untested. See [Missing features](#missing-features). |
| 6 | +
|
| 7 | +--- |
| 8 | + |
| 9 | +## Projects |
| 10 | + |
| 11 | +| Project | Description | |
| 12 | +|---|---| |
| 13 | +| `Nuklear.Net` | High-level C# API (`Context`, `InputFrame`, `NuklearDevice`, …) | |
| 14 | +| `Nuklear.Net.Native` | P/Invoke bindings generated by CppSharp against `NuklearNetNative` | |
| 15 | +| `Nuklear.Net.NativeGen` | Code-gen driver (CppSharp) – run to regenerate the bindings | |
| 16 | +| `Examples/` | Backend integrations: Silk.NET/OpenGL, OpenTK 4, MonoGame | |
| 17 | + |
| 18 | +## NuGet packages |
| 19 | + |
| 20 | +Pre-built packages for all supported platforms are uploaded as the `nuget-packages` artifact on every CI run. Download them from the [latest Build action](https://github.com/SimonSeider/Nuklear.Net/actions/workflows/build.yml) — expand the run, scroll to **Artifacts**, and download `nuget-packages`. |
| 21 | + |
| 22 | +No NuGet feed is published; the packages must be consumed from a local folder source or a private feed. |
| 23 | + |
| 24 | +## Requirements |
| 25 | + |
| 26 | +- .NET 10 SDK |
| 27 | +- CMake ≥ 3.16 |
| 28 | +- A C99 compiler (GCC / Clang / MSVC) |
| 29 | + |
| 30 | +## Building the native library |
| 31 | + |
| 32 | +The native shared library must be built before the managed projects can compile. |
| 33 | + |
| 34 | +**Linux / macOS** |
| 35 | + |
| 36 | +```bash |
| 37 | +./scripts/build-native.sh linux-x64 # or linux-arm64 / osx-x64 / osx-arm64 |
| 38 | +``` |
| 39 | + |
| 40 | +**Windows** |
| 41 | + |
| 42 | +```powershell |
| 43 | +.\scripts\build-native.ps1 -Rid win-x64 # or win-arm64 |
| 44 | +``` |
| 45 | + |
| 46 | +The script runs CMake, builds the shared library, and copies it to `Nuklear.Net.Native/runtimes/<rid>/native/`. |
| 47 | + |
| 48 | +## Building the solution |
| 49 | + |
| 50 | +```bash |
| 51 | +dotnet build Nuklear.Net.slnx |
| 52 | +``` |
| 53 | + |
| 54 | +## Running examples |
| 55 | + |
| 56 | +```bash |
| 57 | +dotnet run --project Examples/SilkNet/Nuklear.Net.Examples.SilkNet.csproj |
| 58 | +dotnet run --project Examples/OpenTK/Nuklear.Net.Examples.OpenTK.csproj |
| 59 | +dotnet run --project Examples/MonoGame/Nuklear.Net.Examples.MonoGame.csproj |
| 60 | +``` |
| 61 | + |
| 62 | +See [`Examples/README.md`](Examples/README.md) for backend implementation details. |
| 63 | + |
| 64 | +## Basic usage |
| 65 | + |
| 66 | +```csharp |
| 67 | +// 1. Create the context once. |
| 68 | +using var ctx = new Context(); |
| 69 | +ctx.Initialize(device, NuklearRenderingOptions.CreatePixelPerfect()); |
| 70 | + |
| 71 | +// 2. Each frame: |
| 72 | +ctx.RunFrame(device, |
| 73 | + input => |
| 74 | + { |
| 75 | + input.MousePosition = new Vec2(mouseX, mouseY); |
| 76 | + input.SetMouseButton(MouseButton.Left, leftPressed); |
| 77 | + }, |
| 78 | + () => |
| 79 | + { |
| 80 | + // Nuklear UI built here via ctx.Native (NkContext) |
| 81 | + }); |
| 82 | +``` |
| 83 | + |
| 84 | +## Architecture |
| 85 | + |
| 86 | +`NuklearDevice` is the rendering contract backends must implement: |
| 87 | + |
| 88 | +- `CreateTexture` – uploads RGBA pixel data (font atlas, etc.) |
| 89 | +- `SetDrawBuffers` – receives converted vertex/index buffers from `nk_convert` |
| 90 | +- `RenderDrawCommand` – issues one draw call per Nuklear draw command (scissor + texture) |
| 91 | + |
| 92 | +`Context` owns the Nuklear context lifetime, the font atlas, input dispatch, display metrics, and HiDPI scaling. |
| 93 | + |
| 94 | +## Missing features |
| 95 | + |
| 96 | +The following Nuklear functionality is not yet surfaced through the managed API: |
| 97 | + |
| 98 | +- Custom font loading (only the built-in default font is exposed) |
| 99 | +- `nk_plot` / `nk_plot_function` (charts) |
| 100 | +- `nk_color_picker` / `nk_color_*` widgets |
| 101 | +- `nk_combo` / `nk_combobox` variants beyond the basic binding |
| 102 | +- `nk_popup_*` managed wrappers |
| 103 | +- `nk_tooltip` convenience API |
| 104 | +- `nk_style_*` full style struct access from C# (only uniform scaling is applied) |
| 105 | +- Multi-font support and glyph range selection |
| 106 | +- `nk_list_view` (field `end` is intentionally ignored by the generator) |
| 107 | + |
| 108 | +Raw access through `ctx.Native` (the generated `NkContext`) is always available as a workaround for any missing wrapper. |
| 109 | + |
| 110 | +## Regenerating bindings |
| 111 | + |
| 112 | +```bash |
| 113 | +dotnet run --project Nuklear.Net.NativeGen/Nuklear.Net.NativeGen.csproj |
| 114 | +``` |
| 115 | + |
| 116 | +Requires the native build for the host RID to already exist. Output is written to `Nuklear.Net.Native/Generated/`. |
0 commit comments