This commit is contained in:
2026-07-15 08:11:18 -04:00
parent 3d48c2170f
commit 5a138aecde
3 changed files with 53 additions and 9 deletions
+14 -1
View File
@@ -9,6 +9,7 @@ pub enum Size {
Fixed(u16),
Flex(u16),
Percent(u16),
Fill,
}
#[derive(Debug, Clone, Copy)]
@@ -20,17 +21,22 @@ pub struct Rect {
}
impl Size {
pub fn is_fill(&self) -> bool {
matches!(self, Self::Fill)
}
pub fn get_fixed(&self, alloc: u16) -> u16 {
match self {
Self::Fixed(v) => *v,
Self::Percent(v) => alloc * (*v) / 100,
Self::Flex(_) => 0,
Self::Flex(_) | Self::Fill => 0,
}
}
pub fn get_flex(&self) -> u16 {
match self {
Self::Flex(f) => *f,
Self::Fill => 1,
_ => 0,
}
}
@@ -46,6 +52,13 @@ impl Size {
remaining * v / total_weight
}
}
Self::Fill => {
if total_weight == 0 {
0
} else {
remaining / total_weight
}
}
}
}
}