Skip to main content

Primitive

Enum Primitive 

Source
pub enum Primitive {
    Rect {
        rect: Rect,
        color: Color,
        color2: Color,
        gradient_dir: [f32; 2],
        radius: BorderRadius,
        border_width: f32,
        border_color: Color,
        blur: f32,
        clip: Rect,
        owner: u64,
    },
    Text {
Show 16 fields position: Point, text: String, size: f32, color: Color, weight: FontWeight, italic: bool, max_width: Option<f32>, soft_wrap: bool, align: TextAlign, decoration: TextDecoration, decoration_color: Option<Color>, height: Option<f32>, family: Option<FontFamily>, clip: Rect, bounds: Rect, owner: u64,
}, RichText { position: Point, runs: Vec<TextRun>, max_width: Option<f32>, soft_wrap: bool, align: TextAlign, clip: Rect, bounds: Rect, owner: u64, }, Path { path: Path, fill: Option<Color>, gradient: Option<PathGradient>, stroke: Option<Stroke>, clip: Rect, owner: u64, }, Image { image: Arc<ImageData>, rect: Rect, uv: Rect, tint: Color, clip: Rect, owner: u64, }, Layer { primitives: Vec<Primitive>, opacity: f32, clip: Rect, clip_shape: ClipShape, transform: Option<LayerTransform>, filter: LayerFilter, owner: u64, }, }
Expand description

A drawing primitive.

Variants§

§

Rect

A rectangle: rounded corners, border, gradient and/or soft shadow.

Fields

§rect: Rect

The rectangle’s bounds.

§color: Color

Fill colour — the start colour when there is a gradient.

§color2: Color

The gradient’s end colour (== color when flat).

§gradient_dir: [f32; 2]

Gradient direction in [0,1]² space; (0,0) means flat.

§radius: BorderRadius

Corner radii, per corner.

§border_width: f32

Border width, in logical pixels; 0 draws no border.

§border_color: Color

Border colour.

§blur: f32

Edge softening, in pixels (0 = crisp; > 0 = a blurred shadow).

§clip: Rect

Clip rectangle: nothing is drawn outside it.

§owner: u64

The emitting widget’s identity, used for exit animation.

§

Text

A line of text, anchored by its top-left corner.

Fields

§position: Point

The top-left corner the text is anchored at.

§text: String

The text itself.

§size: f32

The font size, in logical pixels.

§color: Color

The text’s colour.

§weight: FontWeight

Font weight.

§italic: bool

Italic.

§max_width: Option<f32>

The width of the box the text was given (None = unbounded, in which case explicit \n characters make the lines). It is what soft_wrap wraps at and what align aligns inside.

§soft_wrap: bool

Whether max_width wraps the text or only bounds the alignment. A line that is told where its box ends but not to wrap runs past it, which is what an ellipsised or clipped single line does.

§align: TextAlign

How the lines sit inside max_width. Ignored when there is no width to sit inside — and deliberately so: handing the renderer a width it did not have changes where right-to-left text lands.

§decoration: TextDecoration

Decoration lines (underline, strikethrough, and so on).

§decoration_color: Option<Color>

Decoration colour; None means the text’s own colour.

§height: Option<f32>

The line’s height as a multiple of size; None means crate::DEFAULT_LINE_HEIGHT. Carried on the primitive because the renderer has to lay the lines out at the height the measurement used, and it cannot derive that from the size alone.

§family: Option<FontFamily>

The font family; None means the application’s default. Carried for the same reason as height: the renderer must shape with the face the measurement used, and it cannot know which that was from the words alone.

§clip: Rect

Clip rectangle.

§bounds: Rect

The box the text was laid out in — the emitting widget’s, so an over-estimate of what the glyphs actually cover, never an under-estimate. The renderer needs it to know what the text covers; without it text can only be painted above everything else in the frame. Rect::UNBOUNDED when a scene is built by hand rather than by the widget walk, which the renderer reads as “unknown, keep it on top”.

§owner: u64

The emitting widget’s identity.

§

RichText

Rich text: a sequence of resolved runs, mixing styles and colours, laid out as one piece, on a single shared baseline.

Fields

§position: Point

The top-left corner the text is anchored at.

§runs: Vec<TextRun>

The resolved runs, in reading order, sharing one baseline.

§max_width: Option<f32>

The width of the box the runs were given. See Primitive::Text.

§soft_wrap: bool

Whether max_width wraps the runs or only bounds the alignment.

§align: TextAlign

How the lines sit inside max_width.

§clip: Rect

Clip rectangle.

§bounds: Rect

The box the text was laid out in. See Primitive::Text.

§owner: u64

The emitting widget’s identity.

§

Path

A vector path: arbitrary 2D geometry, filled (fill) and/or stroked (stroke). The building block of icons and custom drawing.

Fields

§path: Path

The geometry to fill and/or stroke.

§fill: Option<Color>

Interior fill colour (None = no fill), and the gradient’s start colour when there is one.

§gradient: Option<PathGradient>

A gradient across the fill, straight or radial; None leaves it flat.

§stroke: Option<Stroke>

Outline (colour plus width); None = no outline.

§clip: Rect

Clip rectangle.

§owner: u64

The emitting widget’s identity.

§

Image

A bitmap image, sampled into a destination rectangle.

Fields

§image: Arc<ImageData>

Shared handle to the pixels (GPU-cached by crate::ImageData::id).

§rect: Rect

Destination rectangle, already fitted per the crate::BoxFit.

§uv: Rect

The sampled sub-region of the texture, in 0..1 (the Cover crop).

§tint: Color

Multiplicative tint (white = unchanged; the alpha drives fading).

§clip: Rect

Clip rectangle.

§owner: u64

The emitting widget’s identity.

§

Layer

A layer: a subgroup of primitives composited as one at opacity. It is rendered separately into a texture at full opacity, then composited, which is what makes the group alpha correct: no double blending where the inner primitives overlap.

Fields

§primitives: Vec<Primitive>

The group’s primitives, in absolute coordinates like the parent scene.

§opacity: f32

Group opacity applied to the whole layer (0..1).

§clip: Rect

The layer’s clip rectangle.

§clip_shape: ClipShape

The clip shape inscribed in clip (rounded or elliptical); its coverage modulates alpha at compositing time. ClipShape::Rect is a plain rectangular clip, and the default.

§transform: Option<LayerTransform>

The affine transform (rotation) applied at compositing. None means the layer is simply composited in place, with group opacity.

§filter: LayerFilter

The pixel effects applied when the layer is composited: an image filter, a colour filter, a mask. LayerFilter::NONE — the usual case — leaves compositing on its original path.

§owner: u64

The emitting widget’s identity.

Implementations§

Source§

impl Primitive

Source

pub fn owner(&self) -> u64

The identity of the widget that emitted this primitive.

Source

pub fn scaled(&self, factor: f32) -> Primitive

Scales the geometry by factor — position, size, radius, border, blur, clip, font size. Colours and text are unchanged. This is how a logical scene becomes a physical one (DPI).

Source

pub fn scaled_xy(&self, sx: f32, sy: f32) -> Primitive

Scales the geometry per axis (sx horizontal, sy vertical). Rectangles and images stretch exactly; scalar quantities (corner radius, border, blur, path) follow the average of the two factors, having no axis of their own; font size follows sy and wrap width follows sx — approximations with no consequence when sx == sy, as with a uniform scale or DPI. This is the basis of non-uniform subtree scaling.

Source

pub fn translated(&self, dx: f32, dy: f32) -> Primitive

Offsets the geometry by (dx, dy) (position, clip); colours, sizes and text are unchanged. Combined with Primitive::scaled, it scales a subtree about a pivot: p.scaled(f).translated(pivot.x * (1 - f), pivot.y * (1 - f)).

Source

pub fn bounds(&self) -> Rect

This primitive’s (approximate) bounding box, in scene coordinates. Text is not measured in this module, so a Text or RichText primitive returns a point rectangle at its position, enough as an x reference.

Source

pub fn with_clip(&self, clip: Rect) -> Primitive

A copy of this primitive with its clip replaced by clip — used to “un-clip” a captured primitive replayed elsewhere, such as the ghost of a dragged header, which overflows its source column.

Source

pub fn scaled_about(&self, pivot: Point, factor: f32) -> Primitive

Scales the geometry by factor about pivot, which stays fixed: pos' = pivot + (pos - pivot) * factor. Sizes, font, radii and strokes all follow the scale.

Source

pub fn scaled_about_xy(&self, pivot: Point, sx: f32, sy: f32) -> Primitive

Like Primitive::scaled_about, but with per-axis factors (sx, sy) — a non-uniform scale about pivot.

Trait Implementations§

Source§

impl Clone for Primitive

Source§

fn clone(&self) -> Primitive

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Primitive

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Primitive

Source§

fn eq(&self, other: &Primitive) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Primitive

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<Msg> IntoMsg<Msg> for Msg

Source§

fn defer(work: impl Fn() -> Msg + 'static) -> Msg

The message that stands for work’s result.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.