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: BorderRadiusCorner radii, per corner. A BoxShape::Circle has none.
shadows: Vec<BoxShadow>The shadows, painted in order, behind the box (box_decoration.dart:448).
shape: BoxShapeA 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
impl BoxDecoration
Sourcepub fn lerp(self, other: BoxDecoration, t: f32) -> BoxDecoration
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
impl BoxDecoration
Sourcepub fn filled(color: Color) -> BoxDecoration
pub fn filled(color: Color) -> BoxDecoration
A decoration with a flat background.
Sourcepub fn radius(self, radius: impl Into<BorderRadius>) -> BoxDecoration
pub fn radius(self, radius: impl Into<BorderRadius>) -> BoxDecoration
Sets the corner radii — uniform through f32, per corner through
BorderRadius.
Sourcepub fn border(self, border: impl Into<BoxBorder>) -> BoxDecoration
pub fn border(self, border: impl Into<BoxBorder>) -> BoxDecoration
Sets the border, side by side or by the line’s start and end.
Sourcepub fn shadow(self, shadow: BoxShadow) -> BoxDecoration
pub fn shadow(self, shadow: BoxShadow) -> BoxDecoration
Adds a shadow, after (so over) those already there.
Sourcepub fn shadows(
self,
shadows: impl IntoIterator<Item = BoxShadow>,
) -> BoxDecoration
pub fn shadows( self, shadows: impl IntoIterator<Item = BoxShadow>, ) -> BoxDecoration
Sets the shadows, painted in order.
Sourcepub fn shape(self, shape: BoxShape) -> BoxDecoration
pub fn shape(self, shape: BoxShape) -> BoxDecoration
Paints a rectangle or a circle.
Sourcepub fn gradient(self, gradient: impl Into<Gradient>) -> BoxDecoration
pub fn gradient(self, gradient: impl Into<Gradient>) -> BoxDecoration
Fills the background with a gradient — linear, radial or sweep — in place of the colour.
Sourcepub fn image(self, image: DecorationImage) -> BoxDecoration
pub fn image(self, image: DecorationImage) -> BoxDecoration
Paints a picture over the background, under the border.
Sourcepub fn background_blend_mode(self, mode: BlendMode) -> BoxDecoration
pub fn background_blend_mode(self, mode: BlendMode) -> BoxDecoration
Blends the background — the colour or the gradient — with what is under the
box by mode, rather than painting it over.
Sourcepub fn content_padding(&self) -> Insets
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.
Sourcepub fn content_padding_in(&self, direction: TextDirection) -> Insets
pub fn content_padding_in(&self, direction: TextDirection) -> Insets
The inner margin the border needs, for a box in direction.
Sourcepub fn paint_into(&self, scene: &mut Scene, rect: Rect, opacity: f32)
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.
Sourcepub fn paint_into_in(
&self,
scene: &mut Scene,
rect: Rect,
opacity: f32,
direction: TextDirection,
)
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
impl Clone for BoxDecoration
Source§fn clone(&self) -> BoxDecoration
fn clone(&self) -> BoxDecoration
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BoxDecoration
impl Debug for BoxDecoration
Source§impl Default for BoxDecoration
impl Default for BoxDecoration
Source§fn default() -> BoxDecoration
fn default() -> BoxDecoration
Source§impl PartialEq for BoxDecoration
impl PartialEq for BoxDecoration
impl StructuralPartialEq for BoxDecoration
Auto Trait Implementations§
impl Freeze for BoxDecoration
impl RefUnwindSafe for BoxDecoration
impl Send for BoxDecoration
impl Sync for BoxDecoration
impl Unpin for BoxDecoration
impl UnsafeUnpin for BoxDecoration
impl UnwindSafe for BoxDecoration
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.