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
use kael_ui::components::input::{self, Input, InputSize, InputState, InputVariant};
use kael_ui::prelude::*;
struct InputTestApp {
input_state: Entity<InputState>,
password_input_state: Entity<InputState>,
output_text: SharedString,
}
impl InputTestApp {
fn new(cx: &mut Context<Self>) -> Self {
let input_state = cx.new(|cx| InputState::new(cx));
let password_input_state = cx.new(|cx| InputState::new(cx));
Self {
input_state,
password_input_state,
output_text: "No input yet".into(),
}
}
}
impl Render for InputTestApp {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
div()
.flex()
.flex_col()
.gap_4()
.p_8()
.bg(rgb(0x1e1e2e))
.size_full()
.child(
div()
.text_xl()
.text_color(rgb(0xcdd6f4))
.child("Input Component Test"),
)
.child(
div()
.flex()
.flex_col()
.gap_2()
.child(
div()
.text_sm()
.text_color(rgb(0xa6adc8))
.child("Basic Input with Clear Button"),
)
.child(
Input::new(&self.input_state)
.placeholder("Enter your name...")
.clearable(true)
.on_change({
let entity = cx.entity();
move |value, cx| {
entity.update(cx, |this, cx| {
this.output_text = format!("You typed: {}", value).into();
cx.notify();
});
}
})
.on_enter({
let entity = cx.entity();
move |value, cx| {
entity.update(cx, |this, cx| {
this.output_text =
format!("Enter pressed with: {}", value).into();
cx.notify();
});
}
}),
),
)
.child(
div()
.flex()
.flex_col()
.gap_2()
.child(
div()
.text_sm()
.text_color(rgb(0xa6adc8))
.child("Password Input with Toggle"),
)
.child(
Input::new(&self.password_input_state)
.placeholder("Enter password...")
.password(true)
.variant(InputVariant::Outline)
.size(InputSize::Lg),
),
)
.child(
div()
.flex()
.flex_col()
.gap_2()
.child(div().text_sm().text_color(rgb(0xa6adc8)).child("Output"))
.child(
div()
.p_4()
.bg(rgb(0x313244))
.rounded_md()
.text_color(rgb(0xf5e0dc))
.child(self.output_text.clone()),
),
)
}
}
fn main() {
Application::new().run(|cx: &mut App| {
// Initialize input key bindings
input::init(cx);
cx.open_window(
WindowOptions {
window_bounds: Some(WindowBounds::Windowed(Bounds {
origin: point(px(100.), px(100.)),
size: size(px(800.), px(600.)),
})),
..Default::default()
},
|_window, cx| cx.new(|cx| InputTestApp::new(cx)),
)
.unwrap();
});
}