From 9906a482ec1160a59cc364a090f0e51fabd6ee6e Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Tue, 6 May 2025 15:31:11 +0800 Subject: [PATCH] style: Add `smaller`, `larger` method to Size. (#831) --- crates/ui/src/styled.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/crates/ui/src/styled.rs b/crates/ui/src/styled.rs index 41ece208..80192f83 100644 --- a/crates/ui/src/styled.rs +++ b/crates/ui/src/styled.rs @@ -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 for Size {