use super::*;
#[derive(Debug, Clone, Copy)]
pub(in crate::layout) struct InlineFloatBand {
pub(in crate::layout) span: LogicalInlineSpan,
}
impl InlineFloatBand {
pub(in crate::layout) fn new(left_offset: f32, width: f32) -> Self {
Self {
span: LogicalInlineSpan::new(left_offset, width.max(0.0)),
}
}
pub(in crate::layout) fn left_offset(self) -> f32 {
self.span.start()
}
pub(in crate::layout) fn width(self) -> f32 {
self.span.size()
}
pub(in crate::layout) fn end(self) -> f32 {
self.span.end()
}
}
#[derive(Debug, Clone, Copy)]
pub(in crate::layout) struct InlineSelectionMeasures {
containing_inline_size: f32,
float_band: InlineFloatBand,
}
impl InlineSelectionMeasures {
pub(in crate::layout) fn new(containing_inline_size: f32, float_band: InlineFloatBand) -> Self {
Self {
containing_inline_size: containing_inline_size.max(0.0),
float_band,
}
}
pub(in crate::layout) fn band_after_indent(self, indent: f32) -> f32 {
(self.float_band.width() - indent).max(0.0)
}
pub(in crate::layout) fn containing_after_indent(self, indent: f32) -> f32 {
(self.containing_inline_size - indent).max(0.0)
}
}
pub(in crate::layout) const INLINE_FLOAT_EPSILON: f32 = 0.01;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(in crate::layout) enum InlineSourceBreakability {
HasLegalSoftWrap,
Unbreakable,
}
impl InlineSourceBreakability {
pub(in crate::layout) const fn has_legal_soft_wrap(self) -> bool {
matches!(self, Self::HasLegalSoftWrap)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(in crate::layout) enum InlineFloatAffectedRange {
None,
Wrappable { marker: InlineGraphPosition },
UnbreakableContinuation { marker: InlineGraphPosition },
}
impl InlineFloatAffectedRange {
pub(in crate::layout) const fn marker(self) -> Option<InlineGraphPosition> {
match self {
Self::None => None,
Self::Wrappable { marker } | Self::UnbreakableContinuation { marker } => Some(marker),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(in crate::layout) enum InlineFloatBandPlacement {
Placed,
PlacedInZeroWidthBand,
Rejected,
}
impl InlineFloatBandPlacement {
pub(in crate::layout) const fn is_placed(self) -> bool {
matches!(self, Self::Placed | Self::PlacedInZeroWidthBand)
}
}
#[derive(Debug, Clone, Copy)]
pub(in crate::layout) struct SelectedInlineLineEnd {
pub(in crate::layout) position: InlineGraphPosition,
pub(in crate::layout) break_opportunity: Option<InlineBreakOpportunity>,
}
#[derive(Debug, Clone, Copy)]
pub(in crate::layout) struct InlineFloatPlacement {
pub(in crate::layout) line_span: PageInlineSpan,
pub(in crate::layout) prefix_width: f32,
pub(in crate::layout) post_float_span: PageInlineSpan,
pub(in crate::layout) fits_remaining_band: bool,
}
impl InlineFloatPlacement {
pub(in crate::layout) fn new(
line_left: f32,
line_right: f32,
prefix_width: f32,
post_float_span: PageInlineSpan,
fits_remaining_band: bool,
) -> Self {
Self {
line_span: PageInlineSpan::from_edges(line_left, line_right),
prefix_width: prefix_width.max(0.0),
post_float_span,
fits_remaining_band,
}
}
pub(in crate::layout) fn prefix_right(self) -> f32 {
self.line_span.left_x() + self.prefix_width
}
pub(in crate::layout) fn fits_remaining_band(self) -> bool {
self.fits_remaining_band
}
pub(in crate::layout) fn same_line_suffix_start(self) -> f32 {
self.prefix_right().max(self.post_float_span.left_x())
}
pub(in crate::layout) fn same_line_suffix_available_width(self) -> f32 {
(self.post_float_span.right_x() - self.same_line_suffix_start()).max(0.0)
}
pub(in crate::layout) fn same_line_suffix_gap(self) -> f32 {
(self.same_line_suffix_start() - self.prefix_right()).max(0.0)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn same_line_suffix_uses_post_float_exclusion_not_signed_outer_extent() {
let placement = InlineFloatPlacement::new(
0.0,
100.0,
30.0,
PageInlineSpan::from_edges(0.0, 100.0),
true,
);
assert_eq!(placement.same_line_suffix_gap(), 0.0);
assert_eq!(placement.same_line_suffix_available_width(), 70.0);
}
}
#[derive(Debug, Clone)]
pub(in crate::layout) struct CombinedInlineFloatLine {
pub(in crate::layout) end: InlineGraphPosition,
pub(in crate::layout) fragment: InlineLineFragment,
}