Skip to main content

BoxDecoration

Struct BoxDecoration 

Source
pub struct BoxDecoration {
    pub color: Option<Color>,
    pub gradient: Option<LinearGradient>,
    pub border: Option<Border>,
    pub radius: BorderRadius,
    pub shadow: Option<BoxShadow>,
}
Expand description

The complete decoration of a rectangular box.

The paint order is fixed: shadow → background → border. The background is either flat (color) or a gradient (color → gradient.end). A border with no background paints an outline over transparency; a wholly empty decoration paints nothing at all.

Fields§

§color: Option<Color>

Background colour, which doubles as the start colour of any gradient.

§gradient: Option<LinearGradient>

A linear gradient for the background.

§border: Option<Border>

A uniform border.

§radius: BorderRadius

Corner radii, per corner.

§shadow: Option<BoxShadow>

Drop shadow.

Implementations§

Source§

impl BoxDecoration

Source

pub fn lerp(self, other: BoxDecoration, t: f32) -> BoxDecoration

The decoration t of the way from self to other — what a decoration transition paints mid-flight. Each part has its own rule, and the rules are the point:

  • Colours mix where both sides have one, in the space colours are stated in, as every animated colour in this framework does.
  • A part on one side only arrives or leaves; it does not come from nowhere. A fill fades, keeping its hue. A border thickens from nought in its own colour. A shadow grows from under the box as it fades in. Each is the part scaled by how far along it is, which is also what the reference does with a part one side lacks.
  • A flat fill is a gradient whose two ends agree, so flat to graded spreads the far end out of the fill rather than laying a gradient over it. Here a gradient starts at the fill colour, so the two always arrive and leave together.
  • Corners travel one by one.

The absent colour here is not the absent colour of a text style, and the two rules differ for that reason. A text style that names no colour is asking the theme for one — a real, visible colour — so it holds still rather than fade. A decoration that names no fill paints nothing, so fading is exactly what reaching it means.

t is clamped to 0..=1, and a t that is not a number is no progress: past its ends a colour has nowhere to go, and a decoration whose colours stopped at the end while its corners kept going would be two clocks. At 0 and 1 the answer is the end itself, exactly.

Source§

impl BoxDecoration

Source

pub fn filled(color: Color) -> BoxDecoration

A decoration with a flat background.

Source

pub fn radius(self, radius: impl Into<BorderRadius>) -> BoxDecoration

Sets the corner radii — uniform through f32, per corner through BorderRadius.

Source

pub fn border(self, border: Border) -> BoxDecoration

Adds a uniform border.

Source

pub fn shadow(self, shadow: BoxShadow) -> BoxDecoration

Adds a shadow.

Source

pub fn gradient(self, gradient: LinearGradient) -> BoxDecoration

Adds a linear gradient to the background.

Source

pub fn content_padding(&self) -> Insets

The inner margin the border needs — add it to the padding so the content is not eaten by the line. This is what feeds taffy.

Source

pub fn paint_into(&self, scene: &mut Scene, rect: Rect, opacity: f32)

Lowers the decoration into scene primitives, in the fixed order shadow → background → border. opacity (0..=1) modulates every colour, which is how a fade-in works. rect is the box in absolute coordinates.

Trait Implementations§

Source§

impl Clone for BoxDecoration

Source§

fn clone(&self) -> BoxDecoration

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 BoxDecoration

Source§

impl Debug for BoxDecoration

Source§

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

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

impl Default for BoxDecoration

Source§

fn default() -> BoxDecoration

Returns the “default value” for a type. Read more
Source§

impl PartialEq for BoxDecoration

Source§

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

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> 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.