cvkg-core 0.2.10

Cyber Viking Kvasir Graph (CVKG) - High-fidelity agentic UI framework
Documentation
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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
//! Renderer sub-traits — logical groupings of the Renderer capability surface.
//!
//! The main `Renderer` trait (in the parent module) aggregates all of these.
//! Backends continue to implement `Renderer` as before. These sub-traits exist
//! so that consumer code can depend on only the capability slice it needs.

use super::{
    BerserkerMode, ColorTheme, Event, Mesh, Rect, TelemetryData,
};

// ══════════════════════════════════════════════════════════════════════════════
// Core — required by every backend
// ══════════════════════════════════════════════════════════════════════════════

/// Core rendering control. Every backend must implement these.
pub trait RendererCore: Send {
    /// Request a redraw as soon as possible.
    fn request_redraw(&mut self);
    /// Return true if the current frame is over its time budget.
    fn is_over_budget(&self) -> bool;
}

// ══════════════════════════════════════════════════════════════════════════════
// Shapes — 2D primitive drawing
// ══════════════════════════════════════════════════════════════════════════════

/// 2D shape drawing operations.
pub trait RendererShapes {
    fn fill_rect(&mut self, rect: Rect, color: [f32; 4]);
    fn fill_rounded_rect(&mut self, rect: Rect, radius: f32, color: [f32; 4]);
    fn fill_ellipse(&mut self, rect: Rect, color: [f32; 4]);
    /// Fill a rounded rect with glass material for frosted backdrop effect.
    fn fill_glass_rect(&mut self, rect: Rect, radius: f32, blur_radius: f32);
    fn stroke_rect(&mut self, rect: Rect, color: [f32; 4], stroke_width: f32);
    fn stroke_rounded_rect(
        &mut self,
        rect: Rect,
        radius: f32,
        color: [f32; 4],
        stroke_width: f32,
    );
    fn stroke_ellipse(&mut self, rect: Rect, color: [f32; 4], stroke_width: f32);
    fn draw_line(
        &mut self,
        x1: f32,
        y1: f32,
        x2: f32,
        y2: f32,
        color: [f32; 4],
        stroke_width: f32,
    );
    fn fill_polygon(&mut self, vertices: &[[f32; 2]], color: [f32; 4]) {}
    fn stroke_polygon(
        &mut self,
        vertices: &[[f32; 2]],
        color: [f32; 4],
        stroke_width: f32,
    ) {
        let _ = (vertices, color, stroke_width);
    }
}

// ══════════════════════════════════════════════════════════════════════════════
// 3D — mesh and cube drawing
// ══════════════════════════════════════════════════════════════════════════════

/// 3D drawing operations. Optional — defaults to no-op.
pub trait Renderer3D {
    fn draw_3d_cube(&mut self, _rect: Rect, _color: [f32; 4], _rotation: [f32; 3]) {}
    fn draw_mesh(&mut self, _mesh: &Mesh, _color: [f32; 4], _transform: glam::Mat4) {}
}

// ══════════════════════════════════════════════════════════════════════════════
// Text — text layout and measurement
// ══════════════════════════════════════════════════════════════════════════════

pub trait RendererText {
    fn draw_text(&mut self, text: &str, x: f32, y: f32, size: f32, color: [f32; 4]);
    fn measure_text(&mut self, text: &str, size: f32) -> (f32, f32);

    fn shape_rich_text(
        &mut self,
        _spans: &[cvkg_runic_text::TextSpan],
        _max_width: Option<f32>,
        _align: cvkg_runic_text::TextAlign,
        _overflow: cvkg_runic_text::TextOverflow,
    ) -> Option<cvkg_runic_text::ShapedText> {
        None
    }

    fn draw_shaped_text(&mut self, _text: &cvkg_runic_text::ShapedText, _x: f32, _y: f32) {}
}

// ══════════════════════════════════════════════════════════════════════════════
// Images — texture and image handling
// ══════════════════════════════════════════════════════════════════════════════

/// Image and texture operations.
pub trait RendererImages {
    fn draw_texture(&mut self, _texture_id: u32, _rect: Rect) {}
    fn draw_image(&mut self, _image_name: &str, _rect: Rect) {}
    fn load_image(&mut self, _name: &str, _data: &[u8]) {}
    fn prewarm_vram(&mut self, _assets: Vec<(String, Vec<u8>)>) {}
}

// ════════════════════════════════════════════════════════════════════════════──
// Data Viz — heatmap / data texture support
// ══════════════════════════════════════════════════════════════════════════════

/// Data-visualisation helpers.
pub trait RendererDataViz {
    fn upload_data_texture(
        &mut self,
        _id: &str,
        _data: &[f32],
        _width: u32,
        _height: u32,
    ) {
    }
    fn draw_heatmap(&mut self, _texture_id: &str, _rect: Rect, _palette: &str) {}
}

// ══════════════════════════════════════════════════════════════════════════════
// Vector Graphics — SVG loading and drawing
// ══════════════════════════════════════════════════════════════════════════════

/// SVG vector graphics.
pub trait RendererVectorGraphics {
    fn load_svg(&mut self, _name: &str, _svg_data: &[u8]) {}
    fn draw_svg(&mut self, _name: &str, _rect: Rect) {}
}

// ══════════════════════════════════════════════════════════════════════════════
// Effects — gradients, shadows, 9-slice, dashed strokes
// ══════════════════════════════════════════════════════════════════════════════

/// Visual effects.
pub trait RendererEffects {
    fn draw_linear_gradient(
        &mut self,
        _rect: Rect,
        _start_color: [f32; 4],
        _end_color: [f32; 4],
        _angle: f32,
    ) {
    }
    fn draw_radial_gradient(
        &mut self,
        _rect: Rect,
        _inner_color: [f32; 4],
        _outer_color: [f32; 4],
    ) {
    }
    fn draw_drop_shadow(
        &mut self,
        _rect: Rect,
        _radius: f32,
        _color: [f32; 4],
        _blur: f32,
        _spread: f32,
    ) {
    }
    fn stroke_dashed_rounded_rect(
        &mut self,
        _rect: Rect,
        _radius: f32,
        _color: [f32; 4],
        _width: f32,
        _dash: f32,
        _gap: f32,
    ) {
    }
    fn draw_9slice(
        &mut self,
        _image_name: &str,
        _rect: Rect,
        _left: f32,
        _top: f32,
        _right: f32,
        _bottom: f32,
    ) {
    }
    fn push_shadow(&mut self, _radius: f32, _color: [f32; 4], _offset: [f32; 2]) {}
    fn pop_shadow(&mut self) {}
}

// ══════════════════════════════════════════════════════════════════════════════
// Clipping — scissor / clip-rect stack
// ══════════════════════════════════════════════════════════════════════════════

/// Clip-rect stack operations.
pub trait RendererClipping {
    fn push_clip_rect(&mut self, _rect: Rect) {}
    fn pop_clip_rect(&mut self) {}
    fn current_clip_rect(&self) -> Rect {
        Rect::new(-10000.0, -10000.0, 20000.0, 20000.0)
    }
}

// ══════════════════════════════════════════════════════════════════════════════
// Transforms — 2D affine transform stack
// ══════════════════════════════════════════════════════════════════════════════

/// 2D transform stack.
pub trait RendererTransforms {
    fn push_transform(&mut self, _translation: [f32; 2], _scale: [f32; 2], _rotation: f32) {}
    fn pop_transform(&mut self) {}
}

// ══════════════════════════════════════════════════════════════════════════════
// Opacity — opacity stack
// ══════════════════════════════════════════════════════════════════════════════

/// Opacity stack operations.
pub trait RendererOpacity {
    fn push_opacity(&mut self, _opacity: f32) {}
    fn pop_opacity(&mut self) {}
}

// ══════════════════════════════════════════════════════════════════════════════
// Berserker — scene / rage / shatter pipeline
// ══════════════════════════════════════════════════════════════════════════════

/// Berserker pipeline (rage, shatter, scene presets).
pub trait RendererBerserker {
    fn set_theme(&mut self, _theme: ColorTheme) {}
    fn set_rage(&mut self, _rage: f32) {}
    fn set_berserker_mode(&mut self, _state: BerserkerMode) {}
    fn trigger_shatter_event(&mut self, _origin: [f32; 2], _force: f32) {}
    fn set_scene(&mut self, _scene: &str) {}
    fn set_scene_preset(&mut self, _preset: u32) {}
}

// ══════════════════════════════════════════════════════════════════════════════
// Export — PNG capture / print
// ══════════════════════════════════════════════════════════════════════════════

/// Frame export operations.
pub trait RendererExport {
    fn capture_png(&mut self) -> Vec<u8> {
        Vec::new()
    }
    fn print(&mut self) {}
}

// ══════════════════════════════════════════════════════════════════════════════
// Cyberpunk — bifrost, gungnir, mani, mjolnir, memoize
// ══════════════════════════════════════════════════════════════════════════════

/// Cyberpunk-specific visual effects.
pub trait RendererCyberpunk {
    fn bifrost(&mut self, _rect: Rect, _blur: f32, _saturation: f32, _opacity: f32) {}
    fn gungnir(&mut self, _rect: Rect, _color: [f32; 4], _radius: f32, _intensity: f32) {}
    fn mani_glow(&mut self, _rect: Rect, _color: [f32; 4], _radius: f32) {}
    fn push_mjolnir_slice(&mut self, _angle: f32, _offset: f32) {}
    fn pop_mjolnir_slice(&mut self) {}
    fn memoize(&mut self, id: u64, data_hash: u64, render_fn: &dyn Fn(&mut dyn super::Renderer));
    fn mjolnir_shatter(
        &mut self,
        _rect: Rect,
        _pieces: u32,
        _force: f32,
        _color: [f32; 4],
    ) {
    }
    fn mjolnir_fluid_shatter(
        &mut self,
        _rect: Rect,
        _pieces: u32,
        _force: f32,
        _color: [f32; 4],
    ) {
    }
    fn draw_mjolnir_bolt(
        &mut self,
        _from: [f32; 2],
        _to: [f32; 2],
        _color: [f32; 4],
    ) {
    }
}

// ══════════════════════════════════════════════════════════════════════════════
// Compute & Particles — fluid simulations, generative physics
// ══════════════════════════════════════════════════════════════════════════════

/// Generic compute and particle dispatch operations for futuristic UIs.
pub trait RendererCompute {
    /// Dispatches a burst of GPU particles (e.g. fireworks, data streams).
    fn dispatch_particles(
        &mut self,
        _origin: [f32; 2],
        _count: u32,
        _effect_type: &str,
        _color: [f32; 4],
    ) {
    }
}

// ══════════════════════════════════════════════════════════════════════════════
// Volumetric — holograms, raymarching
// ══════════════════════════════════════════════════════════════════════════════

/// Volumetric and raymarching projections.
pub trait RendererVolumetric {
    /// Draws a volumetric hologram into the specified bounding rectangle.
    fn draw_hologram(&mut self, _rect: Rect, _hologram_id: &str, _time: f32) {}
}

// ════════════════════════════════════════════════════════════════════════════──
// Accessibility — ARIA / shared elements / keys
// ══════════════════════════════════════════════════════════════════════════════

/// Accessibility helpers.
pub trait RendererAccessibility {
    fn set_aria_role(&mut self, _role: &str) {}
    fn set_aria_label(&mut self, _label: &str) {}
    fn register_shared_element(&mut self, _id: &str, _rect: Rect) {}
    fn set_key(&mut self, _key: &str) {}
}

// ══════════════════════════════════════════════════════════════════════════════
// Telemetry — frame budget / performance data
// ══════════════════════════════════════════════════════════════════════════════

/// Performance telemetry.
pub trait RendererTelemetry {
    fn get_telemetry(&self) -> TelemetryData {
        TelemetryData::default()
    }
}

// ══════════════════════════════════════════════════════════════════════════════
// VDOM — virtual-DOM node tracking + event handler registration
// ══════════════════════════════════════════════════════════════════════════════

/// VDOM integration.
pub trait RendererVDOM {
    fn push_vnode(&mut self, _rect: Rect, _name: &'static str) {}
    fn pop_vnode(&mut self) {}
    fn register_handler(
        &mut self,
        _event_type: &str,
        _handler: std::sync::Arc<dyn Fn(Event) + Send + Sync>,
    ) {
    }
    fn register_lifecycle(
        &mut self,
        _on_appear: Option<std::sync::Arc<dyn Fn() + Send + Sync>>,
        _on_disappear: Option<std::sync::Arc<dyn Fn() + Send + Sync>>,
    ) {
    }
}

// ══════════════════════════════════════════════════════════════════════════════
// Z-Index — depth ordering
// ══════════════════════════════════════════════════════════════════════════════

/// Z-index ordering.
pub trait RendererZIndex {
    fn set_z_index(&mut self, _z: f32) {}
    fn get_z_index(&self) -> f32 {
        0.0
    }
}

// ══════════════════════════════════════════════════════════════════════════════
// Layout Debug — query / visualize layout
// ══════════════════════════════════════════════════════════════════════════════

/// Layout debugging helpers.
pub trait RendererLayoutDebug {
    fn query_layout(
        &self,
        _node_id: super::scene_graph::NodeId,
    ) -> Option<Rect> {
        None
    }
    fn set_debug_layout(&mut self, _enabled: bool) {}
    fn get_debug_layout(&self) -> bool {
        false
    }
}

// ══════════════════════════════════════════════════════════════════════════════
// Pointer — mouse / touch position query
// ══════════════════════════════════════════════════════════════════════════════

/// Pointer position query.
pub trait RendererPointer {
    fn get_pointer_position(&self) -> [f32; 2] {
        [0.0, 0.0]
    }
}

// ══════════════════════════════════════════════════════════════════════════════
// Material — draw call routing for multi-pass pipeline
// ══════════════════════════════════════════════════════════════════════════════

/// Material routing — controls which pass a draw call is routed to.
pub trait RendererMaterial {
    /// Set the active material for subsequent draw calls.
    fn set_material(&mut self, _material: crate::material::DrawMaterial) {}
    /// Return the currently active material.
    fn current_material(&self) -> crate::material::DrawMaterial {
        crate::material::DrawMaterial::Opaque
    }
}