Class WindowAdapter

Nested Relationships

Nested Types

Class Documentation

class WindowAdapter

Base class for the layer between a slint::Window and the windowing system specific window type, such as a Win32 HWND handle or a wayland_surface_t.

Re-implement this class 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 Window API may not be fulfilled.

Your WindowAdapter subclass must hold a renderer (either a SoftwareRenderer or a SkiaRenderer). In the renderer() method, you must return a reference to it.

Example

class MyWindowAdapter : public slint::platform::WindowAdapter {
    slint::platform::SoftwareRenderer m_renderer;
    NativeHandle m_native_window; // a handle to the native window
public:
    void request_redraw() override { m_native_window.refresh(); }
    slint::PhysicalSize size() const override {
       return slint::PhysicalSize({m_native_window.width, m_native_window.height});
    }
    slint::platform::AbstractRenderer &renderer() override { return m_renderer; }
    void set_visible(bool v) override {
        if (v) {
            m_native_window.show();
        } else {
            m_native_window.hide();
        }
    }
    // ...
    void repaint_callback();
}

Rendering is typically asynchronous, and your windowing system or event loop would invoke a callback when it is time to render.

void MyWindowAdapter::repaint_callback()
{
    slint::platform::update_timers_and_animations();
    m_renderer.render(m_native_window.buffer(), m_native_window.width);
    // if animations are running, schedule the next frame
    if (window().has_active_animations())  m_native_window.refresh();
}

Public Functions

inline explicit WindowAdapter()

Construct a WindowAdapter.

virtual ~WindowAdapter() = default
inline virtual void set_visible(bool)

This function is called by Slint when the slint window is shown or hidden.

Re-implement this function to forward the call to show/hide the native window

When the window becomes visible, this is a good time to call slint::Window::dispatch_scale_factor_change_event to initialise the scale factor.

inline virtual void request_redraw()

This function is called when Slint detects that the window need to be repainted.

Reimplement this function to forward the call to the window manager.

You should not render the window in the implementation of this call. Instead you should do that in the next iteration of the event loop, or in a callback from the window manager.

inline virtual void set_size(slint::PhysicalSize)

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 slint::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 call slint::Window::dispatch_resize_event to propagate the new size to the slint view.

virtual slint::PhysicalSize size() = 0

Returns the actual physical size of the window.

inline virtual void set_position(slint::PhysicalPosition)

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 slint::Window::set_position().

inline virtual std::optional<slint::PhysicalPosition> position()

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

The default implementation returns std::nullopt.

Called from slint::Window::position().

inline virtual void update_window_properties(const 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.

virtual AbstractRenderer &renderer() = 0

Re-implement this function to provide a reference to the renderer for use with the window adapter.

Your re-implementation should contain a renderer such as SoftwareRenderer or SkiaRenderer and you must return a reference to it.

inline const Window &window() const

Return the slint::Window associated with this window.

Note that this function can only be called if the window was initialized, which is only the case after it has been returned from a call to Platform::create_window_adapter

inline Window &window()

Overload.

struct WindowProperties

This struct contains getters that provide access to properties of the Window element, and is used with WindowAdapter::update_window_properties().

Public Functions

inline SharedString title() const

Returns the title of the window.

inline Brush background() const

Returns the background brush of the window.

inline bool fullscreen() const

Deprecated:

Use is_fullscreen() instead

inline bool is_fullscreen() const

Returns true if the window should be shown fullscreen; false otherwise.

inline bool is_minimized() const

Returns true if the window should be minimized; false otherwise.

inline bool is_maximized() const

Returns true if the window should be maximized; false otherwise.

inline LayoutConstraints layout_constraints() const

Returns the layout constraints of the window.

struct LayoutConstraints

This struct describes the layout constraints of a window.

It is the return value of WindowProperties::layout_constraints().

Public Members

std::optional<LogicalSize> min

This represents the minimum size the window can be. If this is set, the window should not be able to be resized smaller than this size. If it is left unset, there is no minimum size.

std::optional<LogicalSize> max

This represents the maximum size the window can be. If this is set, the window should not be able to be resized larger than this size. If it is left unset, there is no maximum size.

LogicalSize preferred

This represents the preferred size of the window. This is the size the window should have by default