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
//! Text Input Example
//!
//! Demonstrates the TextInput widget with:
//! - Basic text input
//! - Password field with masking
//! - Real-time display of input values
//! - Submit handling with Enter key
//! - Focused state styling on input containers
//! - Clipboard support (Ctrl+C/V/X)
//! - Undo/redo history (Ctrl+Z/Y)
use guido::prelude::*;
fn main() {
App::new().run(|app| {
let username = create_signal(String::new());
let password = create_password();
let submitted = create_signal(String::new());
let view = container()
.background(Color::rgb(0.12, 0.12, 0.18))
.padding(24.0)
.layout(Flex::column().spacing(16.0))
.child(
// Title
container().child(text("Text Input Demo").font_size(20.0).color(Color::WHITE)),
)
.child(
// Username section
container()
.layout(Flex::column().spacing(4.0))
.child(
container().child(
text("Username")
.font_size(12.0)
.color(Color::rgb(0.7, 0.7, 0.8)),
),
)
.child(
container()
.width(300.0)
.padding(8.0)
.background(Color::rgb(0.18, 0.18, 0.24))
.border(1.0, Color::rgb(0.3, 0.3, 0.4))
.corners(6.0)
// Highlight border when text input is focused
.when_focused(|s| s.border(2.0, Color::rgb(0.4, 0.8, 1.0)))
.child(
text_input(username)
.selection_color(Color::rgba(0.4, 0.6, 1.0, 0.4))
.cursor_color(Color::rgb(0.4, 0.8, 1.0))
.font_size(14.0)
.color(Color::WHITE),
),
),
)
.child(
// Password section
container()
.layout(Flex::column().spacing(4.0))
.child(
container().child(
text("Password")
.font_size(12.0)
.color(Color::rgb(0.7, 0.7, 0.8)),
),
)
.child(
container()
.width(300.0)
.padding(8.0)
.background(Color::rgb(0.18, 0.18, 0.24))
.border(1.0, Color::rgb(0.3, 0.3, 0.4))
.corners(6.0)
// Highlight border when text input is focused
.when_focused(|s| s.border(2.0, Color::rgb(0.4, 0.8, 1.0)))
.child(
password_input(password)
.selection_color(Color::rgba(0.4, 0.6, 1.0, 0.4))
.cursor_color(Color::rgb(0.4, 0.8, 1.0))
.font_size(14.0)
.color(Color::WHITE)
.on_submit(move || {
let msg = format!("Login attempt: {}", username.get());
submitted.set(msg);
}),
),
),
)
.child(
// Current values display
container()
.padding(12.0)
.background(Color::rgb(0.15, 0.15, 0.2))
.corners(6.0)
.layout(Flex::column().spacing(8.0))
.child(
container().child(
text("Current Values:")
.font_size(12.0)
.color(Color::rgb(0.6, 0.6, 0.7)),
),
)
.child(
container().child(
text(move || format!("Username: {}", username.get()))
.font_size(13.0)
.color(Color::rgb(0.8, 0.8, 0.9)),
),
)
.child(
container().child(
text(move || {
format!(
"Password: {} chars",
password.with(|s| s.expose().chars().count())
)
})
.font_size(13.0)
.color(Color::rgb(0.8, 0.8, 0.9)),
),
),
)
.child(
// Submit status
container().child(
text(move || {
let msg = submitted.get();
if msg.is_empty() {
"Press Enter in password field to submit".to_string()
} else {
msg
}
})
.font_size(13.0)
.color(Color::rgb(0.5, 0.8, 0.5)),
),
)
.child(
// Instructions
container()
.padding(12.0)
.background(Color::rgb(0.1, 0.1, 0.14))
.corners(6.0)
.layout(Flex::column().spacing(4.0))
.child(
container().child(
text("Keyboard shortcuts:")
.font_size(11.0)
.color(Color::rgb(0.5, 0.5, 0.6)),
),
)
.child(
container().child(
text("• Click to focus and position cursor")
.font_size(11.0)
.color(Color::rgb(0.5, 0.5, 0.6)),
),
)
.child(
container().child(
text("• Arrow keys to move cursor")
.font_size(11.0)
.color(Color::rgb(0.5, 0.5, 0.6)),
),
)
.child(
container().child(
text("• Shift+Arrow to select text")
.font_size(11.0)
.color(Color::rgb(0.5, 0.5, 0.6)),
),
)
.child(
container().child(
text("• Ctrl+A to select all")
.font_size(11.0)
.color(Color::rgb(0.5, 0.5, 0.6)),
),
)
.child(
container().child(
text("• Ctrl+Arrow for word jump")
.font_size(11.0)
.color(Color::rgb(0.5, 0.5, 0.6)),
),
)
.child(
container().child(
text("• Home/End to go to start/end")
.font_size(11.0)
.color(Color::rgb(0.5, 0.5, 0.6)),
),
)
.child(
container().child(
text("• Enter to submit (in password field)")
.font_size(11.0)
.color(Color::rgb(0.5, 0.5, 0.6)),
),
)
.child(
container().child(
text("• Ctrl+C/X/V to copy/cut/paste")
.font_size(11.0)
.color(Color::rgb(0.5, 0.5, 0.6)),
),
)
.child(
container().child(
text("• Ctrl+Z to undo, Ctrl+Y to redo")
.font_size(11.0)
.color(Color::rgb(0.5, 0.5, 0.6)),
),
),
);
app.add_surface(
SurfaceConfig::new()
.width(400)
.height(500)
.anchor(Anchor::TOP | Anchor::LEFT)
.layer(Layer::Top)
.namespace("text-input-example")
.background_color(Color::rgb(0.12, 0.12, 0.18)),
move || view,
);
});
}