Instantiate builder from within FontFeatures

This commit is contained in:
John Hansler 2025-05-07 10:19:21 -07:00
parent dd27285cda
commit 04dee44812
3 changed files with 11 additions and 11 deletions

View File

@ -367,10 +367,10 @@ impl Default for TextFont {
///
/// # Usage:
/// ```
/// use bevy_text::{FontFeatures, FontFeaturesBuilder};
/// use bevy_text::FontFeatures;
///
/// // Create using FontFeaturesBuilder
/// let font_features = FontFeaturesBuilder::new()
/// // Create using the builder
/// let font_features = FontFeatures::builder()
/// .enable(FontFeatures::STANDARD_LIGATURES)
/// .set(FontFeatures::WEIGHT, 300)
/// .build();
@ -454,6 +454,11 @@ impl FontFeatures {
/// Varies between upright and slanted text. Must be a value greater than -90 and less than +90.
/// A value of 0 is upright.
pub const SLANT: [u8; 4] = *b"slnt";
/// Create a new [`FontFeaturesBuilder`].
pub fn builder() -> FontFeaturesBuilder {
FontFeaturesBuilder::default()
}
}
/// A builder for [`FontFeatures`].
@ -463,11 +468,6 @@ pub struct FontFeaturesBuilder {
}
impl FontFeaturesBuilder {
/// Create a new [`FontFeaturesBuilder`].
pub fn new() -> Self {
FontFeaturesBuilder::default()
}
/// Enable an OpenType feature.
///
/// Most OpenType features are on/off switches, so this is a convenience method that sets the

View File

@ -7,7 +7,7 @@ use bevy::{
color::palettes::css::GOLD,
diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin},
prelude::*,
text::{FontFeatures, FontFeaturesBuilder},
text::FontFeatures,
};
fn main() {
@ -144,7 +144,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
TextFont {
font: opentype_font_handle.clone(),
font_size: 24.0,
font_features: FontFeaturesBuilder::new().enable(feature).build(),
font_features: FontFeatures::builder().enable(feature).build(),
..default()
},
));

View File

@ -15,7 +15,7 @@ commands.spawn((
TextSpan::new("Ligatures: ff, fi, fl, ffi, ffl"),
TextFont {
font: opentype_font_handle,
font_features: FontFeaturesBuilder::new()
font_features: FontFeatures::builder()
.enable(FontFeatures::STANDARD_LIGATURES)
.set(FontFeatures::WIDTH, 300)
.build(),