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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
use crate::*;
use std::sync::Arc;
pub trait View: Sized + Send {
/// The concrete type produced after applying modifiers.
/// For primitive views this is Self.
type Body: View;
fn body(self) -> Self::Body;
/// Render this view into the provided renderer at the specified bounds.
/// Primitive views override this to perform drawing operations.
fn render(&self, _renderer: &mut dyn Renderer, _rect: Rect) {}
/// Calculate the natural (intrinsic) size of this view given proposed constraints.
/// This allows views like Buttons or Labels to inform the layout engine of their needs.
fn intrinsic_size(&self, _renderer: &mut dyn Renderer, _proposal: SizeProposal) -> Size {
Size::ZERO
}
/// Optionally provide a layout implementation for this view.
fn layout(&self) -> Option<&dyn layout::LayoutView> {
None
}
/// Returns the flex weight of this view for proportional distribution in stacks.
fn flex_weight(&self) -> f32 {
0.0
}
/// Returns the grid placement configuration for this view if it is laid out in a Grid.
fn get_grid_placement(&self) -> Option<GridPlacement> {
None
}
/// Provided modifier entry point
fn modifier<M: ViewModifier>(self, m: M) -> ModifiedView<Self, M> {
ModifiedView::new(self, m)
}
/// Apply a Bifrost (Frosted Glass) effect to the view
fn bifrost(
self,
blur: f32,
saturation: f32,
opacity: f32,
) -> ModifiedView<Self, FrostedGlassModifier> {
self.modifier(FrostedGlassModifier {
blur,
saturation,
opacity,
fresnel_strength: 1.0,
})
}
/// Apply a Bifrost (Frosted Glass) effect with full parameter control.
fn bifrost_full(
self,
blur: f32,
saturation: f32,
opacity: f32,
fresnel_strength: f32,
) -> ModifiedView<Self, FrostedGlassModifier> {
self.modifier(FrostedGlassModifier {
blur,
saturation,
opacity,
fresnel_strength,
})
}
/// Apply a Gungnir (Neon Glow) effect to the view
fn gungnir(
self,
color: impl Into<String>,
radius: f32,
intensity: f32,
) -> ModifiedView<Self, NeonGlowModifier> {
self.modifier(NeonGlowModifier {
color: color.into(),
radius,
intensity,
})
}
/// Apply a Mjolnir Slice (Geometric cut) to the view
fn mjolnir_slice(self, angle: f32, offset: f32) -> ModifiedView<Self, GeometricClipModifier> {
self.modifier(GeometricClipModifier { angle, offset })
}
/// Apply a Mjolnir Shatter (Fragmented transition) to the view
fn mjolnir_shatter(self, pieces: u32, force: f32) -> ModifiedView<Self, FragmentModifier> {
self.modifier(FragmentModifier { pieces, force })
}
/// Mark this view as a Bifrost Bridge (Shared Element) for cross-view persistence
fn bifrost_bridge(self, id: impl Into<String>) -> ModifiedView<Self, SharedElementModifier> {
self.modifier(SharedElementModifier { id: id.into() })
}
/// Add a background color to this view
fn background(self, color: [f32; 4]) -> ModifiedView<Self, BackgroundModifier> {
self.modifier(BackgroundModifier { color })
}
/// Add padding to this view
fn padding(self, amount: f32) -> ModifiedView<Self, PaddingModifier> {
self.modifier(PaddingModifier { amount })
}
/// Set the opacity (alpha) of this view in the range [0.0, 1.0].
fn opacity(self, opacity: f32) -> ModifiedView<Self, OpacityModifier> {
self.modifier(OpacityModifier {
opacity: opacity.clamp(0.0, 1.0),
})
}
/// Override the foreground (text / icon) color of this view.
fn foreground_color(self, color: [f32; 4]) -> ModifiedView<Self, ForegroundColorModifier> {
self.modifier(ForegroundColorModifier { color })
}
/// Constrain this view to an explicit width and/or height.
/// Constrains the size of this view using fixed width/height values.
fn frame(self, width: Option<f32>, height: Option<f32>) -> ModifiedView<Self, FrameModifier> {
self.modifier(FrameModifier {
width,
height,
min_width: None,
max_width: None,
min_height: None,
max_height: None,
alignment: Alignment::Center,
})
}
/// Give this view a flex weight for proportional space distribution in stacks.
fn flex(self, weight: f32) -> ModifiedView<Self, FlexModifier> {
self.modifier(FlexModifier { weight })
}
/// Specify the grid placement configuration (column, row, column_span, row_span) for this view.
fn grid_placement(self, placement: GridPlacement) -> ModifiedView<Self, GridPlacementModifier> {
self.modifier(GridPlacementModifier { placement })
}
/// Overlay a view on top of this view, aligned and offset relative to it.
fn overlay<O: View + Clone + 'static>(
self,
overlay: O,
alignment: Alignment,
offset: [f32; 2],
on_dismiss: Option<Arc<dyn Fn() + Send + Sync>>,
) -> ModifiedView<Self, OverlayModifier> {
self.modifier(OverlayModifier {
overlay: overlay.erase(),
alignment,
offset,
on_dismiss,
})
}
/// Automatically add padding to avoid overlapping with platform safe areas (notches, bars).
fn safe_area_padding(self) -> ModifiedView<Self, SafeAreaModifier> {
self.modifier(SafeAreaModifier { ignores: false })
}
/// Explicitly ignore platform safe areas and draw into the margins.
fn ignores_safe_area(self) -> ModifiedView<Self, SafeAreaModifier> {
self.modifier(SafeAreaModifier { ignores: true })
}
/// Clip all child drawing to this view's bounds.
fn clip_to_bounds(self) -> ModifiedView<Self, ClipModifier> {
self.modifier(ClipModifier)
}
/// Draw a colored border around this view.
fn border(self, color: [f32; 4], width: f32) -> ModifiedView<Self, BorderModifier> {
self.modifier(BorderModifier { color, width })
}
/// Add elevation (shadow) to the view. Level determines the shadow depth.
fn elevation(self, level: f32) -> ModifiedView<Self, ElevationModifier> {
self.modifier(ElevationModifier { level })
}
/// Apply an absolute-like position offset to this view.
/// The view is shifted by (x, y) from its layout position.
fn position(self, x: f32, y: f32) -> ModifiedView<Self, PositionModifier> {
self.modifier(PositionModifier { x, y })
}
/// Set the z-index (render order) for this view.
/// Higher values render on top of lower values.
fn z_index(self, z: i32) -> ModifiedView<Self, ZIndexModifier> {
self.modifier(ZIndexModifier { z_index: z })
}
/// Add a magnetic effect that pulls the view towards the cursor.
fn magnetic(self, radius: f32, intensity: f32) -> ModifiedView<Self, MagneticPullModifier> {
self.modifier(MagneticPullModifier { radius, intensity })
}
/// Add a ManiGlow (Lunar Illuminator) effect that glows near the cursor.
fn mani_glow(self, color: [f32; 4], radius: f32) -> ModifiedView<Self, CursorGlowModifier> {
self.modifier(CursorGlowModifier { color, radius })
}
/// Theme this view based on a specific memory layer.
fn memory_layer(self, layer: MemoryLayer) -> ModifiedView<Self, MemoryLayerModifier> {
self.modifier(MemoryLayerModifier { layer })
}
/// Enable Fafnir's Evolution: The component grows and glows as it is used.
fn fafnir_evolve(self, id: u64) -> ModifiedView<Self, EvolvingInteractionModifier> {
self.modifier(EvolvingInteractionModifier { id })
}
/// Enable Mimir's Intent: The component anticipates user interaction via pointer kinematics.
fn mimir_intent(self) -> ModifiedView<Self, IntentPredictionModifier> {
self.modifier(IntentPredictionModifier)
}
/// Enable Kvasir's Vibes: Subconscious telemetry representing cognitive complexity.
fn kvasir_vibes(self, complexity: f32) -> ModifiedView<Self, ComplexityTelemetryModifier> {
self.modifier(ComplexityTelemetryModifier { complexity })
}
/// Bestow Odin's Eye: Global omniscient observability layer.
fn odins_eye(self) -> ModifiedView<Self, ObservabilityOverlayModifier> {
self.modifier(ObservabilityOverlayModifier)
}
/// Trigger an action when the view appears
fn on_appear<F: Fn() + Send + Sync + 'static>(
self,
action: F,
) -> ModifiedView<Self, LifecycleModifier> {
self.modifier(LifecycleModifier {
on_appear: Some(Arc::new(action)),
on_disappear: None,
})
}
/// Trigger an action when the view disappears
fn on_disappear<F: Fn() + Send + Sync + 'static>(
self,
action: F,
) -> ModifiedView<Self, LifecycleModifier> {
self.modifier(LifecycleModifier {
on_appear: None,
on_disappear: Some(Arc::new(action)),
})
}
/// Trigger an action when the view is clicked
fn on_click<F: Fn() + Send + Sync + 'static>(
self,
action: F,
) -> ModifiedView<Self, OnClickModifier> {
self.modifier(OnClickModifier {
action: Arc::new(action),
})
}
/// Trigger an action when the pointer enters the view bounds
fn on_pointer_enter<F: Fn() + Send + Sync + 'static>(
self,
action: F,
) -> ModifiedView<Self, OnPointerEnterModifier> {
self.modifier(OnPointerEnterModifier {
action: Arc::new(action),
})
}
/// Trigger an action when the pointer leaves the view bounds
fn on_pointer_leave<F: Fn() + Send + Sync + 'static>(
self,
action: F,
) -> ModifiedView<Self, OnPointerLeaveModifier> {
self.modifier(OnPointerLeaveModifier {
action: Arc::new(action),
})
}
/// Trigger an action when the pointer moves inside the view bounds
fn on_pointer_move<F: Fn(f32, f32) + Send + Sync + 'static>(
self,
action: F,
) -> ModifiedView<Self, OnPointerMoveModifier> {
self.modifier(OnPointerMoveModifier {
action: Arc::new(action),
})
}
/// Trigger an action when the pointer is pressed down
fn on_pointer_down<F: Fn() + Send + Sync + 'static>(
self,
action: F,
) -> ModifiedView<Self, OnPointerDownModifier> {
self.modifier(OnPointerDownModifier {
action: Arc::new(action),
})
}
/// Trigger an action when the pointer is released
fn on_pointer_up<F: Fn() + Send + Sync + 'static>(
self,
action: F,
) -> ModifiedView<Self, OnPointerUpModifier> {
self.modifier(OnPointerUpModifier {
action: Arc::new(action),
})
}
/// Type-erase this view into AnyView
fn erase(self) -> AnyView
where
Self: Clone + 'static,
{
AnyView::new(self)
}
// =============================================================================
// ACCESSIBILITY
// =============================================================================
/// Return accessibility properties for this view.
/// Override to expose semantic role, label, state to assistive technology.
/// Default returns `None` (view is not explicitly accessible).
fn aria_properties(&self) -> Option<AriaProperties> {
None
}
/// Handle a keyboard navigation event.
/// Return true if consumed, false to bubble.
fn on_key_event(&self, _key: &str, _modifiers: KeyModifiers) -> bool {
false
}
/// Return keyboard shortcuts this view responds to.
fn key_shortcuts(&self) -> Vec<KeyShortcut> {
vec![]
}
/// Return true when this view's render output has changed since last build.
/// Default false (static views skip rebuild). Override for interactive views
/// or views backed by dynamic state.
/// When returns false, VDom::build skips this subtree entirely.
fn changed(&self) -> bool {
false
}
/// Return true when this view needs per-frame updates (animations, timers, etc.).
/// Default false. Views that drive continuous updates (e.g., spring animations,
/// particle effects, real-time data feeds) should override this to return true.
///
/// Unlike `changed()`, this is checked at the top-level render loop to decide
/// whether to request a new frame at all. A static UI with no animations should
/// keep this false to avoid unnecessary frame processing.
fn needs_update(&self) -> bool {
false
}
/// Stable identity for diff keying. Return None for anonymous views.
/// When Some(id), the VDOM layer uses this to match nodes across rebuilds,
/// enabling handler survival and incremental patch generation.
fn view_id(&self) -> Option<u64> {
None
}
}