YogaSharp.Layout 1.0.6

dotnet add package YogaSharp.Layout --version 1.0.6
                    
NuGet\Install-Package YogaSharp.Layout -Version 1.0.6
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="YogaSharp.Layout" Version="1.0.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="YogaSharp.Layout" Version="1.0.6" />
                    
Directory.Packages.props
<PackageReference Include="YogaSharp.Layout" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add YogaSharp.Layout --version 1.0.6
                    
#r "nuget: YogaSharp.Layout, 1.0.6"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package YogaSharp.Layout@1.0.6
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=YogaSharp.Layout&version=1.0.6
                    
Install as a Cake Addin
#tool nuget:?package=YogaSharp.Layout&version=1.0.6
                    
Install as a Cake Tool

<div align="center"> <img src="./assets/logo.svg" alt="YogaSharp Logo" width="128" height="128"> <h1>YogaSharp</h1> <p><b>A modern, zero-allocation, cross-platform .NET wrapper for the Facebook Yoga layout engine.</b></p> </div>


YogaSharp provides a highly optimized, allocation-free .NET API over the widely-used Yoga layout engine by Meta. It allows you to build complex Flexbox layouts in C# with native performance, making it the perfect foundational layer for game engines (like Unity or Godot) or custom retained-mode UI frameworks.

✨ Features

  • Zero-Allocation Hot Path: Layout evaluation (CalculateLayout()), properties, and result fetching (.Layout) trigger absolutely zero heap allocations, relieving pressure from the .NET Garbage Collector.
  • Modern .NET API: Supports .NET 8.0, 9.0, and 10.0 utilizing readonly struct, safe memory handles, and standard C# naming conventions.
  • Cross-Platform Native Binaries: Distributed automatically via NuGet. Runs on Windows (win-x64), Linux (linux-x64), and macOS (osx-arm64) out of the box.
  • Engine Agnostic: Perfect for rendering UI in 2D or 3D spaces. No dependencies on UI toolkits (WPF, Avalonia, MAUI, etc.).

📦 Installation

(Packages will soon be available via NuGet).

The package is split into two logical pieces:

  • YogaSharp.Core: Contains the native interop, memory safe-handles, and fundamental structures. Native binaries are distributed within this package.
  • YogaSharp.Layout: Provides the modern, ergonomic YogaNode object tree API.

🚀 Quick Start

Here is a quick example of setting up a root UI container with a sidebar and content area using standard Flexbox properties:

using System;
using YogaSharp.Core;
using YogaSharp.Layout;

// 1. Initialize the tree
// Notice: You only need to Dispose the root. It owns its children.
using var root = new YogaNode
{
    Width = 800,
    Height = 600,
    Padding = 20,
    FlexDirection = FlexDirection.Row // Layout elements horizontally
};

// 2. Setup a Sidebar
var sidebar = new YogaNode
{
    Width = 200,
    MarginRight = 20
};

// 3. Setup a Content Area that fills the remaining space
var content = new YogaNode
{
    FlexGrow = 1 // Take up remaining width
};

// 4. Build the hierarchy
root.AddChild(sidebar);
root.AddChild(content);

// 5. Compute the Layout!
root.CalculateLayout();

// 6. Access the results (zero allocation!)
Console.WriteLine($"Sidebar: X={sidebar.Layout.X}, Y={sidebar.Layout.Y}, W={sidebar.Layout.Width}, H={sidebar.Layout.Height}");
Console.WriteLine($"Content: X={content.Layout.X}, Y={content.Layout.Y}, W={content.Layout.Width}, H={content.Layout.Height}");

Layout Visualization

<div align="center"> <img src="./assets/layout-example.svg" alt="YogaSharp Layout Math Example" width="80%"> </div>

🏗️ Architecture & Memory

YogaSharp implements a strict ownership model to prevent memory leaks while keeping C# ergonomics pleasant.

  • Native pointers (IntPtr) are never exposed publicly. They are safely enclosed within SafeHandle wrappers.
  • The parent YogaNode owns its children. Disposing the parent cascades destruction natively and managed-side.
  • Read more in the Architecture Guide and Memory Ownership Rules.

This project is built around the Facebook Yoga engine, an open-source project by Meta Platforms, Inc.

  • YogaSharp code wrapper is licensed under the MIT License.
  • The underlying Yoga C++ Engine is licensed under the MIT License by Facebook, Inc.
  • Please refer to THIRD-PARTY-NOTICES.txt for the full Meta copyright notice and license.

YogaSharp is not officially endorsed by or affiliated with Meta Platforms, Inc.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
1.0.6 119 6/11/2026
1.0.5-preview 102 5/23/2026
1.0.4-preview 104 5/13/2026
1.0.3-preview 99 5/13/2026
1.0.2-preview 98 5/12/2026