pub struct BoxStyle {
pub background: Background,
pub border: Border,
pub radius: Radius,
pub shadows: Vec<BoxShadow>,
pub opacity: Opacity,
}Expand description
Visual box decoration: background, border, radius, shadows, opacity.
§Examples
use ailloli_ui_core::style::{Background, BoxStyle, Color};
let style = BoxStyle::new().background(Background::color(Color::WHITE));
assert!(style.background.is_visible());Fields§
§background: BackgroundOptional solid background fill.
border: BorderBorder whose effective widths also participate in layout.
radius: RadiusPer-corner outer radius in logical pixels.
shadows: Vec<BoxShadow>Shadow layers in caller-provided paint order.
opacity: OpacityOpacity multiplier applied to the decorated box.
Implementations§
Source§impl BoxStyle
impl BoxStyle
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a transparent, borderless, shadowless, fully opaque box style.
§Examples
use ailloli_ui_core::style::BoxStyle;
assert!(BoxStyle::new().shadows.is_empty());Sourcepub fn background(self, background: Background) -> Self
pub fn background(self, background: Background) -> Self
Replaces the background configuration.
§Examples
use ailloli_ui_core::style::{Background, BoxStyle, Color};
assert!(BoxStyle::new().background(Background::color(Color::WHITE)).background.is_visible());Sourcepub fn border(self, border: Border) -> Self
pub fn border(self, border: Border) -> Self
Replaces the complete border configuration.
§Examples
use ailloli_ui_core::style::{Border, BoxStyle, Color};
assert!(BoxStyle::new().border(Border::new(1.0, Color::WHITE)).border.is_visible());Sourcepub fn radius(self, radius: impl Into<Radius>) -> Self
pub fn radius(self, radius: impl Into<Radius>) -> Self
Replaces all corner radii.
§Examples
use ailloli_ui_core::style::{BoxStyle, Radius};
assert_eq!(BoxStyle::new().radius(Radius::uniform(4.0)).radius, Radius::uniform(4.0));Sourcepub fn shadow(self, shadow: BoxShadow) -> Self
pub fn shadow(self, shadow: BoxShadow) -> Self
Appends one shadow after existing layers.
§Examples
use ailloli_ui_core::style::{BoxShadow, BoxStyle};
assert_eq!(BoxStyle::new().shadow(BoxShadow::sm()).shadows.len(), 1);Sourcepub fn shadows(self, shadows: Vec<BoxShadow>) -> Self
pub fn shadows(self, shadows: Vec<BoxShadow>) -> Self
Replaces all shadow layers while preserving vector order.
§Examples
use ailloli_ui_core::style::{BoxShadow, BoxStyle};
assert_eq!(BoxStyle::new().shadows(vec![BoxShadow::sm(), BoxShadow::md()]).shadows.len(), 2);Sourcepub fn clear_shadows(self) -> Self
pub fn clear_shadows(self) -> Self
Removes every shadow layer.
§Examples
use ailloli_ui_core::style::{BoxShadow, BoxStyle};
assert!(BoxStyle::new().shadow(BoxShadow::sm()).clear_shadows().shadows.is_empty());Sourcepub fn visual_bounds(&self, rect: Rect) -> Rect
pub fn visual_bounds(&self, rect: Rect) -> Rect
Returns the union of rect and every shadow’s paint bounds.
Inset shadows do not expand the result. Background, border, radius, and opacity do not change these conservative axis-aligned bounds.
§Performance
Runs in linear time over the number of shadow layers without allocation.
§Examples
use ailloli_ui_core::Rect;
use ailloli_ui_core::style::{BoxShadow, BoxStyle};
let bounds = BoxStyle::new().shadow(BoxShadow::sm()).visual_bounds(Rect::new(0.0, 0.0, 10.0, 10.0));
assert!(bounds.w >= 10.0);