Struct Renderer

Source
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 implement Fn().
  • R: The pipeline registration function type. Must implement Fn(&mut WgpuApp) + Clone + 'static.

§Lifecycle

The renderer follows this lifecycle:

  1. Initialization: Create window, initialize WGPU context, register pipelines
  2. Event Loop: Handle window events, input events, and render requests
  3. Frame Rendering: Build component tree → Compute draw commands → Render to surface
  4. 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>

Source

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 call tessera_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(())
}
Source

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 UI
  • register_pipelines_fn: A function that registers rendering pipelines
  • config: 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.

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)

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)

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, )

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 window
  • Resized: Window size changed
  • ScaleFactorChanged: Display scaling changed (high-DPI support)
§Input Events
  • CursorMoved: Mouse cursor position changed
  • CursorLeft: Mouse cursor left the window
  • MouseInput: Mouse button press/release
  • MouseWheel: Mouse wheel scrolling
  • Touch: Touch screen interactions (mobile)
  • KeyboardInput: Keyboard key press/release
  • Ime: Input Method Editor events (international text input)
§Rendering
  • RedrawRequested: System requests a frame to be rendered
§Event Processing Flow
  1. Input Events: Captured and stored in respective state managers
  2. State Updates: Internal state (cursor, keyboard, IME) is updated
  3. 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)

Emitted when new events arrive from the OS to be processed. Read more
§

fn user_event(&mut self, event_loop: &ActiveEventLoop, event: T)

Emitted when an event is sent from EventLoopProxy::send_event.
§

fn device_event( &mut self, event_loop: &ActiveEventLoop, device_id: DeviceId, event: DeviceEvent, )

Emitted when the OS sends an event to a device.
§

fn about_to_wait(&mut self, event_loop: &ActiveEventLoop)

Emitted when the event loop is about to block and wait for new events. Read more
§

fn exiting(&mut self, event_loop: &ActiveEventLoop)

Emitted when the event loop is being shut down. Read more
§

fn memory_warning(&mut self, event_loop: &ActiveEventLoop)

Emitted when the application has received a memory warning. Read more

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>
where F: Unpin, R: Unpin,

§

impl<F, R> !UnwindSafe for Renderer<F, R>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AsAny for T
where T: Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Returns a reference to the concrete type as &dyn Any.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more