Struct LayoutStyle

Source
pub struct LayoutStyle {
    pub width: Length,
    pub height: Length,
    pub min_width: Length,
    pub max_width: Length,
    pub min_height: Length,
    pub max_height: Length,
    pub margin: EdgeInsets,
    pub padding: EdgeInsets,
}
Expand description

Per-widget layout: dimensions, min/max, margin, and padding.

§Examples

use ailloli_ui_core::style::{LayoutStyle, Length};
let layout = LayoutStyle::new().width(120.0).fill_height().padding(8.0);
assert_eq!(layout.width, Length::Px(120.0));

Fields§

§width: Length

Preferred width; Length::Auto uses intrinsic width.

§height: Length

Preferred height; Length::Auto uses intrinsic height.

§min_width: Length

Optional minimum width; Length::Auto means no explicit minimum.

§max_width: Length

Optional maximum width; Length::Auto means no explicit maximum.

§min_height: Length

Optional minimum height; Length::Auto means no explicit minimum.

§max_height: Length

Optional maximum height; Length::Auto means no explicit maximum.

§margin: EdgeInsets

Space outside the widget border in logical pixels.

§padding: EdgeInsets

Space between border and content in logical pixels.

Implementations§

Source§

impl LayoutStyle

Source

pub fn resolve(self, parent: Constraints) -> ResolvedLayout

Resolves width, height, and min/max lengths against parent maximums.

Every percentage and fill value uses the corresponding stored parent maximum. Margin and padding do not participate in this operation.

§Examples
use ailloli_ui_core::Constraints;
use ailloli_ui_core::style::LayoutStyle;
assert_eq!(LayoutStyle::new().width(50.0).resolve(Constraints::loose(100.0, 80.0)).width, Some(50.0));
Source

pub fn constraints_for_children(self, inner: Constraints) -> Constraints

Derives normalized constraints for children from an already inner box.

The caller is responsible for removing margin/padding before passing inner. Explicit dimensions narrow both bounds; min/max declarations then tighten their matching side. The final intervals are reordered if the declarations cross.

§Examples
use ailloli_ui_core::Constraints;
use ailloli_ui_core::style::LayoutStyle;
let children = LayoutStyle::new().width(40.0).constraints_for_children(Constraints::loose(100.0, 80.0));
assert_eq!((children.min_w, children.max_w), (40.0, 40.0));
Source§

impl LayoutStyle

Source

pub fn new() -> Self

Creates an entirely automatic layout with zero margin and padding.

§Examples
use ailloli_ui_core::style::{LayoutStyle, Length};
assert_eq!(LayoutStyle::new().width, Length::Auto);
Source

pub fn width(self, width: impl Into<Length>) -> Self

Replaces the preferred width.

§Examples
use ailloli_ui_core::style::{LayoutStyle, Length};
assert_eq!(LayoutStyle::new().width(20.0).width, Length::Px(20.0));
Source

pub fn height(self, height: impl Into<Length>) -> Self

Replaces the preferred height.

§Examples
use ailloli_ui_core::style::{LayoutStyle, Length};
assert_eq!(LayoutStyle::new().height(20.0).height, Length::Px(20.0));
Source

pub fn fill(self) -> Self

Sets both preferred axes to Length::Fill.

§Examples
use ailloli_ui_core::style::{LayoutStyle, Length};
let layout = LayoutStyle::new().fill();
assert_eq!((layout.width, layout.height), (Length::Fill, Length::Fill));
Source

pub fn fill_width(self) -> Self

Sets only preferred width to Length::Fill.

§Examples
use ailloli_ui_core::style::{LayoutStyle, Length};
assert_eq!(LayoutStyle::new().fill_width().width, Length::Fill);
Source

pub fn fill_height(self) -> Self

Sets only preferred height to Length::Fill.

§Examples
use ailloli_ui_core::style::{LayoutStyle, Length};
assert_eq!(LayoutStyle::new().fill_height().height, Length::Fill);
Source

pub fn min_width(self, value: impl Into<Length>) -> Self

Replaces the minimum-width declaration.

§Examples
use ailloli_ui_core::style::{LayoutStyle, Length};
assert_eq!(LayoutStyle::new().min_width(10.0).min_width, Length::Px(10.0));
Source

pub fn max_width(self, value: impl Into<Length>) -> Self

Replaces the maximum-width declaration.

§Examples
use ailloli_ui_core::style::{LayoutStyle, Length};
assert_eq!(LayoutStyle::new().max_width(10.0).max_width, Length::Px(10.0));
Source

pub fn min_height(self, value: impl Into<Length>) -> Self

Replaces the minimum-height declaration.

§Examples
use ailloli_ui_core::style::{LayoutStyle, Length};
assert_eq!(LayoutStyle::new().min_height(10.0).min_height, Length::Px(10.0));
Source

pub fn max_height(self, value: impl Into<Length>) -> Self

Replaces the maximum-height declaration.

§Examples
use ailloli_ui_core::style::{LayoutStyle, Length};
assert_eq!(LayoutStyle::new().max_height(10.0).max_height, Length::Px(10.0));
Source

pub fn padding(self, value: f32) -> Self

Replaces all four padding edges with value logical pixels.

The value is stored verbatim, including negative or non-finite input.

§Examples
use ailloli_ui_core::style::LayoutStyle;
assert_eq!(LayoutStyle::new().padding(8.0).padding.left, 8.0);
Source

pub fn margin(self, value: f32) -> Self

Replaces all four margin edges with value logical pixels.

The value is stored verbatim, including negative or non-finite input.

§Examples
use ailloli_ui_core::style::LayoutStyle;
assert_eq!(LayoutStyle::new().margin(8.0).margin.top, 8.0);

Trait Implementations§

Source§

impl Clone for LayoutStyle

Source§

fn clone(&self) -> LayoutStyle

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 LayoutStyle

Source§

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

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

impl Default for LayoutStyle

Source§

fn default() -> Self

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

impl PartialEq for LayoutStyle

Source§

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

Source§

impl StructuralPartialEq for LayoutStyle

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.