RectangleRuntime

Introduction

RectangleRuntime draws a rectangle with a fill and an outline (stroke), plus an optional uniform CornerRadius for rounded corners. Its size is controlled by Width and Height. The fill is set by FillColor; the outline is set by StrokeColor and StrokeWidth. On top of fill and outline, a RectangleRuntime can also render a gradient, a drop shadow, and a dashed outline.

A freshly-constructed RectangleRuntime renders as a stroke-only outlineFillColor defaults to transparent, StrokeColor defaults to white, and StrokeWidth defaults to 1. Assign a visible FillColor to light up the fill, or set StrokeWidth to 0 to hide the outline.

For the full property surface — fill, outline, corner radius, gradient, drop shadow, dashed stroke, and the platform/package requirements — see the Shapes page. The examples below cover the common cases.

On MonoGame, KNI, and FNA the outline and geometry render out of the box, but the fill and the richer effects (gradient, drop shadow, dashed stroke, anti-aliasing) only draw once the Gum.Shapes.<platform> package is added — otherwise they are stored and round-trip but silently do not draw. Skia, .NET MAUI, and raylib support the full surface natively. See the Shapes page for setup.

Code Example

The following code creates an outlined RectangleRuntime:

// Initialize
var rectangle = new RectangleRuntime();
rectangle.Width = 120;
rectangle.Height = 24;
rectangle.StrokeColor = Color.Pink; // This is a Microsoft.Xna.Framework.Color
container.Children.Add(rectangle);
Pink outlined rectangle

To fill the rectangle and round its corners, assign a visible FillColor and a CornerRadius. On MonoGame, KNI, and FNA the fill requires the shape support package (see the Shapes page):

Legacy color members

Last updated

Was this helpful?