Renderer

Struct Renderer 

Source
pub struct Renderer { /* private fields */ }
Expand description

The Renderer manages all Views and coordinates painting, network requests, and event dispatch

You don’t have to create this instance directly if you use the AppCore API. The App struct will automatically create a Renderer and perform all rendering within its run loop.

Implementations§

Source§

impl Renderer

Source

pub fn create(config: Config) -> Result<Self, CreationError>

Create the Ultralight Renderer directly.

Unlike App::new, this does not use any native windows for drawing and allows you to manage your own runloop and painting. This method is recommended for those wishing to integrate the library into a game.

This instance manages the lifetime of all Views and coordinates all painting, rendering, network requests, and event dispatch.

You should only call this once per process lifetime.

You must set up your platform handlers (eg, platform::set_gpu_driver, platform::set_logger, platform::enable_default_logger, platform::enable_platform_filesystem, etc.) before calling this.

You will also need to define a font loader before calling this – currently the only way to do this is platform::enable_platform_fontloader.

You should not call this if you are using App::new, it creates its own renderer and provides default implementations for various platform handlers automatically.

Source§

impl Renderer

Source

pub fn update(&self)

Update timers and dispatch internal callbacks. You should call this often from your main application loop.

Source

pub fn render(&self)

Render all active views to their respective render-targets/surfaces.

You should call this once per frame (usually in synchrony with the monitor’s refresh rate).

Views are only repainted if they actually need painting. (See View::needs_paint)

Source

pub fn purge_memory(&self)

Attempt to release as much memory as possible. Don’t call this from any callbacks or driver code.

Source

pub fn log_memory_usage(&self)

Print detailed memory usage statistics to the log. (See platform::set_logger or platform::enable_default_logger)

Source

pub fn create_session( &self, is_persistent: bool, name: &str, ) -> Result<Session, CreationError>

Create a Session to store local data in (such as cookies, local storage, application cache, indexed db, etc).

A default, persistent Session is already created for you. You only need to call this if you want to create private, in-memory session or use a separate session for each View.

§Arguments
  • is_persistent - Whether or not to store the session on disk. Persistent sessions will be written to the path set in ConfigBuilder::cache_path.
  • name - A unique name for this session, this will be used to generate a unique disk path for persistent sessions.
Source

pub fn default_session(&self) -> &Session

Get the default Session. This session is persistent (backed to disk) and has the name “default”.

Source

pub fn create_view( &self, width: u32, height: u32, view_config: &ViewConfig, session: Option<&Session>, ) -> Option<View>

Create a new View.

§Arguments
  • width - The initial width, in pixels.
  • height - The initial height, in pixels.
  • config - The configuration for the view.
  • session - The session to store local data in. Passing None will use the default session.
Source

pub fn start_remote_inspector_server( &self, address: &str, port: u16, ) -> Result<bool, CreationError>

Start the remote inspector server.

While the remote inspector is active, Views that are loaded into this renderer will be able to be remotely inspected from another Ultralight instance either locally (another app on same machine) or remotely (over the network) by navigating a View to:

 inspector://<address>:<port>

Returns true if the server was started successfully, false otherwise.

Source

pub fn refresh_display(&self, display_id: u32)

Notify the renderer that a display has refreshed (you should call this after vsync).

This updates animations, smooth scroll, and window.requestAnimationFrame() for all Views matching the display id.

Source

pub fn set_gamepad_details( &self, index: u32, id: &str, axis_count: u32, button_count: u32, ) -> Result<(), CreationError>

Describe the details of a gamepad, to be used with FireGamepadEvent and related events below. This can be called multiple times with the same index if the details change.

§Arguments
  • index - The unique index (or “connection slot”) of the gamepad. For example, controller #1 would be “1”, controller #2 would be “2” and so on.
  • id - A string ID representing the device, this will be made available in JavaScript as gamepad.id
  • axis_count - The number of axes on the device.
  • button_count - The number of buttons on the device
Source

pub fn fire_gamepad_event( &self, event: GamepadEvent, ) -> Result<(), CreationError>

Fire a gamepad event (connection / disconnection).

Note: The gamepad should first be described via set_gamepad_details before calling this function.

See https://developer.mozilla.org/en-US/docs/Web/API/Gamepad

Source

pub fn fire_gamepad_axis_event( &self, event: GamepadAxisEvent, ) -> Result<(), CreationError>

Fire a gamepad axis event (to be called when an axis value is changed).

Note: The gamepad should be connected via a call to fire_gamepad_event before calling this function.

See https://developer.mozilla.org/en-US/docs/Web/API/Gamepad/axes

Source

pub fn fire_gamepad_button_event( &self, event: GamepadButtonEvent, ) -> Result<(), CreationError>

Fire a gamepad button event (to be called when a button value is changed).

Note: The gamepad should be connected via a call to fire_gamepad_event before calling this function.

See https://developer.mozilla.org/en-US/docs/Web/API/Gamepad/axes

Trait Implementations§

Source§

impl Drop for Renderer

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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