Only this pageAll pages
Powered by GitBook
Couldn't generate the PDF for 434 pages, generation stopped at 100.
Extend with 50 more pages.
1 of 100

Gum

Gum Tool

Loading...

Loading...

Loading...

Loading...

Loading...

Tutorials and Examples

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Animation Tutorials

Loading...

Loading...

Loading...

Loading...

Examples

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Gum Elements

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Y

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Running from Source

Introduction

Gum is an open source project so you can run it from source instead of running the pre-compiled project. Running from source is not a requirement, and is only needed if you intend to contribute to Gum or if you'd like to diagnose problems in a debugger.

Obtaining the source code

  1. Download the source file from GitHub

    1. If you downloaded the .zip file from the GitHub main page, unzip the file

    2. If you downloaded the file through a Git client, be sure to be on the main branch

Gum repository in Github Desktop

Running the code

  1. Locate the Gum.slnx file (Gum.Wpf.sln is the older Windows-only WPF tool)

    1. If you downloaded the .zip, it is in the root folder of the zip

    2. If you cloned the repository, it is at the root of the Gum folder

  2. Double-click it to open Visual Studio, or open Visual Studio and load the .slnx

  3. Be sure to build solution rather than pressing F5 (which only builds the current project). This guarantees that all plugins are built and copied correctly. For more information see below.

Once the project has been built, you can run (with or without a debugger attached).

Building Plugins

Gum depends on a number of plugins for its functionality. By default if you build the project and run it (such as by pressing F5 in Visual Studio), then plugins are not automatically built. To build plugins, you need to explicitly build all plugin projects. The easiest way to do this is to select the Build -> Rebuild Solution option in Visual Studio.

Build -> Rebuild Solution in Visual Studio

Troubleshooting

Missing Editor Tab

If your Editor Tab is missing, be sure to Build -> Build Solution. The Editor tab is a plugin, and you can verify that the plugin is in fact being built/loaded.

First view plugins:

Next, look for the Editor tab plugin in the list that appears:

If you are missing this, be sure to Build -> Build Solution.

A project with an Output Type of Class Library cannot be started directly

If you have this popup, you need to set Gum as the startup project.

In Visual Studio:

  1. Right-click on the Gum project (not the solution)

  2. Select Set as Startup Project

Intro Tutorials

Introduction

The tutorials contained within this section provide an introduction to working with the Gum UI tool. This tutorial is a great place to start whether you are an artist who will be creating screens and components in Gum, or if you are a programmer who will be integrating Gum into your game or application.

If you are using Gum in a game project, you may want to continue reading other sections after you finish these tutorials.

4 - Combining Multiple Categories

Animation keyframes are defined by creating states in categories. If an animation uses two states in the same category then the animation will tween between them

Silhouette (Solid Colored Sprite)

Introduction

Render targets and blend modes can be combined to create a silhouette of any shape. This example uses a Sprite with transparency. It uses the Bear.png file:

Creating a Silhouette Component

To create a Component that can display a Silhouette, first create a new component named SilhouetteSprite.

Add a ColoredRectangle instance and a Sprite instance. The order matters - the Sprite should be drawn on top of the ColoredRectangle (it should show up 2nd in the Project tree view).

For this example, we will use the Alignment tab to adjust each item:

  • SilhouetteSprite (main component) - Dock Size to Children

  • ColoredRectangleInstance - Dock Fill

The Sprite should already be sized according to its source file, although you can change this size if desired.

The ColoredRectangleInstance defines the color of the silhouette so change it to a desired color.

Your component should look similar to the following image:

SilhouetteSprite initial setup

Next we'll adjust the transparency values. To do this:

  1. Set SilhouetteSprite Is Render Target to true

  2. Set SpriteInstance Blend to MinAlpha

Your sprite's silhouette should now appear, using the underlying color as its own color.

General Properties

Introduction

General properties are shared by all Standard Elements and Components.

Has Events

Introduction

The Has Events variable controls whether the selected instance supports UI-related events at runtime such as responding to a cursor click. If this value is false then events are not raised for this instance. If true, then cursor events are raised for this instance.

Usually instances of components should have this value set to true if the component can be interacted with at runtime, such as a button or text box.

This value has no effect in the Gum tool and is only used at runtime.

Has Events and Cursor.WindowOver

If an instance has its Has Events value unchecked then it will not be eligible to be assigned to the Cursor's WindowOver property. For more information, see the Cursor page.

Ignored By Parent Size

Introduction

Ignored By Parent Size determines whether the parent of an instance considers the instance when performing its sizing. This value is only used if the parent has a Height Units or Width Units of Relative To Children. If a parent has a Height Units or Width Units of any other value, then this value has no impact on the parent's size.

Ignored By Parent Size controls whether the parent ignores the child when performing a layout

Default Implementation

Introduction

The Default Implementation property can be used to indicate which component is the default implementation for a behavior. This property is not used by the Gum tool, but instead exists for runtime implementations (such as FlatRedBall) to decide which type of component to create when an instance of a behavior is requested.

ListBoxItemBehavior with a Default Implementation set to Controls/ListBoxItem

As of July 27, 2025 this property is used in the following runtimes:

  • FlatRedBall

  • MonoGame/Kni/FNA

  • raylib

  • Silk.NET

Additional runtimes may add support for this property in the future. If you need it for your project please make a request on GitHub or Discord.

Common Usage

Behaviors are often used to help with the creation of components which need to have a certain set of states and instances. For example, the Button type in Gum Forms is associated with the ButtonBehavior.

At runtime, a game may need to create an instance of the Button type without specifying a component. For example, the following code can be used to create a button:

The Default Implementation property can help runtime libraries determine which component to create for the Button's visual.

The Button type is a good example of why this property might be needed because the default Forms components include multiple components which use ButtonBehavior.

Multiple button components

To resolve this ambiguity, the ButtonBehavior's Default Implementation is automatically set to Controls/ButtonStandard.

ButtonBehavior using ButtonStandard as the Default Implementation

For more information about whether you should set the Default Implementation, refer to the documentation for your particular runtime.

If you have created a custom runtime, such as a new ListBoxItem, you may need to change the Default Implementation for the ListBoxItem behavior.

Blend

Introduction

The Blend variable controls how the selected instance combines its colors with whatever is drawn before. The final appearance of a NineSlice depends on its Blend, Alpha, Source File, and Color values.

For more information and examples, see the Sprite Blend page.

Component

Components are reusable collections of instances. Components can be added in the project's Components folder. Examples of Components include:

  • Button

  • HealthBar

  • Slider

  • Menu

Components can be small and reusable, such as a Label, or they can be large complex objects such as a settings menu with dozens of options.

Component instances can be added to other Components or to Screens.

Shape Properties

Introduction

Shape properties are shared by the standard elements that draw vector shapes. Unlike General Properties, which every Standard Element and Component shares, shape properties only appear on shape elements such as Circle and Rectangle.

These properties control how a shape is filled, whether it draws a gradient, and whether it casts a dropshadow:

  • Has Dropshadow

  • Is Filled

  • Use Gradient

The following element types expose these properties:

  • Circle and Rectangle - the core (non-Skia) shape standard elements.

  • ColoredCircle, RoundedRectangle, and Arc - Skia standard elements.

  • Line supports Has Dropshadow and Use Gradient, but not Is Filled (a line draws as a stroke and has no fill).

Skia Standard Elements

Introduction

Skia standard elements are a collection of elements which use SkiaSharp for rendering. Skia standard elements provide additional types of visuals supported by Gum, but not all runtimes support Skia standard elements.

Skia adds advanced vector graphics support, including the Arc shape and vector file formats such as SVG and Lottie.

The older ColoredCircle, RoundedRectangle, and SolidRectangle Skia shapes are being phased out. Use the core Circle and Rectangle standard elements instead — they support fill, outline, gradients, drop shadows, dashed strokes, and rounded corners, and are not Skia standard elements, so they work without adding Skia to your project. The old shapes remain available so existing projects keep working, but will be removed in a future release.

Using Skia Standard Elements may limit which platforms can run your Gum project. For more information, see the Shapes Platform Support page.

Enabling Skia Standard Elements

Skia standard elements must be explicitly added to gum projects. To add Skia standard elements Select Plugins -> Add Skia Standard Elements.

Add Skia Standard Elements

After clicking this option, Gum adds new standard elements.

Skia standard elements in Gum

Once these Skia standard elements are added, they can be added to Screens and Components just like any other standard element.

Skia standard elements can be added just like any other standard element

Texture Top

Introduction

The Texture Top variable controls the top pixel of the source rectangle used to draw the NineSlice. Texture Top is only available if the NineSlice uses a Texture Address of Custom or Dimension Based.

The following image shows a NineSlice with a Texture Top value of 48.

NineSlice with Texture Top set to 48

Texture Top controls the top side of the region that the NineSlice displays on its source file. In this case, the top-edge of the source rectangle is 48 pixels from the top edge of the entire file.

Texture Top set to 48 pixels in the Texture Coordinates tab

RoundedRectangle

RoundedRectangle is being phased out. Use the Rectangle standard element instead and set its Corner Radius — Rectangle now supports rounded corners along with fill, outline, gradients, drop shadows, and dashed strokes on all platforms. RoundedRectangle remains available so existing projects keep working, but it will be removed in a future release.

Introduction

RoundedRectangle is similar to a ColoredRectangle with the added functionality of supporting rounded corners.

Default RoundedRectangle

RoundedRectangles also support shape properties such as Has Dropshadow, Is Filled, and Use Gradient. For more information and examples, see the Shape Properties pages.

Sprite

Introduction

Sprites are objects which can draw an image (such as a .png) or a portion of a .png.

A Sprite displaying the old FlatRedBall logo

Corner Radius

Introduction

The Corner Radius variable controls the radius of each of the four corners on a rounded rectangle. A value of 0 results in a sharp corner. Increasing this value makes the corners more rounded.

Corner Radius is restricted to half of the smallest absolute dimension. In other words, if the RoundedRectangle is too small to fit its set CornerRadius, then the effective CornerRadius shrinks.

The following shows a RoundedRectangle with a Corner Radius of 60. If it is resized to have an effective width or height of less than 120, then the effective radius shrinks.

Corner radius shrinking in response to smaller size

Similarly, setting a Corner Radius that is larger than half the Width or Height does not affect the RoundedRectangle.

Start Angle

Introduction

Start Angle defines the angle of the starting point of the arc. This value is measured in degrees, with a value of 0 pointing to the right. The value increases counterclockwise. the Start Angle and Sweep Angle values combine to determine the range of angles covered by the Arc.

The following image shows the an Arc with a Start Angle of 0. The red lines and text are not part of the arc and are added to the screen shot to show the location of the Start Angle.

An arc with a Start Angle of 0

Changing the Start Angle moves one side of the arc. The arc appears to rotate if the Start Angle is changed gradually.

Changing the Start Angle makes the arc appear to be rotating

Start Angle defines the starting point of the arc. A value of 270 degrees and a value of -90 place the starting point of the arc in the same location. Values larger than 360 result in the value looping. These values, although normally not needed, can be used to create spinning animatoins.

Introduction

Gum is the best Game UI Layout tool available. It provides a flexible, efficient layout engine capable of producing virtually any layout. Gum can be used in a variety of contexts including in the FlatRedBall game engine, MonoGame, raylib, Silk.NET, and more. Gum can also be rendered on Skia so it can be used in any environment that supports Skia such as WPF and Avalonia.

The Gum layout engine can also be included in any .NET project without requiring the use of a particular graphical API.

To download the Gum UI tool and start building your UI, see the Setup page.

Powerful WYSIWYG Editor

Gum UI includes advanced layout functionality to create and preview your UI

Gum UI

Object Oriented Design Focused on Reusable Controls

Gum allows the creation of components which can be instanced and customized in screens and other components

Gum Components

Gum Objects Support Multiple Size and Position Units

Adjust an object’s origin, position units, size units, and stacking to create fluid UI

Position and Size Units

Simple Integration - Gum Supports Many Runtimes

Grab the NuGet, add a few lines of code, see your Gum project in game! You can use Gum with MonoGame, KNI, FNA, raylib, Silk.NET, SkiaSharp, and many more platforms. For more information on our runtimes, see the Getting Started page.

Gum UI in game

Interact with Gum in Code

Gum objects can be created and modified in code. Create fully-featured UI by subscribing to common UI events.

Time-Tested and Reliable

Gum has been used in commercial projects of all sizes - check them out in our Showcase page.

Need Help?

Gum is actively maintained and provides lots of ways to get answers:

  • Check the rest of the documentation

  • Join the Discord chat (shared discord with FlatRedBall)

  • Create an issue on Github

5 - Exposing Variables

Introduction

The ability to expose variables in Gum makes components flexible. For this example we will continue using the HealthBar component from the previous tutorial.

Recap

The last tutorial created a HealthBar component with two rectangles - Background and Fill. The instances were set up to be positioned correctly according to the size of the HealthBar.

We also created a GameScreen and added a few HealthBar instances. Although we can position and size each HealthBar instance, they all display the same health percent. This tutorial discusses how to use exposed variables to allow each instance to display a different value.

Exposing the Text variable

By default components only exposes top level variables. Variables on instances inside the component are not available when editing an instance. In programming terms these variables are considered protected.

However, we can expose variables inside of our component so that they can be modified in our screen.

To do this:

  1. Select Fill inside the HealthBar component

  2. Find the Width variable in the Variables tab

  3. Right-click on the Width variable Expose Variable

  4. Enter the name HealthPercent for the variable name - note that typically variables are exposed without spaces in them, but Gum will display them with spaces in the variables tab

Right-click Expose Variable

Notice the variable now displays its exposed variable name.

Width variable exposed as HealthPercent

Although this variable belongs to the Fill instance, it is now exposed as a variable on HealthBar. You can now see this variable by selecting the HealthBar component.

Health Percent under HealthBar

Similarly, now each instance can be modified since each now exposes a Health Percent variable.

Health Percent adjusted per-instance

Conclusion

This tutorial shows how to use exposed variables to customize component instances. You can expose other instance variables in your components to customize instances. Other examples of variables which may be exposed include:

  • Visibility of icons on a Button component

  • Font sizes on a Label component

  • Sprite visibility showing the number of connected gamepads on a JoinGame component

It's best to experiment with exposed variables to get a feel for how you can use them in your own components.

1 - Introduction to Animation

Introduction

Gum supports creating and previewing animations in the editor through the use of states. The general workflow for creating an animation is as follows:

  1. Create states representing the keyframes in the animation (usually one category per animation)

  2. Add an animation to the component or screen

  3. Add states to the animation and adjust their time

  4. Set interpolation values for each keyframe to control "easing"

Examples of animations

Gum's animation system is very powerful and can be used in a variety of situations:

  • Animations which play when a screen or component is shown or hidden

  • Animations used to transition between behavior states such as changing a button from regular to highlighted state

  • Lengthy animations which can last multiple seconds for complex transitions

Storage of animations

Animations are stored separate from the screen or component on the file system. If a screen or component contains at least one animation then Gum will save a Gum Animation file (.ganj or .ganx extension) with the word "Animations" appended on the screen or component's name. In other words GameScreen would have a file called GameScreenAnimations.ganj/ganx in the same folder containing information about its animations.

Playing animations

Once an animation has been made it can be played back in editor. The following shows how an animation is played back, both in real time and also by dragging the slider.

Padding

Introduction

The concept of padding is often used to add spacing between the edge of a container and its children. Padding can be achieved by adding sub-containers.

Creating a Container

First we'll create a top-level container. This container controls the size of all objects internally, including the background. We will also include a background object which is sized according to the container. To keep things simple, this example uses a dark blue ColoredRectangle.

The ColoredRectangle is set so its size matches its parent.

Container with a blue background

Next we can add another container to the top-level container. By default this container sits at the top-left of the parent when it is added with a drag+drop.

Container added with drag+drop

To have the container fill its parent, but also include padding:

  1. Select the inner container

  2. Click the Alignment tab

  3. Enter the desired padding in the Margin text box

  4. Click the Dock Fill button

Creating padding by havign an internal continer use Margin of 10

This inner container can now be used to hold all children. Note that if you are creating a Component and you want to make this be the default container for children, you may want to set the Default Child Container to this inner container. For more information see the Default Child Container page.

X Origin

Introduction

The X Origin variable controls the point which an object is positioned by. By default the X Origin is Left. X Origin is shown visually as a white "X" in the editor.

ColoredRectangle with an X Origin of Left

Left

The following image shows a ColoredRectangle with its X Origin set to Left:

Colored Rectangle with X Origin set to Left

Center

The following image shows a ColoredRectangle with its X Origin set to Center:

ColoredRectangle with X Origin set to Center

Right

The following image shows a ColoredRectangle with its X Origin set to Right:

ColoredRectangle with its X Origin set to Right

Clips Children

The Clips Children property controls whether children of a component or container can render outside of the bounds of their parent. By default this is false, which means that all children are not clipped (can fully-render) regardless of whether they are within the bounds of their parent or not. Setting this value to true prevents children from rendering outside of the bounds of their parent.

Clips Children set to true prevents children from rendering outside of the container's bounds

Children outside of the bounds of a container with Clips Children set to true can also be clipped by setting a container's Is Render Target value to true.

The clip region is always axis-aligned, so rotating a container that clips its children leaves the clip region unrotated. To rotate a container and keep its contents clipped, see Rotating and Scaling Clipped Contents.

Min Height

Introduction

The Min Height variable sets the minimum height in pixels. This value is applied after all other layout so it can be used to overwrite automatically-assigned height.

By default this value is <NULL> which means there is no Min Height.

A ColoredRectangle with no Min Height

If Min Height is assigned (not <NULL>), then the effective height cannot be less than the Min Height value. The following animation shows that height is limited to a Min Height of 100.

Min Height set to 100 limits the ColoredRectangle' height

Notice that the Height variable can still be set to a value smaller than Min Height, but it does not apply visually.

Min Height can also be used if Height Units is set to values other than Absolute. For example, Min Height can be used to limit the height of a ColoredRectangle when Height Units is Relative to Parent.

Rectangle's height limited by its Min Height of 100

Max Height

Introduction

The Max Height variable sets the maximum height in pixels. This value is applied after all other layout so it can be used to overwrite automatically-assigned height.

By default this value is <NULL> which means there is no Max Height.

A ColoredRectangle with no Max Height

If Max Height is assigned (not <NULL>), then the effective height cannot be larger than the Max Height value. The following animation shows that height is limited to a Max Height of 100.

Max Height set to 100 limits the ColoredRectangle's height

Notice that the Height variable can still be set to a value larger than the Max Height, but it does not apply visually.

Max Height can also be used if Height Units is set to values other than Absolute. For example, Max Height can be used to limit the height of a ColoredRectangle when Height Units is Relative to Parent.

Rectangle's height limited by its Max Height of 100

Max Height and Relative to Children

Note that Max Height can prevent a container from growing according to its children. For more information, see the Relative to Children Height Units page.

X

Introduction

The X property controls the horizontal position for an object. The X value represents the position of an object's X Origin, using its X Units.

Example

By default, an object's top-left corner is positioned relative to its parent's top-left corner.

Max Width

Introduction

The Max Width variable sets the maximum width in pixels. The value is applied after all other layout so it can be used to overwrite automatically-assigned width.

By default this value is <NULL> which means there is no Max Width.

A ColoredRectangle with no Max Width

If Max Width is assigned (not <NULL>), then the effective width cannot be larger than the Max Width value. The following animation shows that width is limited to a Max Width of 100.

Max Width set to 100 limits the ColoredRectangle's width

Notice that the Width variable can still be set to a value larger than Max Width, but it does not apply visually.

Max Width can also be used if Width Units is set to values other than Absolute. For example, Max Width can be used to limit the width of a ColoredRectangle when Width Units is Relative to Parent.

ColoredRectangle's width limited by its Max Width of 100

Max Width and Relative to Children

Note that Max Width can prevent a container from growing according to its children. For more information, see the Relative to Children Width Units page.

Rotation

Introduction

Rotation can be used to rotate Gum components. Rotation is measured in degrees, where positive values rotate an object counterclockwise about its origin (X Origin and Y Origin).

Example

An object is rotated about its origin, which by default is its top-left corner:

Rotating an object using the Rotation variable

Objects can also be rotated visually by grabbing the rotation handle:

Rotation handles can rotate an object

Holding the SHIFT key snaps angles to 15 degree increments.

SHIFT rotate snaps to 15 degree increments

X Origin and Y Origin

The X Origin and Y Origin properties define the point of rotation for an object. The following animation shows how changing origin values can affect rotation.

Objects rotate about their origin.

Rotation does not rotate the clip region of a container that clips its children, so rotating a container with Clips Children set to true will look broken. To rotate a container and keep its contents clipped, see Rotating and Scaling Clipped Contents.

Circle

Introduction

Circles can be drawn as an outline, filled in, or both, and supports additional effects such as gradients, drop shadows, and dashed strokes. Circles are sized using their Width and Height values.

Circle in Gum using the default white color

The fill, gradient, and drop shadow variable categories only appear for version 3 (or later) projects. New projects use version 3 by default.

Circles support all shape properties. For more information see the Shape Properties page and subpages.

Circles with stroke, fill, gradient, and dropshadow

Contained Type

Introduction

Contained Type enables code generation and Gum runtimes (such as FlatRedBall) to create strongly-typed containers.

Currently the Contained Type variable does not have any affect on objects in the Gum tool and it exists only to support strongly-typed runtimes. This may change in future versions of the Gum tool.

Common Usage

Some Gum components or Containers may exist to hold a list of a particular type of item. For example, consider a game which includes a row of hearts to show the player's current health.

Row of hearts displaying the player's health

In this particular case, the hearts can be filled or empty to show the current and max health, but the max health can also be increased. If the max health increases, then a new heart instance is added to the container at runtime.

Since this container should only ever contain instances of a Heart component, then the container's Contained Type can be set to Heart.

HealthContainer instance with its Contained Type set to Heart

In this example, FlatRedBall respects the Contained Type variable and generates a generic list.

ContainerRuntime can be generic in FlatRedBall, so it respects the Contained Type variable

As mentioned above, the implementation of this variable depends on the runtime you are using. If you are using a runtime which does not implement this feature and you would like to have it added, please create a GitHub issue or make a request in Discord.

Container

Containers are used to group objects to simply movement, alignment, positioning, and size. Containers are usually invisible, although they can draw their outlines in Gum to help visualize their position and size.

A container holding four ColoredRectangle instances

Is Tiling Middle Sections

Introduction

The Is Tiling Middle Sections property controls whether the non-corner sections of a NineSlice are tiled (repeated) instead of stretched. By default this value is false, meaning the middle sections stretch to fill the available space. When set to true, the middle sections repeat their texture at its natural size instead of stretching.

This property appears in the Source category in the Variables tab.

This is useful for textures with repeating patterns like brick walls, chains, or borders where stretching would distort the pattern.

Two NineSlices, one streching and one tiling middle section

Default Behavior (Stretching)

By default, when a NineSlice is resized, the five non-corner sections (Top, Bottom, Left, Right, and Center) are stretched to fill the space between the corners. This works well for smooth or gradient textures, but can create visible distortion with patterned textures.

Tiling Behavior

When Is Tiling Middle Sections is set to true, the five non-corner sections repeat their texture instead of stretching:

  • Top and Bottom edges tile horizontally

  • Left and Right edges tile vertically

  • Center section tiles in both directions

The four corner sections (Top Left, Top Right, Bottom Left, Bottom Right) are never tiled — they always render at their natural size regardless of this setting.

ColoredRectangle

ColoredRectangle is being phased out. Use the Rectangle standard element instead — Rectangle covers the same solid-color fill (through its Fill Color) plus an outline, gradients, drop shadows, dashed strokes, and rounded corners. New projects seed Rectangle rather than ColoredRectangle. ColoredRectangle remains available so existing projects keep working, but it will be removed in a future release.

Introduction

ColoredRectangles are used to display solid color rectangles. It can be used to provide a solid colored background or placeholders for content such as Sprites. ColoredRectangles are also useful for quickly blocking out a UI or learning about Gum's layout with a visual object.

As the name suggests, ColoredRectangles have a Color property which can be modified.

ColoredRectangle with a green color

Canvas

Introduction

The Canvas element creates an instance of a SKCanvas which can be accessed in code to perform custom rendering. The contents of the Canvas cannot be modified in Gum. Since it is a Gum object, it does provide all of the variables for positioning, sizing but the rendering must be performed in custom code.

Since the Canvas cannot perform any rendering in Gum, it appears as an empty container.

Canvas instances in Gum apppear as empty containers

Polygon

Introduction

Polygons are shapes defined by an ordered set of points. Polygons can be used to draw lines, shapes, and define collision in games.

Polygon in Gum

Sweep Angle

Introduction

Sweep Angle defines the angle that the arc covers. This is a signed value, with positive values going counterclockwise.

The following shows an arc with a positive Sweep Angle of 135 degrees.

An arc with a Sweep Angle of 135

Changing the Sweep Angle changes the length of the arc. If the value is negative, then the Sweep Angle increases the size clockwise.

Sweep Angle can be positive or negative

A sweep angle of 360 creates an arc that extends to a full circle. Values greater than 360 appear the same as if Sweep Angle is set to 360.

Sweep Angle of 360

Rectangle

Introduction

Rectangles can be drawn as an outline, filled in, or both, and supports additional effects such as gradients, drop shadows, and dashed strokes.

Rectangle using the default white color

The fill, gradient, and drop shadow variable categories only appear for version 3 (or later) projects. New projects use version 3 by default.

Rectangles support all shape properties. For more information see the Shape Properties page and subpages.

Rectangle with stroke, corner radius, fill, gradient, and dropshadow

Thickness

Introduction

Thickness controls the width of the arc line in pixels. This value can be increased to make the line arc thicker.

Changing the thickness chnages the width of the arc's line

Thickness can be increased to create a wedge.

Increasing Thickness to create a wedge

Note that Thickness can be increased to any value including values larger than the radius of the arc. Large values can result in the arc rendering past its center point creating a bowtie shape.

Bowtie created by setting thickness to be larger than the radius of the arc

Other undesirable rendering effects can happen with large thicknesses when working with arcs which have one size (width or height) larger than the other, as shown in the following image:

Arck with the values Width=340, Height=160, Thickness=95 rendering incorrectly

Arc

Introduction

Arcs are curved lines with variable thickness. Arcs can also be used to draw wedges if the line thickness is large enough.

Three arc instances - a default arc, a rounded arc with gradient graphics, and an arc creating a wedge

Arc dimensions

Arcs draw inside their bounds, with the edge of the arc touching the bounding rectangle. The thickness of the arc remains consisntent regardless of the bound width and height.

The following shows an arc with a Sweep Angle of 270 degrees, being resized in the Editor tab.

Arc thickness remains constant when an arc's dimensions change

Svg

Introduction

Svgs can display .svg files. Since these files are vector art, they can be resized without pixelation.

The following is an Svg instance displaying the FlatRedBall logo. Source SVG: https://github.com/flatredball/FlatRedBallMedia/blob/master/FlatRedBall%20Logos/frb-logo-main.svg

Svg displaying the FlatRedBall logo

Source File

The Source File variable controls the lottie animation displayed. This value can be set and changed just like source files on other elements such as a .png on a Sprite.

Svg Width and Height

Width and Height values can be set on an Svg file just any other Gum element. Unlike rasterized objects such as Sprites, Svgs use Vector art so they can be resized and still retain crisp edges and details.

Resized SVG maintains crisp edges when resized

Svgs are still rasterized in Gum, so they display pixels when the view is zoomed in, especially if the Svg has a small Width or Height.

Small Svgs display pixels if zoomed in

Maintain File Aspect Ratio Width and Height

Svgs support the Maintain File Aspect Ratio Width and Maintain File Aspect Ratio Height units. For more information, see the Width Units and Height Units page.

ColoredCircle

ColoredCircle is being phased out. Use the Circle standard element instead — Circle now supports fill, outline, gradients, drop shadows, and dashed strokes on all platforms. ColoredCircle remains available so existing projects keep working, but it will be removed in a future release.

Introduction

ColoredCircle are round shapes which can be filled in or drawn as an outline, with options for customizing their appearance.

A default ColoredCircle

ColoredCircles support shape properties such as Has Dropshadow, Is Filled, and Use Gradient. For more information and examples, see the Shape Properties pages.

Texture Left

Introduction

The Texture Left variable controls the left pixel of the source rectangle used to draw the NineSlice. Texture Left is only available if the NineSlice uses a Texture Address of Custom or Dimension Based.

The following image shows a NineSlice with a Texture Left value of 96.

NineSlice with Texture Left set to 96

Texture Left controls the left side of the region that the NineSlice displays on its source file. In this case, the left-edge of the source rectangle is 96 pixels from the left edge of the entire file.

Texture Left set to 96 pixels in the Texture Coordinates tab

Shapes Platform Support

Introduction

Shapes (Skia) support varies per platform. See below to see information about your platform.

MonoGame and KNI projects can use the following shapes:

  • Arc

  • Circle

  • Rectangle

The outline (stroke) of Circle and Rectangle, and Rectangle's fill (at square corners), render out of the box. Circle's fill, Rectangle's rounded corners, and the richer effects (gradients, drop shadows, and dashed strokes) are provided by the shape support package (Gum.Shapes.MonoGame or Gum.Shapes.KNI). Without the package those properties are saved but do not draw.

Other types, such as SVG or Lottie, are not currently supported.

For information on adding the shape support package to your project, see the Shapes page.

The older ColoredCircle, RoundedRectangle, and SolidRectangle shapes are being phased out in favor of Circle and Rectangle. They remain available so existing projects keep working, but will be removed in a future release.

FNA renders the outline (stroke) of Circle and Rectangle, and Rectangle's fill (at square corners), out of the box. Circle's fill, Rectangle's rounded corners, and the richer effects (gradients, drop shadows, dashed strokes) are not available on FNA because there is no shape support package for it. We are looking for contributors to help expand FNA shape support.

Raylib supports Circle and Rectangle natively, including fill, gradients, and drop shadows, with no extra package required.

Gradient-on-outline (a gradient applied to the stroke rather than the fill) is not yet implemented on raylib.

All shape types are fully supported.

var button = new Button();
button.Text = "Hello";
StackLayoutInstance.AddChild(button);
void CustomInitialize()
{
    MyButton.Click += HandleOkButtonClick;
}

private void HandleOkButtonClick(object sender, EventArgs args)
{
    // do your logic here
}

Setup

Gum runs natively on Windows, macOS, and Linux — no WINE or other compatibility layer needed. It opens the same projects, saves the same files, and generates the same code on every OS.

Download the latest release directly: https://github.com/vchelaru/Gum/releases/latest

Release history (including older releases): https://github.com/vchelaru/Gum/releases

Gum Source Code: https://www.github.com/vchelaru/Gum

Each release lists these files:

File
For

Gum-win-x64.zip

Windows (64-bit)

Gum-osx-arm64.tar.xz

macOS on Apple Silicon (M1 and later)

Gum-osx-x64.tar.xz

macOS on Intel

Gum-linux-x64.tar.xz

Linux (64-bit)

Each download includes everything it needs, so you do not need to install .NET first. A matching .sha256 file lists the checksum of each download.

  1. Unzip Gum-win-x64.zip into a folder of your choice.

  2. Run Gum.Avalonia.exe.

Gum is not signed, so Windows shows the "Windows protected your PC" popup the first time. Click More info, then Run anyway. Alternatively, right-click the .zip file and select the option to unblock it before extracting.

  1. Double-click the .tar.xz file for your Mac to extract Gum.app.

  2. Move Gum.app into your Applications folder.

  3. Open a terminal and allow the app to run. Gum is not notarized by Apple, so macOS blocks it until you do this once:

    xattr -dr com.apple.quarantine /Applications/Gum.app
  4. Open Gum from Applications or Launchpad.

  1. Extract the download into a folder of your choice:

    mkdir -p ~/gum && tar -xJf
  2. Run Gum:

    ~/gum/Gum.Avalonia

Gum needs a desktop session (X11 or Wayland), a graphics driver with OpenGL 3.0 or newer, and the fontconfig library (libfontconfig1 on Debian and Ubuntu), which desktop installs normally include.

Older releases (the WPF tool)

Releases up to and including September 2, 2026 are the older Windows-only WPF tool, distributed as Gum.zip with Gum.exe inside. That release stays downloadable if you need it, for example for a plugin that has not been migrated yet (see Plugins), but it does not receive new features. Its WINE setup scripts for Linux and macOS are kept at that release's tag (setup_gum_linux.sh, setup_gum_mac.sh); the native downloads above replace them.

Known issues

  • Plugins built only for the older WPF tool do not load. The Plugins dialog lists them as not supported. See Plugins for how to migrate one.

  • The command-line tool (gumcli) is included in the GumCli folder beside the tool, but only the tool's own Export as SVG uses it so far.

  • Gum is not signed on Windows or notarized on macOS, which is why the steps above are needed.

Please report anything else you find on the Gum GitHub issues page, along with your operating system.

Showcase

Austerity X

Deadvivors

Cranky Chibi Cthulhu

TerraScriber

Champions of Anteria

Tetris Blitz

Tula Mobile App

Catnip Coast

War Haven

BattleCrypt Bombers

Teotihuacan

Ship Skwabble

3 - Files

Introduction

Gum supports loading image files for Sprites and NineSlices. This tutorial discusses how to load files, and how they are referenced in Gum.

Setting up a workspace

First we'll set up a workspace:

  1. Create a Screen called SpriteScreen.

  2. Drag+drop a Sprite into the newly-created Screen

Drag+drop a Sprite onto SpriteScreen

Setting the Sprite Source File

Source File is the image that the Sprite displays. Usually Source Files are of the .png file format. To set the source file:

  1. Select SpriteInstance

  2. Find Source File in the Variables tab

  3. Click the "..." button to bring up a file window

  4. Navigate to the location of the file you would like to load

  5. Click "Open" in the file window

  6. Once Source File is set, the Sprite displays the image in the Editor tab

SpriteInstance displaying a bear Source File

If you select a file which is not located in the same folder or a sub folder of your gum project, Gum asks if you would like to reference the file in its original location or create a copy.

Gum asks to copy files if they are outside of the project directory

Usually it's best to copy the file to the Gum project folder so that the Gum project can be moved to different computers without breaking file references.

Texture Coordinates

Sprites can display portions of their Source File. Files which combine multiple images are often called sprite sheets or tile sheets, and are commonly used in game development to keep art organized and to improve performance.

For example, the following file contains images for an animated character, ground tiles, and other entities for a platformer game.

If we download this file and set it as our , then the sprite displays the entire file.

Sprite displaying entire sprite sheet

We can display a portion of the Sprite rather than the entire file:

  1. Click on the Texture Coordinates tab

  2. Check the Snap to grid option to make it easier to select a region

  3. Double-click anywhere on the image to select a region around the cursor

  4. Move the selected region to the desired location to adjust the sprite's texture coordinate values

Texture coordinate values can be adjusted in the Texture Coordinates tab

Bottom-Up Stack

Bottom-up stacks can be used to display stacks of elements which should move up as more are added. This concept is similar to messages received in a chat window. Gum layout can be used to produce this type of stack.

This example shows a bottom-up stack (vertical) but the same approach could be used to create a right-aligned stack.

Items in a bottom-up stack need a parent Container. This Container could be an instance of a Container or a component since components usually have their Base Type set to Container. For this example we'll use a container.

Container instance

This container to stack needs the following variables set:

  • Children Layout set to Top to Bottom Stack so all children stack vertically

    Children Layout set to Top to Bottom Stack
  • Height Units set to Relative to Children so the container resizes itself as more children are added

    Height Units set to Relative to Children
  • Height set to 0 so the effective height of the container is based purely on its children

    Height set to 0
  • Stack Spacing set to 2 (optional) to add spacing between each child

    Stack Spacing set to 2

Now children of the Container stack vertically. This concept works for any type of child, but we'll use ColoredRectangles for this example. Add a few instances to the Container and they stack vertically.

ColoredRectangle instances stacking vertically in a container

Finally we can have the stack grow up instead of down. To do this, change the following variables on the parent container:

  • Y Origin set to Bottom

    Y Origin set to Bottom
  • Y Units set to Pixels from Bottom

    Y Units set to Pixels from Bottom

Now as new children are added, the parent stack grows and all items shift up.

Stack grows upward as more children are added

Centering

Introduction

Gum provides simple controls for centering objects inside of their parents. This page shows how to center objects in a variety of situations. For brevity this document uses vertical centering, but the same concepts apply to horizontal centering.

Centering with Anchors (Alignment Tab)

The easiest way to center an object is to use the center Anchor. This sets all of the values necessary to center an object both vertically and horizontally.

Centering using the alignment tab

Centering Using Units

Objects can be centered by setting their unit and numerical values. The Alignment tab is a shortcut for these values, but we can assign each value individually so an object is centered vertically:

  • Set Y to 0

  • Set Y Units to Pixels from Center

  • Set Y Origin to Center

Centering using Y, Y Units, and Y Origin

Centering with Margins

Centering can be performed with margins by adding an additional container to create the necessary margins. For example, consider a situation where we want to center the green rectangle inside the blue rectangle, but leave a 32 pixel margin at the top.

We may want something similar to the following image:

Green rectangle is centered in the remaining area below the yellow area

To do this, an additional container can be added as shown in the following image:

Container inside the blue rectangle defining the centering space

In this case, the container has the following relevant properties:

  • Y = 0 (so it is pressed against the bottom)

  • Y Units = Pixels From Bottom (so it is bottom justified)

  • Height = -32 (leaving a 32 pixel margin)

  • Height Units = Relative to Parent (so that it always has a 32 pixel margin regardless of parent size)

The green rectangle can be added as a child to the container, and then centered within the container. This results in the green rectangle always being centered within the area that leaves a 32 pixel margin at the top even if the main rectangle is resized, as shown in the following animation:

Blue rectangle resized, keeping the green rectangle centered within the area leaving a 32 pixel margin at the top

Additional margin can also be added to the bottom by changing the container's Y value. For example, a 20 margin border can be added at the bottom, leaving a 32 pixel margin at the top by setting the following values on the container:

  • Y = -20 (move the bottom of the container up by 20 pixels)

  • Height = -52 (leaving a 32 pixel margin at the top, and accounting for the container being moved up an extra 20 pixels)

Centering leaving an extra margin on both top and bottom

Center Stacks

Stacks can be centered horizontally or vertically. To center a stack of objects, an internal container is needed.

A centered stack might look like this:

Centered stacking ColoredRectangles

For this example, we'll begin with a Container and a background ColoredRectangle. The background is not necessary, but it helps visualize the main Container's size.

MainContainer with a blue ColoredRectangle background

Next we'll add another container which will hold our stacking instances.

  1. Drag+drop a container onto the MainContainer

  2. Click the Alignment tab

  3. Click Anchor Center

New inner container centered

We can add children to the container:

  1. Set the inner container's Children Layout to Top to Bottom Stack

  2. Drag+drop children onto the inner container to have them stack

  3. Optionally adjust the Stack Spacing variable to add gaps between the children

  4. Optionally adjust the children such as changing their size or color

Add childre nto the stack

For this example I modified each child rectangle to have

  • Width = 128

  • Height = 32

  • Color = Green

Adjusted rectangle sizes and colors

Finally, we mark the inner container to be sized according to its children. Since it remains centered, whenever its size adjusts (by adding or removing children), the inner container adjusts to remain centered.

Set the inner container to Size to Children

Now if children are added or removed, the container remains centered.

Inner container expanding in response to new children

Alpha

Introduction

Alpha controls an instance's transparency. A fully opaque instance has an Alpha of 255. A fully transparent instance has an Alpha of 0.

Sprites with Alpha of 255, 200, 150, 100, 50, and 0

An object's transparency is a combination of its Alpha, Blend, and its Source File. Shapes may also have transparent portions due to their form (such as ColoredCircle and RoundedRectangle) as well as dropshadows.

Alpha and Children

By default the Alpha property affects the selected instance only - it does not cascade down to its children. For example, the following shows a parent white ColoredRectangle with a child blue ColoredRectangle. If the white ColoredRectangle's Alpha property changes, the BlueRectangle's opacity does not change.

Parent Alpha does not change child opacity

A parent can affect its children's transparency if the parent is a container with Is Render Target set to true. For example, if the white rectangle is added to a Container, the Container can make its entire contents transparent.

Entire Container Alpha makes all children transparent

Note that by setting Is Render Target to true, the entire container's Alpha can be adjusted rather rather than the alpha value cascading to each individual child. This Alpha value is used to control transparency after all children have been drawn. We can see the difference between a partially-transparent Container and each child individually being made partially transparent by overlapping two children ColoredRectangles.

The rectangles on the left each have an Alpha value of 255. These rectangles are in a Container Is Render Target set to true and an Alpha set to 128.

The rectangles on the right each have an Alpha of 128, so the red rectangle is visible behind the blue rectangle.

Container Alpha on the left, individual Alpha on the right

Is Slot

Introduction

By default, when one instance (such as a NineSlice) is attached to another instance (such as a Container), the child attaches to the root of the parent. However, complex components often have internal structures. For example, a Window may have an InnerPanel which acts as the "landing zone" for children.

Slots allow you to designate specific internal parts of a component as an "attachment point". Any instance in a component can be designated as a slot by checking the Is Slot variable.

Note that instances can be marked as Default Slots for automatic parenting. For more information see the Default Slot page.

Example - Using Is Slot

Setting an instance's Is Slot to true is a way to tell Gum that it should be available as a parent. Any number of instances can be slots.

For example, consider a Component with three children: Header, Body, and Footer. In this case all three instances should be considered slots.

To set the value, select each instance and check Is Slot.

Is Slot set to true

If we have an instance of this HeaderBodyFooterComponent in a screen, then other instances can use any of the slots as their parent value. For example, the following screenshot shows a Text instance's available parents. Notice that all three slots are available.

Available slots

We can select any of these as the Text's parent.

Text using a Footer slot

Locked

The behavior of the Locked property is changing for the February 2025 release of Gum as outlined in this issue: https://github.com/vchelaru/Gum/issues/273

Previous versions allowed locked items to be edited once selected, but they only prevented selection in the Editor tab.

Introduction

The Locked property controls whether an instance can be clicked in the Editor tab, and whether any variables can be modified on the locked item.

Locked items appear with a lock icon.

Locked instance with a lock icon

If this value is true, then the following is true:

  • Instance cannot be selected in the Editor tab

  • Instance variables are all disabled and cannot be edited in the Variables tab (except un-locking the instance)

  • Selected instances cannot be moved, resized, or rotated in the Editor tab

  • Polygons cannot have points modified, added, or deleted in the Editor tab

Locked instances cannot be selected by clicking on them in the editor window

The Locked property does not have any impact on the behavior of Gum objects at runtime, such as when running in FlatRedBall or MonoGame. This property only affects editor behavior.

Min Width

Introduction

The Min Width variable sets the minimum width in pixels. The value is applied after all other layout so it can be used to overwrite automatically-assigned width.

By default this value is <NULL> which means there is no Min Width.

A ColoredRectangle with no Min Width

If Min Width is assigned (not <NULL>), then the effective width cannot be smaller than the Min Width value. The following animation shows that the width is limited to a Min Width of 100.

Min Width set to 100 limits the ColoredRectangle's width

Notice that the Width variable can still be set to a value smaller than Min Width, but it does not apply visually.

Min Width can also be used if Width Units is set to values other than Absolute. For example, Min Width can be used to limit the width of a ColoredRectangle when Width Units is Relative to Parent.

ColoredRectangle's width limited by its Min Width of 100

Order

Introduction

Children in a Screen, Component, or parent instance are drawn top-to-bottom, so that children further down are drawn on top.

Red is the first item drawn, so it is under the other rectangles. Blue is the last, so it appears on top.

Changing Order

Gum provides a number of ways to reorder instances.

Items can be right-clicked in the editor to change their order.

  • Bring to Front - reorders the instance so that it is in front of all of its siblings.

  • Move Forward - moves the instance in front of the sibling that is in front of it. In other words, moves the item forward by one index.

  • Move In Front Of - moves the instance in front of the selected sibling.

  • Move Backward - moves the instance behind the sibling that is currently behind it. In other words, moves the item backwards by one index.

  • Send to Back - reorders the instance so that it is behind all of its siblings.

Right-click options can be used to reorder instances

Items can be re-ordered in the Project tree view by holding the alt key and pressing up or down.

Alt+arrow keys can be used to reorder items

Parent and Children Ordering

Gum uses a hierarchical ordering which means that a parent and all of its children draw before any of the siblings of the parent. For example, a container and all of its children draw before any other siblings of the container.

The following animation shows a container named ContainerInstance2 which draws on top of ContainerInstance1. All children of ContainerInstance2 also draw on top of children of ContainerInstance1.

If a parent draws on top of other instances, then its children also draw on top

If a parent is reordered, then all of its children also respect the new order. For example, if ContainerInstance2 is sent to the back, then all of its children draw below ContainerInstance1 and its children.

If a parent is sent to the back, all children also draw behind other siblings of the parent container.

Order and Stacking / Grid

If a parent uses a stack or grid layout for its Children Layout variable, then the order of the children in the Project tab determines their order in the stack or grid.

For more information, see the Children Layout page.

Visible

Introduction

The Visible variable controls whether an object and its children appear.

Example

Setting Visible to false hides the selected instance.

Visible property controls whether an instance is hidden or shown

Parent/Child Visibility

Setting a parent's Visible variable to false also hides all children. Note that this does not explicitly set the Visible property to false for all children, but a child's effective visibility depends on its parent.

A parent's Visible value controls whether children are visible

Visibility and Stacking

If an instance is part of a parent which stacks its children (has a Children Layout of Left to Right Stack or Top to Bottom Stack), then it will no longer be considered when stacking siblings if it is invisible. In other words, making an item invisible removes it from the stack.

Invisible siblings are not considered in stacking

If the stack contains children which use a Width Units of Ratio, then hiding any of the siblings results in the children with ratio width adjusting to occupy the extra space.

Invisible siblings are not considered when calculating used space for Width Units of Ratio.

Selecting Invisible Objects

An invisible object can be selected by clicking on it in the Project tab or in the Editor tab.

Invisible objects can be selected

Visible items are given preferential selection even if they are ordered behind invisible items.

The visible ColoredRectangle is selected before the invisible container

X Units

The X Units variable controls how a unit is horizontally positioned relative to its parent. By default an object is positioned relative to the left of its parent, where each unit represents 1 pixel.

Pixels From Left

The following shows a child ColoredRectangle positioned 50 Pixels From Left relative to its parent:

Pixels From Center

The following shows a child ColoredRectangle positioned 50 Pixels From Center relative to its parent:

Pixels From Right

The following shows a child ColoredRectangle positioned 50 Pixels From Right relative to its Parent:

Percentage Parent Width

The following shows a child ColoredRectangle positioned 50 Percentage Parent Width relative to its Parent. In other words, it will be positioned halfway between the left and right edges of the Parent:

Y Origin

Introduction

The Y Origin variable controls the point which an object is positioned by. By default the Y Origin is Top. The Y Origin is shown visually as a white "X" in the editor.

Top

The following image shows a ColoredRectangle with its Y Origin set to Top:

ColoredRectangle with Top Y Origin

Center

The following image shows a ColoredRectangle with its Y Origin set to Center:

ColoredRectangle with Center Y Origin

Bottom

The following image shows a ColoredRectangle with its Y Origin set to Bottom:

ColoredRectangle with Bottom Y Origin

Baseline

The following shows a Text with its Y Origin set to Baseline:

Text with Baseline Y Origin

Baseline refers to the bottom of the text for letters without descenders. For more information see the Wikipedia Baseline page.

Baseline is often used to align fonts of different sizes. The following image shows two Text instances with different font sizes. Both are positioned by their baseline so their bottoms align properly (ignoring descenders, such as on the letter p and the comma).

50,000 xp aligned by baseline

By contrast, the following image shows the same Text instances using bottom alignment.

Has Dropshadow

Has Dropshadow is a shape property supported by Circle, Rectangle, ColoredCircle, RoundedRectangle, Arc, and Line.

Text also supports Has Dropshadow, but the shadow is baked into the font's texture atlas at generation time rather than drawn at runtime like the shape dropshadows above. This requires the project's FontGenerator setting to be KernSmith — bmfont.exe (the default) cannot bake shadows.

Introduction

Has Dropshadow controls whether a dropshadow is drawn below a shape. By default this value is false.

The following image shows two Rectangles. The left with Has Dropshadow unchecked, the right with Has Dropshadow checked.

Two RoundedRectangle instances

Note that if an instance has a dropshadow, the dropshadow renders outside of the bounds of the instance.

Dark pixels from a dropshadow rendering below the bounds of a RoundedRectangle

Dropshadows draw as part of the object, so if multiple objects stack, their dropshadows also stack.

Multiple stacked ColoredRectangles with dropshadows

Dropshadow Offset X and Dropshadow Offset Y

Dropshadow Offset X and Dropshadow Offset Y control the position of the dropshadow relative to the main body of the instance.

This value can be changed to move the dropshadow, which gives the element a sense of height.

Dropshadow Offset X and Dropshadow Offset Y change the dropshadow position

Dropshadow Blur

Dropshadow Blur controls the dropshadow edge softness. A value of 0 creates a sharp shadow, while a larger value increases blur.

Dropshadow Blur can be adjusted to make a dropshadow more blurry

Dropshadow Blur values roughly measure the number of pixels that it takes to interpolate the edge of a shadow from its full color to fully transparent. This value is not exact due to antialiasing.

Dropshadow Alpha

Dropshadow Alpha controls the transparency of a dropshadow. A fully-opaque dropshadow has an alpha of 255. This value can be modified to decrease or increase the dropshadow's opacity.

Dropshadow Alpha adjusts the dropshadow transparency

Dropshadow Color

Dropshadow Color adjusts the dropshadow color independent of the shape's body color. Usually dropshadows are pure black with their transparency adjusted by Dropshadow Alpha, but they can also include other colors if needed.

Dropshadow color can be changed to create shadow/blur effects

Is Filled

Is Filled is a shape property supported by Circle, Rectangle, ColoredCircle, and RoundedRectangle.

Introduction

Is Filled sets whether a shape is filled in or if it is drawn using stroke - another word for outline.

Circle toggling its Is Filled property

Stroke Width

Stroke Width sets the thickness of the stroke (outline). Increasing the value makes the stroke thicker. Note that increasing the stroke brings the stroke inward, so the shape is still bound by its effective width and height.

Stroke Width controls the thickness of the outline

Stroke, Gradient, and Dropshadow

If a shape element has its Is Filled unchecked, this affects the rendering of gradients and dropshadows.

Gradients only fill the solid parts of a shape, so if a shape has Is Filled set to false, the hollow center of the shape does not show gradient color.

Toggling Is Filled affects the gradient rendering at the center of the shape

Dropshadows respect the opaque part of the shape, so changing Is Filled also affects the dropshadow.

Changing a ColoredCircle's Is Filled to false results in the dropshadow having a hollow center

Is Render Target

Introduction

Is Render Target controls whether all instances contained in this container render directly to the screen (if false), or if they first render to their own dedicated target before rendering to the screen (if true).

Is Render Target defaults to false (unchecked).

Is Render Target enables a number of graphical effects including:

  • Container Alpha (transparency)

  • Container Blend

  • Alpha-only Blend modes on instances contained in the Container

As of February 2025 the Is Render Target variable is considered experimental. You may experience issues when using this as it is being developed. Please report any problems you find through GitHub or on Discord.

Is Render Target Clips Children

Containers with Is Render Target set to true automatically clip their children. This behavior is the same as setting Clips Children to true. This happens because render targets internally create a texture which matches their size. Therefore, any items which are placed outside of the bounds of a render target container are not rendered.

Is Render Target set to true clips children

Using Is Render Target for Special Effects

Once a container is rendered to a render target, additional special effects can be applied at runtime. These include:

  • Scaling

  • Rotating

  • Rendering portions using texture coordinates

For a step-by-step tool walkthrough of rotating and scaling a clipped container, see Rotating and Scaling Clipped Contents. For the same pattern in code, see the SpriteRuntime RenderTargetTextureSource documentation.

If you are managing a render target yourself in code instead of using Is Render Target, see Render Targets for the blend-mode setup needed to composite translucent content correctly on MonoGame and raylib.

Stack Spacing

Introduction

The Stack Spacing variable controls the additional padding between children when a container uses a Children Layout of either Top to Bottom Stack or Left to Right Stack. Stack Spacing serves as an alternative to adjusting the position of each item in a stack.

Setting Stack Spacing

A larger Stack Spacing value increases the spacing between each child. By default Stack Spacing is set to 0 which means that no spacing is added between items in a stack.

Stack Spacing of 0 results in no space between children

Changing the stack spacing adds gaps between each child as shown in the following animation.

Stack Spacing used to add gaps between children

Stack Spacing can also be a negative value resulting in overlapping children. The items in the following animation are partially transparent to show the overlap.

Negative stack spacing results in overlaping children

Stack Spacing and Stacking Direction

Stack Spacing can be used for either Top to Bottom or Left to Right Stacking.

Stack Spacing can apply spacing vertically or horizontally

Stack Spacing and Wrapping

Stack Spacing can be used on container instances which stack and wrap their children. As stack spacing increases, the amount of space allocated to each object also increases, resulting in wrapping occurring earlier.

If wrapping occurs, then stack spacing applies spacing between rows and columns as shown the following animation:

Increasing Stack Spacing results in spacing between children both vertically and horizontally

Wraps Children

The Wraps Children property controls whether children wrap or stack beyond their container's boundaries when the container's Children Layout is set to Top to Bottom Stack or Left to Right Stack.

Wraps children makes children wrap when using either Top to Bottom Stack or Left to Right Stack.

If a parent has Wraps children set to true, the wrapping adjusts in response to resizing the parent.

Resizing a parent can change wrapping

Similarly, resizing a child may result in the stacking changing.

Resizing children can change wrapping

The row height in a Left to Right Stack is determined by the largest child in the row.

Height of each item in the row determines row height

Similarly, column width in a Top to bottom Stack is determined by the largest child in the column.

Width of each item in the column determines column width

Wraps Children and Width Units

Wrapping of children can only be performed if the parent's size does not depend on its children (see more info below). If the parent's size does depend on its children, then the parent will expand to fit is children so wrapping will not occur.

If a parent container's Width Units is set to Relative to Children, then it adjusts in response to children size and positioning, so wrapping will not occur.

Stacking cannot occur if the parent uses a Width Units of Relative To Children

A parent can use the following Width Units and Height Units with children wrapping:

  • ✅Absolute

  • ✅Percentage of Parent

  • ✅Ratio of Parent

  • ✅Percentage of Width/Height

  • ✅Absolute Multiplied by Font Scale

A parent does not wrap its children if it uses:

  • ❌Relative to Children (see below)

Note that Relative to Children can be used on the non-stacking axis. For example, if a parent uses Left to Right Stack, then it can still have its Height Units set to Relative to Children.

Left to Right Stack with Height Units set to Relative to Children

Relative to Children and Max Width and Max Height

If a container has a non-null Max Width, then it will expand according to its children until it reaches its max width. Once it reaches a max width, it wraps its children.

The following animation shows a container which has:

  • Width Units of Relative to Children

  • Max Width of 400

  • Children Layout of Left to Right Stack

  • Wraps Children set to True

Wraps Children allowed when max width is set

Custom Frame Texture Coordinate Width

Introduction

The Custom Frame Texture Coordinate Width property allows a NineSlice to customize the number of pixels used on the source texture when defining its outer frame. This allows for fine control over which parts of a NineSlice stretch and which parts are used as the corners and edges.

By default this value is null, which means the NineSlice automatically dedicates 1/3 of the texture for the edges.

Changing Custom Frame Texture Coordinate Width

If the Custom Frame Texture Coordinate Width value is changed, then the source texture applies a fixed pixel size to the borders. For example, using the image above, the frame can be changed to 3 so that only the black and white pixels are part of the border.

NineSlice with an explicitly-set 3 pixel border width

Custom Frame Texture Coordinate Width Set to 0

If Custom Frame Texture Coordinate Width is set to a value of 0, then the NineSlice does not draw a border. In other words, setting this value to 0 results in the NineSlice behaving like a Sprite.

Texture Address

Introduction

The Texture Address variable can be used to define the area that the NineSlice displays. By default the Texture Address is set to Entire Texture which means the NineSlice will display the entire source file (split up among the nine pieces).

NineSlice only supports Entire Texture and Custom for the Texture Address value. It does not support Dimension Based, which is only available on the Sprite element.

Entire Texture

The following screenshot shows an entire texture being used for a NineSlice.

The entire texture is split up into 3 sections horizontally and 3 sections vertically, matching up the texture coordinates used to display the NineSlice's 9 sections.

Custom

The Custom value allows specifying a custom set of coordinates for the Nine Slice. Custom is most often used when an image is part of a sprite sheet. The following example uses this image:

The NineSlice uses the following variables:

  • Texture Address = Custom

  • Texture Top = 0

  • Texture Left = 0

  • Texture Height = 40

  • Texture Width = 40

These values result in the the following NineSlice:

Height and Width

Introduction

Polygons can be any shape, so their width and height values cannot be explicitly set. Instead, a Polygon's width and height values are determined by their points.

Width and Height from Points

A Polygon's effective width and height is determined by its points. The furthest-right point determines the polygon's width and the furthest down point determines the polygon's height.

For example, a square Polygon with the furthest points at 128,128 has a width of 128 and a height of 128.

A Polygon's height can be used to affect parents, siblings, and children depending on the other instances' Width Units, Height Units, and stacking values.

For example, we can add a rectangle as a child of a ColoredRectangle to see how its points affect the size of the polygon.

Polygons in a ColoredRectangle. The ColoredRectangle sizes itself according to the Polygon's width and height

We can see similar behavior if we place the Polygon in a stacking parent.

A Polygon's height and width are measured from a Polygon's top left corner to the furthest down right point. Points which have a negative value do not affect a Polygon's effective height, so moving points above or to the left of the origin will not affect the layout of any object which depends on the Polygon's size.

For example, if we move Polygon points in a stack up or to the left, this does not shift any of the Polygon's siblings.

Moving points so they have negative values does not affect the effective size of a Polygon

For Figma Users

Introduction

This guide walks through Gum's layout system using Figma as a reference point. The quick reference table below covers the most common mappings. The sections that follow explain the concepts that feel meaningfully different coming from Figma.

Quick Reference: Figma → Gum

Figma Concept
Gum Equivalent

Page

(no equivalent — Screens serve as the organizational unit)

In Figma, you organize your work into Pages, each containing Frames that typically represent individual screens or views. Components live alongside your frames and can be used across pages.

Gum splits this into three explicit categories visible in the Project panel:

  • Screens — represent individual UI states in your game, like a main menu, HUD, or pause screen. You can think of each Screen as a top-level Frame in Figma. Unlike Figma frames though, Screens can't be nested inside other Screens — they're always top-level.

  • Components — reusable elements like buttons, list items, or windows. These work like Figma components: define once, place instances anywhere.

  • Standard Elements — the built-in primitives (Sprite, Text, ColoredRectangle, etc.) that you drag into Screens and Components to build your UI.

There's no equivalent to Figma's Pages — Screens serve as the organizational unit directly.

Gum's coordinate system works the same as Figma's: X increases to the right, Y increases downward, with (0, 0) at the top-left of the canvas or parent.

In Figma, a Frame can hold children and have its own fill and stroke. In Gum, layout containers are called Containers, and they are always invisible — there's no fill or stroke to set. You may notice containers showing up with a dotted outline in the editor, but that's just the container outline display (on by default in Gum) and isn't part of the rendered output.

To give a container a visible background, add a ColoredRectangle or NineSlice as a child. For example, a button component might have a Container at the root, a NineSlice child for the background, and a Text child for the label.

In Figma, you set X and Y and use the nine-point reference selector to control which corner of the object those numbers measure from. In Gum, the same idea is split into three properties:

Property
What It Does

X Units options:

Unit
Meaning

Y Units mirrors this vertically, with positive Y always pointing downward. Pixels From Right and Pixels From Bottom work the same way — X=0 / Y=0 is at the edge, and positive goes outward past it. To position something inside those edges, use negative values.

X Origin / Y Origin options are Left/Top (default), Center, and Right/Bottom — the same as Figma's nine-point reference selector, just set separately per axis.

Center an element horizontally inside its parent (like Figma's "center" horizontal constraint):

Pin an element's right edge 10px inside the parent's right edge (like Figma's right constraint with 10px offset):

Note that Gum doesn't pin both sides of an element at once to stretch it. Stretching is handled by Width/Height Units instead.

Like Figma's Fixed / Fill / Hug, Gum controls sizing through Width Units and Height Units:

Gum Unit
Figma Equivalent
What It Does

Relative to Children works like Hug. The numeric value adds padding — for example, Width = 16 with Relative to Children adds 8px on each side. Note that children whose size depends on the parent's size are excluded from this calculation to avoid a circular dependency.

Ratio of Parent works like CSS flex-grow. Three siblings with ratios of 1, 2, 1 get 25%, 50%, and 25% of the parent's width respectively.

The Alignment tab has shortcut buttons that set X, Y, Width, and Height variables for common layouts. They don't toggle any state — they just write variables, so you undo them with Ctrl+Z.

Anchor sets position variables only (X, Y, and their Units and Origins), similar to Figma's constraint presets. It won't change the element's size.

Dock sets both position and size, for "fill a side" patterns — think of it as Figma's "Fill container" combined with a constraint. Options include Top, Bottom, Left, Right, Fill, Fill Horizontally, Fill Vertically, and Size to Children.

Figma's Auto Layout is called Children Layout in Gum, set on the container itself:

Gum Children Layout
Figma Equivalent

Stack Spacing is the same as Figma's Gap between items. Negative values cause children to overlap.

In Auto Grid modes, the parent's size is divided equally among cells. The number of columns (or rows) is fixed; additional rows (or columns) are added as needed.

A couple of differences from Figma's Auto Layout worth knowing:

  • No padding. To approximate padding, size a child with Relative to Parent and a negative value, or offset children manually.

  • Cross-axis alignment is per-child. In a Top to Bottom Stack, Gum controls each child's Y automatically, but each child sets its own X. In Figma, alignment (left/center/right) is a single setting on the parent.

Wraps Children works like Figma Auto Layout's Wrap mode. Row height is set by the tallest child; column width by the widest.

One constraint: the container's size on the stacking axis can't be Relative to Children at the same time — that would be circular. You can still use Relative to Children on the cross axis (e.g. height on a horizontal stack). Alternatively, set a Max Width on the container — it will grow with its content until hitting the max, then start wrapping.

Figma's Clip content is called Clips Children in Gum. Off by default, meaning children can render freely outside their parent's bounds.

Gum's Components work like Figma's components — define once, place multiple instances, override individual properties per instance.

Gum also has Is Slot, which doesn't have a direct Figma equivalent. You can mark child instances inside a component as slots — named attachment points that elements can parent themselves to when the component is placed in a screen. For example, a Window component with Header, Body, and Footer slots lets you drop children directly into any of those sections.

Same as Figma: items earlier in the tree render behind items later in the tree. Right-click to Bring to Front, Send to Back, Move Forward, or Move Backward. Reordering a parent moves all its children with it.

Rotation is in degrees. One difference from Figma: positive values rotate counterclockwise (Figma rotates clockwise). The pivot point is set by X Origin and Y Origin — by default that's the top-left corner, so set both to Center if you want to rotate around the middle.

Min Width, Max Width, Min Height, and Max Height work the same as in Figma — they clamp the effective size after all other calculations. They work with any Width/Height unit type, so you can combine them with Relative to Parent or Relative to Children layouts.

7 - States

Introduction

States allow you to set multiple variables at one time. Examples of states might include:

  • A button with Regular, Highlighted, Pressed, and Disabled states

  • A game logo in Large and Small modes

  • A game HUD which can appear on and off screen

This tutorial shows how to add states which can be used to display if a player is low, medium, or high health by adjusting the color of the fill bar.

This tutorial builds upon the previous tutorials where a HealthBar component was created. If you haven't yet, you should read through the earlier tutorials to create a HealthBar component.

First we'll define a category and our three states. All components and screens have a Default state automatically. This Default state is uncategorized, but all other states must be in a category. Therefore, we'll first add a new category:

  1. Right-click in the States tab

  2. Select Add Category

  3. Enter the name HealthCategory

Although it's not necessary, categories often have the name "Category" at the end.

To add a new state:

  1. Right-click on HealthCategory

  2. Select Add State

  3. Enter the name "High"

  4. Click OK

The HealthBar component should now have three states.

Once a state is defined and selected, you can make changes to the component and any of those changes are applied to the selected state. In other words, any variable that is set when the High state is selected results in that variable being added to that state.

For this component, we want to change the Fill color depending on whether the health is High, Medium, or Low.

Our High state should display a green color, and if you've set your Fill to be green, then this is already set how we want. This means we don't have to make any changes to the High state.

Instead, we'll make the fill yellow in the Medium state:

  1. Select the Medium state

  2. Select the Fill Rectangle instance under HealthBar

  3. Change the Fill Color variable to a yellow color. Note that the fact that our rectangle is called "Fill" and that we are changing "Fill Color" is a coincidence. We named our Rectangle Fill because it fills the health bar. The Fill Color exists on every Rectangle, and controls the inner color of a rectangle, as opposed to Stroke Color which controls the outline color.

Although this might seem like a simple change, a lot has happened in response to this change, so we should take a moment to break it down.

First, by changing the Fill Color value on the Medium state, we have set every state to explicitly set its color. We can see this by noticing that every state now has an edited icon.

This tells us that the Fill instance is modified by every state in the HealthCategory. Even the High and Low states, which haven't been modified, are now explicitly setting the color to the default green.

We can modify the Low state to be a red color:

  1. Select the Low state

  2. Make sure Fill is still selected

  3. Change the Fill Color variable to a red color

Now we can select any state and see what our state looks like immediately.

Now that we have added a new category to our HealthBar component, we can assign per-instance.

Notice that the Health Category State variable is independent of Health Percent. Although the two are conceptually connected, Gum considers these to be two unrelated variables which can be adjusted individually. These variables would typically be connected in code in a game.

This tutorial covers how to set up a state, but the next tutorial dives deeper into categories, including using multiple categories to mix variable assignments.

2 - Creating an Animation

Introduction

This article shows how to create an animated component. It will contain an animation which can be used when the component first appears.

Creating the Component

First we'll create a component which will be animated. To do this:

  1. Right-click on Components

  2. Select Add Component

  3. Enter the name TextComponent and click OK

  4. Drag+drop the Text Standard into the TextComponent to create a Text instance

  5. Select the Alignment tab and click the middle button to have the TextInstance fill the TextComponent

Now that we have a component we'll add the states needed for animation. We'll add all states in a category called HideShow. Animation states should always be categorized. To create the states:

  1. Right click in the States list box

  2. Select Add Category

  3. Enter the name HideShow

  4. Right-click on the HideShow folder

Now that we have the states defined we can set values for the states. In this case the only thing we'll be modifying is the TextInstance's Font Scale value. To do this:

  1. Select TextInstance

  2. Select the Hidden state

  3. Set the Font Scale to 0. This makes the Text so small that it's invisible

  4. Select the

The two states we created above will be used as the keyframes for our animation. The animation will begin in the Hidden state then interpolate to the Shown state. To add this animation:

  1. Verify that TextComponent or any objects under it are selected

  2. Select View -> View Animations

  3. The Animations tab appears in the bottom right

The animation can now be played or previewed:

The Interpolation Type value sets how one keyframe blends to another. By default keyframes use Linear interpolation, which is a constant change from one state to another. When interpolating from one keyframe to another, the first keframe defines the interpolation type. In our case the Hidden frame defines the interpolation type. We can change the Interpolation Type and preview the animation:

  1. Select the Hidden keyframe

  2. Change Interpolation Type to Elastic

Playing the animation will reflect these changes.

3 - Playing Animations inside other Animations

Introduction

Gum supports creating animations which can play other animations. This is especially useful when creating animations in Screens that contain components which themselves have animations. This tutorial will build upon the previous tutorial where we created an animated component called TextComponent.

Creating a Screen

First we'll create a Screen called AnimatedScreen. To do this:

  1. Right-click on Screens

  2. Select "Add Screen"

  3. Enter the name "AnimatedScreen" and click the OK button

  4. Drag+drop a few TextComponents into the Screen and spread them out visually

The animation we will be creating in our Screen will start with all TextComponents being invisible, then each one appearing by playing their Show animation. The animations will be slightly staggered. First we'll add the initial state where all of the TextComponents are invisible. To do this:

  1. Verify that the AnimatedScreen is selected

  2. Right-click in the states area and select "Add Category" name it "ScreenCategory"

  3. Right-click the category and select "Add State"

  4. Name the state "AllInvisible" and click OK

Now we have all of the states and animations that we'll use as keyframes in our animation. To create the animation:

  1. Select AnimatedScreen

  2. Select "View" -> "View Animations"

  3. Click "Add Animation"

  4. Name the animation "ShowAll"

The animation now sets all TextComponents to their Hidden state initially.

Next we'll be adding animations to animate the TextComponent instances to visible. To do this:

  1. Bring up the animation window for AnimatedScreen if it is not already showing

  2. Select "ShowAll"

  3. Click "Add Sub-animation"

  4. Select the first TextComponentInstance

Now the animation can be played or previewed with the slider bar:

Rotating and Scaling Clipped Contents

Introduction

The Clips Children and Is Render Target properties clip their children to an axis-aligned rectangle. Because the clip region stays aligned to the screen, rotating a container that clips its children leaves the clip region unrotated, so the result looks broken.

To rotate (or scale) a container and keep its contents clipped, you render the container to a render target and display that render target through a Sprite. The Sprite can then be rotated, scaled, positioned, and stacked like any other Gum object, and the clipping rotates along with it.

Clipping doesn't support rotation

The Two-Object Pattern

This effect uses two objects:

  1. A Container with Is Render Target set to true. This container holds the content you want to clip, and it clips its children automatically.

  2. A Sprite with its Render Target Texture Source set to the container above. The Sprite displays the container's render target and can be freely rotated and scaled.

The source container (which has Use Render Terget set to true) can even be made invisible:

  1. Create a Container and add the children you want to clip and rotate.

  2. Select the Container and set its Is Render Target value to true. Its children are now clipped to the container's bounds.

  3. Create a Sprite.

  • A container with Is Render Target set to true performs its layout and rendering even when its Visible value is false. Set the source container's Visible to false to hide the original while still displaying it through the Sprite.

  • Children inside the render target container are not interactive while displayed through the Sprite

  • — the same pattern in code

Use Gradient

Use Gradient is a shape property supported by Circle, Rectangle, ColoredCircle, RoundedRectangle, Arc, and Line.

Introduction

The Use Gradient property controls whether a shape uses gradient values if true or a solid color if false.

Rectangle with Use Gradient set to false

If this value is set to true, then additional properties appear for controlling the gradient.

Rectangle with Use Gradient set to true showing gradient values

Gradient start color and Color2

A gradient creates a smooth interpolation from a start color to Color2.

For Circle, Rectangle, and Arc, the gradient starts from the shape's own color — for Circle and Rectangle that is the Fill color when the shape is filled or the Stroke color when it is outline-only, and for Arc it is the shape's Color. To adjust where the gradient begins, change that color; to adjust where it ends, change Color2. Because the start is the color the shape already shows, turning Use Gradient on and off does not produce a sudden color change.

The older ColoredCircle and RoundedRectangle shapes instead expose a dedicated Color1 for the gradient start.

The gradient values appear at their respective values at the points specified by Gradient X1, Gradient Y1, Gradient X2, and Gradient Y2. For example the gradient points could be visualized as shown in the following image:

Changing the Gradient X or Y values changes the start and end points for the gradient.

Gradient values use Units similar to X Units and Y Units. By default, gradient values are relative to the top-left of the element. Since the gradient values are not affected by size, changing the size of the element does not affect the gradient.

The gradient X and Y units can be changed. Each value can be set independently. For example, the X2 and Y2 units can be adjusted to be relative to the bottom-right corner of the instance. The following shows a RoundedRectangle with the Gradient X2 and Y2 values 100 pixels up and to the left of the bottom-right corner. If the RoundedRectangle is resized, then the gradient adjusts in response.

Gradient X and Y values can exist outside of the visual space of the instance, and even outside of its bounds. The following image shows an Arc with a gradient which is defined below the visual part of the arc. Notice that the Gradient Y values are both 0 PixelsFromBottom.

Gradient Type controls whether the gradient is linear or radial. Radial gradients place the center of the radial gradient at X1,Y1 and the edge of the radial gradient at X2, Y2.

Default Slot

Previous versions of Gum called this variable Default Child Container. This was changed to Default Slot in the February 2026 release.

Default Slot specifies where children are added to instances of the selected component.

By default this value is blank, which means that newly added children treat the entire component as their parent. If Default Slot value is set, children which are dropped on instances of this component type use the Default Slot as their parent.

Default Slot is typically set on containers which are designed to hold children, but which have margins or decoration around the dedicated container instance. Examples include list boxes, tree views, and frames.

The Default Slot property simplifies the addition of new children to a container. Changing this value will not change already-added children. This property is not required, since the Parent can be manually typed and set to the inner container using the "dot". See below for more information on dot assignments.

Multiple instances can act as slots. For information on using multiple slots, see the Is Slot page.

Example

Consider a Component named Frame which has two instances: OuterRectangle and InnerRectangle.

Frame component with two children

This Component is designed to keep all of is children inside the InnerRectangle, so that any child automatically respects the margin specified by InnerRectangle.

To make this kind of relationship the default, the Frame can set its Default Slot property to InnerRectangle.

Once this value is set, instances which are drag+dropped onto Frame instances use the InnerRectangle as their parent, as shown in the following animation.

When one instance is drag+dropped onto another instance, the Parent property is set according to the parent's Default Slot.

Using the example above, the RectangleInstance is dropped on the ContainerTestInstance. Since the ContainerTestInstance is of type Frame, then the Default Slot is applied on the drop, which results in the RectangleInstance's Parent being set to ContainerTestInstance.InnerRectangle.

As mentioned above, if an instance is added to a parent component, the instance automatically attaches itself to the parent's Default Slot. This can be undone by manually changing the Parent property.

For example, the Parent can be manually changed to ContainerTestInstance.

Points

Introduction

Points are an ordered set of X,Y values defining the shape of the polygon. All points are relative to the Polygon's position. Typically the last point is the same as the first point creating a closed polygon.

By default polygons have four sides. Since the first and last point is repeated, a four-sided polygon has five points.

A default four-sided polygon

Each point is relative to the polygon's X and Y (position). Points use pixel coordinates. The following image shows a polygon with the following points:

  • -32, -32

  • 32, -32

  • 32, 32

  • 32, -32

  • -32, -32 (repeat of first point)

Notice that the image above has points which appear above and to the left of the polygon's origin.

The easiest way to add points is by selecting a Polygon, then clicking on the + icon that appears in the center of the line where you would like to add a point. The following animation shows how to add points to a square to create an octagon:

Points can be moved by clicking on them and dragging them in the editor. Note that points can be positioned anywhere, even if lines cross or if a polygon is concave.

A point can be removed by clicking on it and pressing the delete key.

Each point can be edited in the Variables tab. To edit a point, double-click the desired point and type in the new X,Y value.

Points can also be edited manually in the Screen or Component which contains the Polygon instance. You can open the file in a text editor to see a list of points.

For example, consider the following polygon:

The points for this polygon defined in the MainMenu XML file might look like this:

These points can be changed in the XML file. If the file is changed then Gum automatically reloads this file.

Remember that the first and last points should have the same values if you want your polygon to be closed. You can make edits in the XML file to separate the start and end if you would like to draw a segmented line rather than a closed polygon.

Y Units

The Y Units variable controls how a unit is vertically positioned relative to its parent. By default an object is positioned relative to the top of its parent, where each unit represents 1 pixel downward.

Pixels From Top

The following image shows a child ColoredRectangle positioned 50 Pixels From Top relative to its parent:

Rectangle with Y Units of Pixels From Top

Pixels From Center

The following image shows a child ColoredRectangle positioned 50 Pixels From Center relative to its parent:

ColoredRectangle with Y Units of Pixels From Center

Pixels From Bottom

The following image shows a child ColoredRectangle positioned 50 Pixels From Bottom relative to its parent:

The following image shows a child ColoredRectangle positioned 50 Percentage Parent Height relative to its parent:

Pixels From Baseline positions a child relative to the parent's baseline. If the parent is a Text instance, the baseline is the Y position of the bottom of letters which do not have descenders. For more information on the concept of text baseline, see the baseline Wikipedia page

The following image shows a child ColoredRectangle positioned 0 pixels relative to a Text instance's baseline.

When using Pixels From Baseline, the position depends on the font size, baseline definition in the .fnt, and whether the text wraps. For example, changing the Width of the Text causes line wrapping which shifts the baseline.

A text instance's baseline is defined by its Font and Font Scale values. These values ultimately create a .fnt file with a base value indicating the distance from the top of the text instance to the baseline. For example, an Arial font with Font Size 40 has a base value of 36 and a lineHeight of 45.

This means that 36 pixels fall above the baseline, and 9 pixels (45 - 36) below.

Note that if the parent is not a Text instance, then the bottom of the parent is used as the baseline. The following image shows a Colored Rectangle using a Y Units of Pixels From Baseline with a Container parent.

Color

Introduction

The Color value is used to perform a multiply color operation on the sprite. Color values can be used to darken or tint a grayscale texture. By default Sprites us a white color, which means the original texture will display unmodified.

Examples

The following images show the color values as applied to a multi-color sprite.

Red: 255 Green: 255 Blue: 255

Red: 255 Green: 0 Blue: 0

Red: 0 Green: 255 Blue: 0

Red: 0 Green: 0 Blue: 255

Red: 128 Green: 128 Blue: 128

Red: 0 Green: 0 Blue: 0

NineSlice

Introduction

NineSlice is a standard component which can be used to create visual objects which can stretch to any size without creating distortion on the source image. For example, consider the following image:

This image could be used to create nine slices of various sizes without any distortion:

The NineSlice achieves this effect by splitting the texture into nine pieces, and scales each one differently to prevent distortion. Highlighting a nine slice shows how it is split:

This is achieved by splitting the texture into 1/3 sections wide and tall. The following image shows how the original image will be split:

NineSlice Texture

The simplest way to assign a texture to a NineSlice is to use a single file. Setting the SourceFile to a single PNG will result in the NineSlice using that one texture, where each section of the NineSlice displays 1/3 of the width of the file and 1/3 of the height of the file.

A NineSlice's Texture Address property can be used to change the portion of the source texture that it uses. More info can be found in the Texture Address subpage.

Alternatively, nine files can be used to specify each section of the NineSlice independently. To use nine individual files, each file must be given a specific suffix.

The following suffixes can be added to create nine slice graphics. For example, assuming your NineSlice image is called "Image" and you are using the .png file format:

  • Image_BottomCenter.png

  • Image_BottomLeft.png

  • Image_BottomRight.png

  • Image_Center.png

LottieAnimation

Introduction

LottieAnimation instances can render animations in the Lottie format. Lottie files are animated files, usually with vector art, which serve as an alternative to gifs. Since they are often vector art, Lottie files can be resized without pixelation.

Lottie files can be downloaded from various sites or created in application such as Adobe After Effects. If you are interested in testing out Lottie animations, you may want to check lottiefiles.com for sample Lottie files.

The following shows a Lottie animation playing in Gum. Source file: https://lottiefiles.com/free-animation/city-skyline-HFnJYQZLPP

LottieAnimation in Gum

Source File

The Source File variable controls the lottie animation displayed. This value can be set and changed just like source files on other elements such as a .png on a Sprite.

Lottie Width and Height

Width and Height values can be set on a Lottie file just like any other Gum element. Unlike rasterized objects such as Sprites, LottieAnimations use Vector art so they can be resized and still retain crisp edges and details.

LottieAnimations can be resized and maintain their crisp visuals

LottieAnimations are still rasterized in Gum, so they display pixels when the view is zoomed in, especially if the LottieAnimation has a small Width or Height.

1 - The Basics

This page walks you through the basics of using the Gum UI tool, which we'll refer to simply as Gum for this and all other documentation.

Gum separates its elements into three categories: Screens, Components, and Standard. Behaviors are an advanced topic that we'll skip for these tutorials.

Standard elements represent the building-blocks for screens and components. Let's take a look at the different types next.

  • Circle - a circle which can be filled in, outlined, or both. Often used for visualizations or for defining collision in your Gum objects for a game.

2 - Variables Tab

The Gum Variables tab displays all available variables when editing an instance or element. The Variables tab exposes all variables, and is useful for making fine changes to instances, such as by moving an instance by a single pixel.

The Variables tab shows variables for the selected instance or element.

Variables can be edited by changing values on the selected variable. For example, to move the text to the right, change its X value to a positive number. Press Enter or Tab to apply the changes:

Gum provides a flexible positioning system. The position of an element is a result of a number of variables. We'll go over a few here.

By default all instances are positioned by their top-left corner. For example, setting the Text instance's X and Y to 0 aligned its top-left position to the top-left of the screen (which is identified by a dotted line.

4 - Components

Components are reusable objects which can contain instances of other components and of standard objects. Examples of components include:

  • Health Bars

  • Buttons

  • Popup Menus

Components can also be simple such as a button or more complex UI elements such as a full Options menu with dozens of instances.

6 - Parent

Introduction

The Components tutorial shows how Rectangle instances can be sized and positioned according to the component that they are a part of. Instances can use other instances as their parents too. Gum does not place a limit to the depth of the parent/child hierarchy, enabling flexible and responsive layouts through.

Parent/child relationships are useful for

  • Automatically adjusting margins and backgrounds

  • Word-wrapping text relative to a parent

Parent

The Parent variable allows UI elements to be positioned and sized according to other UI elements. Parenting hierarchies can go many levels deep and the parent/child relationship can be visualized by the white line connecting the parent to the child when the child is selected.

Parents control control the position of their children. Parents can also control the size of their objects depending on the child's Width Units and Height Units.

For example, if a parent is moved, its children move along with it. For more information on positioning children, see the and pages.

Children can also be sized according to their parents. For more information on sizing children according to their parent, see the and pages.

Base Type (Inheritance)

The Base Type variable can be used to specify both inheritance but also the type of an instance.

Base Type on an instance indicates its type. This is usually automatically set when an instance is first created - usually by drag+dropping a component or standard element onto its target component or screen.

Gum Screens and Components support changing Base Type to specify inheritance. By setting Base Type, a screen or component automatically inherits the following:

  • Variable values

Gum-linux-x64.tar.xz
-C
~/gum

Select Add State

  • Enter the name Hidden and click OK

  • Right-click on the HideShow folder

  • Select Add State

  • Select Shown

  • Shown
    state
  • Verify the Font Scale is 1, or set it to 1 if not. This makes the Text regular size

  • Click the
    Add Animation
    button
  • Name the animation Show and click OK

  • Select the Show animation and click Add State

  • Select the Hidden state and click OK - this is the first keyframe in our animation

  • Click Add State again

  • Select Shown and click OK

  • Creating the States

    Setting values in the states

    Creating the Show animation

    Adjusting Interpolation Type

    Click to select the "AllInvisible" state.

  • Select one of the TextComponents

  • Set its HideShow State to Hidden

  • Repeat setting the State to Hidden for the other TextComponents

  • Select the ShowAll animation

  • Click "Add State"

  • Select "ScreenCategory/AllInvisible" and click OK

  • Select the Show animation and click OK

  • Select the newly-created animation and set its Time to 0.5

  • Repeat the above steps to add animations for the other two TextComponents, but set their times to 1.0 and 1.5

  • Defining the initial state

    Creating the Animation

    Adding Sub-Animations

    Select the Sprite and set its Render Target Texture Source value to the container created in step 1. The dropdown lists all containers in the current element that have Is Render Target set to true.
  • Set the Sprite's Rotation (and optionally its Width and Height) to rotate and scale the clipped contents.

  • , because input is handled by the original (invisible) container rather than the rotated
    Sprite
    .

    Step by Step

    Notes

    See Also

    Clips Children
    Rotation
    Is Render Target
    RenderTargetTextureSource
    Sprite rotating while referencing a render target container
    Invisible container still used as a source render target
    Sprite with a Render Target Texture Source

    Earlier preview builds gave Circle and Rectangle a separate Color1 for the gradient start. The start is now the shape's Fill/Stroke color, so Color1 no longer appears for these shapes. Arc likewise derives its gradient start from its Color.

    Gradient X1 and 2, Gradient Y1 and 2

    Gradient X1 and X2 Units, Gradient Y1 and Y2 Units

    Gradient Type

    Gradient Color values
    Gradient positions visualized over a RoundedRectangle
    Changing gradient X and Y values changes the gradient direction and interpolation distance
    By default gradient values are relative to the element's top-left corner
    Gradient X and Y units relative to the bottom right of the instance.
    Linear Gradient Type on the left, Radial Gradient Type on the right

    Parent Details

    Ignoring Default Slot

    Setting the Default Child Container
    Adding a child automatically uses the Default Child Container
    Changing the Parent to the name of the instance can force a child to be attached to the root of the parent

    Percentage Parent Height

    Pixels From Baseline

    https://en.wikipedia.org/wiki/Baseline_(typography)
    ColoredRectangle with Y Units of Pixels From Bottom
    ColoredRectangle with Y Units of Percentage Parent Height
    Baseline Example
    ColoredRectangle with Y Units of Pixels From Baseline
    Baseline Shifts when the parent Width changes
    Arial with Font Size 40 has a base value of 36
    Base defines the distance from the top of the Text instance to the baseline
    Pixels from Baseline uses the bottom of the parent if it is not a Text instance

    Image_Left.png

  • Image_Right.png

  • Image_TopCenter.png

  • Image_TopLeft.png

  • Image_TopRight.png

  • LottieAnimations are still rasterized so zooming in shows pixels
    Deadvivors
    Deadvivors
    Cranky Chibi Cthulhu
    Cranky Chibi Cthulhu
    TerraScriber
    TerraScriber
    Champions of Anteria
    Champions of Anteria
    Tetris Blitz
    Tetris Blitz
    Tula Mobile App
    Tula Mobile App
    Catnip Coast
    War Haven
    War Haven
    BattleCrypt Bombers
    BattleCrypt Bombers
    Teotihuacan
    Ship Skwabble
    Deadvivors
    Deadvivors

    Percentage Parent Width

    X=50 places the origin halfway across the parent's width

    Percentage of Parent

    Fill (as %)

    100 = same size as parent

    Relative to Children

    Hug

    Container grows/shrinks to contain its children

    Ratio of Parent

    Flex grow

    Siblings share available parent space proportionally

    Percentage of Width/Height

    Aspect ratio lock

    Ties one dimension to the other

    Auto Grid Horizontal

    Grid, fills columns first

    Auto Grid Vertical

    Grid, fills rows first

    Top-level Frame (a "screen" or "view")

    Screen

    Frame (layout container)

    Container

    Frame fill/stroke

    Child ColoredRectangle or NineSlice inside the Container

    Fixed size

    Width/Height Units = Absolute

    Fill container

    Width/Height Units = Relative to Parent (value 0)

    Hug contents

    Width/Height Units = Relative to Children

    Flex grow

    Width/Height Units = Ratio of Parent

    Padding

    No direct equivalent — use child offsets or Relative to Parent with a negative value

    Constraints (pin left/right)

    X Units = Pixels From Left or Pixels From Right + X Origin

    Constraints (pin center)

    X Units = Pixels From Center, X Origin = Center

    Constraints (scale)

    X Units = Percentage Parent Width

    Nine-point reference selector

    X Origin + Y Origin

    Auto Layout (vertical)

    Children Layout = Top to Bottom Stack

    Auto Layout (horizontal)

    Children Layout = Left to Right Stack

    Gap between items

    Stack Spacing

    Wrap

    Wraps Children = true

    Clip content

    Clips Children = true

    Component

    Component

    Component slot

    Instance with Is Slot = true inside a component

    Layer order

    Tree position (earlier = behind, later = in front)

    Min/Max width

    Min Width / Max Width properties

    Aspect ratio lock

    Width Units = Percentage of Height (or vice versa)

    X / Y

    The numeric position value

    X Units / Y Units

    Which point on the parent to measure from

    X Origin / Y Origin

    Pixels From Left (default)

    X=0 is the parent's left edge; positive X moves right

    Pixels From Center

    X=0 is the parent's horizontal center

    Pixels From Right

    Absolute

    Fixed

    Fixed pixel size, ignores parent

    Relative to Parent

    Fill (with offset)

    Regular (default)

    No Auto Layout

    Top to Bottom Stack

    Auto Layout, vertical

    Left to Right Stack

    Project Organization

    Elements and Containers (Frames)

    Positioning: X/Y + Units + Origin

    Examples

    Sizing: Width/Height Units

    Anchoring and Docking

    Auto Layout → Children Layout

    Wrapping

    Clip Content → Clips Children

    Components and Slots

    Z-Ordering

    Rotation

    Min/Max Constraints

    Which point on the child is placed at that position

    X=0 is the parent's right edge; positive X moves further right (past the edge)

    0 = same size as parent; -20 = 20px smaller

    Auto Layout, horizontal

    Adding Points in the Editor

    Moving Points

    Removing Points

    Editing in Variables

    Currently editing individual points does not automatically keep the first and last points equal. If editing the first or last point, the matching point must also be manually edted to match.

    Advanced Point Editing

    Polygon with points 32 units from the origin on both X and Y
    Points can be added by clicking in the center of lines
    Polygons can be concave and even have crossing lines.
    Press the delete key to remove points
    PolygonInstance in MainMenu
    X = 0,  X Units = Pixels From Center,  X Origin = Center
    X = -10,  X Units = Pixels From Right,  X Origin = Right
    <VariableList xsi:type="VariableListSaveOfVector2">
      <Type>Vector2</Type>
      <Name>PolygonInstance.Points</Name>
      <IsFile>false</IsFile>
      <IsHiddenInPropertyGrid>false</IsHiddenInPropertyGrid>
      <Value>
        <Vector2>
          <X>0</X>
          <Y>46</Y>
        </Vector2>
        <Vector2>
          <X>32</X>
          <Y>32</Y>
        </Vector2>
        <Vector2>
          <X>10</X>
          <Y>0</Y>
        </Vector2>
        <Vector2>
          <X>0</X>
          <Y>46</Y>
        </Vector2>
      </Value>
    </VariableList>

    Add a second state named Medium

  • Add a third state named Low

  • Prerequisites

    Defining States

    Setting Variables in States

    Be careful when editing objects with multiple states. You may end up making changes without realizing that you are doing so in the wrong state.

    Whenever you have a non-Default state selected, Gum displays a label telling you which state you are editing.

    Any unintentional change can be undone by pressing CTRL+Z

    States and Instances

    What's Next - More Categories

    Add Category right-click option
    Add State right-click option
    HealthBar states
    Edited Icon on State
    States previewed in the Gum tool

    Container - invisible object used to contain other objects. These are used to provide margins, change layouts (such as vertical vs horizontal stacking), and to organize your UI.

  • NineSlice - visual object which uses nine sprites to create a resizable object from a source PNG (or portion of a PNG). The corner sprites (4) are not resized. The top, bottom, left, and right sprites are stretched on one axis. The middle sprite stretches both horizontally and vertically. These are used to create resizable frames.

  • Polygon - polygon outline which can have any number of points. These are usually not used for UI, but can be used if you are defining collision in your Gum objects for a game.

  • Rectangle - a rectangle which can be filled in, outlined, or both. Used for solid-colored backgrounds, frames, blocking out a UI, or for defining collision in your Gum objects for a game.

  • Sprite - a visual object which displays a source PNG (or a portion of a PNG). These are used for icons, backgrounds, and other visual objects which are usually not resized dynamically.

  • Text - a visual object which can display characters. These are used for any situation where text needs to be displayed such as labels and paragraphs.

  • Components are objects which can contain standard elements and instances of other components. Components can be very simple, such as a Label, or very complex, such as an options menu with dozens of instances. Items added to components or screens are called instances.

    Screens are objects which can contain standard elements and instances of other components. Unlike Components, Screens cannot be added to other Screens. Screens exist mainly for organization. Screens can be simple, such as a loading screen, or complex such as a HUD in an RTS game.

    Components and screens are similar - both can contain instances of standard elements, and both can contain other components. The only difference between screens and components is that screens cannot contain other screens.

    For example you can think of screens in a video game which might include a main menu, credits screen, options screen, and level selection screen. You can think of components as elements which are composed of multiple standard elements. Examples include a Button component which is made up of a Sprite instance and a Text instance, or a Logo component which may be made up of multiple Sprites and Text objects.

    Before you work on your project, you must first create a new project. You can save this project anywhere on your computer, but it's best to save the project in an empty folder so that all of the project files don't get mixed in with existing files.

    To create a project:

    1. Select File->New Project

    2. Un-check the Include Forms controls option - this tutorial assumes a completely empty project

    3. Select a new location somewhere on your machine for the new project. If you are using a library like MonoGame or raylib, you may want to save the project in a folder under your game project, such as a Content or Resources folder.

    Once your project has been saved you should see its name in Gum's title bar.

    Gum Project Title

    To create a screen:

    1. Right-click on the Screens tree item and select Add Screen

      Right-click, Add Screen option
    2. Enter the name of the new screen - such as MainMenu

    3. Click OK. The newly-created screen is created and selected

      The MainMenu screen in Gum

    Instances of standard and component elements can be added to screens and components. To add an instance:

    1. Select the destination screen or component. For example, select the MainMenu screen

    2. Drag the Text item onto the Editor tab

    3. Release the mouse button. A new text instance appears in your screen.

      Adding a Text instance to the MainMenu screen in the Editor tab

    Alternatively, you can also drag+drop a standard element into a screen in the tree view.

    Adding a Text instance to the MainMenu screen in the Project tab

    Once an instance is a part of a screen or component it can be edited visually in the preview window. The selected instance has eight (8) handles surrounding it. These are called the resize handles and can be used to change the selected instance's width and height.

    A selected Text instance with resize handles

    In the case of the Text object, the resize handles are used to control how the text object performs line wrapping.

    You can use the resize handles to resize the instance, or you can simply push the mouse button and drag inside the instance to change its position. Notice that an object's outline is displayed when the cursor is hovering over the instance.

    Moving and resizing a Text object.

    This tutorial introduces the basics of working with standard elements and adding them to Screens. The next tutorial covers the Variables tab which can be used to access all element variables.

    Introduction

    Gum Elements

    Standard Types

    Empty Gum Project
    Screens, Components, and Standard folders

    Plugins can add additional standard elements. The list above is the default list of standard elements before plugins have made any changes.

    Components

    Screens

    Components vs. Screens

    Creating a Project

    Creating a Screen

    Adding instances

    If an element is dropped in the Editor window, it appears at the location where it has been dropped - setting its X and Y values. If an element is dropped in the Project tab, then it preserves its default X and Y values.

    Editing in the preview window

    Conclusion

    Setting X and Y to 0 positions the instance at the top-left of the screen

    We can change the origin of the Text object by setting its X Origin and Y Origin values. Notice that if X Origin is set to Center then the Text object is positioned by its center:

    Text with X Origin set to Center

    You may need to pan the view in the Editor tab to be able to see the Text object. Gum provides multiple ways to pan the view:

    • Press and hold the middle mouse button while the cursor is over the preview window. While the middle mouse button is down, move the mouse cursor.

    • Use the scroll bars on the bottom and side of the view

    • Hold down CTRL and press the arrow keys

    Changing the X Origin value changes the origin of the selected instance; however, it is still positioned relative to the top-left corner of the Text instance's container - which in this case is the entire screen designated by the dotted outline rectangle.

    We can change the origin that the Text is relative to by changing the X Units. By default the X Units variable is set to Pixels From Left and Y Units is set to Pixels From Top.

    Default X Units

    Changing the X Units to Pixels From Right causes the Text to be positioned on the right-side of the screen.

    Text moved to the right-side of the screen by changing its X Units

    The X,Y, Origin, and Units values are all available for every type of element in Gum; however, these values only change the bounds. In the case of a Text object we may be interested in how the text is aligned within the bounds. The Text object offers two variables for aligning its text: Horizontal Alignment and Vertical Alignment. Changing the Horizontal Alignment to Center centers the Text within its bounds:

    Centered text in its bounds

    You may have noticed that some variables in the Variables tab have an icon next to the variable label, while others are missing this icon.

    Whenever an instance does not explicitly set a variable value, it uses a default value.

    Gum lets us view and edit tese values.

    To edit default values:

    1. Right-click on the chip for a standard type, such as the Text chip

    2. Select Edit Defaults...

    3. Change the values that you would like to edit

    Notice the default alignment values for Text

    Default values for Text Standard Element

    We can make changes to the default values now that the text is selected. For example, we can change the alignment values to be right and bottom. When we are editing any standard, the default values are displayed in the Editor tab so we can see these changes in real time.

    Now if we select the TextIntance we will see that the Vertical Alignment is using the Bottom value; however the Horizontal Alignment is still using Center - this is because a value that is explicitly set on an instance will always override the default value set in the Standard element. Notice that Horizontal Alignment has an icon (indicating a custom value) and Vertical Alignment has no icon (indicating a default value).

    Default values are green, explicitly set values are white

    Values can be reverted back to their default simply by right-clicking on the variable name in the Variables tab and selecting Make Default

    Right-click Make Default option

    You can undo the changes that you made to Standard Text by editing the defaults again and making the changes back to being top-left, or first editing defaults then pressing CTRL+Z to undo the changes.

    Introduction

    Editing Variables

    Positioning Instances

    Variables tab in Gum
    Changing a Text's X variable

    Text Alignment

    Default and overriding values

    Keep in mind, doing this changes the default values for your entire project. Also, by making changes to the default components, you may make your components less portable. However, understanding the default/override behavior in Gum is useful so we cover it here.

    Components can be made from-scratch or can be imported. Gum provides a full set of components for common controls including Button, TextBox, and ListBoxes, but for this tutorial we will be exploring how to build a component from scratch.

    The first step in creating a component is to add an empty component and name it:

    1. Right-click on the Components folder in Gum and select Add Component

    2. Name the Component "HealthBar" (no spaces)

    Next we'll add two Rectangle instances. One will be used as the background for the health bar, and one will be used as the fill for the health bar.

    1. Drag+drop a Rectangle from the Standard folder into your Health Bar

    2. Repeat this again to create a 2nd rectangle

    If you dragged the instances on the tree view, the two Rectangle instances will overlap. We will adjust their positions later in this tutorial.

    HealthBar Component with two overlapping Rectangle instances

    Next we'll rename the instances so their names match their purpose. Rename the first rectangle Background and the second Fill. You can press F2 or change an instance name in its Name text box in the Variables tab.

    Renamed Rectangle instances

    In this case, since Fill comes after Background, then it will draw on top. This ordering will become important when we make changes to these two instances later in the tutorial.

    If you renamed them in the wrong order, you can also adjust their order in the component by selecting one of the instances, holding down the Alt key, and then pressing the up or down arrows to reorder the selected instance. You can also drag+drop to reorder, but be careful to not create an accidental parent/child relationship between the instances.

    Next we'll adjust the Background Rectangle:

    1. Select Background

    2. Check the Is Filled variable

    3. Set Fill Color to black - click on the colored box to open the color editor, or you can type the hex value 000000

    4. Set Stroke Width to 0 - note that the stroke may not disappear since the Fill rectangle is still overlapping Background

    5. Click on the Alignment tab and click the Fill button in the Dock row. This causes the Background to fill the size of its parent, and to adjust its own size if the parent HealthBar size changes.

    Now the Background should be a solid black background to the entire component

    Background filling the entire component

    Before moving on, you might want to spend some time adjusting values on your background. Although we removed the stroke and changed the background to black, you may want your HealthBar to have a different appearance. Try changing other values to get a feel for the different options provided by Rectangles.

    Also, note that we clicked the Fill Dock button. This button is a shortcut which changes a number of variables on the component. Specifically this changed:

    • X, X Units, X Origin - the background will always be positioned horizontally according to its parent's center

    • Y, Y Units, Y Origin - the background will always be positioned vertically according to its parent's center

    • Width, Width Units - the background will always grow or shrink horizontally to fill its parent

    • Height, Height Units - the background will always grow or shrink vertically to fill its parent

    For more information on docking, see the Dock page.

    Next we'll adjust our Fill Rectangle, starting with its color:

    1. Select Fill

    2. Check the Is Filled variable

    3. Set Fill Color to a green color - the exact value doesn't matter too much so pick a color you like

    4. Set Stroke Width to 0

    Fill displaying a Green color

    Unlike Background, the Fill rectangle needs to adjust in response to display how much health a player has. Specifically, the Fill rectangle needs to always fill its parent vertically, but its width depends on a health value.

    First, we can adjust the height to fill its parent. To do this, set these values:

    • Set Height to 0

    • Set Height Units to Relative to Parent

    Fill matching its parent's height

    Height Units and Width Units can be used to adjust the size of your object relative to its parent or children. In this case the parent is the entire health bar itself. Note that we've set up our Height and Height Units to be relative to parent manually, which is exactly what was done earlier when clicked the Fill Dock button. As mentioned earlier, the Fill Dock button is just a shortcut for setting these types of values.

    Next we'll adjust our fill bar so that the width is a percentage of its parent rather than an absolute value.

    • Set Width to any value between 0 and 100. It should be 50 by default which is a good default

    • Set Width Units to Percent of Parent

    Now if we adjust the Width value, the health bar width adjusts relative to its parent.

    Fill using Percent of Parent Width

    Now that we have set up both Background and Fill to be relative to their parent's size, we can adjust the size of the HealthBar component and all of the instances should also adjust automatically.

    Select the HealthBar component and set the following values:

    • Set Width to 200

    • Set Height to 24

    HealthBar with adjusted Width and Height

    Now that we have a component created, we can add instances of this component the same way we have added standard elements. To do this:

    1. Create a new Screen. I'll call mine GameScreen

    2. Drag+drop the HealthBar component into the Screen

    You can move and resize the newly-created HealthBarInstance in your screen. Notice that Background and Fill adjust in response to size changes on health bar.

    You can also create copies by pressing CTRL+C, CTRL+V. Note that newly-created instances overlap the copied instance, so you need to move pasted instances.

    HealthBar instances in a screen

    Although we can can change the size and position of our health bars, we are missing some very important functionality - the ability to change how much health is displayed. The next tutorial discusses how to expose variables so that each instance can be modified.

    Introduction

    Creating a Component and Instances

    Naming Instances

    Setting Background Variables

    Setting Fill Variables

    Changing HealthBar Width and Height

    Creating Component Instances

    What's Next?

    Stacking objects on top of each other or side by side

  • Placing objects next to other objects which are dynamically sized

  • Creating tables and other complicated layout objects

  • For this example we'll create a Component for displaying distance. This component has two Text instances:

    • ValueText - the Text instance responsible for displaying the value for the distance. For example "100".

    • UnitsDisplay - the Text instance responsible for displaying the units for the distance. For example "km" for kilometers.

    The two Text instances will have different colors so that ValueText stands out.

    To create our component:

    1. Create a new component named MeasurementDisplay

    2. Drop two Text objects in the newly-created component

    3. Name the first ValueText

    4. Name the second UnitsDisplay

    MeasurementDisplay component

    Next we'll make the UnitsDisplay use the ValueText as its parent:

    1. Drag+drop UnitsDisplay onto ValueText to create a parent/child relationship

    2. Change UnitsDisplay's X Units to Pixels From Right. This makes the text object positioned according to its parent's right edge

    3. Change its X to 10 . This means the UnitsDisplay text is 10 units offset from the right edge of its parent ValueText

    4. Verify its Y is 0

    UnitsDisplay positioned relative to the right-side of ValueText

    The ValueText actual width should be based on its contents, so we'll do the following:

    1. Select ValueText

    2. Change Width Units to Relative to Children

    3. Change Width to 0

    By setting these values, ValueText is now sized according to its children, which in this case are its letters.

    You may have noticed that UnitsDisplay is also a child of the ValueText. However, since UnitsDisplay is explicitly positioned outside of the bounds of its parent ValueText, then ValueText ignores this child when calculating its own Width. For a detailed discussion of Width Units and whether children are ignored, see the Width Units page.

    Now that we have adjusted the position, size, and parent values on our Text instances, let's modify the color of the UnitsDisplay:

    1. Select the UnitsDisplay

    2. Change Red to 200

    3. Change Green to 150

    4. Change Blue to 0

    Text with changed color values

    Now that we have set up a parent/child relationship between ValueText and UnitsDisplay, UnitsDisplay automatically adjusts its position in response to changes in ValueText. Any change on ValueText resulting in the right-side of the parent changing automatically adjusts the position of UnitsDisplay.

    For example, if we change the Text property on ValueText, it grows or shrinks in response.

    Changing the Text property results in ValueText changing its effective width

    As mentioned above, changing the Text property causes ValueText to grow or shrink. However, regardless of its size, the Width property is still set to 0.

    Width is 0 despite the size being larger than 0

    The Width variable is used in combination with its Width Units to calculate an effective width. In this case, the effective width is determined by the Text property on ValueText. It's important to note that all Gum objects have effective values for x, y, width, and height, all of which are determined by their respective units values.

    Children always depend on their parents' effective values rather than their explicitly set values. Gum helps us visualize the effective values when we mouse over one of the resize handles on the selected object. For example, the following image shows the Width, Width Units, and effective width values of our ValueText.

    Width is 0, Width Units is Relative To Children, effective width is 65

    Creating a Component

    Although single Text instances support inline styling, e use two text instances here to show how to work with the Parent variable. For information on inline text styling see the page.

    Positioning according to a parent

    Adjusting Colors

    Changing ValueText

    Width and Effective Width

    Children can be placed outside of their parent's bounds. In the simplest case, a child can be dragged outside of its parent's bounds in the editor.
    Children can be placed outside of their parents' bounds

    Children outside of their parent's bounds still follow all of the same rules for sizing and positioning, but there are some important things to keep in mind.

    Children placed outside of a parent do not affect the parent's effective width or height. Any unit value that depends on children or parents only considers the immediate child or parent and does not look at sizes beyond the immediate relationship.

    For example if a parent has 100 effective width, and its child is given an X of 200, the parent's effective width remains 100 (assuming the parent does not size itself according to its children). This is important when other children are sized or positioned according to the parent's width.

    The following animation shows three instances:

    1. A parent container

    2. A blue rectangle which is sized according to the parent rectangle

    3. A yellow rectangle which is moved outside of the bounds of its parent

    Notice that when the parent resizes the blue rectangle is also resized, but when the yellow rectangle is moved outside of the parent bounds, the parent and blue rectangle are not resized.

    Children can exist outside of the parent bounds without resizing the parent

    Children outside of bounds may not respond to click events unless the parent is explicitly checking for click events outside of its bounds. This is a property which is set at runtime. For more information see the RaiseChildrenEventsOutsideOfBounds page.

    To change Parent in the Project tab:

    1. Select a child

    2. Drag+drop the child onto the desired parent

    Drag+drop a child onto the desired parent

    The child can be detached from its Parent by drag+dropping it onto the Component.

    Drag+drop a child onto its root component or screen to detach it from its current parent

    Drag+dropping onto a parent may set the Parent property to an instance inside of the parent's Component type sets its Default Child Container value. For more information see the Default Child Container page.

    To set Parent by name:

    1. Select the desired child

    2. Change the Parent property to the desired parent:

    Change Parent using the dropdown

    Introduction

    Parents and Units

    Children Outside of Parent Bounds

    X Units
    Y Units
    Width Units
    Height Units
    Moving a parent also moves its children
    Children can be resized according to their parent

    Example - Drag+Drop in the Tree View

    Example - Using the Dropdown

    Exposed variables

  • Instances

  • Available variables, such as stacking if inheriting from a container

  • Inheritance is useful if your project needs multiple screens or components which share common variables or instances.

    All instances must have a Base Type set. For example, the following instance is of type Container.

    Instance named ContainerInstance is of type Container

    Base Type is automatically assigned when a new instance is created. For example, the following animation shows a new ColoredRectangle instance created. Note that its Base Type is automatically assigned to ColoredRectangle.

    Creating a new ColoredRectangle instance assigns the base type to ColoredRectangle

    Base Type can be changed after an instance is created. Keep in mind that doing so does not change its name or any other properties, so you may need to manually adjust properties when converting between different Base Types. Also, note that default values may change when switching from one Base Type to another.

    The following shows a ColoredRectangle changed to a Container. Since Container and ColoredRectangle have different default Width and Height values, changing Base Type results in changes to default size too.

    Changing Base Type can change other variables such as Width and Height

    All components use inheritance even if their Base Type variable is not set explicitly. By default components inherit from the Container type.

    Button component inheriting from Container

    By inheriting from the Container type, components have access to all Container variables such as Children Layout.

    Components can inherit from standard types. For example, instead of inheriting from Container a component may inherit from ColoredRectangle. By doing so, it has access to all properties on the ColoredRectangle type.

    Component inheriting from ColoredRectangle

    Components can inherit from other components. By doing so the component inherits all children and exposed variables from its base component.

    A component which inherits from another component is often called a derived component. The component which is being inherited from is often called a base component.

    A base component can be used to define instances which the derived component can modify. For example a component named ButtonBase may define that all components have a ColoredRectangle named Background and a Text named TextInstance.

    Example component named ButtonBase

    If another component uses ButtonBase as its Base Type, then this component automatically gets Background and TextInstance children which match the base instances.

    Setting the base to ButtonBase automatically adds the same children to CancelButton

    The CancelButton can modify variables on the added children. For example the CancelButton can modify the Text on the TextInstance and the color values on the Background.

    CancelButton with modified children variables (Text and color values)

    The derived component has the following restrictions when working with children instances:

    • Name cannot be changed. For example Background must always be named Background.

    • Base Type cannot be changed. For example, the base type for Background must be ColoredRectangle

    • Children defined in the base cannot be removed. For example, the Background child cannot be deleted from CancelButton. Children can be made invisible.

    If the base type adds new instances, then the derived types automatically get the same instances added as well. Similarly, if the base type deletes a child, then the child is also removed from the derived type.

    Children added and removed to base types are also added and removed on the derived types

    Derived types get access to all of the exposed variables in the base type. For example, if ButtonBase exposes the TextInstance's Text property, this is also available on the derived component.

    Exposed variables are inherited

    Base Types allow for the customization of a component, including the creation of many variants. Similarly, States also allow for the customization of a component in similar ways. When deciding between whether to use states or inheritance, keep the following in mind:

    • States are often used to set variables temporarily, while inheritance is permanent. For example, a button may set its background color values in response to being highlighted. By contrast, a Cancel button may always say "Cancel".

    • States do not allow for the creation of new instances. Although derived components cannot delete children which are defined by their Base Type, derived components can add additional instances.

    • Components can use multiple categories. Therefore, it may not be clear which category defines the type of component. A component can only have one Base Type, so its type is defined clearly.

    Introduction

    Instance Base Type

    Component Inheritance

    Inheriting from Standard Types

    Most components inherit from the Container type. If a component needs to display visuals, such as a ColoredRectangle, typically the ColoredRectangle is added as a child to the component rather than being used as a Base Type.

    Inheriting from Components

    Base Type vs States

    Health Bar

    Introduction

    Introduction

    Health bars are common UI elements in games. They are similar to progress bars, so this example could be used to create either. This example explains how to create a health bar component.

    Creating the Component

    First we'll define the component:

    1. Open Gum

    2. Open or create a new Gum project

    3. Right-click on the Components folder

    4. Name the component "HealthBar"

    5. Resize the HealthBar component so it is wider than it is tall. For example, assign Width to 200 and Height to 32.

    Next we'll add a background to our HealthBar Component

    1. Drag+drop a ColoredRectangle into the HealthBar\

    2. Select the newly-created ColoredRectangleInstance

    3. Select the Alignment tab

    Now we have a black background in our HealthBar

    The HealthBar displays its current health with another rectangle. This second rectangle will be contained inside a container to provide a boundary. To add an inner container:

    1. Drag+drop a Container onto the HealthBar

    2. Select the Alignment tab

    3. Enter a Margin value of 4

    4. Click the

    Now we have a ContainerInstance with the proper margin

    Finally we'll add the foreground rectangle which displays the health:

    1. Drag+drop another ColoredRectangle onto the ContainerInstance. Be sure to drop it on ContainerInstance so that the newly-added ColoredRectangle is a child of the container

    2. Click the Alignment tab

    3. Set Margin back to 0

    4. Click the Fill Dock button

    Now, the Width value can change between 0 and 100 to indicate the health percentage.

    Next we'll expose the inner ColoredRectangle's Width property so it can be assigned per HealthBar instance:

    1. Select the inner ColoredRectangle instance

    2. Right-click on its Width variable and select Expose Variable\

    3. Enter an appropriate name such as "Percentage" and click OK

    Now we can add instances of the HealthBar to a screen and control its fill percentage.

    \

    8 - State Categories

    States are a powerful way to create expressive groups of variables. Some UI elements may require a combination of states to be applied simultaneously.

    For example, consider a Button component which displays a button callout.

    This button might be a standard Button with the following states:

    • Enabled

    • Disabled

    Custom NineSlice

    Although Gum includes a standard NineSlice element, the Gum layout system can be used to create a custom NineSlice component. Such a component could be used if additional flexibility beyond what is provided by the standard NineSlice is needed.

    As implied by the name, the NineSlice element is composed of nine Sprites. First we'll create the component:

    1. Open Gum

    2. Open or create a new Gum project

    Text property

    Click the Fill Dock button\

    Fill Dock to make the background take up the entire size of its parent HealthBar component
  • Change the ColoredRectangleInstance color to black\

  • Fill Dock
    button

    Change the following values:

    1. X Units to Pixels from Left

    2. X Origin to Left

    3. Width to Percentage of Container

    4. Width to 100

    Adding a Background

    Creating an Inner Container

    Adding the Foreground Rectangle

    Expose Width

    Add ColoredRectangle to HealthBar
    Set Margin to 4, then click the Fill Dock button
    Click Expose Variable
    Percentage value updated on a ScrollBar instance

    Highlighted

  • Pushed

  • But it may also have states for which button icon to display:

    • A

    • B

    • X

    • Y

    • LeftStick

    • RightStick

    These two sets of states could be set independently and combined at runtime. Categories let you create groups of states so that multiple states can be set simultaneously.

    For this tutorial we'll create a new component. This component has state categories for size and for color. To do this:

    1. Open Gum

    2. Create a new Component called CategoryDemo

    3. Right-click anywhere in the State box and select Add Category

    4. Enter the name "Size" for the new category and click OK

    5. Repeat the above steps to create a "Color" category

    Size and Color categories

    Now we can add states to the categories. To do this:

    1. Right-click on the Size category and select Add State

    2. Enter the name "Small" for the new state

    3. Right-click on the Size category again and select Add State

    4. Add a second state to "Big"

    5. Right-click on the Color category and select Add State

    6. Add a state called "Red"

    7. Right-click on the Color category again and select Add State

    8. Add a state called "Blue"

    Now that we have states set up we need to add a visual element to the component so that we can see our changes.

    To do this, select the Default state and drag+drop a Rectangle into your component. Check its Is Filled variable, and set its Stroke Width to 0.

    To modify a state, you can select it and edit in the Editor tab or change properties in the Variables tab to modify what the state sets. Notice that normally for a component like this the RectangleInstance would have its width and height be relative to its container, but we're not doing this for the sake of keeping the tutorial shorter.

    First we'll set the Size states. To do this:

    1. Select the Big state

    2. Resize the colored rectangle so it is larger than the default

    3. Select the Small state

    4. Resize the colored rectangle so it is smaller than the default

    Next we'll set the Color states. To do this:

    1. Select the Red state

    2. Set Fill Color to a red color

    3. Select the Blue state

    4. Set Fill Color to a blue color

    Your states now should reflect the colors set.

    Red state with the correct color values

    Now that we have our CategoryDemo component set up with multiple categories, we can view these states on any CategoryDemo instance. To do this:

    1. Create a Screen called CategoryDemoScreen

    2. Drop an instance of the CategoryDemo component into the CategoryDemoScreen

    3. Select the newly-created CategoryDemoInstance

    4. Scroll down in the Variables list and notice that the instance has drop-downs for each category.

    5. You can set each state independently and the states combine

    Combining states on an instance

    We can revert the states back to their unset values by right-clicking on the state variable and selecting the Make Default item.

    States can be made default through the right-click make Default item

    If a variable is modified in one of the states in a category, then all of the states in that category are automatically assigned the default value, and this value is explicitly set. This concept makes working with states far more predictable.

    For example, consider a component which has:

    • A single Rectangle

    • A category called RectangleSizeCategory

    • States called Big, Medium, and Small

    Initially, all states in a category do not explicitly assign any variables. We can see this by selecting the category and observing the Variables tab.

    RectangleSizeCategory which does not set any variables

    If a variable is changed in one of the states in the category, then that variable propagates to all other states, and the Category lists this as one of the variables that it modifies.

    For example, we can select the Big category and change the Rectangle.Width property to 150.

    Setting ColoredRectangleInstance Width to 150

    Once this value is changed, the RectangleSizeCategory lists this as a variable that it modifies in the Variables tab.

    RectangleSizeCategory lists any variables that it changes

    If we select any of the other states in the category, they show that they explicitly set the Width value as well (the value has a white background instead of light green). The value is inherited from the default state.

    Width value set by Medium state

    Once a variable is set in a category, all states are required to set this value. A variable cannot be removed from a single state in a category. Rather, to remove a variable, all states in the category must remove the variable. This can be done by selecting the category and pressing the X button next to the variable name.

    Press the X next to a variable on a category to remove the assignment of that variable on all states in the category

    Introduction

    Button with Y button callout. Credit Game UI Database https://www.gameuidatabase.com/gameData.php?id=36&autoload=975

    Creating Categorized States

    Adding Visuals

    Setting Variables in States

    Viewing Multiple States on an Instance

    Categories and Variables

    Right-click on the Components folder
  • Select Add Component

  • Name the Component "CustomNineSlice"

  • Component named CustomNineSlice

    Next, we'll add corner Sprite instances to our CustomNineSlice. We'll be using the alignment tab to position Sprites. The alignment tab provides a quick way to place objects, but the same could be achieved using the following variables individually:

    • Width Units

    • X Origin

    • X Units

    • Height Units

    To create the corner Sprites:

    1. Drag+drop a Sprite element onto the CustomNineSlice component

    Drag+drop a Sprite onto CustomNineSlice
    1. Click the Alignment tab

    2. Anchor the newly-created Sprite to the top-left of its container

      Anchor the Sprite to the top-left of its container
    3. Repeat the steps above three more times, creating one Sprite for each of the four corners, anchoring each one to their respective corner

    Four sprites in CustomNineSlice

    Notice if we resize our CustomNineSlice component, each of the four Sprites remains in its respective corner.

    Resized CustomNineSlice keeping its Sprites in the corner

    Next we'll add the four Sprites which will sit on the edges of our component:

    1. Drag+drop a Sprite element onto the CustomNineSlice component

    2. Click on the Alignment tab

    3. Dock the newly-created Sprite to the top of its container. Docking sets the width of the sprite to match the width of the component. We'll address this in the next step.\

      Click the top dock tab
    4. To accommodate for the corner Sprites, we need to adjust the width of the top Sprite. Set the newly-created Sprite's Width to -128. Since the Sprite uses a Width Units of Relative to Parent, setting the value to -128 makes the Sprite 128 units smaller than its parent. We picked 128 because each of the corner sprites is 64.\

    5. Repeat the above steps, but instead setting the dock to create sprites on the left, right, and bottom. adjust width and height values as necessary.

    Finall we'll add the center Sprite:

    1. Drag+drop a Sprite element onto the CustomNineSlice component

    2. Click on the alignment tab

    3. Dock the newly-created Sprite to the center of its container.

    4. Set both the newly created Sprite's Width and Height to -128

    Now the Sprites stretch and adjust whenever the CustomNineSlice is resized.

    Unlike the regular NineSlice, changing the texture values requires a considerable amount of variable assignment. To change the CustomNineSlice to use 9 separate textures, the following values must be set:

    • Each of the Sprite instances must have its SourceFile value set

    • The edge Sprites will have to have their Width and Height values modified to account for the possible resizing of the corner sprites

    • The center Sprite will have to have both its Width and Height values modified

    If using a sprite sheet, then all of the work above will need to be done plus the texture coordinate values will need to be modified.

    Introduction

    Creating the Component

    Adding Corner Sprites

    Adding Edge Sprites

    Adding the Center Sprite

    Assigning values on CustomNineSlice

    Blend

    Introduction

    The Blend variable controls how the selected instance combines its colors with whatever is drawn before. The final appearance depends on its Blend, Alpha, Source File, and Color values.

    Blend is available on the following types:

    • ColoredRectangle

    • (if is set to true)

    Blend is also available on all Skia elements:

    Most examples on this page overlay a Sprite over ColoredRectangles, but the same Blend behavior applies to all items which support the Blend variable.

    Normal Blend is the default value. When an instance uses Normal Blend, it interpolates its color with whatever it draws on top of using its Alpha value as a weight.

    If a Normal Blend Sprite has an Alpha of 255, then the Sprite completely replaces whatever is below.

    If a Sprite has an Alpha of 128 (roughly half of 255), then it averages its color with whatever is below.

    A Sprite with an Alpha of 25 (roughly 10%) blends with whatever is below, but its color is given a weight of roughly 10%.

    Additive Blend results in the color of a element being added to whatever is below. This typically results in brighter colors. Additive Blend can be used to simulate a light.

    Since Additive Blend results in a modification of what is under instead of a replacement, an Additive Blend Sprite typically appear transparent even when Alpha is 255.

    As Alpha is reduced, the brightening effect is reduced. A Sprite with an Alpha of 128 only applies roughly half as much of a brightening effect.

    A Sprite with an Alpha of 25 applies a slight brightening effect.

    Stacking multiple Sprites with Additive Blend results in the brightening effect stacking as well.

    Replace Blend results in the instance completely replacing whatever it is drawn on top of regardless of its Alpha or transparency in the source file.

    A Sprite with no transparency in its source file drawn with Alpha of 255 looks the same whether it uses Replace or Normal Blend.

    Changing the Alpha on a Sprite with Replace Blend does not affect how it is drawn - it is always drawn at full opacity.

    Replace Blend results in a Sprite being fully opaque even if its source file has transparency. The following image shows two Sprites displaying the same image.

    Gum supports Blend modes which modify the alpha (opacity) of whatever is under the instance using the alpha-only Blend . Alpha-only Blend modes ignore the color of the instance using the Blend - only the alpha matters (see note below about premultiplied alpha). Therefore, the following three circles would behave the same despite having different colors:

    Since alpha-only blends operate directly on the alpha of whatever is below, they are only intended to be used on Containers with Is Render Target set to true. Usually objects with these blend modes are drawn on top of all other items in the container. For example, the following image shows a RenderTargetContainer which holds a number of items including the AlphaOnlyCircle. AlphaOnlyCircle is an instance which can be used to apply Alpha-only Blends to whatever is below.

    Using an alpha-only Blend outside of a container with Is Render Target set to true typically results in the instance either being drawn as pure black or being invisible.

    Subtract Alpha Blend subtracts, or "cuts out", the alpha of whatever is below.

    As Alpha is reduced, the amount of opacity removed effect is also reduced. A Sprite with an Alpha of 128 only removes roughly half as much opacity from what is below.

    Replace Alpha forcefully sets the opacity of whatever is below. Rather than subtracting alpha, replace can forcefully set the alpha.

    Replace Alpha with an Alpha value of 255 results in no changes if what is under is already opaque, but it can add alpha if what is under is transparent.

    If Alpha is reduced, then the resulting pixels display the explicitly set alpha. The following shows setting alpha explicitly to 128 (about 50%).

    Setting Alpha to 0 forcefully sets whatever is under to fully transparent. This is similar to performing Subtract Alpha with an Alpha of 255.

    Keep in mind that Replace Alpha can apply different alpha values if the instance itself has variable alpha, such as a Sprite with some parts transparent and some parts opaque.

    Min Alpha modifies the underlying object so that the result is the minimum alpha between the instance and what is below. This can be used to create an alpha mask.

    If the instance alpha is reduced, then the resulting transparency is reduced as well. The following shows setting Alpha to 128 (about 50%).

    Keep in mind that multiple objects can be combined to create larger masks. For example, additional ColoredRectangles can be added to the circle above to create a larger mask. Each rectangle also has its Blend set to Min Alpha.

    Behaviors

    By default, a new Gum project has no behaviors. The most common way behaviors enter a project is automatically: adding Forms controls (Button, TextBox, Slider, and so on) adds their matching behaviors for you - see below.

    Creating or editing behaviors yourself is an advanced, rarely-needed scenario. The vast majority of projects only ever use the behaviors that Forms controls bring in automatically.

    A behavior defines requirements that are reusable across multiple components: required categories and states, required instances, and optionally Behavior Properties - design-time properties that surface in a Behavior category in the Variables tab and connect to properties on the runtime Forms control (such as TextBox's TextWrapping or Slider's Minimum/Maximum). Behavior Properties are covered in below. If a component uses a behavior, then the component is forced to include categories and instances according to the behavior definition.

    Dock

    The Dock section of the Alignment tab is used to easily adjust the variables on an instance for common layouts. All Dock options adjust the dimensions of the current instance, and most also adjust the position.

    Keep in mind that docking an instance does not toggle a dock state, but rather modifies variables on the instance so that it has docking behavior. This distinction has the following consequences:

    • Docking behavior can be achieved by manually modifying variables - this tab does not add any additional behavior which is not already available through the Variables tab.

    • Docking cannot be undone by toggling the dock button, and pressing multiple dock buttons results in multiple dock variables being assigned which may result in undesirable behavior. To undo docking, use the CTRL+Z shortcut for undo.

    Creating New Behaviors (Advanced)

    This document walks through creating a behavior from scratch, using a ButtonBehavior-style definition as a familiar illustration. You would not actually recreate ButtonBehavior in a real project — it already exists - but the same steps apply to any custom behavior you define for your own components.

    To add a behavior:

    1. Right-click on the Behaviors folder

    2. Select Add Behavior:

    Svg

    Normal Blend

    The examples above use the Alpha value to apply transparency. Note that if the source file (.png) has transparency as part of the file, the same effect applies.

    Additive Blend

    Replace Blend

    Alpha-Only Blends

    Runtimes which use premultiplied alpha (such as FlatRedBall) require using objects that are fully white when modifying alpha. Otherwise, the color of the overlaying instance will blend with the underlying object.

    Subtract Alpha Blend

    Replace Alpha Blend

    Min Alpha

    Container
    Is Render Target
    NineSlice
    Sprite
    Arc
    ColoredCircle
    LottieAnimation
    RoundedRectangle
    Normal Blend Sprite with an Alpha of 255
    Normal Blend Sprite with an Alpha of 128
    Normal Blend Sprite with an Alpha of 25
    Additive Blend Sprite with an Alpha of 255
    Additive Blend Sprite with an Alpha of 128
    Additive Blend Sprite with an Alpha of 25
    Four Additive Blend Sprites with an Alpha of 255
    Replace Blend Sprite with an Alpha of 255
    Replace Blend Sprite with an Alpha of 128
    Normal and Replace Blend on the same source file.
    Color values are ignored with Alpha-only Blends
    AlphaOnlyCircle can be used to modify the alpha of what is below
    Subtract Alpha removing the alpha of what is below
    Reducing Alpha results in less opacity being removed
    Replace Alpha with Alpha of 255 results in no changes on already-opaque regions, but can add alpha
    Explicitly setting alpha to 128 with Replace Alpha
    Replace Alpha with Alpha of 0
    Alpha being replaced to opaque in the center and transparent on the edges of the circle
    Min alpha creates a mask
    Min alpha with an alpha of 128
    Extending masks with additional shapes
    Y Origin
    Y Units
    Top Sprite in CustomNineSlice

    Common behavior usage falls into one of two categories:

    1. Behaviors for built-in controls such as Button and TextBox exist to make customization for these types of controls easier.

    2. New behaviors can be created to match the syntax of controls defined in your game project. This is considered an advanced scenario and is rarely used.

    If your project has added forms components, then it should contain a set of default behaviors matching the forms control types.

    Default behavior types

    These behaviors are used by the Gum runtime to decide whether a component should have the behavior of a particular control type.

    For example, a component with a NineSlice background will not respond to cursor hover events by default. However, if the ButtonBehavior is added to this component, then the component is required to contain certain states which are used at runtime to react to hover, push, and disable states.

    In other words, behaviors answer the question "How can I give default forms behavior to my component" by providing a required set of states, instances.

    As mentioned above, if you have added forms controls to your project, then you should have a set of components which already implement the default behaviors defined below.

    For example, we can look at the ButtonStandard component which implements ButtonBehavior.

    ButtonBehavior used by ButtonStandard

    By using the ButtonBehavior, the ButtonStandard will automatically be associated with the Button type at runtime.

    Furthermore, the ButtonStandard component is required to include the category and states defined by ButtonBehavior.

    Notice the categories and states defined by ButtonBehavior:

    Behaviors defined by ButtonBehavior

    These automatically-added states are empty - they do nothing by default. For information on working with states, see the States page.

    Gum prevents the removal or renaming of any of these states from ButtonStandard since they are required by ButtonBehavior.

    Removal is prevented if a state is defined by a used behavior

    If you are creating a new component which should be used as a standard forms type, such as creating a new Button style, then you will need to add a behavior to the component. By adding a new behavior, Gum will add required states automatically and will display errors if any behavior requirements are missing.

    For example, consider the creation of a new component which will have button behavior (responding visually to hover and push, enabled/disabled support, and click events).

    To add the ButtonBehavior to a component:

    1. Select your component

    2. Click the Behaviors tab

    3. Click the Edit button

    4. Check the desired behavior ( ButtonBehavior )

    5. Click OK to apply the selected behavior

    Gum automatically creates the ButtonCategory and required states. Keep in mind that these states are empty - it is up to you to select the states and customize your component appropriately.

    A component using ButtonBehavior

    Some behaviors have instance requirements too. For example, the TextBoxBehavior has two required instances:

    1. TextInstance which uses a base type of Text

    2. CaretInstance which can be of any type

    TextBoxBehavior has required instances

    If this behavior is used in a component, Gum displays errors indicating that instances are missing.

    You need to add instances to your component to satisfy these errors or else the component may not function properly at runtime, and may even cause runtime crashes.

    Beyond categories, states, and instances, a behavior can declare Behavior Properties — design-time properties that appear in a Behavior category in the Variables tab and flow through to the matching property on the runtime Forms control. For example, TextBoxBehavior declares properties matching TextBox's TextWrapping, AcceptsReturn, IsReadOnly, and MaxLength; SliderBehavior declares properties matching Slider's Minimum and Maximum. Setting one of these in the Variables tab sets the corresponding property on the control when your game runs.

    Some Behavior Properties also drive a visual state automatically, so you get a design-time preview even though Forms controls don't run inside the tool. For example, setting TextWrapping in the Behavior category updates the component's visual line-mode state immediately. See Behavior-Driven References for how this works.

    You can add your own Behavior Properties and behavior-driven references to a custom behavior you create, but this is an advanced, rarely-needed scenario. See Behavior Properties on Custom Behaviors for a brief overview.

    Introduction

    Default Behaviors
    Behavior Properties

    C# programmers may find the concept of behaviors to be similar to interfaces in code. Behaviors define requirements for components, but they give components the flexibility to implement these requirements, just like interfaces define required properties and methods which classes can implement.

    Default Behaviors

    Future versions of Gum may add or remove behavior types, so don't worry if your list is different than the screenshot above.

    Default Control Behaviors

    Adding Behaviors to Components

    Behavior Instance Requirements

    Notice that Gum is able to automatically create categories and states when a new behavior is added, but it does not automatically create required instances. This happens because Gum can add empty states which you can choose to fill in or leave as default.

    By contrast, Gum cannot guess how to create instances for your components. For example, the CaretInstance required by a TextBox can be of any type - you may want to use a Sprite to display a texture, a Rectangle, or even a dedicated custom Caret component.

    Future versions of Gum may provide shortcuts to create required types.

    Behavior Properties

    Standard Forms components (Button, TextBox, Slider, and so on) are copied into your project the first time you add a Forms control, rather than referenced live from the Gum tool install. If a later Gum version adds a new Behavior Property to a standard control, that property only reaches components added to your project after upgrading — components already in your project keep whatever properties they had when they were added.

    Custom Behaviors

    This section lists all of the dock types, provides a visual examples, and lists which variables are modified.
    Variable
    Value

    X

    0

    X Units

    Pixels From Center

    Y

    X

    0

    X Units

    Pixels From Left

    Y

    0

    Y Units

    X

    0

    X Units

    Pixels From Center

    Y

    0

    Y Units

    Y

    0

    Y Units

    Pixels From Center

    Y Origin

    Center

    Height

    X

    0

    X Units

    Pixels From Right

    Y

    0

    Y Units

    X

    0

    X Units

    Pixels From Center

    X Origin

    Center

    Width

    X

    0

    X Units

    Pixels From Center

    Y

    0

    Y Units

    Width

    0

    Width Units

    Relative to Children

    Height

    0

    Height Units

    Introduction

    Dock types

    Dock buttons in the Alignment tab

    Top

    Left

    Fill

    Fill Vertically

    Right

    Fill Horizontally

    Bottom

    Size to Children

    Add Behavior menu item
  • Enter the new behavior name. Often time the word Behavior is added at the end of the name, such as ButtonBehavior

  • New behaviors appear in the Project tab.

    ButtonBehavior in the Behaviors folder

    Once a behavior is created, it can be given categories, states, and instances. Components which use this behavior are required to have matching categories and states.

    The process of adding and removing states to behaviors is the same as adding and removing states in other elements. For more information, see the States page.

    For example, the ButtonBehavior may have the following:

    • ButtonCategory (Category)

      • Enabled (State)

      • Disabled (State)

      • Focused (State)

      • Pushed (State)

    ButtonCategory defined on ButtonBehavior

    A behavior can have as many categories and states as needed.

    Once a behavior is added, it can be used in a component. To add a behavior to a component, drag+drop the behavior onto the component in the tree view.

    Add a behavior to a component by drag+dropping the behavior on the component in the Project tab

    Behaviors can also be added and removed on the component's Behaviors tab:

    1. Select a component which should use the behavior

    2. Click the Behaviors tab

    3. Click the Edit button

    4. Check the desired behaviors - a component may use multiple behaviors

    5. Click OK

    Button component adding the ButtonBehavior

    Notice that once a behavior is added to a component, the component automatically creates the matching categories and states.

    If the behavior is selected in the Behaviors tab, the required states and categories are highlighted in the States tab.

    States and Categories required by the selected behavior are highlighted

    These categories cannot be removed as long as the component uses the behavior.

    As mentioned above, if a component uses a behavior, then the component is required to include all of the states and categories defined by the behavior. If a behavior is added to a component, then all states and categories in the behavior are automatically added to the component. Keep in mind that newly-added states do not automatically assign any values. The behavior only requires that the states exist but it does not decide which variables are assigned by the states. These required states can even be left to their default so they have no affect on the component.

    Required states and categories cannot be removed or renamed. Required states cannot be moved to different categories.

    Renaming and deleting states and categories required by behaviors is not allowed

    If a new category or state is added to a behavior, all components which use the behavior also have the new category or state added.

    Adding states and categories in a component adds the states and categories to all components using the behavior

    If a state or category is removed from a behavior, Gum does not remove the state or category from components which implement the behavior. Behaviors only define what is required, but they do not prevent components from defining additional states and categories. Also, the states on components may still be needed even if the behavior is removed. Therefore, if you remove any states or categories from a behavior, you may need to manually remove the same states and categories from components which use the behavior if these are no longer needed.

    Behaviors can include instances, resulting in required instances existing in components which use the behavior. Instances in behaviors only include two properties:

    • Name

    • Base Type

    Instances in behaviors only require that instances in components have these two matching properties. All other properties can be set to any value.

    To add an instance to a behavior, drag+drop a standard element or component onto the behavior in the Project tab.

    Drag+drop standard elements or components onto behaviors to create instances in the behavior

    An instance can have its Name changed, Base Type changed, or removed.

    The Variables tab lets you change Name and Base Type. Right-click to delete an instance.

    If a component is missing a behavior then the Error window provides information about the missing requirement.

    Button component is missing a SpriteInstance which is required by the ButtonBehavior

    The standard Forms behaviors ship with Behavior Properties (see Behavior Properties) that surface a Behavior category in the Variables tab and drive design-time preview. A custom behavior can declare these too, but there is currently no tool UI for it - they are added by hand-editing the behavior's .behx file. This is an advanced, rarely-needed scenario; the standard Forms behaviors already cover the common cases.

    Introduction

    Standard Forms behaviors (ButtonBehavior, TextBoxBehavior, and so on) already ship with every project that uses Forms controls - see Behaviors. Creating or editing a behavior yourself is a rare, advanced scenario, needed only when you're standardizing categories/states/instances for your own components that are not part of Gum Forms.

    Creating a Behavior

    Category and State Requirements

    Instance Requirements

    At this time Gum does not automatically add required instances to components which need them. This may change in future versions of Gum. For now, instances must be manually added to resolve errors.

    Behavior Properties on Custom Behaviors

    Anchor

    Introduction

    The Anchor section of the Alignment tab is used to adjust the variables on an instance for common layouts. All Anchor options adjust position-related variables, but do not adjust dimensions.

    Anchor Buttons

    Using the Anchor buttons does not toggle an anchor state, but rather modifies variables on the selected instances so that it is anchored to the correct side or center. This distinction has the following consequences:

    • Anchoring behavior can be achieved by manually modifying variables - this tab does not add any additional behavior which is not already available through the Variables tab.

    • Anchoring cannot be undone by toggling the anchor button. Pressing the anchor button multiple times results in the same variables being assigned multiple times. To undo anchoring, use the CTRL+Z shortcut for undo.

    Anchor Types

    Top Left

    Variable
    Value
    Variable
    Value
    Variable
    Value
    Variable
    Value
    Variable
    Value
    Variable
    Value
    Variable
    Value
    Variable
    Value
    Variable
    Value
    Variable
    Value
    Variable
    Value

    Children Layout

    Children Layout determines how a container positions its children. The default value is Regular which means that children are positioned according to their and .

    Top to Bottom Stack results in the children stacking one on top of another, from top to bottom.

    Left to Right Stack results in the children stacking one beside another, from left to right.

    Auto Grid Horizontal results in the children being placed in a grid, filling in horizontally first before wrapping to the next row.

    0

    Y Units

    Pixels From Top

    X Origin

    Center

    Y Origin

    Top

    Width

    0

    Width Units

    Relative to Parent

    Pixels From Center

    X Origin

    Left

    Y Origin

    Center

    Height

    0

    Height Units

    Relative to Parent

    Pixels From Center

    X Origin

    Center

    Y Origin

    Center

    Width

    0

    Width Units

    Relative to Parent

    Height

    0

    Height Units

    Relative to Parent

    0

    Height Units

    Relative to Parent

    Pixels From Center

    X Origin

    Right

    Y Origin

    Center

    Height

    0

    Height Units

    Relative to Parent

    0

    Width Units

    Relative to Parent

    Pixels From Bottom

    X Origin

    Center

    Y Origin

    Bottom

    Width

    0

    Width Units

    Relative to Parent

    Relative to Children

    X

    0

    X Units

    Pixels From Left

    Y

    0

    X

    0

    X Units

    Pixels From Center

    Y

    X

    0

    X Units

    Pixels From Right

    Y

    X

    0

    X Units

    Pixels From Right

    Y

    X

    0

    X Units

    Pixels From Center

    Y

    X

    0

    X Units

    Pixels From Center

    Y

    X

    0

    X Units

    Pixels From Left

    Y

    X

    0

    X Units

    Pixels From Center

    Y

    X

    0

    X Units

    Pixels From Right

    Y

    X

    0

    X Units

    Pixels From Center

    X Origin

    Y

    0

    Y Units

    Pixels From Center

    Y Origin

    Top

    Top Right

    Left

    Center

    Right

    Bottom Left

    Bottom

    Bottom Right

    Center Horizontally

    Center Vertically

    Top Left Anchor
    Top Anchor
    Top Right Anchor
    Left Anchor
    Center Anchor
    Right Anchor
    Bottom Left Anchor
    Bottom Anchor
    Bottom Right Anchor
    Center Horizontally Anchor
    Center Vertically Anchor
    Auto Grid Vertical results in the children being placed in a grid, filling in vertically first before wrapping to a new column.

    The following animation shows how to use the ChildrenLayout variable to change the default position of a Container's children:

    Regular layout positions each child independent of every other child. The position of one child does not affect the position other children. This is the default layout for containers.

    Top to Bottom Stack results in each child being positioned after its previous sibling vertically. This can be used to create horizontal stacks.

    Top to Bottom Stack behaves similarly to Left to Right Stack. For a detailed discussion see the Left to Right Stack section below.

    Left to Right Stack results in each child being positioned after its previous sibling horizontally. This can be used to create vertical stacks.

    A container can stack its children and also have its size based on its children. This results in the container growing as children are added.

    For example, the following shows a container with its Height Units set to Relative To Children and its Children Layout set to Top To Bottom Stack. As more children are added the container grows vertically.

    Invisible children are ignored in the stack, so toggling the Visible property removes a child from the stack.

    When children stack, each child's X or Y depends on the boundary of its previous sibling. When stacking vertically, the child's Y value begins at the bottom side of the previous item. Similarly, when stacking horizontally, the child's X value begins at the right side of the previous item.

    For example, the following image shows a Text object with a Y value of 20. Notice that it is positioned 20 units below the item above it.

    This effect is easy to notice when dragging an object inside a stack, as shown in the following animation:

    If instances are stacked in a container, the stacking controls the instance values based on the direction of the stack.

    • Top to Bottom Stack containers control the Y value of their children.

    • Left to Right Stack containers control the X value of their children.

    The position value which is not controlled by the stack can be changed freely without any impact on the stacking.

    For example, if a container stacks its children using a Top to Bottom Stack, the children in the stack are free to change their X values. The following animation shows how children can be left, center, or right anchored (which changes their X Units and X Origin) without affecting the other children in the stack.

    Top to Bottom Stack and Left to Right Stack separate their children using the Stack Spacing value. For more information, see the page.

    The position of a child in a stack is determined by the size of the previous item in the stack and the origin of the child. In most cases children which are stacked should use a Left if the parent uses a Left To Right Stack and should use a Top if the parent uses a Top To Bottom Stack.

    Consider a container with a blue rectangle which stacks horizontally. The blue occupies some space according to its absolute width. The next instance after the blue rectangle is placed relative to the right-side of the blue rectangle.

    For example, if a red rectangle (partially transparent to make it easier to see when overlapping) is added to the container, the stack may create a layout similar to the following image:

    Keep in mind that the stack simply states the position of the next item. Each item can freely adjust its X Origin (or Y Origin in a Top to Bottom Stack). If the red rectangle's is changed to Center, the red rectangle overlaps the blue rectangle.

    If the red rectangle's is changed to Right, then its right side aligns with the right side of the blue rectangle, resulting in the red overlapping the blue completely. In this case the red rectangle's stacking is essentially cancelled out by the .

    This overlapping may not be desirable, so keep this in mind when changing a stacked child's origin.

    The property controls how stacking behaves beyond boundaries. For more information, see the page.

    Children of a container which uses the Top To Bottom Stack or Left To Right Stack are ordered according to their order in the tree view on the left. By default this is the order in which the children are added to a parent container.

    Children can be reordered using the right-click menu on an instance.

    Alternatively, children order can be changed by clicking on the item in the tree view, holding down the ALT key, then pressing the up or down arrows.

    For more information on ordering, see the page.

    Auto Grid Horizontal and Auto Grid Vertical layouts result in each child of the container being placed in its own cell. All position and size values are relative to the entire cell, so children can expand to fill their cell or be positioned according to any side or corner.

    The following image shows a container with 4x4 auto grid. Each child is positioned relative to the top-left corner of each grid. In this case, each child has an Absolute Width and Height of 50 and the parent container is sized 256x256. This results in each rectangle leaving a gap between itself and its neighbor.

    The following shows a container with an Auto Grid Horizontal and Vertical Cells of 2, resulting in a 2x2 grid. As children are added to the container through copy/paste, each child is placed in its own cell.

    The number of cells is controlled by the Auto Grid Horizontal Cells and Auto Grid Vertical Cells. Increasing the number of cells results in the rows or columns adjusting automatically.

    Each child occupies one cell, and the order of the children controls the order of the placement in grids. The first child occupies the top-left row. If using Auto Grid Horizontal, each child is placed to the right of its preceding sibling, wrapping to the next line when reaching the end of a row. If using Auto Grid Vertical, each child is placed below its preceding sibling, wrapping to the next column when reaching the end of a column.

    Children can be reordered by using the alt+arrow key in the tree view, resulting in reordering just like when using a stacking Children Layout.

    Children treat their particular cell in the grid as their parent, so any sizes or positions will be based on their parent cell. In other words, if a child's Width Units is set to Relative To Parent, the parent in this case is the cell, not the entire Container instance.

    The number of cells in a grid is determined by multiplying Auto Grid Cells Horizontal by Auto Grid Cells Vertical. If a container has more children than its total cells and if the container's size does not depend on its children, additional children spill over the bounds of the grid. The following animation shows a 3x3 grid using Auto Grid Horizontal. As more children are added, additional rows are added below the bounds of the grid.

    If the container has its Width Units or Height Units set to Relative To Children, then its size may adjust in response to adding more children. For more information, see the and pages.

    When using Auto Grid Horizontal, the number of columns is fixed, but additional rows can be added beyond the bounds of the container.

    When using Auto Grid Vertical, the number of rows is fixed, but additional columns can be added beyond the bounds of the container.

    Stack Spacing can be used to separate cells in a grid. This is most commonly used when the grid's children use Width Units or Height Units of Relative to Parent.

    The following shows a grid with children which fill their cells. Changing the Stack Spacing adds gaps between each child.

    If a container's Children Layout is set to Auto Grid Horizontal or Auto Grid Vertical, it can size itself according to the largest cell by using Width Units or Height Units of Relative To Children. For more information see the and pages.

    Introduction

    X Units
    Y Units
    Children Layout with Regular selected

    Y Units

    Pixels From Top

    X Origin

    Left

    Y Origin

    Top

    0

    Y Units

    Pixels From Top

    X Origin

    Center

    Y Origin

    Top

    0

    Y Units

    Pixels From Top

    X Origin

    Right

    Y Origin

    Top

    0

    Y Units

    Pixels From Center

    X Origin

    Right

    Y Origin

    Center

    0

    Y Units

    Pixels From Center

    X Origin

    Center

    Y Origin

    Center

    0

    Y Units

    Pixels From Center

    X Origin

    Center

    Y Origin

    Center

    0

    Y Units

    Pixels From Bottom

    X Origin

    Left

    Y Origin

    Bottom

    0

    Y Units

    Pixels From Bottom

    X Origin

    Center

    Y Origin

    Bottom

    0

    Y Units

    Pixels From Bottom

    X Origin

    Right

    Y Origin

    Bottom

    Center

    Center

    Example

    Regular

    Top to Bottom Stack

    Left to Right Stack

    Stacking and Container Height Units and Width Units

    Stacking and X/Y Values

    Stacking and Units

    Stack Spacing

    Stacking and Children Origin

    Wraps Children

    Reordering Children

    Auto Grid Horizontal and Auto Grid Vertical

    Stack Spacing

    Stack Spacing was added to Auto Grid in the January 2026 version of the Gum tool.

    Auto Grid and Width/Height Units

    Stack Spacing
    X Origin
    Y Origin
    X Origin
    X Origin
    X Origin
    Wraps Children
    Wraps Children
    Order
    Width Units
    Height Units
    Width Units
    Height Units
    Changing Children Layout updates the position of all contained children
    Two ColoredRectangles using Regular layout
    Text Instances in a top to bottom stack
    Sprites in a Left to Right Stack
    Top To Bottom Stack can be used with Height Units of Relative To Children to grow the container as children are added
    Visible set to false removes an item from stacking
    A Text's Y value can be used to separate it from its previous sibling in a Top to Bottom Stack
    As a Y value changes, all following siblings move too
    Changing horizontal layout values does not affect siblings in a Top to Bottom Stack
    The next item's position is based on the right-side of the blue rectangle
    Red rectangle is positioned relative to the right-side of the blue rectangle.
    Stack determines a child's position, the child can change its origin
    Red rectangle overlapping blue rectangle
    Item order in the Project tab determines the order of items in a stacked container
    Changing order with ALT+Arrow hotkey
    Blue ColoredRectangles in a Container using Children Layout of Auto Grid Horizontal
    Container using Auto Grid Horizontal creating a 2x2 grid
    Increasing Auto Grid Horizontal Cells adds additional columns
    Auto Grid Vertical and Horizontal change the ordering of children
    Alt+arrow changes the order of the selected item in the tree view, updating the positions in the grid
    Changing Anchor and Dock values results in children being placed relative to their particular cell
    Additional children can create rows or columns outside of the bounds of the grid.
    Stack Spacing in an Auto Grid

    Height Units

    Introduction

    Height Units controls how a unit is vertically sized, which may be relative to its parent. By default most types uses Absolute height, where each unit represents 1 pixel of height in pixels. When using Absolute, an object ignores its parent's Height.

    Absolute

    The following shows a child ColoredRectangle with 50 Absolute Height:

    Rectangle with an Absolute height of 50

    Text instances which use an Absolute height of 0 size themselves to be the height of their contained text. This behavior will likely change in future versions of Gum so this combination is not recommended. Instead, to size a Text instance according to its contained text, Set Height Units to Relative to Children.

    Relative to Parent

    The following shows a child ColoredRectangle with -10 Relative to Parent Height, which means is sized 10 pixels less tall than its parent.

    Rectangle using a Relative to Parent height value of -10

    All relationships between parent and children depend only on the direct parent or child. Grandchildren and grandparents are not considered when performing calculations. For more information, see the page.

    Percentage of Parent

    The following shows a child ColoredRectangle with 100 Percentage of Parent, which means it has 100% of the height of its parent. Note that 100 Percentage is the same as 0 Relative to Parent:

    Ratio of Parent can be used to fill available space or to share available space with other objects using a ratio.

    The simplest case is a single child in a container with its Height Units set to Ratio of Parent.

    In this case the blue has no siblings (its parent has no other children), so it occupies the entire parent height. If a second child is added (by copy/pasting the existing child), then each child is given 1 ratio value, which means each is 1/2 of the size of the entire parent.

    To better visualize the effect of ratio, it's common to set the parent's to Top to Bottom Stack, and to give each child a different color as shown in the following image.

    As more children are added, each child's height is adjusted to make room for the new children.

    Ratio values are distributed among all siblings using Ratio of Parent proportionally. The image above shows four siblings, each given 1/4 of the ratio. If one of the the ratios changes (such as by increasing the second sibling's Height value to 3), then all siblings adjust in response to this change.

    In this case, the total ratio is 6 (1 + 3 + 1 + 1), so the red is given 3/6 (1/2) of the parent's height, while each of the others is given 1/6 of the parent's height.

    Values of 0 are supported, resulting in the object drawing with an absolute height of 0.

    Ratio of Parent is calculated after accounting for the height of children which are using absolute height. For example, if the height of the first child is 80 with a Height Units of Absolute, then the other three shrink to give the first the necessary room.

    This effect can also be seen by adjusting the height using the handles.

    Gum ignores invisible objects when calculating available space for Ratio of Parent units. Therefore, if a sibling is invisible, Gum treats it as if it has 0 height which allows all other ratio siblings to expand.

    Ratio of Parent also respects . A Stack Spacing value greater than 0 removes the available space for all children with a Height Units of Relative to Parent.

    The following image shows a child with 50 Relative to Children Height, which means that it is 50 pixels taller than is necessary to contain its children. Since the rectangle has no children, this is the same as having 50 Absolute Height:

    Relative to Children can be used to size an object based on the position and sizes of a parent's children. The following image shows a container with 0 Relative to Children Height, which means that its height is set just large enough to contain its children. Notice that if the children are moved, the parent's height adjusts. Both children are considered so the container adjusts its height according to the bottom-most side of either child:

    A non-zero Height when using Relative to Children can be used to add additional padding to a parent container. The following animation shows how changing the height can adjust the absolute height relative to children:

    A parent container can ignore its children when it determines its own height when using a Height Units of Relative to Children if any of the following are true:

    1. The child's Ignored By Parent Size is true.

    2. The child's height depends on its parent's height. This circular dependency is resolved by the parent ignoring this child.

    3. The child is explicitly positioned outside of parent's bounds

    4. The child's Y Units

    If a child has its Ignored By Parent Size set to true, then the parent ignores this child when calculating its own size. For more information, see the page.

    If a child's height depends on the parent, then the child is ignored by the parent. Once the parent has determined its own height, then the child is sized according to the parent. This type of circular dependency is common when adding background visuals to a container.

    For example consider a container with two children - BlueRectangle and YellowRectangle - with the following variables:

    • BlueRectangle Y = Pixels from Top

    • BlueRectangle Height Units = Absolute

    • YellowRectangle Height Units

    Only YellowRectangle depends on its parent.

    Since BlueRectangle's absolute height value does not depend on the parent, the parent can use BlueRectangle's absolute height when calculating its own absolute height. Since YellowRectangle depends on the parent, the parent ignores the YellowRectangle. Instead, YellowRectangle depends on the parent container's absolute height for calculating its own absolute height. This in effect creates a situation where BlueRectangle affects the height of both its parent and also its YellowRectangle sibling.

    A parent does not consider a child if the child is explicitly positioned outside of the parent's bounds. This can happen if the child's Y Units and Y values result in the child being drawn outside of the parent's bounds.

    If a child has Y Units of Pixels from Top and its Y value pushes the child out of the top of its parent, then the portion that is outside of the top of the parent is ignored. The BlueRectangle in the following image has an absolute height of 50. Its Y value is -20, so only 30 pixels are used to determine the parent's height.

    Similarly, if a child uses a Y Units of Pixels from Bottom then the parent does not consider the height of any portion which is outside of its bounds. The following animation shows RedRectangle placed outside of the bottom of its bounds with a Y Units of Pixels from Bottom.

    Notice that if RedRectangle is moved so that it is inside the bounds, it can affect the absolute height of the parent. As RedRectangle is moved into the bounds, the parent grows to accommodate the desired RedRectangle Y value.

    If a child is a Text instance using a Y Origin of Baseline and a Y Units of Pixels from Bottom, then portions of the text which fall below the baseline are ignored by the parent's height.

    A parent ignores its child if the child uses a Y Units of Percentage of Parent Height because this also creates a circular dependency (parent height depends on child position, child position depends on parent height).

    If a parent sets its Height Units to Relative to Children, then it resizes itself to contain its children. Normally, the height of the entire parent is determined by the child which needs the most space vertically. If the parent uses an Auto Grid Vertical layout, then the children control the size of the cells as well as the entire parent. Since all cells must be the same size, the child which needs the most amount of space vertically determines the height of all cells.

    For example, the following image shows a four by four grid, each containing one white rectangle. The first rectangle has an Absolute Width and Height of 100, so each cell is sized to be 100x100. Note that the other rectangles are 50x50.

    The largest child determines the cell size for all other children. Therefore, if a child is moved or resized so it outgrows its cell, then the parent height adjusts in response.

    The height of a container is determined by the height of the largest cell multiplied by the number of rows. For example, the following container has 4 columns and 3 rows, resulting in 12 cells. The height of the grid is based on 3 rows multiplied by the height of the largest cell.

    If children are removed from the container, the container's height does not change - the Auto Grid Vertical Cells value determines the number of rows when calculating height, whether the cells contain children or are empty.

    Since Auto Grid Vertical Cells acts only as a minimum and not maximum, more children can be added and the container expands to support the newly-added children.

    Setting a grid's Height value to a non-zero value increases the height of the on top of what is needed to contain its children. This additional height is distributed evenly to all cells, resulting in additional spacing between each child.

    For example, the following 3x3 grid contains children with an absolute height of 50. The grid's Height Units is set to Relative to Children. Notice that as the grid's Height increases, it grows vertically. This vertical growth results in a larger cell size, so each child is spaced apart.

    The term "children" can refer to:

    • Instances added to a parent, such as ColoredRectangles added to a Container

    • Individual letters in a Text instance - each letter and line of text can expand the height of its parent

    The following animation shows a Text instance which has its Height Units set to Relative To Children. As more lines of text are added, the Text automatically expands in size.

    The height of a Text instance using Relative to Children depends on the number of lines displayed by the Text instance and the maximum line height given the current font properties. Therefore, the height of a Text stance remains the same regardless of the contents of a single line.

    For example, the following image contains multiple Text instances. Each has a single line of text, but the line of text differs in the height of each character. Notice that the texts are all the same height even though the contents of their lines differ.

    We can observe the absolute height of a Text instance by mousing over one of the handles for resizing vertically.

    In this case, the height is 41 pixels tall. This is based on the lineHeight as defined on the .fnt file. The image above is using an Arial 36 font which has a lineHeight value of 41 pixels.

    Relative to Max of Children or Parent sizes an element to whichever is larger — its parent's height or the height needed to contain its children. The Height value acts as padding on the children side, the same as Relative to Children. A Height of 0 means the element is exactly the larger of its parent's height or its children's bounds.

    This unit is most useful when multiple siblings all use Relative to Max of Children or Parent. In this case, the sibling with the tallest content drives the parent's height, which in turn sets the height of all shorter siblings. This creates a row of elements that always match each other's height regardless of their individual content.

    For example, consider a horizontal row of text frames (colored rectangles each containing a Text instance). Each frame uses Relative to Max of Children or Parent for its Height Units. When one Text instance wraps to more lines and becomes taller, that frame grows to fit its content. Because the taller frame pushes the parent to grow, all other frames also grow to match — keeping the row uniform.

    Without this unit, you would need to either set a fixed height on all frames (which cannot adapt to content) or use Relative to Children on each frame (which makes each frame a different height based on its own content).

    Percentage of Width adjusts the object's effective height so it remains proportional to the Width value multiplied by the Height value (as a percentage). For example, if a Height value of 200 is entered, then the effective height is 200% (2x) of the Width.

    The following image shows a child ColoredRectangle with a Height of 200 Percentage of Other Dimension. In this image, the Width value is 50 units, so the effective height is 100 units:

    can select a Height Units called Percentage of File Height, which sets the height of the Sprite according to the file that it is displaying. This is the default Height Units for Sprites.

    The following image shows a child Sprite with 200 Percentage of Source File Height, which means it draws two times as tall as its source image:

    This value depends on the Sprite's Texture Height property, so changing Texture Height also changes the Sprite's absolute height.

    Sprites can select a Height Unit called Maintain File Aspect Ratio Height which sets the height of the sprite so its aspect ratio matches its source file multiplied by the Height value. Usually Maintain File Aspect Ratio Height is used with a Height value of 100 so that the Sprite shows is source file at the correct aspect ratio.

    When this value is used, a Sprite's Width can be changed resulting in its absolute height also changing.

    When using Maintain File Aspect Ratio Height, the Sprite's absolute height depends on the Sprite's Texture Height property.

    Absolute Multiplied by Font Scale is a value which multiplies an object's Height value by the global Font Scale value. This can be used to create heights which are responsive to font scale for devices which may have variable text sizes.

    The Font Scale value can be adjusted in the Editor tab to preview different global Font Scale values. When a Gum project is loaded at runtime, the runtime may apply a Font Scale value such as using the Text size from Windows.

    The global Font Scale value is set to 4, so the rectangle in the following image is drawn at an effective height of 200 pixels.

    Width Units

    The Width Units variable controls how a unit is horizontally sized, which may be relative to its parent. By default elements uses Absolute width, where each unit represents 1 pixel of width in absolute terms. When using Absolute, an object ignores its parents' effective width.

    The following shows a child with 50 Absolute Width:

    The following image shows a child ColoredRectangle with -10

    is
    Percentage of Parent Height
    =
    Relative to Parent

    Ratio of Parent

    Relative to Children

    Ignored Height Values

    Child's Ignored By Parent Size is True (1)

    Child Depends on Parent Height (2)

    Child Explicitly Positioned Outside of Parent's Bounds (3)

    Child Y Units is Percentage of Parent Height (4)

    Relative to Children and Auto Grid Vertical

    Relative to Children and Text

    Relative to Max of Children or Parent

    Percentage of Width

    Percentage of File Height

    Maintain File Aspect Ratio Height

    Svgs also support using Maintain File Aspect Ratio Height. For more information on using Svgs see the Skia Standard Elements page.

    Absolute Multiplied by Font Scale

    ColoredRectangle
    Children Layout
    Stack Spacing
    ColoredRectangle
    Ignored By Parent Size
    Sprites
    Parent
    Rectangle using a Percentage of Parent value of 100
    Ratio of Parent Height Units
    Ratio of Parent set to 1
    Two stacked ColoredRectangles, each with a height ratio of 1
    Stacked children with a Height Units of Ratio of Parent
    Children shrink to make room for new ColoredRectangles
    Red ColoredRectangle with a Height value of 3
    ColoredRectangle with a Ratio of Parent Height of 0
    Absolute ColoredRectangle with 80 Height
    Adjusting Height changes all sibling heights
    Toggling visibility removes an object from the height ratio calculation
    Increasing Stack Spacing reduces the available ratio space for all children
    Rectangle using Relative to Children Height of 50, resulting in an absolute height of 50 since it has no children
    Moving children can adjust the absolute height of the parent if the parent is using a Height Units of Relative to Children
    Height is relative to the bottom-most child when using Relative to Children
    Moving BlueRectangle changes the height of both its parent and also YellowRectangle
    Parent absolute height is 30 since the BlueRectangle explicitly has 20 of its height set outside of the parent's bounds
    RedRectangle not affecting the absolute height of its parent since it is placed outside of the parent's bounds
    Moving a child which uses Pixels From Bottom upward can make the parent grow to accommodate the child's Y value
    Portions of the text are ignored when calculating heights
    Y Units of Percentage of Parent Height results in the child ignored
    The largest child determines the height of the cell when the parent uses Relative to Children height
    Resizing or moving a child can result in all cells growing or shrinking
    Auto Grid Horizontal with Height Units Relative To Children
    Removed children do not shrink the container beyond its minimum number of rows
    Container expanding as more children are added to the grid
    Increasing Height Relative to Children spreds the larger size across all cells
    Adding lines of text to a Text instance expands its height if its Height Units is set to Relative To Children
    Texts with the same height despite having different string
    Text which has an absolute height of 41 pixels
    Font36Arial has a lineHeight of 41.
    The right blue rectangle's effective height is controlled by the taller of its parent (red rectangle) or child (white rectangle)
    Changes to the text cause size changes in the blue and ultimately red rectangle, which affects the size of sibling blue rectangles
    Rectangle using Percentage of Other Dimension Height of 200
    Sprite using Percentage of File Height of 200
    Changing a Sprite's Texture Height adjusts its absolute height when using Percentage of File Height
    Changing the Width when using Maintain File Aspect Ratio Height also adjusts absolute height
    Changing either Width or Texture Height affects the Sprite's absolute height
    Height affected by global Font Scale
    Relative to Parent
    Width
    , so it sizes itself 10 pixels less wide than its parent.
    Rectangle using a Relative to Parent Width value of -10

    If an instance does not have a parent, then it uses the canvas size when using a Width Units of Relative to Parent.

    Rectangle using 0 Relative to Parent with no direct parent

    The following shows a child ColoredRectangle with 100 Percentage of Parent Width, which means it has 100% of the effective width of its parent. Note that 100 Percentage of Parent is the same as 0 Relative to Parent:

    Rectangle using 100% of its parent

    If an object does not have a parent, then the width of the canvas is used.

    Rectangle using 100% of the screen when it has no direct parent

    Ratio of Parent can be used to fill available space or to share available space with other objects using a ratio. It behaves similar to a Height Units of Ratio of Parent, but operates horizontally rather than vertically. For a more detailed discussion of Ratio of Parent, see the Height Units page.

    Blue rectangle using a ratio value of 2, next to siblings each using a ratio value of 1

    Ratio of Parent is usually used with a parent that has its Children Layout set to Left to Right Stack or Top to Bottom Stack. For more information, see the Children Layout page.

    The following image shows a child ColoredRectangle with 50 Relative to Children Width, which means that it is sized 50 pixels wider than is necessary to contain its children. Since the rectangle has no children, this is the same as having 50 Absolute Width:

    Rectangle with a width of 50 Relative to Children, but since it has no children it is 50 units wide

    Relative to Children can be used to size an object based on the position and sizes of a parent's children. The following animation shows a container with 0 Relative to Children Width, which means that its effective width is set just large enough to contain its children. Notice that if the children are moved, the parent's effective width adjusts. Both children are considered so the container adjusts its width according to the right-most side of either child:

    Moving children can adjust the absolute width of the parent if the parent is using a Width Units of Relative to Children

    A non-zero Width when using Relative to Children can be used to add additional padding to a parent container. The following animation shows how changing the Width variable can adjust the absolute width relative to children:

    Width is relative to the right-most child when using Relative to Children

    Relative to Children results in effective width dynamically adjusting in response to changes on a container's children. The following animation shows a container with Children Layout of Left to Right Stack. Adding additional children expands the container automatically:

    Adding children expands the effective width of the parent if the children are positioned in a horizontal stack.

    A parent container can ignore its children when it determines its absolute width when using a Width Units of Relative to Children if any of the following are true:

    1. The child's Ignored By Parent Size is true.

    2. The child's width depends on its parent's width. This circular dependency is resolved by the parent ignoring this child.

    3. The child is explicitly positioned outside of the parent's bounds

    4. The child's X Units is Percentage of Parent Width

    If a child has its Ignored By Parent Size set to true, then the parent ignores this child when calculating its own size. For more information, see the Ignored By Parent Size page.

    If a child's width depends on the parent, then the child is ignored by the parent. Once the parent has determined its own width, then the child is sized according to the parent. This type of circular dependency is common when adding background visuals to a container.

    For example consider a container with two children - BlueRectangle and YellowRectangle - with the following variables:

    • BlueRectangle X = Pixels from Left

    • BlueRectangle Width Units = Absolute

    • YellowRectangle Width Units = Relative to Parent

    Only YellowRectangle depends on its parent.

    Since BlueRectangle's absolute width value does not depend on the parent, the parent can use BlueRectangle's absolute width when calculating its own absolute width. Since YellowRectangle depends on the parent, the parent ignores the YellowRectangle. Instead, YellowRectangle depends on the parent container's absolute width for calculating its own absolute width. This in effect creates a situation where BlueRectangle affects the width of both its parent and also its YellowRectangle sibling.

    Moving BlueRectangle changes the width of both its parent and also YellowRectangle

    A parent does not consider a child if the child is explicitly positioned outside of the parent's bounds. This can happen if the child's X Units and X values result in the child being drawn outside of the parent's bounds

    If a child has X Units of Pixels from Left and its X value pushes the child out of the left of the parent, then the portion that is outside of the left of the parent is ignored. The BlueRectangle in the following image has an absolute width of 50. Its X value is -20, so only 30 pixels are used to determine the parent's effective height.

    Parent absolute width is 30 since the BlueRectangle explicitly has 20 of its width set outside of the parent's bounds

    Similarly, if a child uses an X Units of Pixels from Right then the parent does not consider the width of any portion which is outside of its bounds. The following animation shows RedRectangle placed outside of the right of the container's bounds with a X Units of Pixels from Right.

    RedRectangle not affecting the absolute width of its parent since it is placed outside of the parent's bounds

    Notice that if RedRectangle is moved so that it is inside the bounds, it can affect the absolute width of the parent. As RedRectangle is moved into the bounds, the parent grows to accommodate the desired RedRectangle X value.

    Moving a child which uses Pixels from Right can make the parent grow to accommodate the child's X value

    A parent ignores its child if the child uses an X Units of Percentage of Parent Width because this also creates a circular dependency (parent width depends on child position, child position depends on parent width).

    X Units of Percentage of Parent Width result in the child ignored

    If a parent sets its Width Units to Relative to Children, then it resizes itself to contain its children. Normally the width of the entire parent is determined by the child which needs the most space horizontally. If the parent uses an Auto Grid Horizontal layout, then the children control the size of the cells rather than the entire parent. Since all cells must be the same size, the child which needs the most amount of space horizontally determines the width of all cells.

    For example, the following image shows a four by four grid, each containing one white rectangle. The first rectangle has an Absolute Width and Height of 100, so each cell is sized to be 100x100. Note that the other rectangles are 50x50.

    The largest child determines the width of the cell when the parent uses Relative to Children width

    The largest child determines the cell size for all other children. Therefore, if a child is moved or resized so it outgrows its cell, then the parent width adjusts in response.

    Resizing or moving a child can result in all cells growing or shrinking

    The width of a container is determined by the width of the largest cell multiplied by the number of columns. For example, the following container has 3 columns and 4 rows, resulting in 12 cells. The width of the grid is based on 3 columns multiplied by the width of the largest cell.

    Auto Grid vertical with Width Units Relative To Children

    If children are removed from the container, the container's width does not change - the Auto Grid Horizontal Cells value determines the number of columns when calculating width, whether the cells contain children or are empty.

    Removed children do not shrink the container beyond its minimum number of columns

    Since Auto Grid Horizontal Cells acts only as a minimum and not maximum, more children can be added and the container expands to support the newly-added children.

    Container expanding as more children are added to the grid

    Setting a grid's Width value to a non-zero value increases the width of the container on top of what is needed to contain its children. This additional width is distributed evenly to all cells, resulting in additional spacing between each child.

    For example, the following 3x3 grid contains children with an absolute width of 50. The grid's Width Units is set to Relative To Children. Notice that as the grid's Width increases, it grows horizontally. This horizontal growth results in a larger cell size, so each child is spaced apart.

    Increasing Width Relative to Children spreads the larger size across all cells

    Setting a Text instance's Width Units to Relative to Children results in the Text object adjusting according to its text contents. In other words if a Text's Width Units is set to Relative To Children, then the words in the Text do not wrap.

    For example, setting the Width Units to Relative to Children and setting the Width to 0 results in the Text object automatically adjusting its actual width according to the text it contains.

    Text with Relative to Children width results in the contents of the Text instance controlling its size

    Relative to Max of Children or Parent sizes an element to whichever is larger — its parent's width or the width needed to contain its children. The Width value acts as padding on the children side, the same as Relative to Children. A Width of 0 means the element is exactly the larger of its parent's width or its children's bounds.

    This unit is most useful when multiple siblings all use Relative to Max of Children or Parent. In this case, the sibling with the widest content drives the parent's width, which in turn sets the width of all narrower siblings. This creates a column of elements that always match each other's width regardless of their individual content.

    The bottom blue rectangle's effective width is controlled by the wider of its parent (red rectangle) or child (white rectangle)

    For example, consider a vertical menu where each menu item contains a Text instance. Each menu item uses Relative to Max of Children or Parent for its Width Units. When one menu item has longer text, that item grows to fit its content. Because the wider item pushes the parent to grow, all other menu items also grow to match — keeping the menu uniform.

    Changes to the white rectangle cause size changes in the blue and ultimately red rectangle, which affects the size of sibling blue rectangles

    Without this unit, you would need to either set a fixed width on all menu items (which cannot adapt to content) or use Relative to Children on each item (which makes each item a different width based on its own text).

    Percentage of Height adjusts the object's effective width so it remains proportional to the effective height value multiplied by the Width value (as a percentage). For example, if a Width value of 200 is entered, then the effective width is 200% (2x) of the height.

    The following image shows a child ColoredRectangle with a Width of 200 Percentage of Height. In this image, the Height value is 50 units, so the effective width is 100 units:

    Rectangle displaying a width 200% of its height

    Sprites can select a Width Unit called Percentage of File Width, which sets the width of the Sprite according to the file that it is displaying. This is the default Width Unit for Sprites.

    The following image shows a child Sprite with 200 Percentage of Source File Width, which means it draws two times as wide as its source image:

    Sprite using 200 Percentage of File width

    When using Percentage of Source File Width, the Sprite's absolute width depends on the Sprite's Texture Width property.

    Changing a Sprite's Texture Width adjusts its absolute height when using Percentage of File Width

    For more information, see the Sprite Texture Address page.

    Sprites can select a Width Unit called Maintain File Aspect Ratio Width, which sets the effective width of the Sprite so that its aspect ratio matches its source file multiplied by the Width value. Usually Maintain File Aspect Ratio Width is used with a Width value of 100 so that the Sprite shows is source file at the correct aspect ratio.

    When this value is used, a Sprite's Height can be changed resulting in its absolute width also changing.

    Changing the Height when using Maintain File Aspect Ratio Width also adjusts absolute width

    When using Maintain File Aspect Ratio Width, the Sprite's effective width depends on the Sprite's Texture Width property.

    Changing either Height or Texture Width affects the Sprite's effective width

    Absolute Multiplied by Font Scale is a value which multiplies an object's Width value by the global Font Scale value. This can be used to create widths which are responsive to font scales for devices which may have variable text sizes.

    The Font Scale value can be adjusted in the Editor tab to preview different global Font Scale values. When a Gum project is loaded at runtime, the runtime may apply a Font Scale value such as using the Text size from Windows.

    The global Font Scale value is set to 4, so the rectangle in the following image is drawn at an effective width of 200 pixels.

    Width affected by global Font Scale

    Introduction

    Absolute

    Relative to Parent

    ColoredRectangle
    Rectangle with an Absolute Width of 50

    All relationships between parent and children depend only on the direct parent or child. Grandchildren and grandparents are not considered when performing calculations. For more information, see the page.

    Percentage of Parent

    Ratio of Parent

    Relative to Children

    Ignored Width Values

    Child's Ignored By Parent Size is True (1)

    Child Width Depends on its Parent's Width (2)

    Child is Explicitly Positioned Outside of Parent's Bounds (3)

    Child's X Units is Percentage of Parent Width (4)

    Relative to Children and Auto Grid Horizontal

    Relative to Children and Text

    Relative to Max of Children or Parent

    Percentage of Height

    Percentage of File Width

    Maintain File Aspect Ratio Width

    Svgs also support using Maintain File Aspect Ratio Width. For more information on using Svgs see the page.

    Absolute Multiplied by Font Scale

    Variable References

    Variable References allows any variable on an instance or component to reference other variables. These other variables can be on the same instance or component, a different instance, or even variables from a different component.

    One common use of Variable References is to create a centralized style component which can be referenced throughout a Gum project.

    Variables which are assigned through Variable References cannot be directly set on the instance - the value obtained through the reference overwrites any custom value. For example, the reference Height = Width results in Height being read-only and depending on Width. Note that this is using a shorthand variable assignment which is discussed in later sections.

    Parent
    Skia Standard Elements
    Variable References can contain multiple lines. Each line is a separate variable reference. Each variable reference uses the following syntax:

    For example, to assign a Component's X value to a different component's X value, the following syntax could be used:

    X references the X value in OtherComponent. Note that X could be the X value on any component or any instance inside of a component:

    Spaces are optional around the equals sign, but spaces are not allowed in variable names. The following lines are okay:

    However, the following is not allowed:

    Lines can be commented out to disable the reference. If Gum encounters a scripting error, it will automatically comment out lines as well so that you can make corrections:

    An Instance can reference its own Component's X value by using the qualified name:

    An instance or component can reference the variable of another instance in the same component by using the name of the instance. The name of the containing component or screen is not required if the instances are both in the same component or screen:

    Components and instances can reference variables that are contained within instances of other components. In this case the name of the referenced instance is appended to the qualified name of the Screen or Component:

    Elements and Screens inside subfolders can be referenced. The subfolder path is included with forward slashes:

    The right side can be a variable in a Screen, although this isn't too common in practice:

    Similarly, variables on Standards can also be referenced. This is also quite rare, since this modifying the Standard element also has side effects on every other instance that is of the same type:

    Although it's common for variables to reference the same variable on a different object (such as X being set to another object's X value), this is not a requirement. For example, the following lines are valid:

    Instances can reference their own variables, but these must be qualified. For example, ColoredRectangleInstance can assign its Width to equal its own Height. Note that Gum will extend shorthand code as shown in a later section:

    Variables can be assigned to constant values, essentially locking the value:

    Math operations can be used in variable assignments. This includes add, subtract, multiply, divide, and parenthesis to control order of operations:

    Math operations can reference both constant values (1, 2, 3) or other variables:

    Variable references support conditional (ternary) expressions, comparison operators, and logical operators. These can be combined to drive variable values from boolean conditions or to switch between values based on other variables.

    A conditional expression uses the C# cond ? a : b syntax. If cond evaluates to true, the result is a; otherwise the result is b. The condition can be a boolean variable or a comparison:

    Just like simple variable references, the right side can be fully qualified to point at another element:

    Ternary expressions can be nested. Use parenthesis to make the order of evaluation clear:

    The operators ==, !=, <, >, <=, and >= can be used to compare values. The result is a bool, so comparisons are most often used as the condition of a ternary or as the right side of a bool assignment:

    The logical operators && (and) and || (or) combine two bool values into a single bool. Both operands must be bool:

    The ! operator inverts a bool value:

    Variable references can drive a component's categorical state by assigning to <CategoryName>State. The right side must resolve to a string matching one of the state names defined in that category. This is useful for switching visual states from another instance's variable. For example, on a button-derived component with a ButtonCategory containing Enabled and Disabled states:

    If the right side is a literal string, Gum validates it against the category's state names and comments out the line if there is no match.

    Standard Forms behaviors (Button, TextBox, Slider, and so on) can use a category-state assignment to drive a visual state from a Behavior Property — a property in the Variables tab's Behavior category that also flows through to the runtime Forms control. See for what these are.

    For example, a TextBox-derived component previews its multi-line layout at design time using a reference like:

    This works the same as any other category-state assignment — the driven state is read-only, and changing TextWrapping or AcceptsReturn in the Behavior category updates the preview immediately. The only difference is where the right-hand variable comes from: a Behavior Property instead of an ordinary instance variable.

    These references ship pre-authored on the standard Forms behaviors, so you typically won't write one yourself unless you're customizing a Forms component's default visual or authoring a custom behavior.

    Variables whose type is an enumeration — such as ChildrenLayout, or unit and alignment types like XUnits and WidthUnits — can be assigned using the enum value's name as a string. Gum converts the name to the matching enum value:

    Because the right side is a string, an enum can also be selected with a ternary or driven from another variable. For example, a container can switch its layout direction based on a bool:

    The name must match one of the enum's values; if it does not, the assignment is not applied. An enum variable can also be assigned from another variable of the same enum type, or from the enum's underlying integer value:

    Numeric variable types can be mixed. For example, Red is typically an int value (whole number), while X is a float (supports decimals). Gum automatically casts the variable appropriately:

    Gum automatically casts any value to a string (text). For example, a Text's Text variable could be assigned to its own Y value:

    Strings can be concatenated (combined) using the + operator:

    Gum cannot convert unrelated types, including different Units. For example, the following would be commented out by Gum:

    Variable references can include custom variables, both on the left and right side. Custom variables can be combined with variable references to create flexible layouts. For more information on using custom variables, see the .

    As mentioned above, fully qualified assignments are allowed in any context. For example, a component can reference its own qualified variables:

    Components do not need to qualify their own variables. They can reference them without any qualification. Therefore, the following variable reference is equivalent to the fully-qualified reference above:

    Similarly, the following two variable references are equivalent assuming ContainedInstance is part of the component with the reference:

    Instances must qualify their own variables. See for what an unqualified name means instead:

    Gum will automatically qualify assignments when an instance is selected. In other words, X = Y gets qualified to X = SameInstance.Y if SameInstance is the owner of the variable. This automatic qualification makes it easy for an instance to reference its own values. The following animation shows how the Y and Height values become qualified to the instance after tabbing out of the Variable Reference text box.

    Complex assignments are automatically qualified as well.

    The left side of an assignment can be omitted if referencing the same variable on another instance or component. For example, by typing OtherInstance.YUnits , Gum automatically expands the reference to YUnits = OtherInstance.YUnits .

    Note that this only works when assigning one variable directly to another variable. Complex assignments will not be prefixed.

    Assigning color values is a common part of styling, so to help with this situation, Gum also expands the "Color" variable into all three components when the Variable References text box loses focus. For example, the following text can be used to assign all three values at once:

    When the Variable References box loses focus, this is expanded to the following assignments:

    As shown above, Variable References can be used to assign one variable to another. If a variable is referenced, then the variable cannot be manually assigned. The Variable Reference takes priority. For example, if an object references the Red, Green, and Blue variables, then those values cannot be manually set on the object. The values appear disabled and text indicates why they are read-only.

    Typing a variable name can be tedious, especially when referencing a variable in a different Screen or Component. Qualified variable names can be obtained by right-clicking on the variable name in Gum and selecting the Copy Qualified Variable Name option. This can then be pasted in the Variable References box of any other object.

    The following example creates a Styles component which contains a color value which is referenced by objects in a MainMenu Screen.

    Any component can serve as a centralized location for styling, but we use the name Styles by convention.

    The Styles component can contain as many objects as are needed to style your project. Additional objects can be added to help indicate how things are used visually. For example, we include a Text object to indicate the red color is the Primary Color.

    The color value can be referenced by any other object including objects in different screens or components.

    To add a variable reference:

    1. Select the object which should have a variable reference

    2. Click inside the Variable References text box

    3. Type the variable reference. The format of the variable reference is {VariableName} = {Components or Screens}/{ComponentOrScreenName}.{InstanceName}.{InstanceVariable} For example, to reference the Red variable in the Styles component, the syntax is Red = Components/Styles.PrimaryColor.Red\

    Since color values have three components (Red, Green, and Blue), then all three components must be referenced. In this example, the background can reference the three colors with the following assignment text:

    The types of the objects that contain the Variable References or which are being referenced do not matter. For example, a Text object could have its color values depend on the color values defined by a ColoredRectangle in the Styles component.

    Once Variable References are set, the referenced instances (instances in Styles) can be changed and the changes will immediately propagate throughout the entire project.

    The example above references a Styles component from one object at a time. You can go further and build a reusable, semantic color palette (for example: White, Gray, Black, Primary, Success, Warning, Danger) that any instance in your project can select by name, without hardcoding a color anywhere outside of the Styles component.

    This combines two features already covered elsewhere:

    1. A category per Standard Element - Select the NineSlice, Sprite, or Text Standard Element and add a category (for example ColorCategory) with one state per palette name. See for how to create categories and states.

    2. A Variable Reference per state - Select each state in the category and use the Color Expansion shorthand to point it at the matching instance in your Styles component:

    Repeat this for every state in the category (White, Gray, Primary, Success, and so on), pointing each one at its matching Styles instance. Because the reference lives on the Standard Element itself, every instance of that Standard Element across your entire project shares the same palette.

    Repeat the category on each Standard Element that needs coloring (NineSlice, Sprite, Text). Once this is set up, any instance anywhere in the project can select a palette color with a single instead of a color reference:

    Introduction

    Variable references can also be re-evaluated at runtime to support theming and dynamic styling. For details, see .

    Variable references mimic the C# syntax, but provide only a subset of C# functionality. Future versions of Gum may expand supported syntax. If your project requires additional functionality, please post an issue on GitHub, or make a request in the Discord server.

    Variable Reference Syntax

    Component setting its Height relative to its Width
    Height is assigned to Width, so it is read only
    {Variable} = {Components or Screens}/{ComponentOrScreenName}.{Instance}.{Variable}
    X = Components/OtherComponent.X
    X = Components/OtherComponent.X
    Y=Components/OtherComponent.Y
    Width = Components/OtherComponent.Width
    // Spaces are not allowed, so Gum would comment this reference:
    X Units = Components/OtherComponent.X Units
    // This is considered a comment so it will not run
    // Neither will this:
    // X = Components/OtherComponent.Y
    X = Components/ComponentContainingThisInstance.X
    Width = OtherInstanceInSameComponent.Width
    Red = Components/StyleComponent.PrimaryColorRectangle.Red
    XUnits = Components/ComponentFolder/ComponentInFolder.XUnits
    Green = Screens/MainMenuGum.ColoredRectangleInstance.Green
    YUnits = Standards/Text.YUnits
    Y = OtherInstance.X
    Width = Components/OtherComponent.Height
    Width = ColoredRectangleInstance.Height
    X = 100
    Text = "Hello"
    Visible = true
    Y = (TitleText.Y + 2) * 7 - 4
    Width = (OtherInstance.Height * 3) + 10
    Width = TitleText.Visible ? 200 : 100
    X = Background.Width > 500 ? Background.X : 0
    Width = Components/AppState.IsExpanded ? 400 : 200
    Width = Container.Width > 500 ? 300 : (Container.Width > 250 ? 200 : 100)
    Visible = Background.Width > 100
    Width = ScoreText.Y >= TitleText.Y ? 300 : 100
    Visible = ToggleButton.Visible && ContentArea.Visible
    Visible = ErrorIcon.Visible || WarningIcon.Visible
    Visible = !LoadingSpinner.Visible
    ButtonCategoryState = Background.Visible ? "Enabled" : "Disabled"
    LineModeCategoryState = TextWrapping == "Wrap" ? "Multi" : (AcceptsReturn ? "Multi" : "Single")
    ChildrenLayout = "LeftToRightStack"
    ChildrenLayout = IsHorizontal ? "LeftToRightStack" : "TopToBottomStack"
    ChildrenLayout = OtherContainer.ChildrenLayout
    X = ColoredRectangleInstance.Red
    Green = ColoredRectangleInstance.Y
    Text=TextInstance.Y
    Text="My Position is " + TextInstance.X + ", " + TextInstance.Y
    //WidthUnits = TextInstance.HeightUnits
    X = Components/SameComponent.Y
    X = Y
    Y = Components/SameComponent.InstanceInComponent.Y
    // is equivalent to:
    Y = InstanceInComponent.Y
    X = SameInstance.Y
    Components/Styles.PrimaryColor.Color
    Red = Components/Styles.PrimaryColor.Red
    Green = Components/Styles.PrimaryColor.Green
    Blue = Components/Styles.PrimaryColor.Blue
    Red = Components/Styles.PrimaryColor.Red
    Green = Components/Styles.PrimaryColor.Green
    Blue = Components/Styles.PrimaryColor.Blue
    Components/Styles.PrimaryColor.Color
    ColorCategoryState = "Primary"

    Variable Assignment Reference

    Previous versions of Gum included spaces in some variable names. The public release of Gum in February 2025 has removed all spaces to simplify the syntax.

    For more information, see the page.

    Skipping the qualification isn't an error, it's a different reference. X = Height on an instance resolves Height against the containing component, not the instance. To reference the instance's own Height, qualify it: X = ColoredRectangleInstance.Height.

    The Variable References grid protects you from this by auto-qualifying bare names to the selected instance when you tab out, so this mix-up mostly only happens in hand-edited or generated project XML.

    Conditional and Logical Expressions

    Conditional (Ternary) Expressions

    Comparison Operators

    Logical Operators

    Boolean Negation

    Category-State Assignment

    Behavior-Driven References

    Enum Assignment

    Gum treats the prefixes Components/, Screens/, and Standards/ as special prefixes and does not consider this to be a division operator. Therefore, you should not name variables Components, Screens, or Standards as these are reserved words. Other variable references can freely use the forward slash character to create division.

    For example, the following two lines of code show the difference between a simple variable reference assignment and a division operation:

    Referencing Custom Variables

    Unqualified and Shorthand Assignments

    Color Expansion

    Variable References in the Property Grid

    Obtaining a Qualified Variable Name

    Example - Creating Color Styles

    Example: Semantic Color Categories on Standard Elements

    Add a screenshot showing the ColorCategory states on the NineSlice Standard Element, each with a Color Expansion reference into the Styles component.

    This pattern is also what makes the palette recolorable from game code at runtime - for example, letting a game read player-customizable colors from settings and apply them on startup. See .

    Behavior Properties
    Add Variables page
    the warning above
    Categories
    category-state assignment
    Runtime Variable References
    Tabbing automatically qualifies variables to the selected instance
    Y, Width, and Height are automatically qualified to the current instance
    OtherInstance.YUnits is automatically prefixed with the text YUnits=
    Assigning Color expands the variables automatically
    Left-side variables become read-only
    Right-click to obtain the qualified name of a variable
    Background instance referencing the Styles.PrimaryColor color values
    TextInstance also referencing the PrimaryColor color values
    Changing the source color values updates all objects referencing the Style.PrimaryColor values
    Removal of Variable Spaces
    Runtime Variable References
    // This is a direct assignment setting X to 
    // the X value on Components/OtherComponent:
    X = Components/OtherComponent.X
    // This is a division operation setting X to
    // the result of dividing the CustomVariable by OtherComponent.X
    X = CustomVariable/OtherComponent.X