drawing

Vector drawing primitives: paths, fills, strokes, caps, and gradients.

Submodules

Structs

Depth

Logical scene depth for lighting calculations.

Depth is expressed in logical pixels. Unlike [Size], it is not anchored to a viewport or parent box, so percent and combined units are intentionally rejected during value coercion.

Properties

0

Type: Numeric

Implementations

to_float
pub fn to_float(&self) -> f64

Returns the depth as a floating-point logical pixel value.


Fill

One interior paint layer. Index zero in an element's fill stack is topmost.

Properties

paint

Type: Property<Paint>

Color or gradient sampled over the complete local geometry.

material

Type: Property<Material>

Light-reactive surface response, matte by default.

opacity

Type: Property<Opacity>

Opacity of this layer before element opacity is applied.


GradientStop

A color stop for a gradient fill, defined by a position (% or px) and a color.

Properties

position

Type: Size

Stop position, conventionally expressed as a percentage along the gradient.

color

Type: Color

Color at this stop.

Implementations

get
pub fn get(color: Color, position: Size) -> GradientStop

Constructs a gradient stop at position.

with_alpha_factor
pub fn with_alpha_factor(&self, factor: f64) -> GradientStop

Returns a copy of this stop with alpha multiplied by factor.


LinearGradient

Describes a linear gradient fill with a start and end point, and a list of color stops.

Pax templates canonically author each point as [x, y]: magic index 0 is the horizontal coordinate and index 1 is the vertical coordinate.

Properties

start

Type: (Size, Size)

Gradient start point in the primitive's local coordinate space.

end

Type: (Size, Size)

Gradient end point in the primitive's local coordinate space.

stops

Type: Vec<GradientStop>

Ordered color stops along the gradient.


MaterialParams

Tunable response parameters for a light-reactive vector material.

Properties

ambient

Type: Property<f64>

Ambient contribution multiplier.

diffuse

Type: Property<f64>

Diffuse contribution multiplier.

specular

Type: Property<f64>

Specular contribution multiplier.

roughness

Type: Property<f64>

Surface roughness in the [0.0, 1.0] range.

metallic

Type: Property<f64>

Metallic response in the [0.0, 1.0] range.

emissive

Type: Property<Color>

Additive emissive color.

emissive_intensity

Type: Property<f64>

Additive emissive intensity.


MeshGradient

Smooth mesh paint with 2–8 equally sized rows, each containing 2–8 anchors. Automatic shared Bézier controls interpolate the anchors and their premultiplied encoded-sRGB colors. Outside the covered mesh the paint is transparent. Folded patches replace earlier patches in row-major order. Supported by the WGPU renderer. Animate positions/colors to morph; whole [Paint] transitions remain crossfades.

Properties

rows

Type: Vec<Vec<MeshPoint>>

A rectangular lattice; adjacent entries and rows define shared patch edges.

Implementations

validate
pub fn validate(&self) -> Result<(), String>

Checks connectivity and finite inputs. An invalid mesh paints nothing; it is never truncated.


MeshPoint

A colored anchor in a [MeshGradient]. Position uses ordinary pixels, percentages, or combined units, relative to the complete consumer geometry's paint bounds. Rows describe connectivity; anchors in a row may have different y coordinates.

Properties

position

Type: (Size, Size)

Local x/y coordinates relative to the complete paint bounds.

color

Type: Color

Anchor color, including alpha.


RadialGradient

A focal radial gradient, growing from start to the circle at end with radius.

Pax templates canonically author each point as [x, y]: magic index 0 is the horizontal coordinate and index 1 is the vertical coordinate.

Properties

end

Type: (Size, Size)

Center of the outer circle in the primitive's local coordinate space.

start

Type: (Size, Size)

Focal point (0% stop). Equal start/end points give concentric circles.

radius

Type: f64

Outer radius in local logical pixels. Nonpositive/nonfinite radii paint nothing.

stops

Type: Vec<GradientStop>

Ordered color stops along the gradient.

Implementations

resolve_geometry
pub fn resolve_geometry(&self, rect: Rect) -> Option<ResolvedRadialGradient>

Resolves points against the actual shape bounds, including their origin. Invalid geometry paints nothing on all backends. The authored radius is independent of the distance between the focal point and the center.


ResolvedMaterialParams

Plain material coefficients for one settled drawing operation.

Properties

ambient

Type: f64

diffuse

Type: f64

specular

Type: f64

roughness

Type: f64

metallic

Type: f64

emissive

Type: Color

emissive_intensity

Type: f64


ResolvedRadialGradient

Runtime geometry shared by radial color fills and painted alpha masks. Coordinates are local logical pixels, before the element's affine transform.

Properties

focal_point

Type: Point

Point corresponding to the 0% stop.

center

Type: Point

Center of the circle corresponding to the 100% stop.

radius

Type: f64

Radius of the 100% circle in local logical pixels.


ResolvedStroke

Plain drawing values captured before entering a rendering backend. Backends never read live shared properties while recording a frame.

Properties

paint

Type: Paint

material

Type: ResolvedMaterial

opacity

Type: Opacity

width

Type: Size

cap

Type: StrokeCap

join

Type: StrokeJoin

Implementations

width_pixels
pub fn width_pixels(&self) -> f64

Resolves a finite, positive pixel width, or zero for an invisible stroke.


SceneAmbientLight

Resolved ambient light for one logical canvas layer.

Properties

color

Type: Color

Ambient color.

intensity

Type: f64

Ambient intensity.


SceneLight

Resolved light contribution for one logical canvas layer.

Properties

shape

Type: LightShape

Positional or directional light shape.

position

Type: Vector3

Position in logical canvas pixels for point lights.

direction

Type: Vector3

Direction in scene space for directional lights.

color

Type: Color

Light color.

intensity

Type: f64

Light intensity.

radius

Type: f64

Point light radius in logical pixels.

enabled

Type: bool

Whether this light contributes.


SceneLighting

Resolved lighting state for one logical canvas layer.

Properties

active

Type: bool

Whether authored lights or ambient overrides are present.

ambient_is_authored

Type: bool

Whether ambient came from an enabled authored AmbientLight.

The default ambient is only applied to primitives with at least one eligible direct light. An authored ambient remains layer-wide.

ambient

Type: SceneAmbientLight

Singleton ambient contribution.

lights

Type: Vec<SceneLight>

Positional and directional light contributions.

Implementations

DEFAULT_AMBIENT_INTENSITY

Ambient intensity used when point/directional lights exist but no explicit ambient override exists.

MAX_LIGHTS

Maximum number of simultaneously enabled lights in one target canvas layer.

identity
pub fn identity() -> Self

Returns lighting that preserves unlit legacy rendering.

with_default_ambient
pub fn with_default_ambient(lights: Vec<SceneLight>) -> Self

Creates active lighting with Pax's default ambient term.


Stroke

One centered outline layer, drawn above every interior fill. Index zero in an element's stroke stack is topmost.

Properties

paint

Type: Property<Paint>

Color or gradient sampled over the complete, untrimmed geometry.

material

Type: Property<Material>

Light-reactive surface response, matte by default.

opacity

Type: Property<Opacity>

Opacity of this layer before element opacity is applied.

width

Type: Property<Size>

Width in logical pixels. Percentages are unsupported; nonpositive widths draw nothing.

cap

Type: Property<StrokeCap>

Style of exposed endpoints on open paths.

join

Type: Property<StrokeJoin>

Style of joins between adjacent segments.

Implementations

resolve_in_graph
pub fn resolve_in_graph(&self) -> ResolvedStroke

Resolves nested fields from the entered UI graph's settled projections.

snapshot
pub fn snapshot(&self) -> ResolvedStroke

Captures the latest published fields without entering a UI graph. Independently published fields are not a multi-property transaction.

width_pixels
pub fn width_pixels(&self) -> f64

Resolves a finite, positive pixel width, or zero for an invisible stroke.


Vector3

A three-dimensional vector in logical scene space.

Properties

x

Type: f64

X component.

y

Type: f64

Y component.

z

Type: f64

Z component.

Implementations

new
pub fn new(x: f64, y: f64, z: f64) -> Self

Constructs a 3D vector.

Enums

LightShape

Shape of a light contribution in logical scene space.

Variants

Point

A positional light with radius-based attenuation.

Directional

A light with direction but no position or attenuation.


Material

Light-reactive surface response for vector primitives.

This is intentionally named Material; texture is reserved for future bitmap-backed texture maps and pattern data.

Variants

Lit(MaterialParams)

Responds to scene lighting using parameterized material coefficients.

Unlit

Ignores scene lighting and preserves legacy unlit rendering behavior.

Implementations

resolve_in_graph
pub fn resolve_in_graph(&self) -> ResolvedMaterial

Resolves nested coefficients from the entered UI graph's projections.

snapshot
pub fn snapshot(&self) -> ResolvedMaterial

Captures published coefficients without evaluating the UI graph.

custom
pub fn custom(params: MaterialParams) -> Self

Creates a lit material from explicit coefficients.

emissive
pub fn emissive(color: Color, intensity: f64) -> Self

An emissive material that adds color independent of lights.

glossy
pub fn glossy(specular: f64) -> Self

A higher-specular material with lower roughness.

matte
pub fn matte() -> Self

A soft, low-specular material suitable as the default lit response.

metallic
pub fn metallic(metallic: f64) -> Self

A metallic material response.

unlit
pub fn unlit() -> Self

A material that ignores authored lights.


Describes where to open new windows or tabs when navigating to a URL from a Link node.

Variants

Current

Navigate in the current window or tab.

New

Navigate in a new window or tab.


Paint

Describes how to fill vector geometry. Solid fills interpolate their RGBA channels. Other pairs crossfade sampled paints in premultiplied RGBA, preserving each gradient's geometry and stops.

Variants

Solid(Color)

A single solid color.

LinearGradient(LinearGradient)

A linear gradient.

RadialGradient(RadialGradient)

A radial gradient.

Blend(Vec<(Paint, f64)>)

A weighted paint mixture produced by interpolation. Weights are finite, nonnegative, and sum to one. Use [Paint::blend] to normalize weights, flatten nested mixtures, and combine repeated endpoints.

MeshGradient(MeshGradient)

A row-connected bicubic field with independently positioned colored anchors.

Implementations

blend
pub fn blend(terms: Vec<(Paint, f64)>) -> Self

Constructs a normalized mixture of paints. Nested mixtures are flattened and identical endpoints merged, so repeated interruptions between a fixed set of themes do not accumulate a history of blend nodes. Nonpositive or nonfinite weights are ignored; an empty mixture is transparent.

Sampling cost grows with the number of distinct endpoints still visible. A completed interpolation returns its destination paint directly.

coverage_alpha_0_1
pub fn coverage_alpha_0_1(&self) -> f64

Estimates the alpha coverage contributed by this fill.

linearGradient
pub fn linearGradient(start: (Size, Size), end: (Size, Size), stops: Vec<GradientStop>) -> Paint

Constructs a linear gradient paint.

Pax templates should normally use @gradient. When this helper is needed explicitly, pass start and end as [x, y] lists.

max_alpha_0_1
pub fn max_alpha_0_1(&self) -> f64

Returns a conservative upper bound for this paint's alpha. For mixtures, endpoint maxima need not occur at the same point.

representative_color
pub fn representative_color(&self) -> Color

Representative solid color for native text, which currently uses the first stop of a gradient. Mixtures crossfade those representative colors.

with_alpha_factor
pub fn with_alpha_factor(&self, factor: f64) -> Paint

Returns a copy of this paint with alpha multiplied by factor.


PathElement

Describes a single element of a vector path, such as a line, a point, or curve segment.

Variants

Empty

No-op path element.

Point(Size, Size)

Moves the current point to the provided coordinate.

Line

Draws a straight line to the following Point.

Quadratic(Size, Size)

Draws a quadratic Bézier segment with one control point, ending at the following Point.

Cubic(Size, Size, Size, Size)

Draws a cubic Bézier segment with two control points, ending at the following Point.

Close

Closes the current contour.


PathSmoothing

Controls optional curve smoothing for path geometry before tessellation.

PathSmoothing is intended for authored or imported paths whose source data approximates curves with many short line segments, such as single-stroke SVG fonts. Existing paths keep their exact geometry by default.

Variants

None

Preserve the authored path exactly.

Light

Lightly smooth polyline runs while preserving sharp corners.

Strong

More aggressively smooth polyline runs for pen-like paths.


ResolvedMaterial

Material response with no live property handles.

Variants

Lit(ResolvedMaterialParams)
Unlit

StrokeCap

Controls how an open stroke terminates at the exposed endpoints of a path.

StrokeCap affects primitives such as Line and open Path subpaths. Closed geometry ignores cap style because it has no exposed endpoints.

Variants

Butt

Ends exactly at the path endpoint without extending past it.

Round

Adds a semicircular cap whose radius is half the stroke width.

Square

Adds a square cap that extends half the stroke width past the endpoint.


StrokeJoin

Controls how stroke segments are joined at path vertices.

Variants

Miter

Extends outer edges to a point, subject to the renderer's miter limit.

Round

Rounds the outside of each join.

Bevel

Cuts joins off with a straight edge.

Functions

paint_bounds

pub fn paint_bounds(rect: Rect) -> Option<Rect>

Stable local reference frame for paint, independent of outline width and reveal. A collapsed axis gets a centered one-logical-pixel span without adding coverage.