use gpui::{Boundary, Pixels, px};
#[cfg(test)]
mod tests;
#[cfg(test)]
thread_local! {
pub(super) static MEASURED_LINES: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
}
#[derive(Clone, Copy, Debug)]
pub(super) struct WidthRange {
minimum: Pixels,
maximum: Pixels,
}
impl WidthRange {
pub(super) fn all() -> Self {
Self {
minimum: Pixels::MIN,
maximum: Pixels::MAX,
}
}
pub(super) fn empty() -> Self {
Self {
minimum: px(0.),
maximum: px(0.),
}
}
pub(super) fn fits(&mut self, measured: Pixels, available: Pixels, indent: Pixels) -> bool {
let fits = measured <= available;
let boundary = f32::from(measured + indent);
if fits {
self.minimum = self.minimum.max(px(boundary.next_up()));
} else {
self.maximum = self.maximum.min(px(boundary.next_down()));
}
fits
}
pub(super) fn intersect(&mut self, other: Self) {
self.minimum = self.minimum.max(other.minimum);
self.maximum = self.maximum.min(other.maximum);
}
pub(super) fn contains(self, width: Pixels) -> bool {
width >= self.minimum && width < self.maximum
}
}
pub(super) struct MeasuredWrap {
pub(super) boundaries: Vec<Boundary>,
pub(super) valid_widths: WidthRange,
}
impl MeasuredWrap {
pub(super) fn uncached(boundaries: Vec<Boundary>) -> Self {
Self {
boundaries,
valid_widths: WidthRange::empty(),
}
}
}