Skip to main content

BoxDecoration

Struct BoxDecoration 

Source
pub struct BoxDecoration {
    pub color: Option<Color>,
    pub gradient: Option<Gradient>,
    pub border: Option<BoxBorder>,
    pub radius: BorderRadius,
    pub shadows: Vec<BoxShadow>,
    pub shape: BoxShape,
    pub image: Option<DecorationImage>,
    pub background_blend_mode: Option<BlendMode>,
}
Expand description

The complete decoration of a box — the reference’s BoxDecoration (box_decoration.dart:81).

The paint order is fixed, the reference’s (box_decoration.dart:571): the shadows, in order, then the background, then the picture, then the border. The background is either flat (color) or a gradient, which replaces the colour. A border with no background paints an outline over transparency; a wholly empty decoration paints nothing at all.

Fields§

§color: Option<Color>

Background colour.

§gradient: Option<Gradient>

A gradient filling the background, in place of color — linear, radial or sweep (milestone 644).

§border: Option<BoxBorder>

The border, side by side.

§radius: BorderRadius

Corner radii, per corner. A BoxShape::Circle has none.

§shadows: Vec<BoxShadow>

The shadows, painted in order, behind the box (box_decoration.dart:448).

§shape: BoxShape

A rectangle or a circle.

§image: Option<DecorationImage>

A picture over the background, under the border, clipped to the shape (milestone 645).

§background_blend_mode: Option<BlendMode>

How the background — the colour or the gradient — meets what is painted under the box (milestone 646): None paints it over. Nothing else of the decoration is blended, and with no colour or gradient it has nothing to do.

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) -> Self

A decoration with a flat background.

Source

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

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

Source

pub fn border(self, border: impl Into<BoxBorder>) -> Self

Sets the border, side by side or by the line’s start and end.

Source

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

Adds a shadow, after (so over) those already there.

Source

pub fn shadows(self, shadows: impl IntoIterator<Item = BoxShadow>) -> Self

Sets the shadows, painted in order.

Source

pub fn shape(self, shape: BoxShape) -> Self

Paints a rectangle or a circle.

Source

pub fn gradient(self, gradient: impl Into<Gradient>) -> Self

Fills the background with a gradient — linear, radial or sweep — in place of the colour.

Source

pub fn image(self, image: DecorationImage) -> Self

Paints a picture over the background, under the border.

Source

pub fn background_blend_mode(self, mode: BlendMode) -> Self

Blends the background — the colour or the gradient — with what is under the box by mode, rather than painting it over.

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. A directional border is read left to right; see Self::content_padding_in.

Source

pub fn content_padding_in(&self, direction: TextDirection) -> Insets

The inner margin the border needs, for a box in direction.

Source

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

Lowers the decoration into scene primitives, in the fixed order shadows → background → picture → border, for a box read left to right. See Self::paint_into_in.

Source

pub fn paint_into_in( &self, scene: &mut Scene, rect: Rect, opacity: f32, direction: TextDirection, )

Lowers the decoration into scene primitives, in the fixed order shadows → background → picture → border. opacity (0..=1) modulates every colour, which is how a fade-in works. rect is the box in absolute coordinates; direction places a directional border’s start and end.

Trait Implementations§

Source§

impl Clone for BoxDecoration

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 Debug for BoxDecoration

Source§

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

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

impl Default for BoxDecoration

Source§

fn default() -> Self

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

impl PartialEq for BoxDecoration

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