Fix crash with certain right-aligned text (#10271)

# Objective

Fixes #9395
Alternative to #9415 (See discussion here)

## Solution

Do clamping like
[`fit-content`](https://www.w3.org/TR/css-sizing-3/#column-sizing).

## Notes

I am not sure if this is a valid approach. It doesn't seem to cause any
obvious issues with our existing examples.
This commit is contained in:
Rob Parrett 2023-10-26 15:09:34 -07:00 committed by GitHub
parent e5b3cc45ba
commit befbf52a18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -53,7 +53,13 @@ impl Measure for TextMeasure {
_available_height: AvailableSpace,
) -> Vec2 {
let x = width.unwrap_or_else(|| match available_width {
AvailableSpace::Definite(x) => x.clamp(self.info.min.x, self.info.max.x),
AvailableSpace::Definite(x) => {
// It is possible for the "min content width" to be larger than
// the "max content width" when soft-wrapping right-aligned text
// and possibly other situations.
x.max(self.info.min.x).min(self.info.max.x)
}
AvailableSpace::MinContent => self.info.min.x,
AvailableSpace::MaxContent => self.info.max.x,
});