pub struct Renderer<F: Fn(), R: Fn(&mut WgpuApp) + Clone + 'static> { /* private fields */ }
Expand description
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()
.R
: The pipeline registration function type. Must implementFn(&mut WgpuApp) + Clone + 'static
.
§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
§Examples
See the module-level documentation for usage examples.
Implementations§
Source§impl<F: Fn(), R: Fn(&mut WgpuApp) + Clone + 'static> Renderer<F, R>
impl<F: Fn(), R: Fn(&mut WgpuApp) + Clone + 'static> Renderer<F, R>
Sourcepub fn run(
entry_point: F,
register_pipelines_fn: R,
) -> Result<(), EventLoopError>
pub fn run( entry_point: F, register_pipelines_fn: R, ) -> 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.register_pipelines_fn
: A function that registers rendering pipelines with the WGPU app. Typically, you’ll calltessera_ui_basic_components::pipelines::register_pipelines(app)
here.
§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::Renderer;
fn my_ui() {
// Your UI components go here
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
Renderer::run(
my_ui,
|_app| {
// Register your rendering pipelines here
// tessera_ui_basic_components::pipelines::register_pipelines(app);
}
)?;
Ok(())
}
Sourcepub fn run_with_config(
entry_point: F,
register_pipelines_fn: R,
config: TesseraConfig,
) -> Result<(), EventLoopError>
pub fn run_with_config( entry_point: F, register_pipelines_fn: R, 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 UIregister_pipelines_fn
: A function that registers rendering 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::{Renderer, renderer::TesseraConfig};
let config = TesseraConfig {
sample_count: 8, // 8x MSAA for higher quality
};
Renderer::run_with_config(
|| { /* my_ui */ },
|_app| { /* register_pipelines */ },
config
)?;
Trait Implementations§
Source§impl<F: Fn(), R: Fn(&mut WgpuApp) + Clone + 'static> ApplicationHandler for Renderer<F, R>
Implementation of winit’s ApplicationHandler
trait for the Tessera renderer.
impl<F: Fn(), R: Fn(&mut WgpuApp) + Clone + 'static> ApplicationHandler for Renderer<F, R>
Implementation of winit’s ApplicationHandler
trait for the Tessera renderer.
This implementation handles the application lifecycle events from winit, including window creation, suspension/resumption, and various window events. It bridges the gap between winit’s event system and Tessera’s component-based UI framework.
Source§fn resumed(&mut self, event_loop: &ActiveEventLoop)
fn resumed(&mut self, event_loop: &ActiveEventLoop)
Called when the application is resumed or started.
This method is responsible for:
- Creating the application window with appropriate attributes
- Initializing the WGPU context and surface
- Registering rendering pipelines
- Setting up the initial application state
On desktop platforms, this is typically called once at startup. On mobile platforms (especially Android), this may be called multiple times as the app is suspended and resumed.
§Window Configuration
The window is created with:
- Title: “Tessera”
- Transparency: Enabled (allows for transparent backgrounds)
- Default size and position (platform-dependent)
§Pipeline Registration
After WGPU initialization, the register_pipelines_fn
is called to set up
all rendering pipelines. This typically includes basic component pipelines
and any custom shaders your application requires.
Source§fn suspended(&mut self, _event_loop: &ActiveEventLoop)
fn suspended(&mut self, _event_loop: &ActiveEventLoop)
Called when the application is suspended.
This method should handle cleanup and state preservation when the application is being suspended (e.g., on mobile platforms when the app goes to background).
§Current Status
This method is currently not fully implemented (todo!
). In a complete
implementation, it should:
- Save application state
- Release GPU resources if necessary
- Prepare for potential termination
§Platform Considerations
- Desktop: Rarely called, mainly during shutdown
- Android: Called when app goes to background
- iOS: Called during app lifecycle transitions
Source§fn window_event(
&mut self,
event_loop: &ActiveEventLoop,
_window_id: WindowId,
event: WindowEvent,
)
fn window_event( &mut self, event_loop: &ActiveEventLoop, _window_id: WindowId, event: WindowEvent, )
Handles window-specific events from the windowing system.
This method processes all window events including user input, window state changes, and rendering requests. It’s the main event processing hub that translates winit events into Tessera’s internal event system.
§Event Categories
§Window Management
CloseRequested
: User requested to close the windowResized
: Window size changedScaleFactorChanged
: Display scaling changed (high-DPI support)
§Input Events
CursorMoved
: Mouse cursor position changedCursorLeft
: Mouse cursor left the windowMouseInput
: Mouse button press/releaseMouseWheel
: Mouse wheel scrollingTouch
: Touch screen interactions (mobile)KeyboardInput
: Keyboard key press/releaseIme
: Input Method Editor events (international text input)
§Rendering
RedrawRequested
: System requests a frame to be rendered
§Event Processing Flow
- Input Events: Captured and stored in respective state managers
- State Updates: Internal state (cursor, keyboard, IME) is updated
- Rendering: On redraw requests, the full rendering pipeline is executed
§Platform-Specific Handling
Some events have platform-specific behavior, particularly:
- Touch events (mobile platforms)
- IME events (different implementations per platform)
- Scale factor changes (high-DPI displays)
§fn new_events(&mut self, event_loop: &ActiveEventLoop, cause: StartCause)
fn new_events(&mut self, event_loop: &ActiveEventLoop, cause: StartCause)
§fn user_event(&mut self, event_loop: &ActiveEventLoop, event: T)
fn user_event(&mut self, event_loop: &ActiveEventLoop, event: T)
EventLoopProxy::send_event
.§fn device_event(
&mut self,
event_loop: &ActiveEventLoop,
device_id: DeviceId,
event: DeviceEvent,
)
fn device_event( &mut self, event_loop: &ActiveEventLoop, device_id: DeviceId, event: DeviceEvent, )
§fn about_to_wait(&mut self, event_loop: &ActiveEventLoop)
fn about_to_wait(&mut self, event_loop: &ActiveEventLoop)
§fn exiting(&mut self, event_loop: &ActiveEventLoop)
fn exiting(&mut self, event_loop: &ActiveEventLoop)
§fn memory_warning(&mut self, event_loop: &ActiveEventLoop)
fn memory_warning(&mut self, event_loop: &ActiveEventLoop)
Auto Trait Implementations§
impl<F, R> !Freeze for Renderer<F, R>
impl<F, R> !RefUnwindSafe for Renderer<F, R>
impl<F, R> !Send for Renderer<F, R>
impl<F, R> !Sync for Renderer<F, R>
impl<F, R> Unpin for Renderer<F, R>
impl<F, R> !UnwindSafe for Renderer<F, R>
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> 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