use bevy::{
color::palettes::{
css::{WHEAT, YELLOW},
tailwind::ZINC_600,
},
prelude::*,
text::FontCx,
};
fn main() {
let mut app = App::new();
app.add_plugins(DefaultPlugins).add_systems(Startup, setup);
app.run();
}
const FONT_SIZE: FontSize = FontSize::Px(25.);
fn setup(mut commands: Commands, mut font_system: ResMut<FontCx>) {
commands.spawn(Camera2d);
commands
.spawn((Node {
display: Display::Grid,
grid_template_columns: vec![RepeatedGridTrack::fr(3, 1.)],
margin: UiRect::AUTO,
row_gap: px(25),
column_gap: px(15),
..Default::default()
},))
.with_children(|builder| {
builder.spawn((
Node {
justify_self: JustifySelf::Center,
grid_column: GridPlacement::span(3),
margin: UiRect::bottom(px(15)),
..default()
},
Text::new("Generic Font Families"),
TextFont::from_font_size(FONT_SIZE),
Underline,
));
let outline = Outline {
color: ZINC_600.into(),
width: px(2.),
offset: px(4.),
};
for (source, description) in [
(FontSource::SansSerif, "generic sans serif font"),
(FontSource::Serif, "generic serif font"),
(FontSource::Fantasy, "generic fantasy font"),
(FontSource::Cursive, "generic cursive font"),
(FontSource::Monospace, "generic monospace font"),
] {
builder.spawn((
Text::new(description),
TextFont::from(source.clone()).with_font_size(FONT_SIZE),
TextColor(WHEAT.into()),
TextLayout::justify(Justify::Center),
outline,
));
builder.spawn((
Text::new(format!("FontSource::{source:?}")),
TextFont::from_font_size(FONT_SIZE),
TextColor(YELLOW.into()),
TextLayout::justify(Justify::Center),
outline,
));
let family_name = font_system.get_family(&source).unwrap();
builder.spawn((
Text::new(family_name),
TextFont::from_font_size(FONT_SIZE),
TextLayout::justify(Justify::Center),
outline,
));
}
});
}