use crate::{
layout_input::LayoutInput,
layout_options::TextLayoutOptions,
line_breaker::{BreakOpportunity, BrokenLine, Wrapping},
line_text::indent,
paragraph::LineBreak,
text_layout::WidthRange,
};
pub(crate) fn fitting_hold(options: &TextLayoutOptions, line: f32) -> WidthRange {
WidthRange {
min: if options.soft_wrap {
line
} else {
f32::NEG_INFINITY
},
max: f32::INFINITY,
}
}
pub(crate) fn wrapped_hold(
lines: &[BrokenLine],
input: &LayoutInput<'_>,
options: &TextLayoutOptions,
wrapping: &Wrapping<'_>,
breaks: &[BreakOpportunity],
) -> Option<WidthRange> {
if !options.soft_wrap {
return Some(WidthRange::ALL);
}
if !matches!(
input.paragraph.line_break,
LineBreak::Simple | LineBreak::Unspecified
) {
return None;
}
let mut hold = WidthRange::ALL;
for line in lines {
let (min, max) = wrapping.greedy_limits(line, breaks);
let indent = indent(input, line.text.start);
hold.narrow(min + indent, max + indent);
}
Some(hold)
}