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: BorderRadiusCorner radii, per corner.
shadow: Option<BoxShadow>Drop shadow.
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: Border) -> BoxDecoration
pub fn border(self, border: Border) -> BoxDecoration
Adds a uniform border.
Sourcepub fn shadow(self, shadow: BoxShadow) -> BoxDecoration
pub fn shadow(self, shadow: BoxShadow) -> BoxDecoration
Adds a shadow.
Sourcepub fn gradient(self, gradient: LinearGradient) -> BoxDecoration
pub fn gradient(self, gradient: LinearGradient) -> BoxDecoration
Adds a linear gradient to the background.
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.
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
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
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 more