#[non_exhaustive]pub enum Gradient {
Linear {
angle_deg: f32,
stops: Vec<Stop>,
},
Radial {
cx: f32,
cy: f32,
radius: f32,
stops: Vec<Stop>,
},
}Expand description
Multi-stop gradient pattern.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Linear
Straight-line gradient. angle_deg follows CSS conventions:
0° paints bottom-to-top, 90° left-to-right, etc. Stops are
offset-sorted (see Gradient::linear).
Radial
Circular gradient. (cx, cy) is the centre in normalised
canvas coordinates (0.5, 0.5 is dead-centre). radius is in
normalised units of the canvas’s smaller axis. Stops are
offset-sorted.
Implementations§
Source§impl Gradient
impl Gradient
Sourcepub fn linear(angle_deg: f32, stops: impl IntoIterator<Item = Stop>) -> Self
pub fn linear(angle_deg: f32, stops: impl IntoIterator<Item = Stop>) -> Self
Build a linear gradient. Stops are sorted by offset; duplicates
at the same offset keep their original relative order
(sort_by is stable).
Sourcepub fn radial(
cx: f32,
cy: f32,
radius: f32,
stops: impl IntoIterator<Item = Stop>,
) -> Self
pub fn radial( cx: f32, cy: f32, radius: f32, stops: impl IntoIterator<Item = Stop>, ) -> Self
Build a radial gradient. Stops are offset-sorted (see
Gradient::linear).
Sourcepub fn sample(&self, t: f32) -> Option<u32>
pub fn sample(&self, t: f32) -> Option<u32>
Sample the gradient at a normalised position t ∈ [0, 1]
along the gradient axis (for linear) or along the radius (for
radial). Out-of-range t clamps to the nearest endpoint stop.
Returns None if the gradient has no stops.
Interpolation is linear per channel — the same lerp used by
crate::animation::KeyframeValue::Color keyframes — so the
behaviour is consistent across the data model.