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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
use kael_ui::{components::icon::Icon, prelude::*};
use std::path::PathBuf;
struct Assets {
base: PathBuf,
}
impl kael::AssetSource for Assets {
fn load(&self, path: &str) -> Result<Option<std::borrow::Cow<'static, [u8]>>> {
std::fs::read(self.base.join(path))
.map(|data| Some(std::borrow::Cow::Owned(data)))
.map_err(|err| err.into())
}
fn list(&self, path: &str) -> Result<Vec<kael::SharedString>> {
std::fs::read_dir(self.base.join(path))
.map(|entries| {
entries
.filter_map(|entry| {
entry
.ok()
.and_then(|entry| entry.file_name().into_string().ok())
.map(kael::SharedString::from)
})
.collect()
})
.map_err(|err| err.into())
}
}
fn main() {
Application::new()
.with_assets(Assets {
base: PathBuf::from(env!("CARGO_MANIFEST_DIR")),
})
.run(|cx| {
kael_ui::init(cx);
kael_ui::set_icon_base_path("assets/icons");
cx.open_window(
WindowOptions {
titlebar: Some(TitlebarOptions {
title: Some("Icon Test".into()),
..Default::default()
}),
window_bounds: Some(WindowBounds::Windowed(Bounds::centered(
None,
size(px(600.0), px(400.0)),
cx,
))),
..Default::default()
},
|window, cx| cx.new(|cx| IconTestApp::new(window, cx)),
)
.unwrap();
});
}
struct IconTestApp {}
impl IconTestApp {
fn new(_window: &mut Window, cx: &mut App) -> Self {
let theme = Theme::light();
install_theme(cx, theme.clone());
Self {}
}
}
impl Render for IconTestApp {
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
let theme = use_theme();
div()
.flex()
.flex_col()
.items_center()
.justify_center()
.size_full()
.bg(theme.tokens.background)
.gap_8()
.child(
div()
.text_2xl()
.text_color(theme.tokens.foreground)
.child("Icon Test - If you see icons below, it works!"),
)
.child(
div()
.flex()
.flex_row()
.gap_8()
.items_center()
// Test 1: Simple named icon
.child(
div()
.flex()
.flex_col()
.items_center()
.gap_2()
.child(
Icon::new("heart")
.size(px(64.0))
.color(rgb(0xff0000).into()),
)
.child(
div()
.text_sm()
.text_color(theme.tokens.foreground)
.child("heart (red)"),
),
)
.child(
div()
.flex()
.flex_col()
.items_center()
.gap_2()
.child(
Icon::new("arrow-down")
.size(px(64.0))
.color(rgb(0x0000ff).into()),
)
.child(
div()
.text_sm()
.text_color(theme.tokens.foreground)
.child("arrow-down (blue)"),
),
)
.child(
div()
.flex()
.flex_col()
.items_center()
.gap_2()
.child(
Icon::new("check")
.size(px(64.0))
.color(rgb(0x00ff00).into()),
)
.child(
div()
.text_sm()
.text_color(theme.tokens.foreground)
.child("check (green)"),
),
),
)
.child(
div()
.text_sm()
.text_color(theme.tokens.muted_foreground)
.child("Icons should be rendered above in different colors"),
)
}
}