-
-
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ keywords = ["bevy"] | |
|
||
[features] | ||
subpixel_glyph_atlas = [] | ||
default_font = [] | ||
|
||
[dependencies] | ||
# bevy | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ mod pipeline; | |
mod text; | ||
mod text2d; | ||
|
||
#[cfg(feature = "default_font")] | ||
use bevy_reflect::TypeUuid; | ||
mockersf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pub use error::*; | ||
pub use font::*; | ||
pub use font_atlas::*; | ||
|
@@ -26,7 +28,11 @@ pub mod prelude { | |
} | ||
|
||
use bevy_app::prelude::*; | ||
#[cfg(feature = "default_font")] | ||
use bevy_asset::load_internal_binary_asset; | ||
mockersf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
use bevy_asset::AddAsset; | ||
#[cfg(feature = "default_font")] | ||
use bevy_asset::HandleUntyped; | ||
use bevy_ecs::prelude::*; | ||
use bevy_render::{camera::CameraUpdateSystem, ExtractSchedule, RenderApp}; | ||
use bevy_sprite::SpriteSystem; | ||
|
@@ -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 commentThe 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 |
||
HandleUntyped::weak_from_u64(Font::TYPE_UUID, 1491772431825224042); | ||
|
||
impl Plugin for TextPlugin { | ||
fn build(&self, app: &mut App) { | ||
app.add_asset::<Font>() | ||
|
@@ -98,5 +108,13 @@ impl Plugin for TextPlugin { | |
extract_text2d_sprite.after(SpriteSystem::ExtractSprites), | ||
); | ||
} | ||
|
||
#[cfg(feature = "default_font")] | ||
load_internal_binary_asset!( | ||
app, | ||
DEFAULT_FONT_HANDLE, | ||
"FiraMono-subset.ttf", | ||
|bytes: &[u8]| { Font::try_from_bytes(bytes.to_vec()).unwrap() } | ||
); | ||
} | ||
} |
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 cratebevy_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!