Skip to main content

Gradient

Struct Gradient 

Source
pub struct Gradient {
    pub shape: GradientShape,
    pub center: Point,
    pub radius: Option<f32>,
    /* private fields */
}
Expand description

Colors that blend into each other across a widget’s box, drawn over its background with the same corners.

use crabshell_ui::{Color, Gradient, Style};

const DUSK: Style = Style::new().gradient(
    Gradient::linear(90.0, Color::hex("#1e1e2e"), Color::hex("#45475a"))
        .stop(0.5, Color::hex("#313244")),
);

Fields§

§shape: GradientShape

Which way the colors run.

§center: Point

Where a radial or sweep gradient is centered, as fractions of the box: 0, 0 is its top-left corner and 1, 1 its bottom-right. 0.5, 0.5 by default. A linear gradient ignores it.

§radius: Option<f32>

A radial gradient’s radius in logical pixels, or None, the default, to reach the farthest corner from its center. Other shapes ignore it.

Implementations§

Source§

impl Gradient

Source

pub const fn linear(angle: f32, from: Color, to: Color) -> Gradient

A gradient from from to to along a line at angle degrees: 0 runs from the bottom up, 90 from left to right.

Source

pub const fn radial(from: Color, to: Color) -> Gradient

A gradient from from in the middle to to at the farthest corner. center moves the middle and radius sets how far it reaches.

use crabshell_ui::{Color, Gradient, Style};

// A glow up and to the right, 42 pixels across.
const GLOW: Style = Style::new().gradient(
    Gradient::radial(Color::rgba(255, 255, 255, 89), Color::rgba(255, 255, 255, 0))
        .center(0.7, 0.3)
        .radius(42.0),
);
Source

pub const fn sweep(angle: f32, from: Color, to: Color) -> Gradient

A gradient from from to to once around the middle, clockwise from angle degrees: 0 starts at 12 o’clock, 90 at 3, as CSS’s conic-gradient(from 90deg, …). The end meets the start there. center moves the middle.

use crabshell_ui::{Color, Gradient, Style};

const RING: Style = Style::new().radius(20.0).gradient(
    Gradient::sweep(0.0, Color::hex("#89b4fa"), Color::hex("#89b4fa"))
        .stop(0.5, Color::hex("#f5c2e7")),
);
Source

pub const fn stop(self, at: f32, color: Color) -> Gradient

Adds color at at, from 0 to 1, before the end color. Add them in order. A gradient has at most eight colors, so a seventh stop panics, which is a compile error in a const.

Source

pub const fn center(self, x: f32, y: f32) -> Gradient

Centers a radial or sweep gradient at x, y, fractions of the box: 0, 0 is its top-left corner and 1, 1 its bottom-right. The default is 0.5, 0.5. A center outside the box works, as CSS’s at 120% 50%. A linear gradient ignores it.

Source

pub const fn radius(self, radius: f32) -> Gradient

Sets a radial gradient’s radius to radius logical pixels, instead of reaching the farthest corner from its center. Past the radius the end color holds, as in CSS, and a radius of 0 or less leaves only the end color. Other shapes ignore it.

Source

pub fn stops(&self) -> &[(f32, Color)]

Each color and where it sits, from the start to the end.

Trait Implementations§

Source§

impl Clone for Gradient

Source§

fn clone(&self) -> Self

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 Copy for Gradient

Source§

impl Debug for Gradient

Source§

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

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

impl From<Gradient> for Paint

Source§

fn from(gradient: Gradient) -> Paint

Converts to this type from the input type.
Source§

impl PartialEq for Gradient

Source§

fn eq(&self, other: &Self) -> 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 Gradient

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more