pub struct Gradient {
pub kind: GradientKind,
pub stops: Vec<ColorStop>,
pub repeating: bool,
}Expand description
A gradient image (backgroundImage, maskImage).
Fields§
§kind: GradientKindGeometry.
stops: Vec<ColorStop>At least two stops.
repeating: boolRepeats past the last stop.
Implementations§
Source§impl Gradient
impl Gradient
Sourcepub fn lerp(&self, to: &Self, t: f32) -> Option<Self>
pub fn lerp(&self, to: &Self, t: f32) -> Option<Self>
The gradient t of the way to to (t beyond 0..1 overshoots):
each stop’s color (in premultiplied RGBA, as CSS mixes them) and
position, and the geometry’s angle and center. None when the two
do not interpolate and to applies at once, as CSS’s discrete
interpolation does: different kinds, sizes or repeating, a different
number of stops, a linear gradient toward a different corner, or a
stop placed in one and not the other, or as a fraction in one and a
length in the other.
Sourcepub fn has_lengths(&self) -> bool
pub fn has_lengths(&self) -> bool
Whether a stop is placed in points, so the stops depend on the
size of the box (Gradient::resolved_stops).
Sourcepub fn line_length(&self, size: Size<Points>) -> Points
pub fn line_length(&self, size: Size<Points>) -> Points
The length of the gradient line over a box of size, what
lengths of stops are fractions of (CSS Images 3): a linear
gradient’s line through the center, long enough that the corners
get the end colors; a radial gradient’s ray to the right, from the
center to the ending shape; 0 for a conic gradient, whose stops
are angles.
Sourcepub fn resolved_stops(&self, size: Size<Points>) -> Vec<(Color, Percentage)>
pub fn resolved_stops(&self, size: Size<Points>) -> Vec<(Color, Percentage)>
Stop positions over a box of size as fractions of the gradient
line, resolved as CSS does: lengths against the line’s length,
missing ones spread evenly, each at least the one before it.
Sourcepub fn resolve_stops(
&self,
size: Size<Points>,
out: &mut Vec<(Color, Percentage)>,
)
pub fn resolve_stops( &self, size: Size<Points>, out: &mut Vec<(Color, Percentage)>, )
Gradient::resolved_stops into a reused buffer.
Sourcepub fn unrolled_stops(
&self,
size: Size<Points>,
reach: Percentage,
) -> Vec<(Color, Percentage)>
pub fn unrolled_stops( &self, size: Size<Points>, reach: Percentage, ) -> Vec<(Color, Percentage)>
The stops over a box of size as a toolkit gradient that repeats
nothing and takes stops within 0..=1 (Core Animation’s, Android’s
shaders) draws them over 0..reach of the gradient line (1: the
whole line of a linear or conic gradient; a radial gradient’s rings
go on past its ending shape, to the box’s farthest corner): the
positions as fractions of reach. A repeating gradient’s stops are
repeated over all of it, with period last − first, both ways (CSS
Images 3), and cut at both ends with the colors there. A
non-repeating gradient’s, or one whose period is too short to
repeat, are Gradient::resolved_stops.