DIR.Lib
6.14.1491
See the version list below for details.
dotnet add package DIR.Lib --version 6.14.1491
NuGet\Install-Package DIR.Lib -Version 6.14.1491
<PackageReference Include="DIR.Lib" Version="6.14.1491" />
<PackageVersion Include="DIR.Lib" Version="6.14.1491" />
<PackageReference Include="DIR.Lib" />
paket add DIR.Lib --version 6.14.1491
#r "nuget: DIR.Lib, 6.14.1491"
#:package DIR.Lib@6.14.1491
#addin nuget:?package=DIR.Lib&version=6.14.1491
#tool nuget:?package=DIR.Lib&version=6.14.1491
DIR.Lib
Device-Independent input + Rendering library for .NET. Provides the shared foundation for both GPU (SDL3 + Vulkan) and terminal (Console) applications. Pure-managed, AOT-compatible, no native dependencies.
Rendering Primitives
PointInt— 2D integer pointRectInt— 2D integer rectangle (note: constructor argument order is(LowerRight, UpperLeft))RectF32— 2D float rectangle (x, y, width, height) for pixel-based layoutRGBAColor32— 32-bit RGBA color with Lerp, WithAlpha, LuminanceTextAlign— Near/Center/Far alignment enumRenderer<TSurface>— Abstract renderer: FillRectangle, DrawRectangle, FillEllipse / DrawEllipse, DrawLine, DrawLineDashed, DrawPolyline, DrawPolylineDashed, DrawText, MeasureTextRgbaImage/RgbaImageRenderer : Renderer<RgbaImage>— pure software renderer for tests and headless scenarios; output is plain RGBA pixels (callers own the choice of PNG / JPEG / TIFF / sixel encoder)GlyphBitmap/SdfGlyphBitmap— raw RGBA glyph bitmap with bearing/advance info; SDF variant for scalable text on the GPU sideManagedFontRasterizer— pure-managed glyph rasterizer backed bySharpAstro.Fonts.OpenTypeFont; supports COLRv1 color glyphs, grayscale, and PDF subset fonts. AOT-compatible, no GC pinning, no native bindings.FontResolver— resolves platform-default monospace fonts and enumerates installed font files across system + per-user font directories (incl. Windows 11%LOCALAPPDATA%\Microsoft\Windows\Fonts)
Input Handling
InputEvent— open record hierarchy:KeyDown,TextInput,MouseDown,MouseUp,MouseMove,Scroll,Pinch,PinchEndInputKey— platform-agnostic key codes (letters, digits, function keys, navigation, symbols)InputModifier— modifier flags (Shift, Ctrl, Alt)MouseButton— Left / Middle / RightIWidget— shared interface withHandleInputfor both pixel and terminal widgets
Platform bridges (in downstream packages):
SdlVulkan.RendererprovidesSdlInputMapping(SDL3 Scancode → InputKey)Console.LibprovidesConsoleInputMapping(ConsoleKey → InputKey)
Widget System
IPixelWidget— extends IWidget with pixel-coordinate hit testing and click dispatchPixelWidgetBase<TSurface>— base class for pixel widgets: clickable regions, text input, buttons, dropdowns, drawing helpersPixelLayout+PixelDockStyle— dock-based layout engine (Top/Bottom/Left/Right/Fill)DockLayout<T>— generic dock layout usingINumber<T>(the integer / pixel layouts above are built on this)ClickableRegion+ClickableRegionTracker— registered during render, walked in reverse for hit testingHitResult— open discriminated union:TextInputHit,ButtonHit,ListItemHit,SlotHit<T>,SliderHitDropdownMenuState— dropdown / popup menu state machine
Declarative Layout (DIR.Lib.Layout)
A surface-agnostic declarative layout engine. Describe a tree of immutable records; the engine measures + arranges it into rects; a per-surface painter (PixelWidgetBase.PaintLayout) draws each node and binds its click region from the same arranged rect — draw == hit by construction, with no separate hit-rect arithmetic that can drift.
Layout.Node— the tree. Variants:Stack(vertical/horizontal),Dock(edge strips + a fill remainder),Grid,Wrap(children flow and wrap into new lines when out of extent — the flexboxwrapfor toolbars/chip rows on narrow surfaces),Overlay(base/top, for modals/popups),Split(two resizable panes + a draggable divider),Leaf(aContent). Chrome lives on the base node:Width/Height(Sizing),Padding,Background,Hit,OnClick,CollapseThreshold.Layout.Content— leaf payload:Text(value + colour + alignment),Box(fixed icon/swatch/spacer),Fill(an app-drawn escape hatch — chart, image, text input; routed byKey).Layout.Sizing—Fixed(designUnits)|Auto(shrink-to-content) |Star(weight, min, max)(proportional split of leftover). Values are design units mapped to surface units (px × DPI, or character cells) byLayout.IMeasureContext.Min/Maxclamp the resolved extent of an Auto/Star axis (0 = unclamped): a min-clamped Star holds its floor and overflows visibly instead of starving to zero when Fixed siblings eat the container, and a max-clamped Star's surplus redistributes to its Star siblings.- Collapse-below-minimum —
.CollapseBelow(designUnits): when a parentStackwould give the node a main-axis extent under the threshold, it drops out of the arrangement entirely (not painted, no hit, no gap) and its space redistributes to the survivors. The declarative form of "show the strip only when it is at least N tall". Layout.Engine.Arrange(root, rect, ctx)— two-pass measure/arrange; returns a pre-orderImmutableArray<Layout.ArrangedNode>the painter walks in order for correct z-stacking. Generic over the coordinate type (floatpixels /intcells), so it is headless-testable with a stubIMeasureContext.
Layout.Builder DSL
Author trees with the fluent DSL rather than new Layout.Node.X { } initializers — it emits the same records:
using Layout = DIR.Lib.Layout; // alias once per project; keep `using DIR.Lib;`
Layout.Builder.HStack(
Layout.Builder.Text(label, 14f, dim).WStar(0.35f).HStar(),
Layout.Builder.Fill(key: "input").Stretch())
.RowH(28f)
.Bg(active ? activeBg : normalBg)
.Clickable(new HitResult.ButtonHit("go"), onClick);
- Factories —
VStack/HStack/Text/Box/Fill/Spacer/Grid/WrapH/WrapV/Overlay/Split/Dock(+Left/Right/Top/Bottomdock-strip helpers). - Fluent modifiers (instance methods on
Layout.Node, each a purethis with { … }transform) —.W/.H/.WFixed/.WStar(weight, min, max)/.WAuto(+H*),.WClamp/.HClamp(min, max)(clamp the current kind),.RowH(u)(full-width row),.ColW(u)(fixed-width column),.Stretch()(fill both axes),.Bg,.Pad,.Clickable(hit, onClick?),.CollapseBelow(u),.WithGap/.WithGaps/.WithLineGap. - Consumer convention — alias
using Layout = DIR.Lib.Layout;(aglobal using, or a csproj<Using Include="DIR.Lib.Layout" Alias="Layout" />) and write the qualifiedLayout.Node/Layout.Builder. Do notusing DIR.Lib.Layout;directly — it drops the collision-prone barewords (Node,Content,Size<T>) into scope. (A plainusing DIR.Lib;does not surface the nestedLayoutnamespace; a using-directive imports types, not nested namespaces.) A consumer that already owns aLayouttype must rename it.
Text Input
TextInputState— single-line text input state machine with cursor, selection, undoTextInputRenderer— renders text input using anyRenderer<T>(blinking cursor, selection highlight)- Callbacks:
OnCommit(async),OnCancel,OnTextChanged,OnKeyOverride
Signals & Async
SignalBus— thread-safe typed event bus.Post<T>()is thread-safe,ProcessPending()runs on the render thread.- Built-in signals:
ActivateTextInputSignal,DeactivateTextInputSignal,RequestExitSignal,RequestRedrawSignal SignalDirectory(source-generated) — the package ships a Roslyn source generator that emitsSignalDirectory.BuildFactories(SignalBus bus, …overrides), aname → Action<JsonElement>map over every*Signaltype in the consuming assembly, with no runtime reflection. Each factory constructs its signal from a JSON payload via the reflection-freeSignalJsonscalar binders (camelCase key = parameter name; missing field → the parameter's declared default) and posts it to the bus. Lets a live UI inspector / test harness list and post any bus signal by name. Gated on theDEBUGsymbol (nothing generated in Release) and onSignalBusbeing referenced; signals with a required non-scalar parameter are skipped.BackgroundTaskTracker— collects background tasks, checks completions per frame, logs errors viaILogger. CallProcessCompletions()each frame,DrainAsync()at shutdown.
Math Layout (DIR.Lib.MathLayout)
TeX-style box model for rendering mathematical expressions. Each Box exposes Width / Height (ascent) / Depth (descent) and paints itself relative to a (penX, baselineY) the parent provides.
Box+BoxStyle— abstract box with baseline, plus a record of font / size / spacing parameters threaded through layout. Pixel-valued math metrics (axis height, fraction-rule thickness, …) come from the font's OpenType MATH table when available, with TeX-style ratio fallbacks.- Box types:
GlyphBox,MathGlyphBox,HBox,FracBox,SqrtBox,BracketBox,BigOperatorBox,SupSubBox,AccentBox,LimitsBox,MatrixBox,OverlayBox,StretchyVerticalBox BoxRasterizer.RenderToRgba(box, style)— rasterizes aBoxto a transparentRgbaImage. Pure — no encoder coupling; callers choose PNG / sixel / half-block downstream.
Markdown + LaTeX (DIR.Lib.Markdown)
A LALR.CC-driven markdown + math-mode LaTeX pipeline. The math, markdown-inline, and markdown-block grammars (grammars/*.lalr.yaml) are compiled at build time by the SharpAstro.LALR.CC source generator into partial classes baked into this assembly — no runtime parser construction, AOT-clean.
MdAst— block & inline AST records (MdParagraph,MdHeading,MdMathBlock,MdList,MdTable,MdInline, …)MarkdownBlockVisitor/MarkdownInlineVisitor— visitors over the generated grammars; produce the AST.LatexUnicodeVisitor— math-mode LaTeX → Unicode (inline math:$x^2$→x²).BoxBuildingVisitor— math-mode LaTeX → deferredBoxbuilders (display math:$$..$$→MathLayoutbox tree →BoxRasterizer).Mhchem— renders an mhchem\ce{...}body to Unicode (auto-subscripts, arrows, ion charges, …).MarkdownMacros— parser-side facade: macro expansion (\text{},\boxed{},\ce{},\begin/\endenvironments), backslash-escape resolution, and theRenderMathUnicodeentry point.
Usage
using DIR.Lib;
using DIR.Lib.MathLayout;
using DIR.Lib.Markdown;
// Rendering
renderer.FillRectangle(rect, new RGBAColor32(0x30, 0x50, 0x90, 0xff));
renderer.DrawText("Hello", fontPath, 14f, white, layout);
renderer.DrawPolyline(points, color, thickness: 2);
// Input handling
widget.HandleInput(new InputEvent.KeyDown(InputKey.Enter, InputModifier.Ctrl));
// Pixel layout
var layout = new PixelLayout(contentRect);
var header = layout.Dock(PixelDockStyle.Top, 28f);
var sidebar = layout.Dock(PixelDockStyle.Left, 200f);
var content = layout.Fill();
// Background tasks
tracker.Run(async () => await SaveAsync(), "Save profile");
if (tracker.ProcessCompletions(logger)) needsRedraw = true;
// Math rendering (display LaTeX → RGBA image)
var unicode = MarkdownMacros.RenderMathUnicode("E = mc^2"); // "E = mc²"
var image = BoxRasterizer.RenderToRgba(boxBuilder(style), style);
Dependencies
- SharpAstro.Fonts — pure-managed OpenType font loader & rasterizer (COLRv1, MATH table, CFF/glyf, hinting)
- SharpAstro.LALR.CC — LALR(1) parser + source generator (compile-time, build-only)
- Microsoft.Extensions.Logging.Abstractions —
ILoggerinterface forBackgroundTaskTracker
DIR.Lib is codec-agnostic (4.0+): BoxRasterizer.RenderToRgba returns an RgbaImage, and consumers that need TIFF / PNG / JPEG / ICC encoding declare those packages (SharpAstro.Tiff, SharpAstro.Png, SharpAstro.Color.Icc, …) themselves.
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0)
- SharpAstro.Fonts (>= 1.6.671)
- SharpAstro.LALR.CC (>= 3.1.0)
NuGet packages (5)
Showing the top 5 NuGet packages that depend on DIR.Lib:
| Package | Downloads |
|---|---|
|
TianWen.Lib
Package Description |
|
|
SdlVulkan.Renderer
Package Description |
|
|
Console.Lib
Package Description |
|
|
WebGl.Renderer
WebGL2 rendering backend for DIR.Lib's Renderer<TSurface> — Blazor WebAssembly, command-buffer JS interop, MSDF text via the shared SdfFontAtlas core. AOT compatible. |
|
|
DIR.Lib.Shaping
Pure-managed OpenType text-shaping adapter for DIR.Lib: an ITextShaper backed by SharpAstro.Fonts.Shaping (script itemization, GSUB/GPOS, Arabic joining, RTL). Optional satellite — DIR.Lib core stays shaping-free. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 6.16.1541 | 0 | 7/22/2026 |
| 6.15.1531 | 0 | 7/22/2026 |
| 6.14.1511 | 0 | 7/22/2026 |
| 6.14.1491 | 139 | 7/20/2026 |
| 6.13.1481 | 53 | 7/20/2026 |
| 6.12.1461 | 25 | 7/19/2026 |
| 6.11.1451 | 60 | 7/19/2026 |
| 6.11.1441 | 254 | 7/16/2026 |
| 6.10.1431 | 111 | 7/16/2026 |
| 6.9.1421 | 62 | 7/13/2026 |
| 6.8.1411 | 137 | 7/13/2026 |
| 6.8.1401 | 56 | 7/11/2026 |
| 6.8.1381 | 123 | 7/11/2026 |
| 6.8.1361 | 148 | 7/9/2026 |
| 6.8.1341 | 80 | 7/7/2026 |
| 6.7.1321 | 36 | 7/6/2026 |
| 6.6.1301 | 74 | 7/6/2026 |
| 6.5.1281 | 55 | 7/5/2026 |
| 6.4.1261 | 75 | 7/5/2026 |
| 6.4.1241 | 46 | 7/5/2026 |