pub struct ColorStop {
pub color: Rgba,
pub offset: Length,
}Expand description
A color stop in a gradient.
Fields§
§color: RgbaThe color.
offset: LengthOffset point where the color is fully visible.
Relative lengths are calculated on the length of the gradient line. The Length::Default value
indicates this color stop is positional.
Implementations§
Source§impl ColorStop
impl ColorStop
Sourcepub fn new(color: impl Into<Rgba>, offset: impl Into<Length>) -> Self
pub fn new(color: impl Into<Rgba>, offset: impl Into<Length>) -> Self
New color stop with a defined offset.
Sourcepub fn new_positional(color: impl Into<Rgba>) -> Self
pub fn new_positional(color: impl Into<Rgba>) -> Self
New color stop with a undefined offset.
See is_positional for more details.
Sourcepub fn is_positional(&self) -> bool
pub fn is_positional(&self) -> bool
If this color stop offset is resolved relative to the position of the color stop in the stops list.
A Length::Default offset indicates that the color stop is positional.
§Layout
When a GradientStops calculates layout, positional stops are resolved like this:
- If it is the first stop, the offset is 0%.
- If it is the last stop, the offset is 100% or the previous stop offset whichever is greater.
- If it is surrounded by two stops with known offsets it is the mid-point between the two stops.
- If there is a sequence of positional stops, they split the available length that is defined by the two stops with known length that define the sequence.
§Note
Use ColorStop::is_layout_positional if you already have the layout offset.
Sourcepub fn is_layout_positional(layout_offset: f32) -> bool
pub fn is_layout_positional(layout_offset: f32) -> bool
If a calculated layout offset is positional.
Positive infinity (f32::INFINITY) is used to indicate that the color stop is
positional in webrender units.
Sourcepub fn layout(&self, axis: LayoutAxis) -> RenderGradientStop
pub fn layout(&self, axis: LayoutAxis) -> RenderGradientStop
Compute a RenderGradientStop in the current LAYOUT context.
The axis value is used to select the LAYOUT axis inside the offset length.
Note that if this color stop is positional the returned offset is f32::INFINITY.
You can use ColorStop::is_layout_positional to check a layout offset.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for ColorStop
impl<'de> Deserialize<'de> for ColorStop
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<ColorStop> for GradientStop
impl From<ColorStop> for GradientStop
Source§impl IntoVar<GradientStop> for ColorStop
impl IntoVar<GradientStop> for ColorStop
fn into_var(self) -> Var<GradientStop>
Source§impl Transitionable for ColorStop
impl Transitionable for ColorStop
Source§fn lerp(self, to: &Self, step: EasingStep) -> Self
fn lerp(self, to: &Self, step: EasingStep) -> Self
self -> to by step.impl Eq for ColorStop
impl<C: Into<Rgba>, O: Into<Length>> IntoValue<ColorStop> for (C, O)
impl IntoValue<ColorStop> for Hsla
impl IntoValue<ColorStop> for Hsva
impl IntoValue<ColorStop> for Rgba
impl IntoValue<GradientStop> for ColorStop
impl StructuralPartialEq for ColorStop
Auto Trait Implementations§
impl Freeze for ColorStop
impl RefUnwindSafe for ColorStop
impl Send for ColorStop
impl Sync for ColorStop
impl Unpin for ColorStop
impl UnwindSafe for ColorStop
Blanket Implementations§
Source§impl<T> AnyVarValue for T
impl<T> AnyVarValue for T
Source§fn clone_boxed(&self) -> BoxAnyVarValue
fn clone_boxed(&self) -> BoxAnyVarValue
Source§fn eq_any(&self, other: &(dyn AnyVarValue + 'static)) -> bool
fn eq_any(&self, other: &(dyn AnyVarValue + 'static)) -> bool
self and other are equal.Source§fn try_swap(&mut self, other: &mut (dyn AnyVarValue + 'static)) -> bool
fn try_swap(&mut self, other: &mut (dyn AnyVarValue + 'static)) -> bool
other if both are of the same type.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more