Skip to content

Commit 4dd805a

Browse files
authored
Adds some helpful methods to TextFont (#16370)
# Objective - Add methods to facilitate `TextFont` component creation and insertion. ## Solution - Added `from_font` and `from_font_size` which return a new `TextFont` with said attributes provided as parameters. - Added `with_font` and `with_font_size` which return an existing `TextFont` modifying said attributes with the values provided as parameters. ## Testing - CI Checks. - Tested methods locally by changing values and running the `text_debug` example.
1 parent 81db6ec commit 4dd805a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

crates/bevy_text/src/text.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,28 @@ pub struct TextFont {
289289
}
290290

291291
impl TextFont {
292+
/// Returns a new [`TextFont`] with the specified font face handle.
293+
pub fn from_font(font: Handle<Font>) -> Self {
294+
Self::default().with_font(font)
295+
}
296+
297+
/// Returns a new [`TextFont`] with the specified font size.
298+
pub fn from_font_size(font_size: f32) -> Self {
299+
Self::default().with_font_size(font_size)
300+
}
301+
302+
/// Returns this [`TextFont`] with the specified font face handle.
303+
pub fn with_font(mut self, font: Handle<Font>) -> Self {
304+
self.font = font;
305+
self
306+
}
307+
308+
/// Returns this [`TextFont`] with the specified font size.
309+
pub const fn with_font_size(mut self, font_size: f32) -> Self {
310+
self.font_size = font_size;
311+
self
312+
}
313+
292314
/// Returns this [`TextFont`] with the specified [`FontSmoothing`].
293315
pub const fn with_font_smoothing(mut self, font_smoothing: FontSmoothing) -> Self {
294316
self.font_smoothing = font_smoothing;

0 commit comments

Comments
 (0)