pub struct ColorStop {
pub color: Rgba,
pub offset: Length,
}
Expand description
A color stop in a gradient.
Fields§
§color: Rgba
The color.
offset: Length
Offset 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
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<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 Twhere
T: VarValue,
impl<T> AnyVarValue for Twhere
T: VarValue,
source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
dyn Any
methods.source§fn clone_boxed(&self) -> Box<dyn AnyVarValue>
fn clone_boxed(&self) -> Box<dyn AnyVarValue>
source§fn clone_boxed_var(&self) -> Box<dyn AnyVar>
fn clone_boxed_var(&self) -> Box<dyn AnyVar>
LocalVar<Self>
.source§fn eq_any(&self, other: &(dyn AnyVarValue + 'static)) -> bool
fn eq_any(&self, other: &(dyn AnyVarValue + 'static)) -> bool
self
equals other
.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,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§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