pelican/
theme.rs

1use roost::{Assets, include_dir};
2use roost::drawable::Color;
3
4pub mod colors;
5pub use colors::*;
6pub mod fonts;
7pub use fonts::*;
8pub mod icons;
9pub use icons::*;
10pub mod brand;
11pub use brand::*;
12pub mod layout;
13pub use layout::*;
14
15/// Contains all visual and layout resources for the 
16/// application's theme, including colors, fonts, icons, 
17/// branding, and layout.
18pub struct Theme {
19    pub colors: ColorResources,
20    pub fonts: FontResources,
21    pub icons: IconResources,
22    pub brand: BrandResources,
23    pub layout: LayoutResources,
24}
25
26// impl Plugin for Theme {
27//     fn new(ctx: &mut Context) -> Self where Self: Sized {
28//         ctx.assets.include_assets(include_dir!("./resources")); 
29//         Theme::default(&ctx.assets)
30//     }
31// }
32
33impl Theme {
34    pub fn default(ctx: &mut Assets) -> Self {
35        ctx.include_assets(include_dir!("./resources"));
36        Theme {
37            colors: ColorResources::default(),
38            fonts: FontResources::default(ctx),
39            icons: IconResources::default(ctx),
40            brand: BrandResources::default(ctx),
41            layout: LayoutResources::default(),
42        }
43    }
44
45    /// Creates a new instance of the Theme object.
46    pub fn new(
47        ctx: &mut Assets,
48        colors: ColorResources, 
49        fonts: FontResources, 
50        icons: IconResources,
51        brand: BrandResources,
52        layout: LayoutResources,
53    ) -> Self {
54        ctx.include_assets(include_dir!("./resources"));
55        Theme { colors, fonts, icons, brand, layout } 
56    }
57
58    pub fn from(ctx: &mut Assets, primary: Color) -> Self {
59        ctx.include_assets(include_dir!("./resources"));
60        Theme {
61            colors: ColorResources::from(primary),
62            fonts: FontResources::default(ctx),
63            icons: IconResources::default(ctx),
64            brand: BrandResources::default(ctx),
65            layout: LayoutResources::default(),
66        }
67    }
68
69    pub fn light(ctx: &mut Assets, primary: Color) -> Self {
70        ctx.include_assets(include_dir!("./resources"));
71        Theme {
72            colors: ColorResources::light(primary),
73            fonts: FontResources::default(ctx),
74            icons: IconResources::default(ctx),
75            brand: BrandResources::default(ctx),
76            layout: LayoutResources::default(),
77        }
78    }
79
80    pub fn dark(ctx: &mut Assets, primary: Color) -> Self {
81        ctx.include_assets(include_dir!("./resources"));
82        Theme {
83            colors: ColorResources::dark(primary),
84            fonts: FontResources::default(ctx),
85            icons: IconResources::default(ctx),
86            brand: BrandResources::default(ctx),
87            layout: LayoutResources::default(),
88        }
89    }
90}