HyperChad Renderer
Core rendering abstractions and traits for HyperChad UI frameworks.
Overview
The HyperChad Renderer package provides:
- Renderer Traits: Abstract interfaces for different rendering backends
- Content Types: Structured content representation (View, JSON, Raw)
- Event System: Renderer event handling and processing
- HTML Generation: HTML tag rendering and CSS generation
- Asset Management: Optional static asset handling
- Canvas Support: Optional canvas rendering capabilities
Features
Core Abstractions
- Renderer Trait: Main rendering interface for backends
- RenderRunner: Application execution and lifecycle management
- ToRenderRunner: Conversion trait for renderer instances
- HtmlTagRenderer: HTML-specific rendering capabilities
Content System
- View: View with primary content and optional fragments
- Content Enum: Unified content representation (View, Raw, Json)
- JSON Support: Optional JSON content handling (with
jsonfeature)
Event Handling
- RendererEvent: Event types for renderer communication
- Custom Events: User-defined event processing
- Canvas Events: Optional canvas update events
- Async Events: Async event emission and handling
HTML Rendering
- Tag Generation: HTML element and attribute generation
- CSS Media Queries: Responsive CSS generation
- Root HTML: Complete HTML document generation
- Partial HTML: Fragment HTML generation
Installation
Add this to your Cargo.toml:
[]
# With default features (assets, canvas, html, viewport, viewport-immediate, viewport-retained)
= { = "../hyperchad/renderer" }
# With custom features
= {
path = "../hyperchad/renderer",
= false,
= ["json", "html", "canvas"]
}
Usage
Implementing a Renderer
use ;
use async_trait;
;
Content Creation
use ;
use Container;
// Create view content with primary container
let view_content = builder
.with_primary
.build;
// Create view with primary and fragments
let view_with_fragments = builder
.with_primary
.with_fragment
.build;
// From string (as raw HTML)
let string_content: Content = "<div>Hello World</div>".try_into?;
// From container
let container_content = from;
HTML Tag Renderer
use ;
use Container;
use BTreeMap;
Event Handling
use RendererEvent;
// Handle renderer events
match event
Canvas Support (with canvas feature)
use CanvasUpdate;
Asset Management (with assets feature)
use ;
Viewport APIs (with viewport features)
viewport::is_visible(...) -> (bool, f32): Core visibility check used by viewport systemsviewport::immediate::ViewportListener: Immediate mode visibility tracking vianew(...)andcheck()viewport::retained::Viewport: Retained mode viewport creation viaViewport::new(...)viewport::retained::ViewportListener: Retained mode callback-driven visibility tracking vianew(...)andcheck()
Content Types
View
- primary: Optional primary container content (swaps to triggering element)
- fragments: Additional containers to swap by ID (each must have an
idattribute) - delete_selectors: Element selectors to delete from the DOM
Content Enum
- View: View with primary content and optional fragments
- Raw: Raw data with content type
- Json: JSON response (with
jsonfeature)
Traits
Renderer
Core rendering interface with initialization, rendering, and event handling.
RenderRunner
Application execution interface for running renderer instances.
ToRenderRunner
Conversion trait for creating runner instances from renderers.
HtmlTagRenderer
HTML-specific rendering with CSS generation and document structure.
Feature Flags
Default Features
assets: Static asset managementcanvas: Canvas rendering capabilitieshtml: HTML rendering supportviewport: Viewport utilitiesviewport-immediate: Immediate mode viewport renderingviewport-retained: Retained mode viewport rendering
Optional Features
json: JSON content supportlogic: Logic components supportserde: Serialization/deserialization supportprofiling-puffin: Puffin profiler integrationprofiling-tracing: Tracing profiler integrationprofiling-tracy: Tracy profiler integrationbenchmark: Benchmarking utilitiesfail-on-warnings: Treat warnings as errors
Dependencies
Core dependencies:
- hyperchad_transformer: UI transformation and container system (with
htmlfeature) - hyperchad_color: Color handling and conversion
- switchy_async: Async runtime abstraction (with
rt-multi-threadandtokiofeatures) - async-trait: Async trait support
- bytes: Byte buffer utilities
- log: Logging support
Optional dependencies:
- serde: Serialization framework (with
serdefeature) - serde_json: JSON serialization (with
jsonfeature)
Integration
This package is designed for:
- Rendering Backends: Implementation base for different renderers
- UI Frameworks: Core rendering abstractions
- Web Applications: HTML and CSS generation
- Desktop Applications: Native rendering interfaces
- Static Generation: Static site and asset generation