Xui.Core.Canvas.Composition.Graphics
Assembly: Xui.Core · C# declarations · Assembly overview
Types
enum BackdropMaterialref struct CompositionGroupclass GraphicsNodereadonly struct GroupOptionsclass ImmediateCompositionContextreadonly record struct OutlineBorderreadonly record struct OutlineShadowclass SurfaceEffects
enum BackdropMaterial
A backdrop material rather than a filter of the group's foreground drawing.
public enum BackdropMaterial
{
None,
Blur,
LiquidGlass
}
BackdropMaterial.Blur
Blur
Native system material blur where available.
BackdropMaterial.LiquidGlass
LiquidGlass
Native Liquid Glass on supported iOS versions; system blur on older iOS.
BackdropMaterial.None
None
No backdrop material.
ref struct CompositionGroup
An allocation-free, stack-only lifetime for a canvas composition group.
Use with a using declaration or statement. Scopes must close in reverse opening order; do not copy a live scope. Balance all Save/Restore calls inside the scope before closing it.
public ref struct CompositionGroup
{
public bool NeedsRedraw { get; }
public CompositionGroup(ICompositionContext owner, bool needsRedraw);
public void Dispose();
}
CompositionGroup.CompositionGroup(ICompositionContext owner, bool needsRedraw)
public CompositionGroup(ICompositionContext owner, bool needsRedraw);
Creates a scope for an already-opened group. Intended for context implementations.
void CompositionGroup.Dispose()
public void Dispose();
Closes the group and restores its enclosing drawing state.
bool CompositionGroup.NeedsRedraw
public bool NeedsRedraw { get; }
Whether the caller must emit this group's content into the context.
class GraphicsNode
A retained 2D drawing surface with recorded canvas commands and ordered composition children.
Command buffers and reconciliation caches belong here; shared presentation is provided by Node. Platforms may derive from this class to own their native resources and release them in DisposeCore. Native backends replay Commands when needed.
public class GraphicsNode : Node
{
public readonly CanvasCommandBuffer Inherited;
public readonly CanvasCommandBuffer Commands;
public override int Count { get; }
public override Node this[int index] { get; }
public readonly List<Node> HiddenChildren;
public bool HasDrawing { get; }
protected override void DisposeCore();
}
CanvasCommandBuffer GraphicsNode.Commands
public readonly CanvasCommandBuffer Commands;
Recorded 2D drawing content owned by this surface.
int GraphicsNode.Count
public override int Count { get; }
Number of visible children in back-to-front order. Leaf nodes return zero.
void GraphicsNode.DisposeCore()
protected override void DisposeCore();
Overrides release their owned content, children and platform resources, then call base.
bool GraphicsNode.HasDrawing
public bool HasDrawing { get; }
Whether the command stream contains visible drawing operations.
List<Node> GraphicsNode.HiddenChildren
public readonly List<Node> HiddenChildren;
Cached, omitted children. Backends detach these surfaces until they are declared again.
CanvasCommandBuffer GraphicsNode.Inherited
public readonly CanvasCommandBuffer Inherited;
Inherited canvas state replayed before this surface's own commands.
Node GraphicsNode.this[int index]
public override Node this[int index] { get; }
Returns the visible child at the given index.
readonly struct GroupOptions
Identity, content invalidation, and presentation of an explicit canvas group.
public readonly struct GroupOptions
{
public required object Key { get; init; }
public bool HasUpdates { get; init; }
public Rect? Bounds { get; init; }
public AffineTransform Transform { get; init; }
public bool ClipToBounds { get; init; }
public bool ViewBacking { get; init; }
public nfloat CornerRadius { get; init; }
public Color? Background { get; init; }
public BackdropMaterial Backdrop { get; init; }
public OutlineShadow? Shadow { get; init; }
public OutlineBorder? Border { get; init; }
public bool CacheWhenHidden { get; init; }
public GroupOptions();
public void Validate();
}
GroupOptions.GroupOptions()
public GroupOptions();
Creates options that request drawing and preserve the parent transform.
BackdropMaterial GroupOptions.Backdrop
public BackdropMaterial Backdrop { get; init; }
Native backdrop material, approximated by a translucent surface in portable renderers.
Color? GroupOptions.Background
public Color? Background { get; init; }
Optional surface color, updated independently of recorded drawing content.
OutlineBorder? GroupOptions.Border
public OutlineBorder? Border { get; init; }
Optional border drawn inside the rounded bounds.
Rect? GroupOptions.Bounds
public Rect? Bounds { get; init; }
Optional content bounds in the group's coordinate system. Does not translate the origin or clip implicitly. Retained backends may use these bounds for backing storage.
bool GroupOptions.CacheWhenHidden
public bool CacheWhenHidden { get; init; }
Keep this keyed surface in a bounded cache when omitted by culling. A parent retains at most eight hidden children; older entries release their native resources.
bool GroupOptions.ClipToBounds
public bool ClipToBounds { get; init; }
Clips drawing to Bounds, after applying Transform. Requires Bounds.
NFloat GroupOptions.CornerRadius
public nfloat CornerRadius { get; init; }
Uniform radius of the surface outline and optional bounds clip.
bool GroupOptions.HasUpdates
public bool HasUpdates { get; init; }
Whether the group's graphics or descendants have changed. Defaults to true. False permits a backend to reuse content, but callers must still check NeedsRedraw.
object GroupOptions.Key
public required object Key { get; init; }
A stable reference identifying this group among its siblings. Never serialized as an SVG ID.
OutlineShadow? GroupOptions.Shadow
public OutlineShadow? Shadow { get; init; }
Optional shadow of the bounds outline, independent of the drawn content's alpha.
AffineTransform GroupOptions.Transform
public AffineTransform Transform { get; init; }
Local transform concatenated with the parent transform. Defaults to identity.
void GroupOptions.Validate()
public void Validate();
Checks required identity and bounds before a backend changes drawing state.
bool GroupOptions.ViewBacking
public bool ViewBacking { get; init; }
Requests a retained native surface. Requires Bounds. Draw its content before declaring child groups.
class ImmediateCompositionContext
Explicit immediate-mode implementation for backends without retained composition. Groups isolate Save/Restore drawing state and apply presentation, but always redraw. Surface effects use portable approximations; this does not create native views or retain pixels.
public sealed class ImmediateCompositionContext(IContext context) : ICompositionContext
{
public CompositionGroup Group(scoped in GroupOptions options);
public void EndGroup();
}
ImmediateCompositionContext.ImmediateCompositionContext(IContext context)
public ImmediateCompositionContext(IContext context);
Explicit immediate-mode implementation for backends without retained composition. Groups isolate Save/Restore drawing state and apply presentation, but always redraw. Surface effects use portable approximations; this does not create native views or retain pixels.
void ImmediateCompositionContext.EndGroup()
public void EndGroup();
Closes the innermost group. Called by Xui.Core.Canvas.Composition.Graphics.CompositionGroup.Dispose; prefer disposing the returned scope over calling this directly.
CompositionGroup ImmediateCompositionContext.Group(scoped in GroupOptions options)
public CompositionGroup Group(scoped in GroupOptions options);
Opens a group and applies its presentation properties. Draw through the same context only when the returned scope's Xui.Core.Canvas.Composition.Graphics.CompositionGroup.NeedsRedraw is true. Dispose the scope before drawing subsequent siblings.
Keys identify siblings by reference, not value equality. Use a stable reference, not a boxed value or a newly allocated key each frame. HasUpdates=false permits reuse; it never guarantees it. Export and immediate contexts always request drawing. A retained backend must also redraw when it lacks valid content. Reusing a group reuses its entire subtree, so HasUpdates must include relevant descendant changes. Presentation changes are processed even when content can be reused. HasUpdates=true must request drawing; it is also used by capture middleware to force both the display and export branches to accept the same drawing commands. Groups inherit drawing state and restore it on disposal, with the same path and state semantics as Save/Restore. Bounds do not change the coordinate origin. In a view-backed group, issue direct drawing before declaring child surfaces. To draw above those children, declare a separate overlay group. Retained backends reject drawing that violates this ordering instead of silently changing its depth. An inherited arbitrary canvas clip may require flattening a surface into its parent; that fallback requests drawing on every frame. Prefer group bounds clipping when native composition and content reuse are needed.
Example
using var group = context.Group(new GroupOptions
{
Key = this,
HasUpdates = HasRenderUpdates,
Bounds = Frame
});
if (group.NeedsRedraw)
DrawContent(context);
readonly record struct OutlineBorder
A solid border following the inside of a surface's rounded bounds.
public readonly record struct OutlineBorder(Color Color, nfloat Width)
{
public void Validate();
}
OutlineBorder.OutlineBorder(Color Color, NFloat Width)
public OutlineBorder(Color Color, nfloat Width);
A solid border following the inside of a surface's rounded bounds.
Color OutlineBorder.Color
public Color Color { get; init; }
void OutlineBorder.Validate()
public void Validate();
Checks a finite, nonnegative width.
NFloat OutlineBorder.Width
public nfloat Width { get; init; }
readonly record struct OutlineShadow
A drop shadow cast by the group's rounded bounds, not by its glyphs or transparent pixels.
public readonly record struct OutlineShadow(Color Color, nfloat Radius, Vector Offset)
{
public void Validate();
}
OutlineShadow.OutlineShadow(Color Color, NFloat Radius, Vector Offset)
public OutlineShadow(Color Color, nfloat Radius, Vector Offset);
A drop shadow cast by the group's rounded bounds, not by its glyphs or transparent pixels.
Color OutlineShadow.Color
public Color Color { get; init; }
Vector OutlineShadow.Offset
public Vector Offset { get; init; }
NFloat OutlineShadow.Radius
public nfloat Radius { get; init; }
void OutlineShadow.Validate()
public void Validate();
Checks finite, nonnegative blur and finite offsets.
class SurfaceEffects
Portable surface approximation for contexts without native backdrop effects.
public static class SurfaceEffects
{
public static void Draw(IContext context, in GroupOptions options);
}
void SurfaceEffects.Draw(IContext context, in GroupOptions options)
public static void Draw(IContext context, in GroupOptions options);
Draws an outline shadow and translucent material without filtering foreground text.