pub struct Renderer<F: Fn()> { /* private fields */ }Expand description
§Renderer
The main renderer struct that manages the application lifecycle and rendering.
The Renderer is the core component of the Tessera UI framework,
responsible for:
- Managing the application window and WGPU context
- Handling input events (mouse, touch, keyboard, IME)
- Coordinating the component tree building and rendering process
- Managing rendering pipelines and resources
§Type Parameters
F: The entry point function type that defines your UI. Must implementFn().
§Lifecycle
The renderer follows this lifecycle:
- Initialization: Create window, initialize WGPU context, register pipelines
- Event Loop: Handle window events, input events, and render requests
- Frame Rendering: Build component tree → Compute draw commands → Render to surface
- Cleanup: Automatic cleanup when the application exits
§Thread Safety
The renderer runs on the main thread and coordinates with other threads for:
- Component tree building (potentially parallelized)
- Resource management
- Event processing
§Usage
§Basic Usage
It’s suggested to use cargo-tessera to create your project from templates
which include all necessary setup. However, here’s a minimal example of how
to use the renderer through the Renderer::run method:
use tessera_ui::{PipelineContext, RenderModule, Renderer};
#[derive(Debug)]
struct DemoModule;
impl RenderModule for DemoModule {
fn register_pipelines(&self, _context: &mut PipelineContext<'_>) {}
}
// Define your UI entry point
fn my_app() {
// Your UI components go here
}
// Run the application
Renderer::run(my_app, vec![Box::new(DemoModule)]).unwrap();§Android Usage
On android, Renderer::run requires an additional AndroidApp parameter
from app context or android_main function.
§Configuration
You can customize the renderer behavior by passing TesseraConfig when
using Renderer::run_with_config. instead of Renderer::run.
use tessera_ui::{PipelineContext, RenderModule, Renderer, renderer::TesseraConfig};
#[derive(Debug)]
struct DemoModule;
impl RenderModule for DemoModule {
fn register_pipelines(&self, _context: &mut PipelineContext<'_>) {}
}
let config = TesseraConfig {
sample_count: 8, // 8x MSAA
window_title: "My Tessera App".to_string(), // Custom window title
..Default::default()
};
Renderer::run_with_config(|| { /* my_app */ }, vec![Box::new(DemoModule)], config)?;§Performance Monitoring
The renderer includes built-in performance monitoring that logs frame statistics when performance drops below 60 FPS.
Implementations§
Source§impl<F: Fn()> Renderer<F>
impl<F: Fn()> Renderer<F>
Sourcepub fn run(
entry_point: F,
modules: Vec<Box<dyn RenderModule>>,
) -> Result<(), EventLoopError>
pub fn run( entry_point: F, modules: Vec<Box<dyn RenderModule>>, ) -> Result<(), EventLoopError>
Runs the Tessera application with default configuration on desktop platforms.
This is the most convenient way to start a Tessera application on
Windows, Linux, or macOS. It uses the default TesseraConfig
settings (4x MSAA).
§Parameters
entry_point: A function that defines your UI. This function will be called every frame to build the component tree. It should contain your root UI components.modules: Render modules that register pipelines.
§Returns
Returns Ok(()) when the application exits normally, or an
EventLoopError if the event loop fails to start or encounters a
critical error.
§Examples
use tessera_ui::{PipelineContext, RenderModule, Renderer};
#[derive(Debug)]
struct DemoModule;
impl RenderModule for DemoModule {
fn register_pipelines(&self, _context: &mut PipelineContext<'_>) {}
}
fn my_ui() {
// Your UI components go here
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
Renderer::run(my_ui, vec![Box::new(DemoModule)])?;
Ok(())
}Sourcepub fn run_with_config(
entry_point: F,
modules: Vec<Box<dyn RenderModule>>,
config: TesseraConfig,
) -> Result<(), EventLoopError>
pub fn run_with_config( entry_point: F, modules: Vec<Box<dyn RenderModule>>, config: TesseraConfig, ) -> Result<(), EventLoopError>
Runs the Tessera application with custom configuration on desktop platforms.
This method allows you to customize the renderer behavior through
TesseraConfig. Use this when you need to adjust settings like
MSAA sample count or other rendering parameters.
§Parameters
entry_point: A function that defines your UImodules: Render modules that register pipelinesconfig: Custom configuration for the renderer
§Returns
Returns Ok(()) when the application exits normally, or an
EventLoopError if the event loop fails to start.
§Examples
use tessera_ui::{PipelineContext, RenderModule, Renderer, renderer::TesseraConfig};
#[derive(Debug)]
struct DemoModule;
impl RenderModule for DemoModule {
fn register_pipelines(&self, _context: &mut PipelineContext<'_>) {}
}
let config = TesseraConfig {
sample_count: 8, // 8x MSAA for higher quality
..Default::default()
};
Renderer::run_with_config(|| { /* my_ui */ }, vec![Box::new(DemoModule)], config)?;Auto Trait Implementations§
impl<F> !Freeze for Renderer<F>
impl<F> !RefUnwindSafe for Renderer<F>
impl<F> !Send for Renderer<F>
impl<F> !Sync for Renderer<F>
impl<F> Unpin for Renderer<F>where
F: Unpin,
impl<F> !UnwindSafe for Renderer<F>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more