pub struct Gradient { /* private fields */ }Expand description
A box’s gradient: see the module’s notes. Built by Gradient::to,
Gradient::angle or Gradient::radial, or read from plain data by
parse_with.
Implementations§
Source§impl Gradient
impl Gradient
Sourcepub fn to<S: Into<Stop>>(side: Side, stops: impl IntoIterator<Item = S>) -> Self
pub fn to<S: Into<Stop>>(side: Side, stops: impl IntoIterator<Item = S>) -> Self
A linear gradient towards a side or a corner of the box. To a
corner the half-way line runs through the other two corners at any
aspect, which is CSS’s to bottom right.
Sourcepub fn angle<S: Into<Stop>>(
turns: f32,
stops: impl IntoIterator<Item = S>,
) -> Self
pub fn angle<S: Into<Stop>>( turns: f32, stops: impl IntoIterator<Item = S>, ) -> Self
A linear gradient along turns, clockwise from east (0.25 is
downwards), measured in the box’s unit square — so an eighth of a
turn runs corner to corner whatever the box’s aspect, which CSS’s
45deg, measured in pixels, does not.
Sourcepub fn radial<S: Into<Stop>>(stops: impl IntoIterator<Item = S>) -> Self
pub fn radial<S: Into<Stop>>(stops: impl IntoIterator<Item = S>) -> Self
A radial gradient from the middle of the box out to its corners.
Sourcepub fn radial_at<S: Into<Stop>>(
at: Vec2,
stops: impl IntoIterator<Item = S>,
) -> Self
pub fn radial_at<S: Into<Stop>>( at: Vec2, stops: impl IntoIterator<Item = S>, ) -> Self
A radial gradient from at — fractions of the box, (0.5, 0) the
middle of its top edge — out to the corner farthest from it.
Sourcepub fn is_drawable(&self) -> bool
pub fn is_drawable(&self) -> bool
Whether there is anything to paint: two stops or more, and a shape made of numbers.
Sourcepub fn key(&self) -> u64
pub fn key(&self) -> u64
The key its raster is held under: equal for equal gradients, whatever box draws them.
Sourcepub fn stops(&self) -> &[(Color, f32)]
pub fn stops(&self) -> &[(Color, f32)]
The stops as resolved: a colour and its position, in order.
Sourcepub fn raster_size(&self) -> (u32, u32)
pub fn raster_size(&self) -> (u32, u32)
The raster’s size in texels: a strip along the axis the gradient runs on, or the square.
Sourcepub fn slot_size(&self) -> (u32, u32)
pub fn slot_size(&self) -> (u32, u32)
The texels its slot takes: Self::raster_size and a gutter of
one all round.
Sourcepub fn rasterize(&self) -> Vec<u8> ⓘ
pub fn rasterize(&self) -> Vec<u8> ⓘ
The raster: Self::slot_size texels of straight RGBA, row after
row, each the gradient at its texel’s centre. The quad draws the
inner Self::raster_size of them; the gutter is the gradient
carried on a texel past each edge, because the quad is stretched
and sampled linearly, and at the box’s edge the sampler reads half
a texel past the rect it was given — a strip one texel high would
otherwise fade into whatever the atlas holds above and below it.