Skip to main content

Shadow

Struct Shadow 

Source
pub struct Shadow {
    pub x: f32,
    pub y: f32,
    pub blur: f32,
    pub spread: f32,
    pub color: Color,
    pub cut_out: bool,
    pub follow_content: bool,
}
Expand description

A shadow cast by a widget’s box, as CSS’s box-shadow: the box’s shape moved by x and y, grown by spread and blurred over blur logical pixels. Unlike CSS’s, it is drawn under the box too, so a translucent background shows it through, unless it is cut_out.

use crabshell_ui::{Color, Shadow, Style};

const CARD: Style = Style::new()
    .background(Color::hex("#1e1e2e"))
    .radius(8.0)
    .shadow(Shadow::new(0.0, 4.0, 12.0, Color::rgba(0, 0, 0, 96)));

Fields§

§x: f32

How far right it is moved.

§y: f32

How far down it is moved.

§blur: f32

How far its edge is blurred. 0 is a sharp edge.

§spread: f32

How much larger than the box it is on each side, or smaller when negative.

§color: Color

Its color.

§cut_out: bool

Whether it is left out under the box, as under translucent glass.

§follow_content: bool

Whether it is cast by what the widget and its children draw, through their alpha, instead of by its box.

Implementations§

Source§

impl Shadow

Source

pub const fn new(x: f32, y: f32, blur: f32, color: Color) -> Shadow

A shadow moved by x and y and blurred over blur, the box’s size.

Source

pub const fn spread(self, spread: f32) -> Shadow

The same shadow spread larger on each side.

Source

pub const fn cut_out(self) -> Shadow

The same shadow left out under the box’s own shape, so a translucent background, such as glass the compositor blurs, shows what is behind it instead of the shadow. CSS’s box-shadow is always drawn this way.

Source

pub const fn follow_content(self) -> Shadow

The same shadow cast by what the widget and everything inside it draw, through their alpha, instead of by its box, so text and icons get a drop shadow, as Qt’s MultiEffect shadow gives. It is drawn under them, offset, spread and blurred as a box shadow is, and after a mask, so it follows the masked shape. Cut out, it is left out under the content’s own alpha.

use crabshell_ui::{Color, Shadow, Style};

const LABEL: Style = Style::new()
    .color(Color::hex("#cdd6f4"))
    .shadow(Shadow::new(0.0, 1.0, 3.0, Color::rgba(0, 0, 0, 160)).follow_content());
Source

pub fn casts_from_content(&self) -> bool

Whether this shadow is cast by the content and can be: its numbers are finite and it reaches at most 64 logical pixels past what casts it, the size of its spread plus one and a half blurs. One reaching farther is left out whole and the content drawn without it, so the work of casting it stays bounded.

Trait Implementations§

Source§

impl Clone for Shadow

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Shadow

Source§

impl Debug for Shadow

Source§

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

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

impl PartialEq for Shadow

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Shadow

Auto Trait Implementations§

§

impl Forget for Shadow

§

impl Freeze for Shadow

§

impl Move for Shadow

§

impl RefUnwindSafe for Shadow

§

impl Send for Shadow

§

impl Sync for Shadow

§

impl Unpin for Shadow

§

impl UnsafeUnpin for Shadow

§

impl UnwindSafe for Shadow

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

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more