Skip to content

Commit 56c4100

Browse files
authored
Remove scale_value (#20589)
# Objective Remove this function: ``` /// Scales `value` by `factor`. pub fn scale_value(value: f32, factor: f32) -> f32 { value * factor } ``` ## Solution Replace it with a multiplication.
1 parent 3225068 commit 56c4100

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

crates/bevy_text/src/text2d.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,9 @@ pub fn update_text2d_layout(
198198
width: if block.linebreak == LineBreak::NoWrap {
199199
None
200200
} else {
201-
bounds.width.map(|width| scale_value(width, scale_factor))
201+
bounds.width.map(|width| width * scale_factor)
202202
},
203-
height: bounds
204-
.height
205-
.map(|height| scale_value(height, scale_factor)),
203+
height: bounds.height.map(|height| height * scale_factor),
206204
};
207205

208206
let text_layout_info = text_layout_info.into_inner();
@@ -229,21 +227,13 @@ pub fn update_text2d_layout(
229227
panic!("Fatal error when processing text: {e}.");
230228
}
231229
Ok(()) => {
232-
text_layout_info.size.x =
233-
scale_value(text_layout_info.size.x, inverse_scale_factor);
234-
text_layout_info.size.y =
235-
scale_value(text_layout_info.size.y, inverse_scale_factor);
230+
text_layout_info.size *= inverse_scale_factor;
236231
}
237232
}
238233
}
239234
}
240235
}
241236

242-
/// Scales `value` by `factor`.
243-
pub fn scale_value(value: f32, factor: f32) -> f32 {
244-
value * factor
245-
}
246-
247237
/// System calculating and inserting an [`Aabb`] component to entities with some
248238
/// [`TextLayoutInfo`] and [`Anchor`] components, and without a [`NoFrustumCulling`] component.
249239
///

crates/bevy_ui/src/widget/text.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ use bevy_image::prelude::*;
1818
use bevy_math::Vec2;
1919
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
2020
use bevy_text::{
21-
scale_value, ComputedTextBlock, CosmicFontSystem, Font, FontAtlasSets, LineBreak, SwashCache,
22-
TextBounds, TextColor, TextError, TextFont, TextLayout, TextLayoutInfo, TextMeasureInfo,
23-
TextPipeline, TextReader, TextRoot, TextSpanAccess, TextWriter,
21+
ComputedTextBlock, CosmicFontSystem, Font, FontAtlasSets, LineBreak, SwashCache, TextBounds,
22+
TextColor, TextError, TextFont, TextLayout, TextLayoutInfo, TextMeasureInfo, TextPipeline,
23+
TextReader, TextRoot, TextSpanAccess, TextWriter,
2424
};
2525
use taffy::style::AvailableSpace;
2626
use tracing::error;
@@ -367,8 +367,7 @@ fn queue_text(
367367
panic!("Fatal error when processing text: {e}.");
368368
}
369369
Ok(()) => {
370-
text_layout_info.size.x = scale_value(text_layout_info.size.x, inverse_scale_factor);
371-
text_layout_info.size.y = scale_value(text_layout_info.size.y, inverse_scale_factor);
370+
text_layout_info.size *= inverse_scale_factor;
372371
text_flags.needs_recompute = false;
373372
}
374373
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
title: Remove `scale_value`
3+
pull_requests: [19143]
4+
---
5+
6+
The `scale_value` function from `bevy::text::text2d` has been removed. Multiply by the scale factor instead.

0 commit comments

Comments
 (0)