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: ImageHandle,
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
radius: BorderRadiusCorner radii, per corner.
Text
A line of text, anchored by its top-left corner.
Fields
weight: FontWeightFont weight.
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: boolWhether 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: TextAlignHow 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: TextDecorationDecoration lines (underline, strikethrough, and so on).
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.
bounds: RectThe 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”.
RichText
Rich text: a sequence of resolved runs, mixing styles and colours, laid out as one piece, on a single shared baseline.
Fields
max_width: Option<f32>The width of the box the runs were given. See Primitive::Text.
bounds: RectThe box the text was laid out in. See Primitive::Text.
Path
A vector path: arbitrary 2D geometry, filled (fill) and/or stroked
(stroke). The building block of icons and custom drawing.
Fields
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.
Image
A bitmap image, sampled into a destination rectangle.
Fields
image: ImageHandleShared handle to the pixels (GPU-cached by crate::ImageData::id).
rect: RectDestination rectangle, already fitted per the crate::BoxFit.
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
clip_shape: ClipShapeThe 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: LayerFilterThe 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.
Implementations§
Source§impl Primitive
impl Primitive
Sourcepub fn scaled(&self, factor: f32) -> Primitive
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).
Sourcepub fn scaled_xy(&self, sx: f32, sy: f32) -> Primitive
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.
Sourcepub fn translated(&self, dx: f32, dy: f32) -> Primitive
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)).
Sourcepub fn bounds(&self) -> Rect
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.
Sourcepub fn with_clip(&self, clip: Rect) -> Primitive
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.
Sourcepub fn scaled_about(&self, pivot: Point, factor: f32) -> Primitive
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.
Sourcepub fn scaled_about_xy(&self, pivot: Point, sx: f32, sy: f32) -> Primitive
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.