From e8c1d33454a0a0dc0d009dd140b93513357b55a0 Mon Sep 17 00:00:00 2001 From: Dongdong Zhou Date: Wed, 27 Sep 2023 21:11:26 +0100 Subject: [PATCH] add some quick shortcuts for 100% units --- src/style.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/style.rs b/src/style.rs index 5a5076e0..dc8b54c8 100644 --- a/src/style.rs +++ b/src/style.rs @@ -325,10 +325,18 @@ define_styles!( ); impl Style { + pub fn width_full(self) -> Self { + self.width_pct(100.0) + } + pub fn width_pct(self, width: f64) -> Self { self.width(width.pct()) } + pub fn height_full(self) -> Self { + self.height_pct(100.0) + } + pub fn height_pct(self, height: f64) -> Self { self.height(height.pct()) } @@ -337,18 +345,34 @@ impl Style { self.width(width).height(height) } + pub fn size_full(self) -> Self { + self.size_pct(100.0, 100.0) + } + pub fn size_pct(self, width: f64, height: f64) -> Self { self.width(width.pct()).height(height.pct()) } + pub fn min_width_full(self) -> Self { + self.min_width_pct(100.0) + } + pub fn min_width_pct(self, min_width: f64) -> Self { self.min_width(min_width.pct()) } + pub fn min_height_full(self) -> Self { + self.min_height_pct(100.0) + } + pub fn min_height_pct(self, min_height: f64) -> Self { self.min_height(min_height.pct()) } + pub fn min_size_full(self) -> Self { + self.min_size_pct(100.0, 100.0) + } + pub fn min_size( self, min_width: impl Into, @@ -361,10 +385,18 @@ impl Style { self.min_size(min_width.pct(), min_height.pct()) } + pub fn max_width_full(self) -> Self { + self.max_width_pct(100.0) + } + pub fn max_width_pct(self, max_width: f64) -> Self { self.max_width(max_width.pct()) } + pub fn max_height_full(self) -> Self { + self.max_height_pct(100.0) + } + pub fn max_height_pct(self, max_height: f64) -> Self { self.max_height(max_height.pct()) } @@ -377,6 +409,10 @@ impl Style { self.max_width(max_width).max_height(max_height) } + pub fn max_size_full(self) -> Self { + self.max_size_pct(100.0, 100.0) + } + pub fn max_size_pct(self, max_width: f64, max_height: f64) -> Self { self.max_size(max_width.pct(), max_height.pct()) }