bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Introduce a FontRef

Open IceSentry opened this issue 3 years ago • 6 comments
trafficstars

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.

IceSentry avatar Jul 31 '22 18:07 IceSentry

I'm on board with this 👍

Weibye avatar Jul 31 '22 18:07 Weibye

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.

komadori avatar Jul 31 '22 20:07 komadori

Yeah, I'm in agreement with Komadori. This feels like a problem (and solution) for assets in general.

alice-i-cecile avatar Jul 31 '22 20:07 alice-i-cecile

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.

IceSentry avatar Jul 31 '22 21:07 IceSentry

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

Weibye avatar Aug 01 '22 06:08 Weibye

what would be a default scene?

The Blender cube scene 😂

Nilirad avatar Aug 01 '22 11:08 Nilirad

See also #9725.

viridia avatar Dec 05 '23 07:12 viridia