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
use crate::class::{styles::StyleClass, ApplyClass};
use bevy::ui::{Style, Val};

pub const H_AUTO: StyleClass = StyleClass::Height(Height(Val::Auto));
pub const H_FULL: StyleClass = StyleClass::Height(Height(Val::Percent(100.0)));
pub const H_SCREEN: StyleClass = StyleClass::Height(Height(Val::Vh(100.0)));
pub const H_SVW: StyleClass = StyleClass::Height(Height(Val::VMin(100.0)));
pub const H_LVW: StyleClass = StyleClass::Height(Height(Val::VMax(100.0)));

pub fn h_px(px: f32) -> StyleClass {
    StyleClass::Height(Height(Val::Px(px)))
}

pub fn h_vh(percent: f32) -> StyleClass {
    StyleClass::Height(Height(Val::Vh(percent)))
}

pub fn h_vmin(percent: f32) -> StyleClass {
    StyleClass::Height(Height(Val::VMin(percent)))
}

pub fn h_vmax(percent: f32) -> StyleClass {
    StyleClass::Height(Height(Val::VMax(percent)))
}

pub fn h_div(n: u32, d: u32) -> StyleClass {
    StyleClass::Height(Height(Val::Percent((n as f32 / d as f32) * 100.0)))
}

pub fn h_perc(percent: f32) -> StyleClass {
    StyleClass::Height(Height(Val::Percent(percent)))
}

#[derive(Debug, Clone, Copy)]
pub struct Height(pub Val);

impl ApplyClass for Height {
    type Component = Style;

    fn apply_class(&self, component: &mut Self::Component) {
        component.height = self.0;
    }
}