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§
- Animated
Image - An animated image containing multiple frames.
- Animation
Controller - Controls playback of an animated image.
- Animation
Frame - A single frame in an animation.
- Async
Image Handle - A handle to an async image load operation.
- Async
Image Loader - Async image loader that decodes images on background threads.
- Async
Image Loader Config - Configuration for the async image loader.
- BoxShadow
- A box shadow definition (CSS box-shadow model).
- BoxShadow
Params - Parameters for rendering a box shadow on a rounded rectangle.
- Color
- An RGBA color with premultiplied alpha.
- Corner
Radii - Corner radii for rounded rectangles.
- Dash
Pattern - Dash pattern for stroked lines.
- Disk
Cache Config - Configuration for the disk image cache.
- Disk
Cache Stats - Statistics about the disk cache.
- Disk
Image Cache - A disk-based cache for downloaded images.
- Embedded
Icon Data - Embedded icon data that is compiled into the binary.
- Embedded
Icon Set - A collection of embedded icons.
- Font
Face Id - A unique per database face ID.
- Frame
Stats - Statistics from a frame render.
- Glyph
Cache Key - Key for building a glyph cache
- GpuRenderer
- GPU-accelerated 2D renderer.
- GpuResources
- Shared GPU resources used across all rendering surfaces.
- Gradient
Stop - A gradient color stop.
- Graphics
Config - Configuration options for graphics context initialization.
- Graphics
Context - 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.
- Image
Buffer - A CPU-side image buffer for manipulation operations.
- Image
Cache - An LRU (Least Recently Used) cache for decoded images.
- Image
Cache Config - Configuration for the image cache.
- Image
Cache Stats - Statistics about the image cache.
- Image
Loader - Builder for loading images into the rendering system.
- Image
Manager - Manages multiple texture atlases for efficient image storage.
- Linear
Gradient - A linear gradient definition.
- Nine
Patch - Nine-patch (9-slice) image definition.
- Offscreen
Config - Configuration for offscreen surface creation.
- Offscreen
Surface - An offscreen render surface for headless rendering.
- Path
- A 2D path for complex vector shapes.
- Point
- A point in 2D space.
- Prepared
Glyph - A positioned glyph ready for rendering.
- Radial
Gradient - A radial gradient definition.
- Rect
- A rectangle defined by origin and size.
- Render
State - Saved renderer state for save/restore operations.
- Render
State Stack - Common state management for renderers.
- Render
Surface - A render surface attached to a window.
- Rounded
Rect - A rectangle with rounded corners.
- Scalable
Image - An image with multiple resolution variants for HiDPI support.
- Size
- A size in 2D space (width and height).
- Sized
Icon Set - Collection of icon variants for different sizes.
- Stateful
Icon Set - Collection of icon variants for different states.
- Stroke
- Stroke style options.
- Surface
Config - Configuration options for surface creation.
- Surface
Frame - A frame ready for rendering.
- SvgCache
- An LRU cache for rasterized SVG images.
- SvgCache
Config - Configuration for the SVG cache.
- SvgCache
Key - Cache key for SVG rasterizations.
- SvgCache
Stats - Statistics about the SVG cache.
- SvgImage
- An SVG image that can be rendered at any resolution.
- Tessellated
Path - Tessellated path output suitable for GPU rendering.
- Text
Render Pass - A pass for rendering text glyphs.
- Text
Renderer - GPU-accelerated text renderer.
- Text
Renderer Config - Text rendering configuration options.
- Text
Renderer Stats - Statistics about text rendering performance.
- Texture
Atlas - A texture atlas that packs multiple images into a single GPU texture.
- Themed
Icon Set - Collection of icon variants for different theme modes.
- Transform2D
- A 2D affine transformation matrix.
- Transform
Stack - A stack of transforms for save/restore functionality.
Enums§
- Blend
Mode - Blend mode for compositing.
- Cache
Key - Key type for cache entries.
- Fill
Rule - Fill rule for determining the interior of a path.
- Icon
Mode - Mode for displaying an icon in a widget.
- Icon
Position - Position of an icon relative to text in a widget.
- Icon
Size - Standard icon sizes following desktop conventions.
- Icon
Source - Source for an icon - either a pre-loaded image or a path for lazy loading.
- Icon
State - Complete set of icon states for widget interaction.
- Icon
Theme Mode - Theme mode for icon variants.
- Image
Blend Mode - Blend mode for image composition operations.
- Image
Format - Image format for embedded icon data.
- Image
Scale Mode - How to scale an image when rendering to a different size.
- LineCap
- Line cap style.
- Line
Join - Line join style.
- Loading
State - The current state of an async image load operation.
- Loop
Count - Loop behavior for animations.
- Output
Format - Output format for image encoding.
- Paint
- A paint style for filling shapes.
- Path
Command - Commands that make up a path.
- Playback
State - Playback state for an animation.
- Present
Mode - Present mode (VSync behavior) preference.
- Render
Error - Errors that can occur during graphics operations.
- Resize
Filter - 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
IconStatewith hover effects. - tessellate_
fill - Tessellate a path for filling.
- tessellate_
stroke - Tessellate a path for stroking.
Type Aliases§
- Render
Result - Result type for render operations.