pub enum DimensionValue {
Fixed(Px),
Wrap {
min: Option<Px>,
max: Option<Px>,
},
Fill {
min: Option<Px>,
max: Option<Px>,
},
}
Expand description
Defines how a dimension (width or height) should be calculated.
This enum represents the three fundamental sizing strategies available in Tessera’s layout system. Each variant provides different behavior for how a component determines its size in a given dimension.
Variants§
Fixed(Px)
The dimension is a fixed value in logical pixels.
This variant represents a component that has a specific, unchanging size. Fixed dimensions cannot be overridden by parent constraints and will always maintain their specified size regardless of available space.
§Example
let button_width = DimensionValue::Fixed(Px(120));
Wrap
The dimension should wrap its content, optionally bounded by min and/or max logical pixels.
This variant represents a component that sizes itself based on its content. The component will be as small as possible while still containing all its content, but can be constrained by optional minimum and maximum bounds.
§Parameters
min
: Optional minimum size - the component will never be smaller than thismax
: Optional maximum size - the component will never be larger than this
§Examples
// Text that wraps to its content size
let text_width = DimensionValue::Wrap { min: None, max: None };
// Text with minimum width to prevent being too narrow
let min_text_width = DimensionValue::Wrap { min: Some(Px(100)), max: None };
// Text that wraps but never exceeds container width
let bounded_text = DimensionValue::Wrap { min: Some(Px(50)), max: Some(Px(300)) };
Fill
The dimension should fill the available space, optionally bounded by min and/or max logical pixels.
This variant represents a component that expands to use all available space provided by its parent. The expansion can be constrained by optional minimum and maximum bounds.
§Parameters
min
: Optional minimum size - the component will never be smaller than thismax
: Optional maximum size - the component will never be larger than this
§Examples
// Fill all available space
let flexible_width = DimensionValue::Fill { min: None, max: None };
// Fill space but ensure minimum usability
let min_fill_width = DimensionValue::Fill { min: Some(Px(200)), max: None };
// Fill space but cap maximum size for readability
let capped_fill = DimensionValue::Fill { min: Some(Px(100)), max: Some(Px(800)) };
Implementations§
Source§impl DimensionValue
impl DimensionValue
Sourcepub fn to_max_px(&self, default: Px) -> Px
pub fn to_max_px(&self, default: Px) -> Px
Converts this dimension value to a maximum pixel value.
This method is useful during layout calculation when you need to determine the maximum space a component might occupy.
§Parameters
default
: The value to use when no maximum is specified
§Returns
- For
Fixed
: Returns the fixed value - For
Wrap
andFill
: Returns themax
value if specified, otherwise thedefault
§Example
let fixed = DimensionValue::Fixed(Px(100));
assert_eq!(fixed.to_max_px(Px(200)), Px(100));
let wrap_unbounded = DimensionValue::Wrap { min: None, max: None };
assert_eq!(wrap_unbounded.to_max_px(Px(200)), Px(200));
let wrap_bounded = DimensionValue::Wrap { min: None, max: Some(Px(150)) };
assert_eq!(wrap_bounded.to_max_px(Px(200)), Px(150));
Sourcepub fn get_max(&self) -> Option<Px>
pub fn get_max(&self) -> Option<Px>
Returns the maximum value of this dimension, if defined.
This method extracts the maximum constraint from a dimension value, which is useful for layout calculations and constraint validation.
§Returns
- For
Fixed
: ReturnsSome(fixed_value)
since fixed dimensions have an implicit maximum - For
Wrap
andFill
: Returns themax
value if specified, otherwiseNone
§Example
let fixed = DimensionValue::Fixed(Px(100));
assert_eq!(fixed.get_max(), Some(Px(100)));
let wrap_bounded = DimensionValue::Wrap { min: Some(Px(50)), max: Some(Px(200)) };
assert_eq!(wrap_bounded.get_max(), Some(Px(200)));
let wrap_unbounded = DimensionValue::Wrap { min: None, max: None };
assert_eq!(wrap_unbounded.get_max(), None);
Sourcepub fn get_min(&self) -> Option<Px>
pub fn get_min(&self) -> Option<Px>
Returns the minimum value of this dimension, if defined.
This method extracts the minimum constraint from a dimension value, which is useful for layout calculations and ensuring components maintain their minimum required size.
§Returns
- For
Fixed
: ReturnsSome(fixed_value)
since fixed dimensions have an implicit minimum - For
Wrap
andFill
: Returns themin
value if specified, otherwiseNone
§Example
let fixed = DimensionValue::Fixed(Px(100));
assert_eq!(fixed.get_min(), Some(Px(100)));
let fill_bounded = DimensionValue::Fill { min: Some(Px(50)), max: Some(Px(200)) };
assert_eq!(fill_bounded.get_min(), Some(Px(50)));
let fill_unbounded = DimensionValue::Fill { min: None, max: None };
assert_eq!(fill_unbounded.get_min(), None);
Trait Implementations§
Source§impl Add<Px> for DimensionValue
impl Add<Px> for DimensionValue
Source§impl AddAssign<Px> for DimensionValue
impl AddAssign<Px> for DimensionValue
Source§fn add_assign(&mut self, rhs: Px)
fn add_assign(&mut self, rhs: Px)
+=
operation. Read moreSource§impl Clone for DimensionValue
impl Clone for DimensionValue
Source§fn clone(&self) -> DimensionValue
fn clone(&self) -> DimensionValue
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for DimensionValue
impl Debug for DimensionValue
Source§impl Default for DimensionValue
impl Default for DimensionValue
Source§impl From<Dp> for DimensionValue
impl From<Dp> for DimensionValue
Source§impl From<Px> for DimensionValue
impl From<Px> for DimensionValue
Source§impl Hash for DimensionValue
impl Hash for DimensionValue
Source§impl PartialEq for DimensionValue
impl PartialEq for DimensionValue
Source§impl Sub<Px> for DimensionValue
impl Sub<Px> for DimensionValue
Source§impl SubAssign<Px> for DimensionValue
impl SubAssign<Px> for DimensionValue
Source§fn sub_assign(&mut self, rhs: Px)
fn sub_assign(&mut self, rhs: Px)
-=
operation. Read moreimpl Copy for DimensionValue
impl Eq for DimensionValue
impl StructuralPartialEq for DimensionValue
Auto Trait Implementations§
impl Freeze for DimensionValue
impl RefUnwindSafe for DimensionValue
impl Send for DimensionValue
impl Sync for DimensionValue
impl Unpin for DimensionValue
impl UnwindSafe for DimensionValue
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.