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>) -> 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
fn into_var(self) -> Var<GradientStop>
Source§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 Eq 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 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<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
§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
key and return true if they are equal.§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
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