pub struct Renderer { /* private fields */ }
Expand description
Implementations§
Source§impl Renderer
impl Renderer
Sourcepub fn create(config: Config) -> Result<Self, CreationError>
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 View
s 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
impl Renderer
Sourcepub fn update(&self)
pub fn update(&self)
Update timers and dispatch internal callbacks. You should call this often from your main application loop.
Sourcepub fn render(&self)
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).
View
s are only repainted if they actually need painting.
(See View::needs_paint
)
Sourcepub fn purge_memory(&self)
pub fn purge_memory(&self)
Attempt to release as much memory as possible. Don’t call this from any callbacks or driver code.
Sourcepub fn log_memory_usage(&self)
pub fn log_memory_usage(&self)
Print detailed memory usage statistics to the log.
(See platform::set_logger
or
platform::enable_default_logger
)
Sourcepub fn create_session(
&self,
is_persistent: bool,
name: &str,
) -> Result<Session, CreationError>
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 inConfigBuilder::cache_path
.name
- A unique name for this session, this will be used to generate a unique disk path for persistent sessions.
Sourcepub fn default_session(&self) -> &Session
pub fn default_session(&self) -> &Session
Get the default Session. This session is persistent (backed to disk) and has the name “default”.
Sourcepub fn create_view(
&self,
width: u32,
height: u32,
view_config: &ViewConfig,
session: Option<&Session>,
) -> Option<View>
pub fn create_view( &self, width: u32, height: u32, view_config: &ViewConfig, session: Option<&Session>, ) -> Option<View>
Sourcepub fn start_remote_inspector_server(
&self,
address: &str,
port: u16,
) -> Result<bool, CreationError>
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.
Sourcepub fn refresh_display(&self, display_id: u32)
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.
Sourcepub fn set_gamepad_details(
&self,
index: u32,
id: &str,
axis_count: u32,
button_count: u32,
) -> Result<(), CreationError>
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.idaxis_count
- The number of axes on the device.button_count
- The number of buttons on the device
Sourcepub fn fire_gamepad_event(
&self,
event: GamepadEvent,
) -> Result<(), CreationError>
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
Sourcepub fn fire_gamepad_axis_event(
&self,
event: GamepadAxisEvent,
) -> Result<(), CreationError>
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
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