Platform: Add a Resized event and use that to convey the changes in size (#2759)

This commit is contained in:
Olivier Goffart 2023-05-21 12:12:30 +02:00 committed by GitHub
parent 846c48b81d
commit dd5ef9993f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 121 additions and 47 deletions

View file

@ -61,6 +61,9 @@ public:
/// do that in the next iteration of the event loop, or in a callback from the window manager.
virtual void request_redraw() const { }
/// Returns the actual physical size of the window
virtual slint::PhysicalSize physical_size() const = 0;
private:
friend class Platform;
virtual cbindgen_private::WindowAdapterRcOpaque initialize() = 0;
@ -94,7 +97,11 @@ private:
},
[](void *wa) { reinterpret_cast<const WA *>(wa)->show(); },
[](void *wa) { reinterpret_cast<const WA *>(wa)->hide(); },
[](void *wa) { reinterpret_cast<const WA *>(wa)->request_redraw(); }, &self);
[](void *wa) { reinterpret_cast<const WA *>(wa)->request_redraw(); },
[](void *wa) -> cbindgen_private::IntSize {
return reinterpret_cast<const WA *>(wa)->physical_size();
},
&self);
m_renderer.init(&self);
was_initialized = true;
return self;
@ -143,6 +150,16 @@ public:
}
}
/// Set the logical size of this window after a resize event
// Note: in rust, this is an event on the Window
void dispatch_resize_event(slint::LogicalSize s)
{
private_api::assert_main_thread();
if (was_initialized) {
cbindgen_private::slint_windowrc_dispatch_resize_event(&self, s.width, s.height);
}
}
/// Returns true if the window is currently animating
bool has_active_animations() const
{