fonts/
fonts.rs

1#![feature(type_alias_impl_trait, impl_trait_in_assoc_type)]
2
3use nuit::{Bind, Font, FontDesign, FontLevel, FontWeight, ForEach, HStack, Text, VStack, View, ViewExt};
4
5#[derive(Bind)]
6struct FontsView;
7
8impl View for FontsView {
9    type Body = impl View;
10
11    fn body(&self) -> Self::Body {
12        HStack::with_spacing(50, (
13            VStack::new(
14                ForEach::with_index_id([
15                    FontLevel::ExtraLargeTitle2,
16                    FontLevel::ExtraLargeTitle,
17                    FontLevel::LargeTitle,
18                    FontLevel::Title,
19                    FontLevel::Title2,
20                    FontLevel::Title3,
21                    FontLevel::Headline,
22                    FontLevel::Subheadline,
23                    FontLevel::Body,
24                    FontLevel::Callout,
25                    FontLevel::Caption,
26                    FontLevel::Caption2,
27                    FontLevel::Footnote,
28                ], |_, level| {
29                    Text::new(format!("{:?}", level))
30                        .font(Font::with_level(level))
31                })
32            ),
33            VStack::new(
34                ForEach::with_index_id([
35                    FontWeight::Black,
36                    FontWeight::Bold,
37                    FontWeight::Heavy,
38                    FontWeight::Light,
39                    FontWeight::Medium,
40                    FontWeight::Regular,
41                    FontWeight::Semibold,
42                    FontWeight::Thin,
43                    FontWeight::UltraLight,
44                ], |_, weight| {
45                    Text::new(format!("{weight:?}"))
46                        .font(Font::system(18, None, Some(weight)))
47                })
48            ),
49            VStack::new(
50                ForEach::with_index_id([
51                    FontDesign::Default,
52                    FontDesign::Monospaced,
53                    FontDesign::Rounded,
54                    FontDesign::Serif,
55                ], |_, design| {
56                    Text::new(format!("{design:?}"))
57                        .font(Font::system(18, Some(design), None))
58                })
59            ),
60            VStack::new(
61                ForEach::new((0..10).rev(), |i| {
62                    let size = i * 4 + 8;
63                    Text::new(format!("{size}"))
64                        .font(Font::with_size(size))
65                })
66            ),
67        ))
68    }
69}
70
71fn main() {
72    nuit::run_app(FontsView);
73}