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: GradientShapeWhich way the colors run.
center: PointWhere 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
impl Gradient
Sourcepub const fn linear(angle: f32, from: Color, to: Color) -> Gradient
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.
Sourcepub const fn radial(from: Color, to: Color) -> Gradient
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),
);Sourcepub const fn sweep(angle: f32, from: Color, to: Color) -> Gradient
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")),
);Sourcepub const fn stop(self, at: f32, color: Color) -> Gradient
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.
Sourcepub const fn center(self, x: f32, y: f32) -> Gradient
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.