Struct BoxShadow

Source
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: Offset

Shadow translation from the source box in logical pixels.

§blur_radius: f32

Non-negative blur inflation radius in logical pixels.

§spread: f32

Non-negative pre-blur shape expansion in logical pixels.

§color: Color

Linear-RGBA shadow color.

§inset: bool

true paints inside the source box; false paints an outer shadow.

Implementations§

Source§

impl BoxShadow

Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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));
Source

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);
Source

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

Trait Implementations§

Source§

impl Clone for BoxShadow

Source§

fn clone(&self) -> BoxShadow

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BoxShadow

Source§

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

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

impl PartialEq for BoxShadow

Source§

fn eq(&self, other: &BoxShadow) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for BoxShadow

Source§

impl StructuralPartialEq for BoxShadow

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> Same for T

Source§

type Output = T

Should always be Self
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 = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.