pub struct BoxShadow {
pub offset: Offset,
pub blur_radius: f32,
pub spread: f32,
pub color: Color,
pub inset: bool,
}Expand description
Paint-only shadow cast by a widget box.
§Examples
use ailloli_ui_core::style::{BoxShadow, Color};
let shadow = BoxShadow::new(0.0, 2.0, 8.0, 0.0, Color::BLACK);
assert_eq!(shadow.offset.y, 2.0);Fields§
§offset: OffsetShadow translation from the source box in logical pixels.
blur_radius: f32Non-negative blur inflation radius in logical pixels.
spread: f32Non-negative pre-blur shape expansion in logical pixels.
color: ColorLinear-RGBA shadow color.
inset: booltrue paints inside the source box; false paints an outer shadow.
Implementations§
Source§impl BoxShadow
impl BoxShadow
Sourcepub fn new(
offset_x: f32,
offset_y: f32,
blur_radius: f32,
spread: f32,
color: Color,
) -> Self
pub fn new( offset_x: f32, offset_y: f32, blur_radius: f32, spread: f32, color: Color, ) -> Self
Creates an outer box shadow.
Negative blur/spread values and NaN are clamped to zero through
floating-point max; positive infinity remains infinite. Offsets and
color are stored verbatim.
§Examples
use ailloli_ui_core::style::{BoxShadow, Color};
assert_eq!(BoxShadow::new(0.0, 0.0, -1.0, -2.0, Color::BLACK).blur_radius, 0.0);Sourcepub fn inset(
offset_x: f32,
offset_y: f32,
blur_radius: f32,
spread: f32,
color: Color,
) -> Self
pub fn inset( offset_x: f32, offset_y: f32, blur_radius: f32, spread: f32, color: Color, ) -> Self
Creates an inset box shadow with the same normalization as Self::new.
The model is available even where a widget does not expose an inset
builder. Inset shadows never expand Self::paint_bounds.
§Examples
use ailloli_ui_core::style::{BoxShadow, Color};
assert!(BoxShadow::inset(0.0, 1.0, 2.0, 0.0, Color::BLACK).inset);Sourcepub fn sm() -> Self
pub fn sm() -> Self
Returns the small elevation preset: (0, 1), blur 2, alpha 0.18.
§Examples
use ailloli_ui_core::style::BoxShadow;
assert_eq!(BoxShadow::sm().blur_radius, 2.0);Sourcepub fn md() -> Self
pub fn md() -> Self
Returns the medium elevation preset: (0, 4), blur 12, alpha 0.24.
§Examples
use ailloli_ui_core::style::BoxShadow;
assert_eq!(BoxShadow::md().offset.y, 4.0);Sourcepub fn lg() -> Self
pub fn lg() -> Self
Returns the large elevation preset: (0, 10), blur 24, alpha 0.28.
§Examples
use ailloli_ui_core::style::BoxShadow;
assert_eq!(BoxShadow::lg().blur_radius, 24.0);Sourcepub fn xl() -> Self
pub fn xl() -> Self
Returns the extra-large preset: (0, 16), blur 40, alpha 0.32.
§Examples
use ailloli_ui_core::style::BoxShadow;
assert_eq!(BoxShadow::xl().blur_radius, 40.0);Sourcepub fn glow(color: Color) -> Self
pub fn glow(color: Color) -> Self
Returns a centered outer glow with an 18-logical-pixel blur radius.
§Examples
use ailloli_ui_core::style::{BoxShadow, Color};
assert_eq!(BoxShadow::glow(Color::WHITE).blur_radius, 18.0);Sourcepub fn shape_rect(&self, rect: Rect) -> Rect
pub fn shape_rect(&self, rect: Rect) -> Rect
Returns the translated and spread-inflated box before blur inflation.
§Examples
use ailloli_ui_core::Rect;
use ailloli_ui_core::style::{BoxShadow, Color};
assert_eq!(BoxShadow::new(2.0, 3.0, 0.0, 1.0, Color::BLACK).shape_rect(Rect::new(0.0, 0.0, 10.0, 10.0)), Rect::new(1.0, 2.0, 12.0, 12.0));Sourcepub fn paint_bounds(&self, rect: Rect) -> Rect
pub fn paint_bounds(&self, rect: Rect) -> Rect
Returns conservative axis-aligned bounds needed to paint the shadow.
Inset shadows return the original box. Outer shadows add the offset, spread, and blur radius.
§Examples
use ailloli_ui_core::Rect;
use ailloli_ui_core::style::{BoxShadow, Color};
let rect = Rect::new(0.0, 0.0, 10.0, 10.0);
assert_eq!(BoxShadow::inset(2.0, 3.0, 8.0, 1.0, Color::BLACK).paint_bounds(rect), rect);Sourcepub fn paint_insets(&self) -> EdgeInsets
pub fn paint_insets(&self) -> EdgeInsets
Returns conservative per-side outer inflation in logical pixels.
Inset shadows return four zeros. The values combine blur, spread, and only the outward component of each signed offset.
§Examples
use ailloli_ui_core::EdgeInsets;
use ailloli_ui_core::style::{BoxShadow, Color};
assert_eq!(BoxShadow::inset(0.0, 0.0, 8.0, 1.0, Color::BLACK).paint_insets(), EdgeInsets::all(0.0));