mirror of
https://github.com/servo/servo.git
synced 2025-08-08 15:05:35 +01:00
Move clamp_*
functions to methods of Length
This commit is contained in:
parent
8a7de32d5b
commit
a2c2b294d5
2 changed files with 34 additions and 24 deletions
|
@ -657,14 +657,14 @@ impl CSSPixelLength {
|
|||
|
||||
/// Return the containing pixel value.
|
||||
#[inline]
|
||||
pub fn px(&self) -> CSSFloat {
|
||||
pub fn px(self) -> CSSFloat {
|
||||
self.0
|
||||
}
|
||||
|
||||
/// Return the length with app_unit i32 type.
|
||||
#[inline]
|
||||
pub fn to_i32_au(&self) -> i32 {
|
||||
Au::from(*self).0
|
||||
pub fn to_i32_au(self) -> i32 {
|
||||
Au::from(self).0
|
||||
}
|
||||
|
||||
/// Return the absolute value of this length.
|
||||
|
@ -692,9 +692,29 @@ impl CSSPixelLength {
|
|||
}
|
||||
|
||||
/// Sets `self` to the maximum between `self` and `other`.
|
||||
#[inline]
|
||||
pub fn max_assign(&mut self, other: Self) {
|
||||
*self = self.max(other);
|
||||
}
|
||||
|
||||
/// Clamp the value to a lower bound and an optional upper bound.
|
||||
///
|
||||
/// Can be used for example with `min-width` and `max-width`.
|
||||
#[inline]
|
||||
pub fn clamp_between_extremums(self, min_size: Self, max_size: Option<Self>) -> Self {
|
||||
self.clamp_below_max(max_size).max(min_size)
|
||||
}
|
||||
|
||||
/// Clamp the value to an optional upper bound.
|
||||
///
|
||||
/// Can be used for example with `max-width`.
|
||||
#[inline]
|
||||
pub fn clamp_below_max(self, max_size: Option<Self>) -> Self {
|
||||
match max_size {
|
||||
None => self,
|
||||
Some(max_size) => self.min(max_size),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Zero for CSSPixelLength {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue