-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
add a default font #8445
add a default font #8445
Conversation
Is there any kind of licensing concerns when distributing a font like that? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is an important enough UX win that I'm fine to eat the cost of having this on by default.
Feature flag means that in real projects this is actually zero cost. This is by far the simplest solution to this problem, and will make prototyping and examples much quicker.
The font appears to already be listed in https://github.com/bevyengine/bevy/blob/main/CREDITS.md. The license for them does not appear to impose any relevant restrictions, either to us or to downstream users. |
Can you configure the default font for your entire app? |
No: this is baked into the source code of Bevy (when using the provided feature flag). Better theming support is also important, but this feature is strictly intended for easy debugging and teaching. |
Yes, if you set the default font handle to another font, it will be used by default in your app. But then that doesn't depend on this PR, this already works... Something like: use bevy::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.add_systems(
Update,
set_default_font.run_if(resource_exists::<FontHandle>()),
)
.run();
}
#[derive(Resource)]
struct FontHandle(Handle<Font>);
fn set_default_font(
mut commands: Commands,
mut fonts: ResMut<Assets<Font>>,
font_handle: Res<FontHandle>,
) {
if let Some(font) = fonts.remove(&font_handle.0) {
fonts.set_untracked(TextStyle::default().font, font);
commands.remove_resource::<FontHandle>();
}
}
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
let font = asset_server.load("fonts/FiraSans-Bold.ttf");
commands.insert_resource(FontHandle(font));
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally in favor of this. Glad you could slim the fira font down so much!
@@ -67,6 +73,10 @@ pub enum YAxisOrientation { | |||
BottomToTop, | |||
} | |||
|
|||
#[cfg(feature = "default_font")] | |||
pub const DEFAULT_FONT_HANDLE: HandleUntyped = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @UkoeHB: I think this should not be behind a feature flag so other people can set the default font (without needing to include the fira default font). I think "default fonts" should be supported without flags and the current default_font
feature should be default_font_fira_sans
or something similar.
What was the motivation behind choosing a monospace font as the default? Don't most people typically want to use proportional fonts? |
Debug UIs: more likely to prefer monospace (but could probably get away with proportional) I suspect "real game uis" will most often want proportional, but "real game uis" will also probably want their own fonts. |
Oh right: proportional fonts will have additional bugs, so at least internally we probably want to use a proportional one for testing. |
For a placeholder / debug font, it seemed more natural to me |
I think proportional will probably have my vote, but I also dont think we need to make that call now. Once comments are resolved I see no reason not to merge this. We can always swap out later. |
Same here on both counts. Proportional seems like a better default to me (but I don't feel super-strongly about this), and in any case this is easy to change later and need not block this PR. |
Personally, I saw this as more of a debug tool and I prefer mono for that. Maybe have a |
Another reason for mono: I may have messed up, but my "small" FiraSans font is 39kB while FiraMono ends up at 19kB |
Hmm yeah thats a big difference. Lets stick with mono for now and we can make a call later |
I saw this and immediately thought ‘great! Now we can implement debug plugins with UI overlays!’ |
Also in favor of mono. Whenever I need debug overlays, I need to render numbers, and mono is necessary to make those overlays useful.
I think this makes mono much better fit for purpose. |
@@ -97,6 +97,8 @@ bevy_render = ["dep:bevy_render", "bevy_scene?/bevy_render"] | |||
# Enable assertions to check the validity of parameters passed to glam | |||
glam_assert = ["bevy_math/glam_assert"] | |||
|
|||
default_font = ["bevy_text?/default_font"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mockersf is that ?
a typo or a special syntax I don't know? 😊
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a typo! https://doc.rust-lang.org/cargo/reference/features.html#dependency-features
it means "enable default_font
feature of optional crate bevy_text
only if the crate is enabled from another feature, otherwise just ignore it"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet, I didn't know about that feature, quite useful. Thanks!
Objective
Solution
default_font
enabled by defaultChangelog
TextStyle
, the text will be displayed