Skip to content

Commit

Permalink
Add util::clamp function
Browse files Browse the repository at this point in the history
  • Loading branch information
notriddle committed Sep 27, 2016
1 parent fe20186 commit abe8c0d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
7 changes: 2 additions & 5 deletions components/layout/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ use style::logical_geometry::{LogicalPoint, LogicalRect, LogicalSize, WritingMod
use style::properties::ServoComputedValues;
use style::values::computed::{LengthOrNone, LengthOrPercentageOrNone};
use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto};
use util::clamp;
use util::geometry::max_rect;

/// The number of screens of data we're allowed to generate display lists for in each direction.
Expand Down Expand Up @@ -1534,12 +1535,8 @@ impl BlockFlow {
box_sizing::T::content_box =>
size + self.fragment.border_padding.inline_start_end(),
}
} else if available_inline_size > max_inline_size {
max_inline_size
} else if available_inline_size < min_inline_size {
min_inline_size
} else {
available_inline_size
clamp(min_inline_size, available_inline_size, max_inline_size)
};
self.base.position.size.inline = inline_size + self.fragment.margin.inline_start_end();

Expand Down
10 changes: 10 additions & 0 deletions components/util/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,13 @@ pub fn servo_version() -> String {
None => format!("Servo {}", cargo_version),
}
}

pub fn clamp<T: Ord>(lo: T, mid: T, hi: T) -> T {
if mid < lo {
lo
} else if mid > hi {
hi
} else {
mid
}
}

0 comments on commit abe8c0d

Please sign in to comment.