Remove redundant code in stack

This commit is contained in:
mkorje 2025-02-23 20:03:52 +11:00 committed by mkorje
parent 9818d257f1
commit db46115891
No known key found for this signature in database
2 changed files with 6 additions and 20 deletions

View File

@ -117,7 +117,6 @@ pub fn stack(
gap: Abs, gap: Abs,
baseline: usize, baseline: usize,
alternator: LeftRightAlternator, alternator: LeftRightAlternator,
minimum_ascent_descent: Option<(Abs, Abs)>,
) -> Frame { ) -> Frame {
let AlignmentResult { points, width } = alignments(&rows); let AlignmentResult { points, width } = alignments(&rows);
let rows: Vec<_> = rows let rows: Vec<_> = rows
@ -125,13 +124,9 @@ pub fn stack(
.map(|row| row.into_line_frame(&points, alternator)) .map(|row| row.into_line_frame(&points, alternator))
.collect(); .collect();
let padded_height = |height: Abs| {
height.max(minimum_ascent_descent.map_or(Abs::zero(), |(a, d)| a + d))
};
let mut frame = Frame::soft(Size::new( let mut frame = Frame::soft(Size::new(
width, width,
rows.iter().map(|row| padded_height(row.height())).sum::<Abs>() rows.iter().map(|row| row.height()).sum::<Abs>()
+ rows.len().saturating_sub(1) as f64 * gap, + rows.len().saturating_sub(1) as f64 * gap,
)); ));
@ -142,14 +137,11 @@ pub fn stack(
} else { } else {
Abs::zero() Abs::zero()
}; };
let ascent_padded_part = minimum_ascent_descent let pos = Point::new(x, y);
.map_or(Abs::zero(), |(a, _)| (a - row.ascent()))
.max(Abs::zero());
let pos = Point::new(x, y + ascent_padded_part);
if i == baseline { if i == baseline {
frame.set_baseline(y + row.baseline() + ascent_padded_part); frame.set_baseline(y + row.baseline());
} }
y += padded_height(row.height()) + gap; y += row.height() + gap;
frame.push_frame(pos, row); frame.push_frame(pos, row);
} }

View File

@ -312,14 +312,8 @@ fn layout_underoverspreader(
} }
}; };
let frame = stack( let frame =
rows, stack(rows, FixedAlignment::Center, gap, baseline, LeftRightAlternator::Right);
FixedAlignment::Center,
gap,
baseline,
LeftRightAlternator::Right,
None,
);
ctx.push(FrameFragment::new(styles, frame).with_class(body_class)); ctx.push(FrameFragment::new(styles, frame).with_class(body_class));
Ok(()) Ok(())