Skip to main content

GradientRamp

Struct GradientRamp 

Source
pub struct GradientRamp {
    pub shape: RampShape,
    pub stops: Vec<(f32, Color)>,
    pub tile: TileMode,
    pub transform: Affine,
}
Expand description

What a layer does at compositing, for painting a scene by hand. A gradient with any number of stops, for a path: its shape, its colours, what it does past its ends, and where it sits.

The shape is in the gradient’s own space and transform takes it to the path’s, so a gradient that is turned, skewed or squashed — an SVG gradientTransform, a bounding box’s units — is drawn exactly: the renderer maps each pixel back into the gradient’s space, where the shape is simple.

use frus_core::{Affine, Color, GradientRamp, Point, RampShape, TileMode};
let ramp = GradientRamp {
    shape: RampShape::Linear { from: Point::new(0.0, 0.0), to: Point::new(100.0, 0.0) },
    stops: vec![(0.0, Color::BLACK), (1.0, Color::WHITE)],
    tile: TileMode::Clamp,
    transform: Affine::default(),
};
assert_eq!(ramp.t_at(Point::new(25.0, 40.0)), Some(0.25));

Fields§

§shape: RampShape

Where the colours run, in the gradient’s own space.

§stops: Vec<(f32, Color)>

(offset, colour) pairs, offsets from 0 to 1 in order. A colour holds before the first stop and after the last.

§tile: TileMode

What happens past the ends of the shape.

§transform: Affine

The gradient’s space to the path’s.

Implementations§

Source§

impl GradientRamp

Source

pub fn t_at(&self, p: Point) -> Option<f32>

How far through the gradient the point p (in the path’s space) is, tiled; None where nothing is drawn — past the ends of a TileMode::Decal one, or outside both circles’ reach. What the renderer computes for every pixel.

Source

pub fn sample(&self, t: f32) -> Color

The colour at offset t, between the stops either side of it.

Source

pub fn color_at(&self, p: Point) -> Color

The colour at the point p, in the path’s space: transparent where nothing is drawn.

Trait Implementations§

Source§

impl Clone for GradientRamp

Source§

fn clone(&self) -> GradientRamp

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for GradientRamp

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl PartialEq for GradientRamp

Source§

fn eq(&self, other: &GradientRamp) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for GradientRamp

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<Msg> IntoMsg<Msg> for Msg

Source§

fn defer(work: impl Fn() -> Msg + 'static) -> Msg

The message that stands for work’s result.
Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.