layout: Make geom.rs logical geoemetry types more ergonomic (#32633)

Make using the logical geometry types more ergonomic by having them all
implement `Copy` (at most 4 64-bit numbers), similar to what `euclid`
does. In addition add an implementation of `Neg` for `LogicalVec` and
`LogicalSides` as it will be used in upcoming table implementation code.
This commit is contained in:
Martin Robinson 2024-06-28 10:20:50 +02:00 committed by GitHub
parent e9cf4d4971
commit adc0fc984d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 80 additions and 102 deletions

View file

@ -223,10 +223,10 @@ impl TextRunLineItem {
// The block start of the TextRun is often zero (meaning it has the same font metrics as the
// inline box's strut), but for children of the inline formatting context root or for
// fallback fonts that use baseline relatve alignment, it might be different.
let start_corner = &LogicalVec2 {
let start_corner = LogicalVec2 {
inline: state.inline_position,
block: (state.baseline_offset - self.font_metrics.ascent).into(),
} - &state.parent_offset;
} - state.parent_offset;
let rect = LogicalRect {
start_corner,
@ -283,8 +283,8 @@ impl InlineBoxLineItem {
state: &mut LineItemLayoutState,
) -> Option<BoxFragment> {
let style = self.style.clone();
let mut padding = self.pbm.padding.clone();
let mut border = self.pbm.border.clone();
let mut padding = self.pbm.padding;
let mut border = self.pbm.border;
let mut margin = self.pbm.margin.auto_is(Au::zero);
if !self.is_first_fragment {
@ -297,7 +297,7 @@ impl InlineBoxLineItem {
border.inline_end = Au::zero();
margin.inline_end = Au::zero();
}
let pbm_sums = &(&padding + &border) + &margin;
let pbm_sums = padding + border + margin;
state.inline_position += pbm_sums.inline_start.into();
let space_above_baseline = self.calculate_space_above_baseline();
@ -335,7 +335,7 @@ impl InlineBoxLineItem {
border.inline_end = Au::zero();
margin.inline_end = Au::zero();
}
let pbm_sums = &(&padding + &border) + &margin.clone();
let pbm_sums = padding + border + margin;
// If the inline box didn't have any content at all, don't add a Fragment for it.
let box_has_padding_border_or_margin = pbm_sums.inline_sum() > Au::zero();
@ -361,13 +361,13 @@ impl InlineBoxLineItem {
};
// Make `content_rect` relative to the parent Fragment.
content_rect.start_corner = &content_rect.start_corner - &state.parent_offset;
content_rect.start_corner -= state.parent_offset;
// Relative adjustment should not affect the rest of line layout, so we can
// do it right before creating the Fragment.
if style.clone_position().is_relative() {
content_rect.start_corner +=
&relative_adjustement(&style, state.ifc_containing_block).into();
relative_adjustement(&style, state.ifc_containing_block).into();
}
let mut fragment = BoxFragment::new(
@ -466,12 +466,11 @@ impl AtomicLineItem {
self.calculate_block_start(state.line_metrics).into();
// Make the final result relative to the parent box.
self.fragment.content_rect.start_corner =
&self.fragment.content_rect.start_corner - &state.parent_offset.into();
self.fragment.content_rect.start_corner -= state.parent_offset.into();
if self.fragment.style.clone_position().is_relative() {
self.fragment.content_rect.start_corner +=
&relative_adjustement(&self.fragment.style, state.ifc_containing_block);
relative_adjustement(&self.fragment.style, state.ifc_containing_block);
}
state.inline_position += self.size.inline.into();
@ -571,8 +570,7 @@ impl FloatLineItem {
inline: state.parent_offset.inline,
block: state.line_metrics.block_offset + state.parent_offset.block,
};
self.fragment.content_rect.start_corner =
&self.fragment.content_rect.start_corner - &distance_from_parent_to_ifc.into();
self.fragment.content_rect.start_corner -= distance_from_parent_to_ifc.into();
self.fragment
}
}