bevy
bevy copied to clipboard
Introduce a FontRef
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
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<Shader>`](bevy_asset::Assets) resource
Handle(Handle<Font>),
/// An asset path leading to a font file
Path(AssetPath<'static>),
}
This should be done alongside an impl Into<FontRef> 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.
I'm on board with this 👍
Why wouldn't you want this functionality for all types of asset? Generalise ShaderRef/FontRef to AssetRef<T> and use that in all parts of the API where the user supplies an asset.
Yeah, I'm in agreement with Komadori. This feels like a problem (and solution) for assets in general.
I'm not sure how generalizable it is. For example, what would be a default scene? For a shader the default isn't empty it's just the default mesh shader. For a font it would be a user configurable default. For images it would probably be a pink texture. For scenes and sound it would just be empty. My point being that it could be generalized, but I'd prefer waiting on the bigger asset rework to consider a more general AssetRef.
I'm not sure how generalizable it is. For example, what would be a default scene?
Yeah I think we can generalize this later once we have multiple usages of this pattern and figured out the "default-asset"-story in the engine
what would be a default scene?
The Blender cube scene 😂
See also #9725.