> For the complete documentation index, see [llms.txt](https://docs.flatredball.com/gum/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.flatredball.com/gum/code/getting-started/setup/adding-initializing-gum/skiasharp-general-canvas.md).

# SkiaSharp (General Canvas)

## Introduction

This page is for projects that render with SkiaSharp but don't fit one of Gum's dedicated SkiaSharp hosts (see [Runtimes](https://docs.flatredball.com/gum/code/about/runtimes.md)). It assumes you already have your own `SKCanvas` rendering in your project, gotten however your platform requires. Skia itself is just a 2D graphics API, not a windowing or input system, so beyond "get an `SKCanvas` on screen," Gum can't offer platform-specific setup guidance here, that part is entirely up to your own project. To draw into an offscreen surface and read the pixels back instead, see [Rendering to an Image](https://docs.flatredball.com/gum/code/getting-started/setup/adding-initializing-gum/skiasharp-general-canvas/skiasharp-rendering-to-an-image.md).

{% hint style="info" %}
If your engine or framework has its own page in [Adding/Initializing Gum](https://docs.flatredball.com/gum/code/getting-started/setup/adding-initializing-gum.md), use that page instead. Each of those wires up a canvas view or window for you. This page is for everything else.
{% endhint %}

{% hint style="warning" %}
This setup is rendering and layout only. There is no supported way to wire mouse, keyboard, or Forms control interactivity (hover, click, focus) here, not even as DIY glue code. If you need interactive Forms controls on SkiaSharp, use the dedicated setup page for your engine or framework instead (see [Adding/Initializing Gum](https://docs.flatredball.com/gum/code/getting-started/setup/adding-initializing-gum.md)).
{% endhint %}

## Adding Gum NuGet package

The easiest way to add Gum to your project is to use the NuGet package. Open your project in your preferred IDE, or add Gum through the command line.

Add the Gum.SkiaSharp.Standalone NuGet package (<https://www.nuget.org/packages/Gum.SkiaSharp.Standalone>)

Modify csproj:

```xml
<PackageReference Include="Gum.SkiaSharp.Standalone" />
```

Or add through command line:

```bash
dotnet add package Gum.SkiaSharp.Standalone
```

{% hint style="warning" %}
Don't name your project `SkiaGum`, that's the assembly name inside the `Gum.SkiaSharp` package. A same-named project produces a same-named output DLL that silently overwrites the runtime's copy in your `bin` folder, causing a `TypeLoadException` at runtime with no build warning. Gum's build now catches this for you: if your `AssemblyName` collides, the build fails with an error telling you to change it.
{% endhint %}

## Adding Source (Optional)

You can directly link your project to source instead of a NuGet package for improved debuggability, access to fixes and features before NuGet packages are published, or if you are interested in contributing.

To add source, first clone the Gum repository: <https://github.com/vchelaru/Gum>

If you have already added the Gum NuGet package to your project, remove it.

Add the following project to your solution:

* \<Gum Root>/Runtimes/SkiaGum.Standalone/SkiaGum.Standalone.csproj

`SkiaGum.Standalone.csproj` already references `SkiaGum` and `GumCommon` itself, so you do not need to add them separately.

Next, add SkiaGum.Standalone as a project reference in your game project. Your project might look like this depending on the location of the Gum repository relative to your game project:

```xml
<ProjectReference Include="..\Gum\Runtimes\SkiaGum.Standalone\SkiaGum.Standalone.csproj" />
```

## Initializing Gum

{% hint style="info" %}
`GumService` for this page's setup is available in `Gum.SkiaSharp.Standalone` starting September 2026, or now if building Gum from source. Before that, WPF and MAUI hosts still get their own copy of the same type through their dedicated packages (see [WPF](https://docs.flatredball.com/gum/code/getting-started/setup/adding-initializing-gum/wpf.md) / [.NET MAUI](https://docs.flatredball.com/gum/code/getting-started/setup/adding-initializing-gum/.net-maui.md)); this page's setup did not have one until now.
{% endhint %}

`Gum.SkiaSharp.Standalone` includes a render-only `GumService`, the same `Initialize`/`Update`/`Draw`/`HandleResize` API shape used by the dedicated SkiaSharp hosts, just without input. Call `GumUI.Initialize` once you have an `SKCanvas`, passing a `.gumj` project path only if you're loading one (omit it for a code-only setup):

```csharp
// Initialize
using Gum;
using SkiaSharp;

GumService GumUI = GumService.Default;

GumUI.Initialize(canvas, "Content/GumProject/GumProject.gumj");
```

`Initialize` reads the size from `canvas.DeviceClipBounds`. If your canvas's clip is not configured yet, pass the size yourself with `GumUI.Initialize(canvas, width, height, "Content/GumProject/GumProject.gumj")`.

Each frame, update and then draw:

```csharp
// Update
GumUI.Update(totalSecondsSinceStart);
```

```csharp
// Draw
GumUI.Draw();
```

Whenever your canvas is resized, tell Gum so layout re-runs against the new size:

```csharp
GumUI.HandleResize(newWidth, newHeight);
```

{% hint style="info" %}
Gum does not clear the canvas for you, so your own draw code is expected to clear or paint the background before calling `GumUI.Draw()`.
{% endhint %}

## Adding Shader Support (Optional)

`Gum.SkiaSharp.ShadowDusk` lets a render target container's `SourceShaderFile` point at an `.fx` or `.slang` shader file.

Add the NuGet package:

```bash
dotnet add package Gum.SkiaSharp.ShadowDusk
```

Then call `UseShadowDusk` after `GumUI.Initialize`:

```csharp
// Initialize
GumUI.Initialize(canvas, width, height, "Content/GumProject/GumProject.gumj");
GumUI.UseShadowDusk();
```

If linking to source instead of NuGet, add `<Gum Root>/Runtimes/SkiaGum.ShadowDusk/SkiaGum.ShadowDusk.csproj` to your solution.

For loading, errors, and examples, see [Render Target Shaders on SkiaSharp](https://docs.flatredball.com/gum/code/standard-visuals/containerruntime.md#render-target-shaders-on-skiasharp). The supported formats are listed in [Shader Files](https://docs.flatredball.com/gum/code/files-and-fonts/supported-files.md#shader-files).

## Adding Expression Support (Optional)

If your Gum project uses arithmetic expressions in variable references (such as `Width = OtherInstance.Width + 20`), you can add the `Gum.Expressions` NuGet package for full expression evaluation at runtime. Without this package, simple variable references like `Width = OtherInstance.Width` still work.

Add the NuGet package:

```bash
dotnet add package Gum.Expressions
```

Then call `UseExpressions` after `GumUI.Initialize`. Expression support is typically used with a Gum project that has variable references defined in the tool:

{% hint style="info" %}
Available in preview NuGet packages (use a `-preview` version), or now if building Gum from source.
{% endhint %}

```csharp
// Initialize
GumUI.Initialize(canvas, width, height, "Content/GumProject/GumProject.gumj");
GumUI.UseExpressions();
```

If linking to source instead of NuGet, add `<Gum Root>/Runtimes/GumExpressions/GumExpressions.csproj` to your solution.

For more information, see the [Runtime Variable References](https://docs.flatredball.com/gum/code/styling/runtime-variable-references.md) page.

## Adding a Circle and Text (Testing the Setup)

Gum can be tested by adding a couple of renderables after Gum is initialized:

```csharp
// Initialize
GumUI.Initialize(canvas, width, height);

var circle = new ColoredCircleRuntime();
circle.Color = SKColors.Red;
circle.Width = 200;
circle.Height = 200;
circle.AddToRoot();

var text = new TextRuntime();
text.Text = "SkiaGum on a general canvas!";
text.Dock(Gum.Wireframe.Dock.Top);
text.AddToRoot();
```

After adding these, trigger a redraw through whatever mechanism your host uses to repaint the canvas. You should see a red circle with text docked above it.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.flatredball.com/gum/code/getting-started/setup/adding-initializing-gum/skiasharp-general-canvas.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
