Skip to content

Commit

Permalink
add some quick shortcuts for 100% units
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhou121 committed Sep 27, 2023
1 parent 211ad53 commit e8c1d33
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand All @@ -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<PxPctAuto>,
Expand All @@ -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())
}
Expand All @@ -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())
}
Expand Down

0 comments on commit e8c1d33

Please sign in to comment.