Add support for set_position(), position(), and set_physical_size() to the C++ WindowAdapter (#3367)

Closes #3349
This commit is contained in:
Simon Hausmann 2023-08-28 18:43:04 +02:00 committed by GitHub
parent d3b89df095
commit d160eb7a31
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 137 additions and 2 deletions

View file

@ -256,6 +256,12 @@ public:
}
}
void set_physical_size(slint::PhysicalSize size) override
{
float scale_factor = devicePixelRatio();
resize(size.width / scale_factor, size.height / scale_factor);
}
slint::PhysicalSize physical_size() const override
{
auto windowSize = slint::LogicalSize({ float(width()), float(height()) });
@ -264,6 +270,20 @@ public:
uint32_t(windowSize.height * scale_factor) });
}
void set_position(slint::PhysicalPosition position) override
{
float scale_factor = devicePixelRatio();
setFramePosition(QPointF(position.x / scale_factor, position.y / scale_factor).toPoint());
}
std::optional<slint::PhysicalPosition> position() const override
{
auto pos = framePosition();
float scale_factor = devicePixelRatio();
return { slint::PhysicalPosition(
{ int32_t(pos.x() * scale_factor), int32_t(pos.y() * scale_factor) }) };
}
void request_redraw() override { requestUpdate(); }
void update_window_properties(const slint::platform::WindowProperties &props) override