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>) -> ColorStop
pub fn new(color: impl Into<Rgba>, offset: impl Into<Length>) -> ColorStop
New color stop with a defined offset.
sourcepub fn new_positional(color: impl Into<Rgba>) -> ColorStop
pub fn new_positional(color: impl Into<Rgba>) -> ColorStop
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) -> GradientStop
pub fn layout(&self, axis: LayoutAxis) -> GradientStop
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<ColorStop, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<ColorStop, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
source§impl From<ColorStop> for GradientStop
impl From<ColorStop> for GradientStop
source§fn from(color_stop: ColorStop) -> GradientStop
fn from(color_stop: ColorStop) -> GradientStop
source§impl IntoVar<GradientStop> for ColorStop
impl IntoVar<GradientStop> for ColorStop
source§fn into_var(self) -> <ColorStop as IntoVar<GradientStop>>::Var
fn into_var(self) -> <ColorStop as IntoVar<GradientStop>>::Var
source§fn into_boxed_var(self) -> Box<dyn VarBoxed<T>>where
Self: Sized,
fn into_boxed_var(self) -> Box<dyn VarBoxed<T>>where
Self: Sized,
BoxedVar<T>
. Read moresource§impl Serialize for ColorStop
impl Serialize for ColorStop
source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
source§impl Transitionable for ColorStop
impl Transitionable for ColorStop
impl<C, O> 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§
§impl<T> AnyEq for T
impl<T> AnyEq for T
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
source§impl<T> FsChangeNote for T
impl<T> FsChangeNote for T
§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> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§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