Skip to main content

Getting started

Prerequisites​

  • The .NET 10 SDK.
  • Windows is the tested platform. Roboto and Noto Sans Arabic are bundled in Sway.Assets; other fonts come from the system (see Known limits for platform caveats).
  • For the live window, a GPU and driver with OpenGL 3.3 core. Headless rendering runs on the CPU and needs no GPU.
  • For the browser host, the wasm-tools workload: dotnet workload install wasm-tools.

Solution layout​

Sway.slnx
Core
Sway.Widgets/ platform- and design-neutral library
Sway.Assets/ bundled fonts and the Material icon set
Sway.Gl/ OpenGL inside widgets
Sway.Media/ media controller, video surface, IMediaBackend
Sway.Media.LibVlc/ LibVLC backend (Windows, Linux, macOS, Android)
Sway.Media.Web/ browser media backend
Platforms
Sway.Platform.Desktop/ window, input, OS theme (Silk.NET); provides App.Run
Sway.Platform.Android/ GL surface, touch, soft keyboard, back gesture
Sway.Platform.Web/ Blazor WebAssembly component (SwayView)
Sway.Platform.Headless/ windowless host that renders to PNG
Extra (design systems)
Sway.Extras.Material3/ Material 3
Sway.Extras.Material3.Media/ Material 3 video and audio players
Sway.Extras.Ibm/ IBM Carbon
Sway.Extras.Fiori/ SAP Fiori
Sway.Extras.Shopify/ commerce components
Sway.Extras.Blueprint/ Blueprint tokens (early)
Examples
Sway.Example/ the shared demo UI
Sway.Example.Desktop/ .Android/ .Web/ .Headless/ one runner per host
Tests
Sway.Widgets.Tests/ and Sway.Extras.{Material3,Ibm,Fiori,Shopify}.Tests/
templates/sway-app/ dotnet new template
website/ this documentation site

An app references Sway.Widgets, one platform project, and the design system it wants. Sway.Widgets depends only on SkiaSharp and HarfBuzz, so it carries no windowing or OS code. On desktop, reference Sway.Platform.Desktop as well and call App.Run. Add using Sway.Widgets;, plus the design system's namespace (Sway.Extras.Material3, Sway.Extras.Ibm, Sway.Extras.Fiori, Sway.Extras.Shopify). The examples here use Material 3.

Run the demo​

dotnet build Sway.slnx
dotnet run --project Sway.Example.Desktop

The demo is a Material 3 app with a navigation rail and pages for components, layout, forms, motion, effects, right-to-left, a stress test, media, icons, navigation, a Carbon page and a Shopify-style storefront. The app bar has switches for light/dark mode, the seed colour and text direction. Run the tests with dotnet test.

Sway.Example.Desktop/Program.cs currently launches the Fiori component catalogue (DemoPage). Set SWAY_GL_DEMO=1 to see the OpenGL demo instead, or edit Program.cs to start DemoRoot, the multi-page Material 3 demo described above.

Run in the browser​

dotnet run --project Sway.Example.Web

To host Sway in your own Blazor WebAssembly app, add <SwayView Root="new MyApp()" />. A web app needs a server that answers every path with index.html if it uses the Router. The soft keyboard on touch devices is not supported on the web yet.

Create a project from the template​

dotnet new install templates/sway-app
dotnet new sway -n MyApp --swayRoot ../Sway

This makes a desktop project with a Material 3 counter. --swayRoot points at your Sway checkout.

Your first app​

using Sway.Extras.Material3;
using Sway.Widgets;

App.Run(new MaterialApp(home: new HelloPage()), "Hello", 640, 480);

class HelloPage : StatelessWidget
{
public override Widget Build(BuildContext context) => new Scaffold(
appBar: new AppBar(title: new Text("Hello")),
body: new Center(new FilledButton(new Text("Press me"),
() => Dialogs.ShowSnackBar(context, "Pressed"))));
}

App.Run(widget, title, width, height) opens the window and mounts the widget. MaterialApp installs the theme, default text style, overlay and surface colour. Without it the Material 3 widgets still work with the default light theme.

Stateful widgets​

class Counter : StatefulWidget
{
public override State CreateState() => new CounterState();
}

class CounterState : State<Counter>
{
int _count;

public override Widget Build(BuildContext context) =>
new FilledButton(new Text($"Clicked {_count} times"), () => SetState(() => _count++));
}

Constructors use C# named arguments and collection expressions, which keeps trees close to Flutter's shape:

new Column(
crossAxisAlignment: CrossAxisAlignment.Start,
spacing: 8,
children:
[
new Text("Title", style: Theme.Of(context).TextTheme.TitleLarge),
new Row(children: [new Icon(Icons.Info), new Text("Details")]),
])

Headless mode: screenshots and benchmarks​

Sway.Example.Headless renders without a window, which is useful for checking layout changes or scripting input on a machine with no display:

# Render a page to PNG
dotnet run --project Sway.Example.Headless -- --screenshot out.png --page layout

# Dark mode, right-to-left, custom size
dotnet run --project Sway.Example.Headless -- --screenshot out.png --page rtl --dark --size 1100x900

# Script pointer and keyboard input before capturing
dotnet run --project Sway.Example.Headless -- --screenshot out.png --page forms --click 300,230 --type "hello" --key Tab

# Per-frame cost for scrolling and hovering a page (CPU raster)
dotnet run --project Sway.Example.Headless -- --bench --page stress

Pages: material, layout, forms, motion, effects, rtl, stress, media, icons, carbon, shopify. Options: --dark, --rtl, --size WxH. Steps: --move x,y, --click x,y, --wheel x,y,delta, --key [ctrl+][shift+]Name, --type text, --advance ms (advances the manual animation clock). Steps run in order and the PNG shows the final state.

You can do the same in your own code, for example in a test:

Headless.Screenshot(new MyPage(), "out.png", 800, 600, new Action<WidgetsBinding>[]
{
b => b.Gestures.PointerDown(100, 100),
b => b.Gestures.PointerUp(100, 100),
b => b.AdvanceClock(TimeSpan.FromMilliseconds(300)),
});