Skip to main content

Renderer

Trait Renderer 

Source
pub trait Renderer {
Show 25 methods // Required methods fn init(&mut self) -> Result<()>; fn create_window(&mut self, config: &WindowConfig) -> Result<WindowHandle>; fn load_url(&self, window: WindowHandle, url: &str) -> Result<()>; fn load_html(&self, window: WindowHandle, html: &str) -> Result<()>; fn eval_script(&self, window: WindowHandle, script: &str) -> Result<()>; fn set_ipc_handler(&mut self, handler: Box<dyn IpcHandler>); fn send_to_frontend( &self, window: WindowHandle, message: &str, ) -> Result<()>; fn set_title(&self, window: WindowHandle, title: &str) -> Result<()>; fn set_size( &self, window: WindowHandle, width: u32, height: u32, ) -> Result<()>; fn set_resizable(&self, window: WindowHandle, resizable: bool) -> Result<()>; fn set_visible(&self, window: WindowHandle, visible: bool) -> Result<()>; fn close_window(&mut self, window: WindowHandle) -> Result<()>; fn minimize_window(&self, window: WindowHandle) -> Result<()>; fn maximize_window(&self, window: WindowHandle) -> Result<()>; fn is_maximized(&self, window: WindowHandle) -> Result<bool>; fn set_fullscreen( &self, window: WindowHandle, fullscreen: bool, ) -> Result<()>; fn is_fullscreen(&self, window: WindowHandle) -> Result<bool>; fn start_drag(&self, window: WindowHandle) -> Result<()>; fn start_resize(&self, window: WindowHandle, edge: ResizeEdge) -> Result<()>; fn set_decorations( &self, window: WindowHandle, decorations: bool, ) -> Result<()>; fn set_always_on_top( &self, window: WindowHandle, always: bool, ) -> Result<()>; fn run(self: Box<Self>) -> Result<()>; fn kind(&self) -> RendererKind; // Provided methods fn load_html_with_base_url( &self, window: WindowHandle, html: &str, base_url: &str, ) -> Result<()> { ... } fn set_click_through( &self, _window: WindowHandle, _enabled: bool, ) -> Result<()> { ... }
}
Expand description

Core trait that both WebView and Chrome backends must implement.

This provides a unified API for creating windows, loading content, executing JavaScript, and handling IPC regardless of the underlying rendering engine.

Required Methods§

Source

fn init(&mut self) -> Result<()>

Initialize the renderer.

Source

fn create_window(&mut self, config: &WindowConfig) -> Result<WindowHandle>

Create a new window with the given configuration.

Source

fn load_url(&self, window: WindowHandle, url: &str) -> Result<()>

Load a URL in the specified window.

Source

fn load_html(&self, window: WindowHandle, html: &str) -> Result<()>

Load HTML content directly.

Source

fn eval_script(&self, window: WindowHandle, script: &str) -> Result<()>

Execute JavaScript in the specified window.

Source

fn set_ipc_handler(&mut self, handler: Box<dyn IpcHandler>)

Set the IPC handler for messages from the frontend.

Source

fn send_to_frontend(&self, window: WindowHandle, message: &str) -> Result<()>

Send a message to the frontend JavaScript.

Source

fn set_title(&self, window: WindowHandle, title: &str) -> Result<()>

Set the window title.

Source

fn set_size(&self, window: WindowHandle, width: u32, height: u32) -> Result<()>

Set the window size.

Source

fn set_resizable(&self, window: WindowHandle, resizable: bool) -> Result<()>

Set whether the window is resizable.

Source

fn set_visible(&self, window: WindowHandle, visible: bool) -> Result<()>

Show or hide the window.

Source

fn close_window(&mut self, window: WindowHandle) -> Result<()>

Close a window.

Source

fn minimize_window(&self, window: WindowHandle) -> Result<()>

Minimize the window.

Source

fn maximize_window(&self, window: WindowHandle) -> Result<()>

Toggle maximize/restore.

Source

fn is_maximized(&self, window: WindowHandle) -> Result<bool>

Check whether the window is currently maximized.

Source

fn set_fullscreen(&self, window: WindowHandle, fullscreen: bool) -> Result<()>

Toggle fullscreen mode.

Source

fn is_fullscreen(&self, window: WindowHandle) -> Result<bool>

Check whether the window is currently fullscreen.

Source

fn start_drag(&self, window: WindowHandle) -> Result<()>

Begin an interactive window drag.

Call this from a mousedown handler on a custom title bar element to allow the user to drag the window from any region.

Source

fn start_resize(&self, window: WindowHandle, edge: ResizeEdge) -> Result<()>

Begin an interactive window resize.

edge specifies which edge/corner to resize from.

Source

fn set_decorations(&self, window: WindowHandle, decorations: bool) -> Result<()>

Set whether the window has OS decorations (title bar + borders).

Source

fn set_always_on_top(&self, window: WindowHandle, always: bool) -> Result<()>

Set the window’s always-on-top state.

Source

fn run(self: Box<Self>) -> Result<()>

Run the main event loop. This blocks until the application exits.

Source

fn kind(&self) -> RendererKind

Get the renderer kind.

Provided Methods§

Source

fn load_html_with_base_url( &self, window: WindowHandle, html: &str, base_url: &str, ) -> Result<()>

Load HTML content with a document base URL for relative assets.

WebView backends commonly implement load_html with an in-memory document (NavigateToString on WebView2). Such documents do not have a useful filesystem base, so relative Vite assets like ./assets/index.js fail to load. This helper injects a <base> tag before delegating to the backend and keeps local-first renderers portable across WebView2, WKWebView, and WebKitGTK.

Source

fn set_click_through(&self, _window: WindowHandle, _enabled: bool) -> Result<()>

Enable or disable click-through: when enabled, pointer events fall through the window to whatever is behind it (used by wallpaper and click-through overlays). Applied at window creation by default; this method allows toggling it at runtime where the platform supports it.

Default implementation is a no-op; backends override it to call the platform-specific window API.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§