Skip to main content

PaintStyle

Struct PaintStyle 

Source
pub struct PaintStyle {
    pub bg: Option<Color32>,
    pub border: Option<Stroke>,
    pub radius: Option<f32>,
    pub shadow: bool,
    pub custom_shadow: Option<Shadow>,
    pub opacity: Option<f32>,
}
Expand description

How a box looks: background, border, corner radius, shadow and opacity.

Every field is optional and Default paints nothing, so an element that nobody styled costs no shapes at all.

The three shapes all sit on the node’s border box — its whole box, not the content rect — and share one radius. A border of width n is also reserved by the layout (ItemStyle::to_taffy sets taffy’s border), so the stroke is drawn StrokeKind::Inside and lands exactly in the band the children were kept out of.

Fields§

§bg: Option<Color32>

Background colour, filled behind the children or the widget.

§border: Option<Stroke>

Border stroke, drawn on top of them and reserved by the layout.

§radius: Option<f32>

Corner radius, shared by the shadow, the background and the border.

§shadow: bool

Cast the theme’s Visuals::window_shadow.

§custom_shadow: Option<Shadow>

Cast this shadow instead, whatever shadow says.

§opacity: Option<f32>

Multiply the opacity of the node and everything under it.

Implementations§

Source§

impl PaintStyle

Source

pub fn bg(self, v: impl Into<Color32>) -> Self

Set the background colour.

Source

pub fn border(self, v: impl Into<Stroke>) -> Self

Set the border stroke. The layout reserves its width.

Source

pub fn radius(self, v: f32) -> Self

Set the corner radius of all three shapes.

Source

pub fn shadow(self, v: bool) -> Self

Cast the theme’s window shadow, or stop casting it.

Source

pub fn custom_shadow(self, v: Shadow) -> Self

Cast this shadow instead of the theme’s.

Source

pub fn opacity(self, v: f32) -> Self

Multiply the opacity of this node and everything under it.

Source

pub fn is_none(&self) -> bool

Whether this style does nothing, so the engine can skip the node.

radius alone does not count: it only rounds shapes that another field asks for. opacity does, even though it draws nothing itself, because the engine still has to set it around the children.

Source

pub fn shadow_shape(&self, rect: Rect, visuals: &Visuals) -> Option<Shape>

The shadow shape under rect, if this style casts one.

custom_shadow wins over shadow; shadow alone is the theme’s window shadow, which is why this needs the Visuals. Shadow::as_shape offsets and expands the rect itself, so rect is the plain border box.

Source

pub fn bg_shape(&self, rect: Rect) -> Option<Shape>

The background shape filling rect, if there is a bg.

Source

pub fn border_shape(&self, rect: Rect) -> Option<Shape>

The border shape around rect, if there is a border.

StrokeKind::Inside: the layout already reserved the stroke’s width inside the border box, so drawing it there costs no extra room and two neighbours with borders do not overlap.

Trait Implementations§

Source§

impl Clone for PaintStyle

Source§

fn clone(&self) -> PaintStyle

Returns a duplicate 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 PaintStyle

Source§

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

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

impl Default for PaintStyle

Source§

fn default() -> PaintStyle

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

impl PartialEq for PaintStyle

Source§

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

Source§

impl StructuralPartialEq for PaintStyle

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

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

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,