Skip to main content

content_core/
content_core.rs

1use beuvy_runtime::text::FontResource;
2use beuvy_runtime::{AddImage, AddLink, AddText, UiKitPlugin};
3use bevy::prelude::*;
4use bevy::text::TextLayout;
5
6fn main() {
7    App::new()
8        .add_plugins(DefaultPlugins.set(WindowPlugin {
9            primary_window: Some(Window {
10                title: "beuvy-runtime content core".to_string(),
11                resolution: (980, 640).into(),
12                ..default()
13            }),
14            ..default()
15        }))
16        .add_plugins(UiKitPlugin)
17        .add_systems(Startup, setup)
18        .run();
19}
20
21fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
22    commands.spawn(Camera2d);
23    commands.insert_resource(FontResource::from_handle(
24        asset_server.load("fonts/SarasaFixedSC-Regular.ttf"),
25    ));
26    commands
27        .spawn((
28            Node {
29                width: Val::Percent(100.0),
30                height: Val::Percent(100.0),
31                padding: UiRect::axes(Val::Px(40.0), Val::Px(28.0)),
32                row_gap: Val::Px(14.0),
33                flex_direction: FlexDirection::Column,
34                ..default()
35            },
36            BackgroundColor(Color::srgb_u8(248, 250, 252)),
37        ))
38        .with_children(|parent| {
39            text(parent, "Content page essentials", 30.0, Color::srgb_u8(15, 23, 42));
40            text(
41                parent,
42                "Heading, paragraph, helper text, image, link, rule, and list primitives.",
43                15.0,
44                Color::srgb_u8(71, 85, 105),
45            );
46            parent.spawn((
47                Node {
48                    width: Val::Px(120.0),
49                    height: Val::Px(120.0),
50                    ..default()
51                },
52                AddImage {
53                    src: "branding/icon.png".to_string(),
54                    alt: "Project icon".to_string(),
55                    ..default()
56                },
57            ));
58            parent.spawn((
59                Node {
60                    width: Val::Px(220.0),
61                    ..default()
62                },
63                AddLink {
64                    name: "docs".to_string(),
65                    href: "/docs/getting-started".to_string(),
66                    text: "Open getting started docs".to_string(),
67                    ..default()
68                },
69            ));
70            parent.spawn((
71                Node {
72                    width: Val::Percent(100.0),
73                    height: Val::Px(1.0),
74                    ..default()
75                },
76                BackgroundColor(Color::srgb_u8(203, 213, 225)),
77            ));
78            parent
79                .spawn((
80                    Node {
81                        row_gap: Val::Px(8.0),
82                        flex_direction: FlexDirection::Column,
83                        ..default()
84                    },
85                ))
86                .with_children(|list| {
87                    text(list, "• Semantic content tags", 15.0, Color::srgb_u8(30, 41, 59));
88                    text(
89                        list,
90                        "• Fieldset and legend defaults",
91                        15.0,
92                        Color::srgb_u8(30, 41, 59),
93                    );
94                    text(
95                        list,
96                        "• Small / strong / emphasis styling hooks",
97                        15.0,
98                        Color::srgb_u8(30, 41, 59),
99                    );
100                });
101        });
102}
103
104fn text(parent: &mut ChildSpawnerCommands, value: &str, size: f32, color: Color) {
105    parent.spawn((
106        Node::default(),
107        TextLayout::default(),
108        AddText {
109            text: value.to_string(),
110            size,
111            color,
112            ..default()
113        },
114    ));
115}