1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use crate::views::ui::accessibility::Scale;

fn size_xxxl(i: f32) -> f32 {
    size_xxl(i) + 2.0
}

fn size_xxl(i: f32) -> f32 {
    size_xl(i) + 2.0
}

fn size_xl(i: f32) -> f32 {
    size_l(i) + 2.0
}

fn size_l(i: f32) -> f32 {
    size_m(i)
        + match i {
            i if i < 0.5 => 0.0,
            i if i < 6.5 => 1.0,
            _ => 2.0,
        }
}

fn size_m(i: f32) -> f32 {
    size_s(i)
        + match i {
            i if i < 6.5 => 1.0,
            _ => 2.0,
        }
}

fn size_s(i: f32) -> f32 {
    size_xs(i)
        + match i {
            i if i < 0.5 => 0.0,
            i if i < 6.5 => 1.0,
            _ => 2.0,
        }
}

fn size_xs(i: f32) -> f32 {
    size_xxs(i)
        + match i {
            i if i < 6.5 => 1.0,
            _ => 2.0,
        }
}

fn size_xxs(i: f32) -> f32 {
    // fi = f₀ × r^(i/n)
    let r = 1.618034f32; // Φ
    let n = 5.0f32;
    let f = 10.0f32;

    (f * r.powf(i / n)).round().max(10.0)
}

impl Scale {
    /// `Font` scale per `Accessibility` level
    #[inline(never)]
    pub fn scale(&self, i: f32) -> f32 {
        match self {
            Scale::XXS => size_xxs(i),
            Scale::XS => size_xs(i),
            Scale::S => size_s(i),
            Scale::M => size_m(i),
            Scale::L => size_l(i),
            Scale::XL => size_xl(i),
            Scale::XXL => size_xxl(i),
            Scale::XXXL => size_xxxl(i),
        }
    }
}