Vixen
dd8b0a81
csharp
public readonly struct DrawContext

What an element is given to draw itself with.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

The escape hatch out of the declarative side. A stylesheet describes boxes, and most of an interface is boxes; a chart, a sparkline, a knob and a hand-drawn icon are not, and there is no font-family for those. OnDraw is where a control draws whatever it is, and this is the surface it draws on.

Everything is in document space, the same as the rest of the draw list. Bounds is where the element ended up, so a control that wants to draw inside itself starts from there rather than from an origin it has to be handed.

A struct passed by value, not a class handed out per element per frame. It is three references' worth of state and it exists for the length of one virtual call.

⚠ There is no text method here, and that does not mean a drawn layer cannot write a word — #1112, which read the absence as a wall and is why this paragraph exists. Every piece is public and reachable from here: Fonts resolves a face, Shaping shapes one run through the same LRU the layout pass uses — so a canvas of forty labels costs forty lookups and not forty shapings — TextRun.Place gives the glyphs on a baseline, and List takes them through AddGlyphs, AddFont and a DrawCommandKind.Text command. That is five calls, and it is what DrawListBuilder does per run without the layout pass a layer is avoiding.

Vixen.Ui.Tests.DrawnLayerTextTests is that recipe, executed, rather than a paragraph that can rot. ⚠ What a layer does not get from it is a paragraph: no line breaking, no bidi reordering, no fallback across scripts and no cascade — those are an element's, and a layer wanting them wants an element. There is no shorthand on this type because no production layer has needed one twice; the day a second does, it wraps those five calls.

Fields and properties (4)

  • public UiElement Element

    The element being drawn.

  • public DrawList List

    The list being filled, for anything this does not wrap.

  • public Rectangle Bounds

    Where the element is, in document space.

  • public Color4 Foreground

    The element's color, which is what a control draws itself in by default.

Methods (8)

Used by (41, showing 40)

  • BoxVixen.Ui.Tests
  • CodeEditorVixen.Ui.Controls.Advanced
  • CodeOverlayVixen.Ui.Controls.Advanced
  • ColorFieldVixen.Ui.Controls.Advanced
  • ColorStripVixen.Ui.Controls.Advanced
  • ColorSwatchVixen.Ui.Controls.Advanced
  • CurveEditorVixen.Ui.Controls.Advanced
  • DrawContextBoxTestsVixen.Ui.Tests
  • DrawListBuilderVixen.Ui
  • DrawnLayerTextTestsVixen.Ui.Tests
  • GradientBarVixen.Ui.Controls.Advanced
  • GradientRailVixen.Ui.Controls.Advanced
  • IconVixen.Ui.Controls
  • ImageVixen.Ui.Controls
  • ImageViewVixen.Ui.Controls.Advanced
  • LayerVixen.Ui.Tests
  • NodeCanvasVixen.Ui.Controls.Advanced
  • NodeMinimapVixen.Ui.Controls.Advanced
  • NodeOverlayLayerVixen.Ui.Controls.Advanced
  • NodeWireLayerVixen.Ui.Controls.Advanced
  • PathTestsVixen.Ui.Tests
  • ProgressBarVixen.Ui.Controls
  • RangeBaseVixen.Ui.Controls
  • RangeSliderVixen.Ui.Controls
  • ScrollBarVixen.Ui.Controls
  • SliderVixen.Ui.Controls
  • SpinnerVixen.Ui.Controls
  • TextFieldVixen.Ui.Controls
  • TimelineLanesVixen.Ui.Controls.Advanced
  • TimelineRulerVixen.Ui.Controls.Advanced
  • TreeRowVixen.Ui.Controls.Advanced
  • TriangleVixen.Ui.Tests
  • UiElementVixen.Ui
  • ViewportVixen.Ui.Controls.Advanced
  • ViewportGizmoVixen.Ui.Controls.Advanced
  • FontAtlasViewVixen.Editor.AssetEditors
  • MarqueeOverlayVixen.Editor.SceneView
  • NodeGraphViewVixen.Editor.NodeGraph
  • NodePreviewLayerVixen.Editor.NodeGraph
  • StateMapViewVixen.Editor.AssetEditors