Skip to main content

horizon_lattice_render/
lib.rs

1//! Graphics rendering backend for Horizon Lattice.
2//!
3//! This crate provides the GPU-accelerated rendering layer built on wgpu.
4//! It handles surface management, rendering primitives, and GPU resource management.
5
6#![warn(missing_docs)]
7// Allow pre-existing clippy lints - these are intentional patterns
8#![allow(clippy::too_many_arguments)]
9#![allow(clippy::explicit_counter_loop)]
10//!
11//! # Getting Started
12//!
13//! Before any rendering can occur, you must initialize the [`GraphicsContext`]:
14//!
15//! ```no_run
16//! use horizon_lattice_render::{GraphicsContext, GraphicsConfig};
17//!
18//! // Initialize with default configuration
19//! let ctx = GraphicsContext::init(GraphicsConfig::default())
20//!     .expect("Failed to initialize graphics");
21//!
22//! // Get adapter information
23//! let info = ctx.adapter_info();
24//! println!("Using GPU: {} ({:?})", info.name, info.backend);
25//! ```
26//!
27//! # Creating Render Surfaces
28//!
29//! Each window needs a [`RenderSurface`] to render to:
30//!
31//! ```no_run
32//! use std::sync::Arc;
33//! use horizon_lattice_render::{GraphicsContext, GraphicsConfig, RenderSurface, SurfaceConfig};
34//! use winit::event_loop::ActiveEventLoop;
35//! use winit::window::Window;
36//!
37//! # fn example(event_loop: &ActiveEventLoop) -> horizon_lattice_render::RenderResult<()> {
38//! // Initialize graphics first
39//! GraphicsContext::init(GraphicsConfig::default())?;
40//!
41//! // Create a window (must be Arc for surface lifetime)
42//! let window = Arc::new(event_loop.create_window(Window::default_attributes()).unwrap());
43//!
44//! // Create a render surface
45//! let mut surface = RenderSurface::new(window, SurfaceConfig::default())?;
46//! # Ok(())
47//! # }
48//! ```
49//!
50//! # Using the Renderer
51//!
52//! The [`GpuRenderer`] provides a high-level 2D drawing API:
53//!
54//! ```no_run
55//! use horizon_lattice_render::{
56//!     GraphicsContext, GraphicsConfig, RenderSurface, SurfaceConfig,
57//!     GpuRenderer, Renderer, Color, Rect, Size,
58//! };
59//! use std::sync::Arc;
60//! use winit::window::Window;
61//!
62//! # fn example(window: Arc<Window>) -> horizon_lattice_render::RenderResult<()> {
63//! GraphicsContext::init(GraphicsConfig::default())?;
64//! let mut surface = RenderSurface::new(window, SurfaceConfig::default())?;
65//! let mut renderer = GpuRenderer::new(&surface)?;
66//!
67//! // Begin a frame
68//! renderer.begin_frame(Color::WHITE, Size::new(800.0, 600.0));
69//!
70//! // Draw some shapes
71//! renderer.fill_rect(Rect::new(10.0, 10.0, 100.0, 50.0), Color::RED);
72//!
73//! renderer.save();
74//! renderer.translate(200.0, 100.0);
75//! renderer.fill_rect(Rect::new(0.0, 0.0, 80.0, 80.0), Color::BLUE);
76//! renderer.restore();
77//!
78//! // End frame and render to surface
79//! renderer.end_frame();
80//! renderer.render_to_surface(&mut surface)?;
81//! # Ok(())
82//! # }
83//! ```
84//!
85//! # Handling Window Events
86//!
87//! The surface needs to be resized when the window is resized:
88//!
89//! ```no_run
90//! # use horizon_lattice_render::RenderSurface;
91//! # fn example(surface: &mut RenderSurface, width: u32, height: u32) {
92//! // In your window event handler:
93//! // WindowEvent::Resized(size) => {
94//! surface.resize(width, height).ok();
95//! // }
96//! # }
97//! ```
98
99mod animated_image;
100mod async_image;
101mod atlas;
102mod context;
103pub mod damage;
104mod disk_cache;
105mod embedded_icon;
106mod error;
107mod gpu_renderer;
108mod gradient;
109mod icon;
110mod image;
111mod image_buffer;
112mod image_cache;
113pub mod image_data;
114pub mod layer;
115mod paint;
116mod path;
117mod renderer;
118mod scalable_image;
119pub mod stencil;
120mod surface;
121mod svg;
122mod svg_cache;
123pub mod text;
124mod text_render_pass;
125mod text_renderer;
126mod transform;
127mod types;
128
129pub mod capture;
130mod offscreen;
131
132// Shader hot-reload support (optional)
133#[cfg(feature = "shader-hot-reload")]
134mod shader_watcher;
135
136// Core infrastructure
137pub use context::{GpuResources, GraphicsConfig, GraphicsContext};
138pub use error::{RenderError, RenderResult};
139pub use offscreen::{OffscreenConfig, OffscreenSurface};
140pub use surface::{PresentMode, RenderSurface, SurfaceConfig, SurfaceFrame};
141
142// Renderer API
143pub use gpu_renderer::GpuRenderer;
144pub use renderer::{FrameStats, RenderState, RenderStateStack, Renderer};
145
146// Drawing types
147pub use paint::{
148    BlendMode, BoxShadow, BoxShadowParams, DashPattern, FillRule, GradientStop, LineCap, LineJoin,
149    LinearGradient, Paint, RadialGradient, Stroke,
150};
151pub use path::{DEFAULT_TOLERANCE, TessellatedPath, tessellate_fill, tessellate_stroke};
152pub use transform::{Transform2D, TransformStack};
153pub use types::{Color, CornerRadii, Path, PathCommand, Point, Rect, RoundedRect, Size};
154
155// Image types
156pub use animated_image::{
157    AnimatedImage, AnimationController, AnimationFrame, LoopCount, PlaybackState,
158};
159pub use async_image::{AsyncImageHandle, AsyncImageLoader, AsyncImageLoaderConfig, LoadingState};
160pub use atlas::{ImageManager, TextureAtlas};
161pub use disk_cache::{DiskCacheConfig, DiskCacheStats, DiskImageCache};
162pub use image::{Image, ImageLoader, ImageScaleMode, NinePatch};
163pub use image_buffer::{ImageBlendMode, ImageBuffer, OutputFormat, ResizeFilter};
164pub use image_cache::{CacheKey, ImageCache, ImageCacheConfig, ImageCacheStats};
165pub use scalable_image::ScalableImage;
166pub use svg::SvgImage;
167pub use svg_cache::{SvgCache, SvgCacheConfig, SvgCacheKey, SvgCacheStats, SvgSource};
168
169// Icon types
170pub use icon::{
171    Icon, IconMode, IconPosition, IconSize, IconSource, IconState, IconThemeMode, SizedIconSet,
172    StatefulIconSet, ThemedIconSet, icon_tint_for_state, icon_tint_for_state_full,
173    icon_tint_for_state_with_hover,
174};
175
176// Embedded icon support
177pub use embedded_icon::{EmbeddedIconData, EmbeddedIconSet, ImageFormat};
178
179// Image metadata
180pub use image_data::{
181    ColorType, ExifData, ImageMetadata, Orientation, read_dimensions, read_dimensions_from_bytes,
182    read_metadata, read_metadata_from_bytes,
183};
184
185// Damage tracking
186pub use damage::DamageTracker;
187
188// Layer compositing
189pub use layer::{Compositor, Layer, LayerConfig, LayerId};
190
191// Stencil clipping
192pub use stencil::{ClipShape, ClipStack};
193
194// Text rendering
195pub use text::{
196    // Text layout
197    BackgroundRect,
198    DecorationLine,
199    Font,
200    FontBuilder,
201    FontFaceId,
202    FontFaceInfo,
203    FontFamily,
204    FontFeature,
205    FontLoadError,
206    FontMetrics,
207    FontQuery,
208    FontStretch,
209    FontStyle,
210    FontSystem,
211    FontSystemConfig,
212    FontWeight,
213    // Glyph rendering
214    GlyphAllocation,
215    GlyphAtlas,
216    GlyphAtlasStats,
217    GlyphCache,
218    // Text shaping
219    GlyphCacheKey,
220    GlyphCacheStats,
221    GlyphId,
222    GlyphPixelFormat,
223    GlyphRenderMode,
224    HorizontalAlign,
225    LayoutGlyph,
226    LayoutLine,
227    RasterizedGlyph,
228    // Rich text
229    RichText,
230    RichTextSpan,
231    ShapedGlyph,
232    ShapedText,
233    ShapingOptions,
234    // Text decoration
235    TextDecoration,
236    TextDecorationStyle,
237    TextDecorationType,
238    TextLayout,
239    TextLayoutOptions,
240    TextShaper,
241    TextSpan,
242    VerticalAlign,
243    WrapMode,
244};
245
246// Text renderer
247pub use text_render_pass::TextRenderPass;
248pub use text_renderer::{PreparedGlyph, TextRenderer, TextRendererConfig, TextRendererStats};
249
250// Shader hot-reload support
251#[cfg(feature = "shader-hot-reload")]
252pub use shader_watcher::{ShaderKind, ShaderReloadResult, ShaderWatcher, load_shader_source};
253
254// Re-export wgpu types that users commonly need
255pub use wgpu;