RenderTargetTextureSource
Introduction
The RenderTargetTextureSource property allows a Sprite to render a texture produced by a different ContainerRuntime which is drawing to a render target. This feature allows a render target to be scaled, rotated, positioned, stacked, or to use any other Gum layout functionality.
RenderTargetTextureSource Requirements
To use RenderTargetTextureSource, the following must exist:
A container which has its IsRenderTarget set to true. This container can contain any number of children.
A Sprite which has its RenderTargetTextureSource set to the container
Code Example: Scaling a ListBox
The following code creates a ListBox which is displayed on a render target with wavy scaling:
SpriteRuntime sprite;
protected override void Initialize()
{
GumUI.Initialize(this);
var container = new ContainerRuntime();
container.AddToRoot();
container.Name = "Render target container";
container.IsRenderTarget = true;
container.Dock(Dock.SizeToChildren);
container.Visible = false;
var listBox = new ListBox();
container.AddChild(listBox);
for (int i = 0; i < 20; i++)
{
listBox.Items.Add($"Item {i}");
}
sprite = new SpriteRuntime();
sprite.AddToRoot();
sprite.Anchor(Anchor.Center);
sprite.RenderTargetTextureSource = container;
base.Initialize();
}
protected override void Update(GameTime gameTime)
{
var gameSeconds = (float)gameTime.TotalGameTime.TotalSeconds;
sprite.Width = 100 + 50 * MathF.Sin(gameSeconds * 4);
sprite.Height = 100 + 50 * MathF.Sin(gameSeconds * 3);
GumUI.Update(gameTime);
base.Update(gameTime);
}

Last updated
Was this helpful?