pub trait WindowAdapter {
    // Required methods
    fn window(&self) -> &Window;
    fn size(&self) -> PhysicalSize;
    fn renderer(&self) -> &dyn Renderer;

    // Provided methods
    fn set_visible(&self, _visible: bool) -> Result<(), PlatformError> { ... }
    fn position(&self) -> Option<PhysicalPosition> { ... }
    fn set_position(&self, _position: WindowPosition) { ... }
    fn set_size(&self, _size: WindowSize) { ... }
    fn request_redraw(&self) { ... }
    fn update_window_properties(&self, _properties: WindowProperties<'_>) { ... }
}
Expand description

This trait represents the adaptation layer between the Window API and then windowing specific window representation, such as a Win32 HWND handle or a wayland_surface_t.

Implement this trait to establish the link between the two, and pass messages in both directions:

If the implementation of this bi-directional message passing protocol is incomplete, the user may experience unexpected behavior, or the intention of the developer calling functions on the crate::Window API may not be fulfilled.

Your implementation must hold a renderer, such as crate::software_renderer::SoftwareRenderer. In the Self::renderer() function, you must return a reference to it.

It is also required to hold a crate::Window and return a reference to it in your implementation of Self::window().

See also MinimalSoftwareWindow for a minimal implementation of this trait using the software renderer

Required Methods§

fn window(&self) -> &Window

Returns the window API.

fn size(&self) -> PhysicalSize

Return the size of the Window on the screen

fn renderer(&self) -> &dyn Renderer

Return the renderer.

The Renderer trait is an internal trait that you are not expected to implement. In your implementation you should return a reference to an instance of one of the renderers provided by Slint.

Currently, the only public struct that implement renderer is SoftwareRenderer.

Provided Methods§

fn set_visible(&self, _visible: bool) -> Result<(), PlatformError>

Show the window if the argument is true, hide otherwise.

fn position(&self) -> Option<PhysicalPosition>

Returns the position of the window on the screen, in physical screen coordinates and including a window frame (if present).

The default implementation returns None

Called from Window::position()

fn set_position(&self, _position: WindowPosition)

Sets the position of the window on the screen, in physical screen coordinates and including a window frame (if present).

The default implementation does nothing

Called from Window::set_position()

fn set_size(&self, _size: WindowSize)

Request a new size for the window to the specified size on the screen, in physical or logical pixels and excluding a window frame (if present).

This is called from Window::set_size()

The default implementation does nothing

This function should sent the size to the Windowing system. If the window size actually changes, you should dispatch a WindowEvent::Resized using Window::dispatch_event() to propagate the new size to the slint view

fn request_redraw(&self)

Issues a request to the windowing system to re-render the contents of the window.

This request is typically asynchronous. It is called when a property that was used during window rendering is marked as dirty.

An implementation should repaint the window in a subsequent iteration of the event loop, throttled to the screen refresh rate if possible. It is important not to query any Slint properties to avoid introducing a dependency loop in the properties, including the use of the render function, which itself queries properties.

See also Window::request_redraw()

fn update_window_properties(&self, _properties: WindowProperties<'_>)

Re-implement this function to update the properties such as window title or layout constraints.

This function is called before set_visible(true), and will be called again when the properties that were queried on the last call are changed. If you do not query any properties, it may not be called again.

Implementors§