Introduce a FontRef
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 171
Description
## What problem does this solve or what need does it fill?
Declaring a `TextStyle` whenever you create a `Text` node is annoying because you _need_ an asset_server to load the font
## What solution would you like?
Implement a `FontRef` inspired by the `ShaderRef` of the new `Material`
Here's what I assume it would look like
```rust
pub enum FontRef{
/// Use the "default" font for the current context. This can be customized with the `FontConfig` resource
Default,
/// A handle to a shader stored in the [`Assets`](bevy_asset::Assets) resource
Handle(Handle),
/// An asset path leading to a font file
Path(AssetPath<'static>),
}
```
This should be done alongside an `impl Into for &str` to make it easy to just create a FontRef from a static string path.
## What alternative(s) have you considered?
Font inheritance would be an interesting possibility, but I think font inheritance could be implemented on top of this `FontRef`
## Additional context
This would also partially fix the lack of a default font with bevy since we could register a font once in a startup resource and just use it everytime `FontRef::Default` is used.
Contributor guide
Research direction
Start by examining Bevy's existing ShaderRef and new Material APIs, then trace how TextStyle, Text, AssetServer, and FontConfig currently handle fonts. Define the FontRef variants and string conversion described in the issue, and verify that default, handle, and asset-path font references work wherever text styles are created.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- game-dev
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100