style: Add smaller, larger method to Size. (#831)

This commit is contained in:
Jason Lee 2025-05-06 15:31:11 +08:00 committed by GitHub
parent 0c6d631a39
commit 9906a482ec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -221,6 +221,28 @@ impl Size {
},
}
}
/// Returns a smaller size.
pub fn smaller(&self) -> Self {
match self {
Size::XSmall => Size::XSmall,
Size::Small => Size::XSmall,
Size::Medium => Size::Small,
Size::Large => Size::Medium,
Size::Size(val) => Size::Size(*val * 0.2),
}
}
/// Returns a larger size.
pub fn larger(&self) -> Self {
match self {
Size::XSmall => Size::Small,
Size::Small => Size::Medium,
Size::Medium => Size::Large,
Size::Large => Size::Large,
Size::Size(val) => Size::Size(*val * 1.2),
}
}
}
impl From<Pixels> for Size {