anchor_kit_core/
style.rs

1use crate::primitives::color::Color;
2
3#[derive(Debug, Clone, Copy)]
4pub enum SizingPolicy {
5    Auto,       // hug to child elements
6    Fixed(u32), // individual policy for width and height so only need 1 u32 here
7    FillParent, // take up entire space of parent element
8}
9
10#[derive(Debug, Clone, Copy)]
11pub enum Align {
12    Start, // left for rows, top for cols
13    Middle,
14    End, // right for rows, bottom for cols
15}
16
17#[derive(Default, Debug, Clone, Copy)]
18pub struct Insets {
19    pub top: u32,
20    pub right: u32,
21    pub bottom: u32,
22    pub left: u32,
23}
24
25#[derive(Clone, Copy, Debug)]
26pub struct Style {
27    pub padding: Insets,
28    pub margin: Insets,
29    pub width: SizingPolicy,
30    pub height: SizingPolicy,
31    pub align_x: Align, // element alignment
32    pub align_y: Align,
33    pub justify_x: Align, // content within element alignment
34    pub justify_y: Align,
35    pub background_color: Color,
36    pub border_color: Color,
37    pub border_radius: [f32; 4], // top-left, top-right, bottom-right, bottom-left (clockwise)
38    pub border_width: f32,       // thickness of border
39}
40
41impl Default for Style {
42    fn default() -> Self {
43        Self {
44            padding: Insets::default(),
45            margin: Insets::default(),
46            width: SizingPolicy::Auto,
47            height: SizingPolicy::Auto,
48            align_x: Align::Start,
49            align_y: Align::Start,
50            justify_x: Align::Start,
51            justify_y: Align::Start,
52            background_color: Color::default(),
53            border_color: Color::default(),
54            border_radius: [0.0, 0.0, 0.0, 0.0],
55            border_width: 0.0,
56        }
57    }
58}
59
60#[derive(Clone, Debug)]
61pub enum FontFamily {
62    Name(String),
63    Serif,
64    SansSerif,
65    Cursive,
66    Fantasy,
67    Monospace,
68}
69
70#[derive(Clone, Debug)]
71pub enum FontWeight {
72    Thin,
73    ExtraLight,
74    Light,
75    Normal,
76    Medium,
77    SemiBold,
78    Bold,
79    ExtraBold,
80    Black,
81}
82
83#[derive(Clone, Debug)]
84pub enum FontStyle {
85    Normal,
86    Italic,
87    Oblique,
88}
89
90// text style is pretty different (specific to text rendering) so we should keep it seperate
91// the items in this struct will be generic, and then integrate with glyphon in the wgpu integration (to allow support for other rendering frameworks in the future)
92#[derive(Clone, Debug)]
93pub struct TextStyle {
94    pub font_size: f32,
95    pub line_height: f32,
96    pub font_family: FontFamily,
97    pub font_weight: FontWeight,
98    pub font_style: FontStyle,
99    pub text_color: Color,
100}
101
102impl Default for TextStyle {
103    fn default() -> Self {
104        Self {
105            font_size: 16.0,
106            line_height: 20.0,
107            font_family: FontFamily::SansSerif,
108            font_weight: FontWeight::Normal,
109            font_style: FontStyle::Normal,
110            text_color: Color::default(),
111        }
112    }
113}