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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
use kael_ui::{
components::input::{Input, InputState, InputVariant},
components::scrollable::scrollable_vertical,
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<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(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");
install_theme(cx, Theme::dark());
cx.open_window(
WindowOptions {
titlebar: Some(TitlebarOptions {
title: Some("Input Styled Trait Demo".into()),
..Default::default()
}),
window_bounds: Some(WindowBounds::Windowed(Bounds {
origin: Point::default(),
size: size(px(900.0), px(800.0)),
})),
..Default::default()
},
|_, cx| cx.new(|cx| InputStyledDemo::new(cx)),
)
.unwrap();
});
}
struct InputStyledDemo {
input1: Entity<InputState>,
input2: Entity<InputState>,
input3: Entity<InputState>,
input4: Entity<InputState>,
input5: Entity<InputState>,
input6: Entity<InputState>,
input7: Entity<InputState>,
input8: Entity<InputState>,
input9: Entity<InputState>,
input10: Entity<InputState>,
input11: Entity<InputState>,
input12: Entity<InputState>,
}
impl InputStyledDemo {
fn new(cx: &mut Context<Self>) -> Self {
Self {
input1: cx.new(|cx| InputState::new(cx)),
input2: cx.new(|cx| InputState::new(cx)),
input3: cx.new(|cx| InputState::new(cx)),
input4: cx.new(|cx| InputState::new(cx)),
input5: cx.new(|cx| InputState::new(cx)),
input6: cx.new(|cx| InputState::new(cx)),
input7: cx.new(|cx| InputState::new(cx)),
input8: cx.new(|cx| InputState::new(cx)),
input9: cx.new(|cx| InputState::new(cx)),
input10: cx.new(|cx| InputState::new(cx)),
input11: cx.new(|cx| InputState::new(cx)),
input12: cx.new(|cx| InputState::new(cx)),
}
}
}
impl Render for InputStyledDemo {
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
let theme = use_theme();
div()
.size_full()
.bg(theme.tokens.background)
.overflow_hidden()
.child(
scrollable_vertical(
div()
.flex()
.flex_col()
.text_color(theme.tokens.foreground)
.p(px(32.0))
.gap(px(32.0))
.child(
VStack::new()
.gap(px(8.0))
.child(
div()
.text_size(px(24.0))
.font_weight(FontWeight::BOLD)
.child("Input Styled Trait Customization Demo")
)
.child(
div()
.text_size(px(14.0))
.text_color(theme.tokens.muted_foreground)
.child("Demonstrating full GPUI styling control via Styled trait")
)
)
// 1. Custom Width Examples
.child(
VStack::new()
.gap(px(16.0))
.child(
div()
.text_size(px(18.0))
.font_weight(FontWeight::SEMIBOLD)
.child("1. Custom Width (via Styled trait)")
)
.child(
VStack::new()
.gap(px(12.0))
.child(
Input::new(&self.input1)
.placeholder("Default width")
.variant(InputVariant::Default)
)
.child(
Input::new(&self.input2)
.placeholder("Full width input")
.variant(InputVariant::Default)
.w_full() // Styled trait method
)
.child(
Input::new(&self.input3)
.placeholder("Custom width (600px)")
.variant(InputVariant::Default)
.w(px(600.0)) // Styled trait method
)
)
)
// 2. Custom Padding
.child(
VStack::new()
.gap(px(16.0))
.child(
div()
.text_size(px(18.0))
.font_weight(FontWeight::SEMIBOLD)
.child("2. Custom Padding")
)
.child(
VStack::new()
.gap(px(12.0))
.child(
Input::new(&self.input4)
.placeholder("Default padding")
.variant(InputVariant::Outline)
)
.child(
Input::new(&self.input5)
.placeholder("Extra padding - p_4()")
.variant(InputVariant::Outline)
.p_4() // Styled trait method
)
.child(
Input::new(&self.input6)
.placeholder("More padding - p_8()")
.variant(InputVariant::Outline)
.p_8() // Styled trait method
)
)
)
// 3. Custom Background Colors
.child(
VStack::new()
.gap(px(16.0))
.child(
div()
.text_size(px(18.0))
.font_weight(FontWeight::SEMIBOLD)
.child("3. Custom Background Colors")
)
.child(
VStack::new()
.gap(px(12.0))
.child(
Input::new(&self.input7)
.placeholder("Blue background")
.variant(InputVariant::Ghost)
.bg(rgb(0x1e3a8a)) // Styled trait
.text_color(kael::white())
)
.child(
Input::new(&self.input8)
.placeholder("Purple background")
.variant(InputVariant::Ghost)
.bg(rgb(0x581c87)) // Styled trait
.text_color(kael::white())
)
)
)
// 4. Custom Border Radius
.child(
VStack::new()
.gap(px(16.0))
.child(
div()
.text_size(px(18.0))
.font_weight(FontWeight::SEMIBOLD)
.child("4. Custom Border Radius")
)
.child(
VStack::new()
.gap(px(12.0))
.child(
Input::new(&self.input9)
.placeholder("No radius (sharp corners)")
.variant(InputVariant::Default)
.rounded(px(0.0)) // Styled trait
)
.child(
Input::new(&self.input10)
.placeholder("Large radius (20px)")
.variant(InputVariant::Default)
.rounded(px(20.0)) // Styled trait
)
)
)
// 5. Combined Styling
.child(
VStack::new()
.gap(px(16.0))
.child(
div()
.text_size(px(18.0))
.font_weight(FontWeight::SEMIBOLD)
.child("5. Combined Styling (Multiple Styled Trait Methods)")
)
.child(
VStack::new()
.gap(px(12.0))
.child(
Input::new(&self.input11)
.placeholder("Fully customized input")
.variant(InputVariant::Ghost)
.w_full() // Styled trait
.p(px(20.0)) // Styled trait
.bg(rgb(0x047857)) // Styled trait
.text_color(kael::white())
.rounded(px(12.0)) // Styled trait
.shadow_lg() // Styled trait
)
.child(
Input::new(&self.input12)
.placeholder("Ultra custom with border")
.variant(InputVariant::Outline)
.w_full() // Styled trait
.px(px(24.0)) // Styled trait
.py(px(16.0)) // Styled trait
.bg(hsla(43.0 / 360.0, 0.96, 0.56, 0.2)) // Styled trait
.rounded(px(16.0)) // Styled trait
.border_2() // Styled trait
.border_color(rgb(0xfbbf24))
)
)
)
// Info Box
.child(
div()
.mt(px(16.0))
.p(px(16.0))
.bg(theme.tokens.accent)
.rounded(px(8.0))
.child(
div()
.text_size(px(14.0))
.text_color(theme.tokens.accent_foreground)
.child("All customizations above use the Styled trait for full GPUI styling control!")
)
.child(
div()
.mt(px(8.0))
.text_size(px(12.0))
.text_color(theme.tokens.accent_foreground)
.child("Methods used: .w_full(), .w(), .p_4(), .p_8(), .p(), .px(), .py(), .bg(), .rounded(), .border_2(), .shadow_lg()")
)
)
)
)
}
}