Skip to main content

Crate horizon_lattice_render

Crate horizon_lattice_render 

Source
Expand description

Graphics rendering backend for Horizon Lattice.

This crate provides the GPU-accelerated rendering layer built on wgpu. It handles surface management, rendering primitives, and GPU resource management.

§Getting Started

Before any rendering can occur, you must initialize the GraphicsContext:

use horizon_lattice_render::{GraphicsContext, GraphicsConfig};

// Initialize with default configuration
let ctx = GraphicsContext::init(GraphicsConfig::default())
    .expect("Failed to initialize graphics");

// Get adapter information
let info = ctx.adapter_info();
println!("Using GPU: {} ({:?})", info.name, info.backend);

§Creating Render Surfaces

Each window needs a RenderSurface to render to:

use std::sync::Arc;
use horizon_lattice_render::{GraphicsContext, GraphicsConfig, RenderSurface, SurfaceConfig};
use winit::event_loop::ActiveEventLoop;
use winit::window::Window;

// Initialize graphics first
GraphicsContext::init(GraphicsConfig::default())?;

// Create a window (must be Arc for surface lifetime)
let window = Arc::new(event_loop.create_window(Window::default_attributes()).unwrap());

// Create a render surface
let mut surface = RenderSurface::new(window, SurfaceConfig::default())?;

§Using the Renderer

The GpuRenderer provides a high-level 2D drawing API:

use horizon_lattice_render::{
    GraphicsContext, GraphicsConfig, RenderSurface, SurfaceConfig,
    GpuRenderer, Renderer, Color, Rect, Size,
};
use std::sync::Arc;
use winit::window::Window;

GraphicsContext::init(GraphicsConfig::default())?;
let mut surface = RenderSurface::new(window, SurfaceConfig::default())?;
let mut renderer = GpuRenderer::new(&surface)?;

// Begin a frame
renderer.begin_frame(Color::WHITE, Size::new(800.0, 600.0));

// Draw some shapes
renderer.fill_rect(Rect::new(10.0, 10.0, 100.0, 50.0), Color::RED);

renderer.save();
renderer.translate(200.0, 100.0);
renderer.fill_rect(Rect::new(0.0, 0.0, 80.0, 80.0), Color::BLUE);
renderer.restore();

// End frame and render to surface
renderer.end_frame();
renderer.render_to_surface(&mut surface)?;

§Handling Window Events

The surface needs to be resized when the window is resized:

// In your window event handler:
// WindowEvent::Resized(size) => {
surface.resize(width, height).ok();
// }

Re-exports§

pub use image_data::ColorType;
pub use image_data::ExifData;
pub use image_data::ImageMetadata;
pub use image_data::Orientation;
pub use image_data::read_dimensions;
pub use image_data::read_dimensions_from_bytes;
pub use image_data::read_metadata;
pub use image_data::read_metadata_from_bytes;
pub use damage::DamageTracker;
pub use layer::Compositor;
pub use layer::Layer;
pub use layer::LayerConfig;
pub use layer::LayerId;
pub use stencil::ClipShape;
pub use stencil::ClipStack;
pub use text::BackgroundRect;
pub use text::DecorationLine;
pub use text::Font;
pub use text::FontBuilder;
pub use text::FontFaceInfo;
pub use text::FontFamily;
pub use text::FontFeature;
pub use text::FontLoadError;
pub use text::FontMetrics;
pub use text::FontQuery;
pub use text::FontStretch;
pub use text::FontStyle;
pub use text::FontSystem;
pub use text::FontSystemConfig;
pub use text::FontWeight;
pub use text::GlyphAllocation;
pub use text::GlyphAtlas;
pub use text::GlyphAtlasStats;
pub use text::GlyphCache;
pub use text::GlyphCacheStats;
pub use text::GlyphId;
pub use text::GlyphPixelFormat;
pub use text::GlyphRenderMode;
pub use text::HorizontalAlign;
pub use text::LayoutGlyph;
pub use text::LayoutLine;
pub use text::RasterizedGlyph;
pub use text::RichText;
pub use text::RichTextSpan;
pub use text::ShapedGlyph;
pub use text::ShapedText;
pub use text::ShapingOptions;
pub use text::TextDecoration;
pub use text::TextDecorationStyle;
pub use text::TextDecorationType;
pub use text::TextLayout;
pub use text::TextLayoutOptions;
pub use text::TextShaper;
pub use text::TextSpan;
pub use text::VerticalAlign;
pub use text::WrapMode;
pub use wgpu;

Modules§

capture
Screenshot capture and texture readback utilities.
damage
Damage tracking for efficient partial rendering.
image_data
Image metadata and data structures for image loading.
layer
Layer compositing system for rendering complex UI hierarchies.
stencil
Stencil-based clipping support.
text
Text rendering subsystem for Horizon Lattice.

Structs§

AnimatedImage
An animated image containing multiple frames.
AnimationController
Controls playback of an animated image.
AnimationFrame
A single frame in an animation.
AsyncImageHandle
A handle to an async image load operation.
AsyncImageLoader
Async image loader that decodes images on background threads.
AsyncImageLoaderConfig
Configuration for the async image loader.
BoxShadow
A box shadow definition (CSS box-shadow model).
BoxShadowParams
Parameters for rendering a box shadow on a rounded rectangle.
Color
An RGBA color with premultiplied alpha.
CornerRadii
Corner radii for rounded rectangles.
DashPattern
Dash pattern for stroked lines.
DiskCacheConfig
Configuration for the disk image cache.
DiskCacheStats
Statistics about the disk cache.
DiskImageCache
A disk-based cache for downloaded images.
EmbeddedIconData
Embedded icon data that is compiled into the binary.
EmbeddedIconSet
A collection of embedded icons.
FontFaceId
A unique per database face ID.
FrameStats
Statistics from a frame render.
GlyphCacheKey
Key for building a glyph cache
GpuRenderer
GPU-accelerated 2D renderer.
GpuResources
Shared GPU resources used across all rendering surfaces.
GradientStop
A gradient color stop.
GraphicsConfig
Configuration options for graphics context initialization.
GraphicsContext
The main graphics context for the application.
Icon
An icon that can be displayed in widgets.
Image
A GPU-backed image that can be rendered.
ImageBuffer
A CPU-side image buffer for manipulation operations.
ImageCache
An LRU (Least Recently Used) cache for decoded images.
ImageCacheConfig
Configuration for the image cache.
ImageCacheStats
Statistics about the image cache.
ImageLoader
Builder for loading images into the rendering system.
ImageManager
Manages multiple texture atlases for efficient image storage.
LinearGradient
A linear gradient definition.
NinePatch
Nine-patch (9-slice) image definition.
OffscreenConfig
Configuration for offscreen surface creation.
OffscreenSurface
An offscreen render surface for headless rendering.
Path
A 2D path for complex vector shapes.
Point
A point in 2D space.
PreparedGlyph
A positioned glyph ready for rendering.
RadialGradient
A radial gradient definition.
Rect
A rectangle defined by origin and size.
RenderState
Saved renderer state for save/restore operations.
RenderStateStack
Common state management for renderers.
RenderSurface
A render surface attached to a window.
RoundedRect
A rectangle with rounded corners.
ScalableImage
An image with multiple resolution variants for HiDPI support.
Size
A size in 2D space (width and height).
SizedIconSet
Collection of icon variants for different sizes.
StatefulIconSet
Collection of icon variants for different states.
Stroke
Stroke style options.
SurfaceConfig
Configuration options for surface creation.
SurfaceFrame
A frame ready for rendering.
SvgCache
An LRU cache for rasterized SVG images.
SvgCacheConfig
Configuration for the SVG cache.
SvgCacheKey
Cache key for SVG rasterizations.
SvgCacheStats
Statistics about the SVG cache.
SvgImage
An SVG image that can be rendered at any resolution.
TessellatedPath
Tessellated path output suitable for GPU rendering.
TextRenderPass
A pass for rendering text glyphs.
TextRenderer
GPU-accelerated text renderer.
TextRendererConfig
Text rendering configuration options.
TextRendererStats
Statistics about text rendering performance.
TextureAtlas
A texture atlas that packs multiple images into a single GPU texture.
ThemedIconSet
Collection of icon variants for different theme modes.
Transform2D
A 2D affine transformation matrix.
TransformStack
A stack of transforms for save/restore functionality.

Enums§

BlendMode
Blend mode for compositing.
CacheKey
Key type for cache entries.
FillRule
Fill rule for determining the interior of a path.
IconMode
Mode for displaying an icon in a widget.
IconPosition
Position of an icon relative to text in a widget.
IconSize
Standard icon sizes following desktop conventions.
IconSource
Source for an icon - either a pre-loaded image or a path for lazy loading.
IconState
Complete set of icon states for widget interaction.
IconThemeMode
Theme mode for icon variants.
ImageBlendMode
Blend mode for image composition operations.
ImageFormat
Image format for embedded icon data.
ImageScaleMode
How to scale an image when rendering to a different size.
LineCap
Line cap style.
LineJoin
Line join style.
LoadingState
The current state of an async image load operation.
LoopCount
Loop behavior for animations.
OutputFormat
Output format for image encoding.
Paint
A paint style for filling shapes.
PathCommand
Commands that make up a path.
PlaybackState
Playback state for an animation.
PresentMode
Present mode (VSync behavior) preference.
RenderError
Errors that can occur during graphics operations.
ResizeFilter
Resampling filter for resize operations.
SvgSource
Source identifier for SVG images.

Constants§

DEFAULT_TOLERANCE
Default tessellation tolerance.

Traits§

Renderer
The core 2D rendering trait.

Functions§

icon_tint_for_state
Calculate the tint color for an icon based on widget state.
icon_tint_for_state_full
Calculate the tint color for an icon based on IconState.
icon_tint_for_state_with_hover
Calculate the tint color combining IconState with hover effects.
tessellate_fill
Tessellate a path for filling.
tessellate_stroke
Tessellate a path for stroking.

Type Aliases§

RenderResult
Result type for render operations.