Skip to main content

Padding

Struct Padding 

Source
pub struct Padding {
    pub top: f32,
    pub right: f32,
    pub bottom: f32,
    pub left: f32,
}
Expand description

An amount of space to pad for each side of a box

You can leverage the From trait to build Padding conveniently:

let padding = Padding::from(20);              // 20px on all sides
let padding = Padding::from([10, 20]);        // top/bottom, left/right

Normally, the padding method of a widget will ask for an Into<Padding>, so you can easily write:

impl Widget {
    pub fn padding(mut self, padding: impl Into<Padding>) -> Self {
        // ...
        self
    }
}

let widget = Widget::new().padding(20);              // 20px on all sides
let widget = Widget::new().padding([10, 20]);        // top/bottom, left/right

Fields§

§top: f32

Top padding

§right: f32

Right padding

§bottom: f32

Bottom padding

§left: f32

Left padding

Implementations§

Source§

impl Padding

Source

pub const ZERO: Padding

Padding of zero

Source

pub const fn new(padding: f32) -> Padding

Create a Padding that is equal on all sides.

Source

pub fn top(self, top: impl Into<Pixels>) -> Self

Sets the top of the Padding.

Source

pub fn bottom(self, bottom: impl Into<Pixels>) -> Self

Sets the bottom of the Padding.

Source

pub fn left(self, left: impl Into<Pixels>) -> Self

Sets the left of the Padding.

Source

pub fn right(self, right: impl Into<Pixels>) -> Self

Sets the right of the Padding.

Source

pub fn vertical(self) -> f32

Returns the total amount of vertical Padding.

Source

pub fn horizontal(self) -> f32

Returns the total amount of horizontal Padding.

Source

pub fn fit(self, inner: Size, outer: Size) -> Self

Fits the Padding between the provided inner and outer Size.

Trait Implementations§

Source§

impl Clone for Padding

Source§

fn clone(&self) -> Padding

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 Padding

Source§

impl Debug for Padding

Source§

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

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

impl Default for Padding

Source§

fn default() -> Padding

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

impl From<Padding> for Size

Source§

fn from(padding: Padding) -> Self

Converts to this type from the input type.
Source§

impl From<Pixels> for Padding

Source§

fn from(pixels: Pixels) -> Self

Converts to this type from the input type.
Source§

impl From<[f32; 2]> for Padding

Source§

fn from(p: [f32; 2]) -> Self

Converts to this type from the input type.
Source§

impl From<[u16; 2]> for Padding

Source§

fn from(p: [u16; 2]) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for Padding

Source§

fn from(p: f32) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for Padding

Source§

fn from(p: u16) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Padding

Source§

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

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