From befbf52a185ccefdc96044ebf92ef2d857d00ded Mon Sep 17 00:00:00 2001 From: Rob Parrett Date: Thu, 26 Oct 2023 15:09:34 -0700 Subject: [PATCH] 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. --- crates/bevy_ui/src/widget/text.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/bevy_ui/src/widget/text.rs b/crates/bevy_ui/src/widget/text.rs index 5ff128ebb6..e3fc5eb659 100644 --- a/crates/bevy_ui/src/widget/text.rs +++ b/crates/bevy_ui/src/widget/text.rs @@ -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, });