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
//! Example demonstrating dynamic surface property modification.
//!
//! This example shows how to:
//! - Configure keyboard interactivity at surface creation
//! - Get a handle for surfaces added via `add_surface()`
//! - Dynamically modify surface properties (layer, keyboard interactivity, etc.)
//!
//! Click the buttons to change the surface's layer and keyboard mode.
use guido::prelude::*;
fn main() {
App::new().run(|app| {
// Store the surface ID so we can get a handle to it later
let surface_id_signal = create_signal(None::<SurfaceId>);
// Track current layer and keyboard mode for display
let current_layer = create_signal("Top");
let current_keyboard = create_signal("OnDemand");
let surface_id = app.add_surface(
SurfaceConfig::new()
.width(500)
.height(300)
.anchor(Anchor::TOP | Anchor::LEFT)
.exclusive_zone(ExclusiveZone::Auto)
.layer(Layer::Top)
.keyboard_interactivity(KeyboardInteractivity::OnDemand)
.namespace("surface-properties-example")
.background_color(Color::rgb(0.1, 0.1, 0.15)),
move || {
container()
.padding(24.0)
.layout(Flex::column().spacing(16.0))
.child(
container().child(
text("Surface Properties Demo")
.font_size(20.0)
.color(Color::WHITE),
),
)
// Current state display
.child(
container()
.padding(12.0)
.background(Color::rgb(0.15, 0.15, 0.2))
.corners(8.0)
.layout(Flex::column().spacing(8.0))
.child(
container().child(
text(move || format!("Current Layer: {}", current_layer.get()))
.font_size(14.0)
.color(Color::rgb(0.7, 0.9, 0.7)),
),
)
.child(
container().child(
text(move || {
format!(
"Keyboard Interactivity: {}",
current_keyboard.get()
)
})
.font_size(14.0)
.color(Color::rgb(0.7, 0.9, 0.7)),
),
),
)
// Layer controls
.child(
container()
.layout(Flex::column().spacing(8.0))
.child(
container().child(
text("Change Layer:")
.font_size(12.0)
.color(Color::rgb(0.6, 0.6, 0.7)),
),
)
.child(
container()
.layout(Flex::row().spacing(8.0))
.child(layer_button(
"Background",
Layer::Background,
surface_id_signal,
current_layer,
))
.child(layer_button(
"Bottom",
Layer::Bottom,
surface_id_signal,
current_layer,
))
.child(layer_button(
"Top",
Layer::Top,
surface_id_signal,
current_layer,
))
.child(layer_button(
"Overlay",
Layer::Overlay,
surface_id_signal,
current_layer,
)),
),
)
// Keyboard interactivity controls
.child(
container()
.layout(Flex::column().spacing(8.0))
.child(
container().child(
text("Change Keyboard Interactivity:")
.font_size(12.0)
.color(Color::rgb(0.6, 0.6, 0.7)),
),
)
.child(
container()
.layout(Flex::row().spacing(8.0))
.child(keyboard_button(
"None",
KeyboardInteractivity::None,
surface_id_signal,
current_keyboard,
))
.child(keyboard_button(
"OnDemand",
KeyboardInteractivity::OnDemand,
surface_id_signal,
current_keyboard,
))
.child(keyboard_button(
"Exclusive",
KeyboardInteractivity::Exclusive,
surface_id_signal,
current_keyboard,
)),
),
)
// Instructions
.child(
container()
.padding(12.0)
.background(Color::rgb(0.12, 0.12, 0.16))
.corners(6.0)
.layout(Flex::column().spacing(4.0))
.child(
container().child(
text("Tips:")
.font_size(11.0)
.color(Color::rgb(0.5, 0.5, 0.6)),
),
)
.child(
container().child(
text("- Overlay layer appears above other windows")
.font_size(11.0)
.color(Color::rgb(0.5, 0.5, 0.6)),
),
)
.child(
container().child(
text("- Background layer appears below the desktop")
.font_size(11.0)
.color(Color::rgb(0.5, 0.5, 0.6)),
),
)
.child(
container().child(
text("- Exclusive keyboard grabs focus from other apps")
.font_size(11.0)
.color(Color::rgb(0.5, 0.5, 0.6)),
),
),
)
},
);
// Store the surface ID so the buttons can access it
surface_id_signal.set(Some(surface_id));
});
}
fn layer_button(
label: &'static str,
layer: Layer,
surface_id_signal: RwSignal<Option<SurfaceId>>,
current_layer: RwSignal<&'static str>,
) -> Container {
container()
.padding([8.0, 12.0])
.background(Color::rgb(0.25, 0.25, 0.35))
.corners(6.0)
.when_hovered(|s| s.lighter(0.1))
.when_pressed(|s| s.ripple())
.on_click(move || {
if let Some(id) = surface_id_signal.get() {
let handle = surface_handle(id);
handle.set_layer(layer);
current_layer.set(label);
}
})
.child(text(label).font_size(13.0).color(Color::WHITE))
}
fn keyboard_button(
label: &'static str,
mode: KeyboardInteractivity,
surface_id_signal: RwSignal<Option<SurfaceId>>,
current_keyboard: RwSignal<&'static str>,
) -> Container {
container()
.padding([8.0, 12.0])
.background(Color::rgb(0.25, 0.3, 0.35))
.corners(6.0)
.when_hovered(|s| s.lighter(0.1))
.when_pressed(|s| s.ripple())
.on_click(move || {
if let Some(id) = surface_id_signal.get() {
let handle = surface_handle(id);
handle.set_keyboard_interactivity(mode);
current_keyboard.set(label);
}
})
.child(text(label).font_size(13.0).color(Color::WHITE))
}