iced-yoda/core/src/length.rs

44 lines
1.2 KiB
Rust
Raw Normal View History

2019-09-24 15:15:34 +02:00
/// The strategy used to fill space in a specific dimension.
2022-08-17 16:09:25 +02:00
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
2019-09-20 19:15:31 +02:00
pub enum Length {
2019-11-18 07:16:19 +01:00
/// Fill all the remaining space
2019-09-20 19:15:31 +02:00
Fill,
2019-11-18 07:16:19 +01:00
/// Fill a portion of the remaining space relative to other elements.
///
/// Let's say we have two elements: one with `FillPortion(2)` and one with
/// `FillPortion(3)`. The first will get 2 portions of the available space,
/// while the second one would get 3.
///
/// `Length::Fill` is equivalent to `Length::FillPortion(1)`.
FillPortion(u16),
2019-11-18 07:16:19 +01:00
/// Fill the least amount of space
2019-09-20 19:15:31 +02:00
Shrink,
2019-11-18 07:16:19 +01:00
/// Fill a fixed amount of space
2019-09-20 19:15:31 +02:00
Units(u16),
}
impl Length {
2019-11-18 07:16:19 +01:00
/// Returns the _fill factor_ of the [`Length`].
///
/// The _fill factor_ is a relative unit describing how much of the
/// remaining space should be filled when compared to other elements. It
/// is only meant to be used by layout engines.
pub fn fill_factor(&self) -> u16 {
match self {
Length::Fill => 1,
Length::FillPortion(factor) => *factor,
Length::Shrink => 0,
Length::Units(_) => 0,
}
}
}
impl From<u16> for Length {
fn from(units: u16) -> Self {
Length::Units(units)
}
}