Skip to content
Permalink
Browse files

Add `util::clamp` function

  • Loading branch information
notriddle committed Sep 27, 2016
1 parent fe20186 commit abe8c0d457e51940b85675fdd3679cc9fbca2e75
Showing with 12 additions and 5 deletions.
  1. +2 −5 components/layout/block.rs
  2. +10 −0 components/util/lib.rs
@@ -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.
@@ -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();

@@ -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.
You can’t perform that action at this time.