Skip to content

Replace from_ constructors on TextFont with From impls #20450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions crates/bevy_text/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,21 +305,11 @@ pub struct TextFont {
}

impl TextFont {
/// Returns a new [`TextFont`] with the specified font face handle.
pub fn from_font(font: Handle<Font>) -> Self {
Self::default().with_font(font)
}

/// Returns a new [`TextFont`] with the specified font size.
pub fn from_font_size(font_size: f32) -> Self {
Self::default().with_font_size(font_size)
}

/// Returns a new [`TextFont`] with the specified line height.
pub fn from_line_height(line_height: LineHeight) -> Self {
Self::default().with_line_height(line_height)
}

/// Returns this [`TextFont`] with the specified font face handle.
pub fn with_font(mut self, font: Handle<Font>) -> Self {
self.font = font;
Expand Down
2 changes: 1 addition & 1 deletion examples/testbed/2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ mod text {
);
}

let sans_serif = TextFont::from_font(asset_server.load("fonts/FiraSans-Bold.ttf"));
let sans_serif = TextFont::from(asset_server.load("fonts/FiraSans-Bold.ttf"));

const NUM_ITERATIONS: usize = 10;
for i in 0..NUM_ITERATIONS {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
title: `TextFont` constructor methods replaced with `From` impls
pull_requests: [20335, 20450]
---

The `TextFont::from_font` and `TextFont::from_line_height` constructor methods have been removed in favor of `From` trait implementations.

```rust
// 0.16
let text_font = TextFont::from_font(font_handle);
let text_font = TextFont::from_line_height(line_height);

// 0.17
Comment on lines +9 to +13
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed 0.17 cutoff so:

Suggested change
// 0.16
let text_font = TextFont::from_font(font_handle);
let text_font = TextFont::from_line_height(line_height);
// 0.17
// 0.17
let text_font = TextFont::from_font(font_handle);
let text_font = TextFont::from_line_height(line_height);
// 0.18

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the intent here for this PR to wait until 0.17's release to get this change in? This otherwise seems trivial.

let text_font = TextFont::from(font_handle);
let text_font = TextFont::from(line_height);
```
Loading