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: LengthPreferred width; Length::Auto uses intrinsic width.
height: LengthPreferred height; Length::Auto uses intrinsic height.
min_width: LengthOptional minimum width; Length::Auto means no explicit minimum.
max_width: LengthOptional maximum width; Length::Auto means no explicit maximum.
min_height: LengthOptional minimum height; Length::Auto means no explicit minimum.
max_height: LengthOptional maximum height; Length::Auto means no explicit maximum.
margin: EdgeInsetsSpace outside the widget border in logical pixels.
padding: EdgeInsetsSpace between border and content in logical pixels.
Implementations§
Source§impl LayoutStyle
impl LayoutStyle
Sourcepub fn resolve(self, parent: Constraints) -> ResolvedLayout
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));Sourcepub fn constraints_for_children(self, inner: Constraints) -> Constraints
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
impl LayoutStyle
Sourcepub fn new() -> Self
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);Sourcepub fn width(self, width: impl Into<Length>) -> Self
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));Sourcepub fn height(self, height: impl Into<Length>) -> Self
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));Sourcepub fn fill(self) -> Self
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));Sourcepub fn fill_width(self) -> Self
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);Sourcepub fn fill_height(self) -> Self
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);Sourcepub fn min_width(self, value: impl Into<Length>) -> Self
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));Sourcepub fn max_width(self, value: impl Into<Length>) -> Self
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));Sourcepub fn min_height(self, value: impl Into<Length>) -> Self
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));Sourcepub fn max_height(self, value: impl Into<Length>) -> Self
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));Trait Implementations§
Source§impl Clone for LayoutStyle
impl Clone for LayoutStyle
Source§fn clone(&self) -> LayoutStyle
fn clone(&self) -> LayoutStyle
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more