Tralys.Ui.FreeType
0.1.0-preview.2
dotnet add package Tralys.Ui.FreeType --version 0.1.0-preview.2
NuGet\Install-Package Tralys.Ui.FreeType -Version 0.1.0-preview.2
<PackageReference Include="Tralys.Ui.FreeType" Version="0.1.0-preview.2" />
<PackageVersion Include="Tralys.Ui.FreeType" Version="0.1.0-preview.2" />
<PackageReference Include="Tralys.Ui.FreeType" />
paket add Tralys.Ui.FreeType --version 0.1.0-preview.2
#r "nuget: Tralys.Ui.FreeType, 0.1.0-preview.2"
#:package Tralys.Ui.FreeType@0.1.0-preview.2
#addin nuget:?package=Tralys.Ui.FreeType&version=0.1.0-preview.2&prerelease
#tool nuget:?package=Tralys.Ui.FreeType&version=0.1.0-preview.2&prerelease
Tralys.Ui
A UI library for .NET game clients, rendered through bgfx. You write views as C# components. A component renders its nodes from its props and the observable models it reads, and renders again only when something it read changes. Once warm, a frame allocates nothing, and analyzers keep it that way.
| Package | Role |
|---|---|
Tralys.Ui |
The core: components, flex and grid layout, input, focus, text editing, virtual lists, overlays, animation, theming and the built-in components. Carries the generators and analyzers. |
Tralys.Ui.Engine |
What the core and renderers build on: draw lists, tessellation, fonts, text layout, input contracts, item sources, popup placement, themes and their token compiler, and AllocationGate. |
Tralys.Ui.Bgfx |
The bgfx renderer, with SPIR-V, D3D11, Metal and WGSL shaders embedded. |
Tralys.Ui.FreeType |
The FreeType font backend: Android's libfreetype.so included, desktop libraries from FreeTypeSharp. |
Tralys.Ui.Mvvm |
ObservableObject, [ObservableProperty], [NotifyPropertyChangedFor] and [DelegateCommand], with their generators. |
Tralys.Ui.Docking |
Tab groups that split, float and tear out into windows, with layouts that save and load. |
Tralys.Ui.DevTools |
An in-app inspector for nodes, components, props, render counts and what each render read, plus layout, picking and repaint flashing. |
Tralys.Ui.Testing |
UiDriver, which mounts UI headless and clicks, types, drags and presses through real hit testing. |
- Targets
net11.0. The runtime packages are trim- and NativeAOT-compatible. Tralys.Ui.DevToolsandTralys.Ui.Testingpin the core, and the core pinsTralys.Ui.Engine, each to the exact version of its own release.
Install
dotnet add package Tralys.Ui
dotnet add package Tralys.Ui.Bgfx
dotnet add package Tralys.Ui.FreeType
Use
sealed partial class CounterModel : ObservableObject
{
[ObservableProperty]
public partial int Count { get; set; }
[DelegateCommand]
void Increment() => Count++;
}
readonly record struct CounterProps
{
public CounterModel? Model { get; init; }
}
sealed class Counter : Component<CounterProps>
{
protected override void Render(Ui ui, in CounterProps p)
{
var model = p.Model!;
using (ui.Box(direction: Direction.Column, gap: 8))
{
ui.Text(ui.Format($"{model.Count}"));
ui.Button(text: "Add", onClick: model.IncrementCommand);
}
}
}
var context = new UiContext(textServices);
var view = new UiView(context, host) { Size = new Size(1280, 720) };
view.Mount<Counter, CounterProps>(new CounterProps { Model = model });
// Each frame:
context.Advance(now);
view.Update();
device.BeginFrame();
renderer.Render(view, viewId);
Components
- A component is a sealed class over a
readonly record structof props. The generators give it its own call,ui.Counter(model: model), which takes its props and the placement every node takes (grow,margin,id, ...). - The analyzers require named arguments,
staticcallbacks and slots, and keyed loops. - A model property read during render is observed, so a change re-renders only the components that read it.
ui.Stateholds a component's own state.ui.Rememberkeeps a value,ui.Effectruns an effect andui.Loopanimates.
Hosting
- The host implements
IViewHost(cursor, clipboard, text input). - It feeds input through
PointerMove,PointerDown,PointerUp,Wheel,KeyDown,KeyUp,TextInput,GamepadandStick.
Themes and icons
Themes.DarkandThemes.Lightship with the engine.- For your own themes, add W3C design tokens as
AdditionalFiles:*.tokens.jsonfiles and one*.resolver.json. The build emits aThemesclass. Your tokens lay over the built-in ones, so they set only what they change. - Icons come from your icon font. Add its
IconCodepoints.json(or a*.icons.json) asAdditionalFiles, and set<TralysIconFonts>lucide=lucide</TralysIconFonts>. - The build then emits an
Iconsclass. GiveIcons.SettoUiContext.Icons; a built-in icon role it leaves out is a build error.
Text
- Text maps each character to its font's glyph and kerns the pairs, left to right.
- There are no OpenType substitutions, bidirectional text or colour glyphs. Ligatures, joining or reordering scripts, right-to-left text and emoji sequences don't render correctly.
- Editing still moves the caret and selects by whole user-perceived characters.
Tooling
new Inspector(view, host)inspects aUiViewfrom a view of its own.UiDriver.Render(ui => ui.Counter(model: model))mounts a component headless for a test.- Drive it with
Click,Type,Press,DragandSettle.
- Drive it with
[FramePath]makes the analyzers reject allocation in your per-frame code and in everything of yours it calls.[ColdPath]marks a callee that runs once for what it makes, such as a cache filled on first use.
Shipping builds
- Nodes are told apart by their caller's source path, which the compiler writes into your assembly.
<TralysStripCallerPaths>true</TralysStripCallerPaths>replaces those paths withAssemblyName#Ntokens.- The build decodes them in
obj/AssemblyName.callerpaths.txt. - The inspector can then no longer open the source.
- The build decodes them in
Custom renderers
- A renderer of your own reads a
DrawList's vertices, batches and layers. - They are
[Experimental]as TRL5001 while the vertex format may change: opt in with<NoWarn>$(NoWarn);TRL5001</NoWarn>.
tests/Tralys.Ui.PackageSmoke is a
complete headless consumer: fonts, renderer, a model-bound component, a command, the inspector and a test driver.
Render to a texture
A BgfxRenderTarget works both ways:
- To show your game's pixels in the UI (a minimap, or a 3D preview with
depth: true), draw into itsFrameBufferand show it withui.Image(target). - To put a view on a surface in your world, draw the view into a target and sample
target.Color:
var target = new BgfxRenderTarget(512, 512, mips: true);
var renderer = new BgfxViewRenderer(device);
var view = new UiView(context, host) { Size = new Size(target.Width, target.Height) };
view.Mount<Panel, PanelProps>(props);
// Each frame, after device.BeginFrame(), on view ids that sort before the one sampling the target:
view.Update();
if (renderer.RenderTo(view, target, (ushort)(nextView + LayerViews), nextView, LayerViews))
nextView += LayerViews + 1;
- Shared device:
- Make one
BgfxRenderDeviceafter bgfx starts; every view's renderer shares it. - Call its
BeginFrameonce a frame, before any view renders.
- Make one
- Redraws:
RenderTodraws only when the view changed, so an idle panel costs no draw calls and no view ids.- Pass
force: truewhen a texture the view draws has new pixels.
- Texels:
- Coordinate (0, 0) is the view's top left.
- Texels are premultiplied and gamma-encoded: blend with one and inverse source alpha.
- In a lit or tone-mapped pipeline, convert them in your shader.
- Input:
- Turn your ray hit into view pixels and call
PointerMove,PointerDownandPointerUp. - While a press is held, keep sending moves after the ray leaves; otherwise call
PointerLeave. PointerCancelends a press that never released.WindowFocustells the view whether it has the keyboard.
- Turn your ray hit into view pixels and call
Demo
dotnet run --project samples/Tralys.Ui.Demo -c Release
This opens a gallery of every component's stories; --help lists the options and F12 toggles the inspector. The
gallery also runs in the browser wherever WebGPU is available, and
?story=Switch.States opens a single story there.
Contributing
Building, testing and releasing: CLAUDE.md.
License
MIT.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- FreeTypeSharp (>= 3.1.0)
- Tralys.Ui.Engine (>= 0.1.0-preview.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.0-preview.2 | 53 | 11/19/2026 |
| 0.1.0-preview.1 | 58 | 11/19/2026 |