Struct BoxStyle

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

Optional solid background fill.

§border: Border

Border whose effective widths also participate in layout.

§radius: Radius

Per-corner outer radius in logical pixels.

§shadows: Vec<BoxShadow>

Shadow layers in caller-provided paint order.

§opacity: Opacity

Opacity multiplier applied to the decorated box.

Implementations§

Source§

impl BoxStyle

Source

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

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

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

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

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

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

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

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

pub fn opacity(self, opacity: Opacity) -> Self

Replaces the box opacity multiplier.

§Examples
use ailloli_ui_core::style::{BoxStyle, Opacity};
assert_eq!(BoxStyle::new().opacity(Opacity::new(0.5)).opacity, Opacity(0.5));

Trait Implementations§

Source§

impl Clone for BoxStyle

Source§

fn clone(&self) -> BoxStyle

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 BoxStyle

Source§

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

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

impl Default for BoxStyle

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for BoxStyle

Source§

fn eq(&self, other: &BoxStyle) -> 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 StructuralPartialEq for BoxStyle

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.