Trait slint::platform::WindowAdapter
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<'_>) { ... }
fn window_handle_06(&self) -> Result<WindowHandle<'_>, HandleError> { ... }
fn display_handle_06(&self) -> Result<DisplayHandle<'_>, HandleError> { ... }
}
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:
-
When receiving messages from the windowing system about state changes, such as the window being resized, the user requested the window to be closed, input being received, etc. you need to create a
crate::platform::WindowEvent
and send it to Slint viacreate::Window::dispatch_event()
. -
Slint sends requests to change visibility, position, size, etc. via functions such as
Self::set_visible
,Self::set_size
,Self::set_position
, orSelf::update_window_properties()
. Re-implement these functions and delegate the requests to the windowing system.
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 size(&self) -> PhysicalSize
fn size(&self) -> PhysicalSize
Return the size of the Window on the screen
fn renderer(&self) -> &dyn Renderer
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>
fn set_visible(&self, _visible: bool) -> Result<(), PlatformError>
Show the window if the argument is true, hide otherwise.
fn position(&self) -> Option<PhysicalPosition>
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)
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)
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)
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<'_>)
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.
fn window_handle_06(&self) -> Result<WindowHandle<'_>, HandleError>
fn window_handle_06(&self) -> Result<WindowHandle<'_>, HandleError>
Re-implement this to support exposing raw window handles (version 0.6).
fn display_handle_06(&self) -> Result<DisplayHandle<'_>, HandleError>
fn display_handle_06(&self) -> Result<DisplayHandle<'_>, HandleError>
Re-implement this to support exposing raw display handles (version 0.6).