cvkg_render_native/lib.rs
1//! # CVKG Agentic Development Guidelines (v1.2)
2//!
3//! All AI agents contributing to this crate MUST follow ALL seven rules:
4//!
5//! ── Karpathy Guidelines (1–4) ────────────────────────────────────────────
6//! 1. THINK FIRST — State assumptions. Surface ambiguity. Push back on complexity.
7//! 2. STAY SIMPLE — Minimum code. No speculative features. No unasked-for abstractions.
8//! 3. BE SURGICAL — Touch only what's required. Own your orphans. Don't improve neighbors.
9//! 4. VERIFY GOALS — Turn tasks into checkable criteria. Loop until they pass. Never commit broken.
10//!
11//! ── CVKG Extended Protocols (5–7) ────────────────────────────────────────
12//! 5. TRIPLE-PASS — Read the target, its surrounding context, and its full call graph
13// at least THREE TIMES before making any edit or revision.
14//! 6. COMMENT ALL — Every major pub fn, unsafe block, and non-trivial algorithm in
15// every .rs/.ts/.h/.wgsl file MUST have a descriptive doc comment.
16// Comments describe WHY and WHAT CONTRACT, not HOW mechanically.
17//! 7. MONITOR LOOPS — Check every tool call / command for progress every 30 seconds.
18// After 3 consecutive identical failures, stop, write BLOCKED.md,
19// and move to unblocked work. Never silently accept a broken state.
20//!
21//! Sources:
22// Karpathy: https://github.com/multica-ai/andrej-karpathy-skills
23// CVKG Extended: Section 2 of the CVKG Design Specification
24
25//! Platform-native widget delegation using winit and AccessKit
26//!
27//! This crate provides platform-specific rendering backends for native desktop targets
28// using winit for window/event handling and AccessKit for accessibility tree integration.
29
30use cvkg_core::Rect;
31use winit::event_loop::EventLoop;
32
33/// Native renderer backend implementing the CvkgRenderer trait
34pub struct NativeRenderer {
35 window: Option<winit::window::Window>,
36 event_loop: Option<EventLoop<()>>,
37 accesskit_tree: Option<accesskit::Tree>,
38}
39
40impl NativeRenderer {
41 #[doc(hidden)]
42 pub fn new() -> Self {
43 Self {
44 window: None,
45 event_loop: None,
46 accesskit_tree: None,
47 }
48 }
49}
50
51/// Abstract trait that all renderer backends must implement
52pub trait CvkgRenderer: Send + Sync {
53 fn begin_frame(&mut self, size: winit::dpi::PhysicalSize<u32>, scale: f32);
54 fn end_frame(&mut self);
55
56 fn fill_rect(&mut self, rect: Rect, color: [f32; 4]);
57 fn stroke_rect(&mut self, rect: Rect, color: [f32; 4], stroke_width: f32);
58 fn fill_rounded_rect(&mut self, rect: Rect, radius: f32, color: [f32; 4]);
59 fn draw_text(&mut self, text: &str, x: f32, y: f32, color: [f32; 4]);
60}
61
62// TODO: Implement actual native rendering with winit and AccessKit integration
63// TODO: Platform-specific implementations for macOS, Windows, and Linux