mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 22:31:14 +00:00
Set the size to the Window element when it is shown, when the size would otherwise be empty
This commit is contained in:
parent
8a08e06ee0
commit
cdcf0faa5f
2 changed files with 29 additions and 7 deletions
|
@ -424,10 +424,20 @@ impl PlatformWindow for GraphicsWindow {
|
||||||
let backend = window.backend.borrow();
|
let backend = window.backend.borrow();
|
||||||
let winit_window = backend.window();
|
let winit_window = backend.window();
|
||||||
winit_window.set_title(&window_item.title());
|
winit_window.set_title(&window_item.title());
|
||||||
let size: winit::dpi::PhysicalSize<u32> =
|
let mut size = winit_window.inner_size();
|
||||||
(window_item.width(), window_item.height()).into();
|
let mut must_resize = false;
|
||||||
if size.width > 0 && size.height > 0 {
|
let mut apply = |r: &mut u32, v| {
|
||||||
winit_window.set_inner_size(size);
|
if v > 0. {
|
||||||
|
*r = v as _
|
||||||
|
} else {
|
||||||
|
must_resize = true
|
||||||
|
}
|
||||||
|
};
|
||||||
|
apply(&mut size.width, window_item.width());
|
||||||
|
apply(&mut size.height, window_item.height());
|
||||||
|
winit_window.set_inner_size(size);
|
||||||
|
if must_resize {
|
||||||
|
self.set_geometry(size.width as _, size.height as _)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -933,14 +933,26 @@ impl PlatformWindow for QtWindow {
|
||||||
fn apply_window_properties(&self, window_item: Pin<&items::Window>) {
|
fn apply_window_properties(&self, window_item: Pin<&items::Window>) {
|
||||||
let widget_ptr = self.widget_ptr();
|
let widget_ptr = self.widget_ptr();
|
||||||
let title: qttypes::QString = window_item.title().as_str().into();
|
let title: qttypes::QString = window_item.title().as_str().into();
|
||||||
let size = qttypes::QSize {
|
let mut size = qttypes::QSize {
|
||||||
width: window_item.width().ceil() as _,
|
width: window_item.width().ceil() as _,
|
||||||
height: window_item.height().ceil() as _,
|
height: window_item.height().ceil() as _,
|
||||||
};
|
};
|
||||||
|
if size.width == 0 || size.height == 0 {
|
||||||
|
let existing_size = cpp!(unsafe [widget_ptr as "QWidget*"] -> qttypes::QSize as "QSize" {
|
||||||
|
return widget_ptr->size();
|
||||||
|
});
|
||||||
|
if size.width == 0 {
|
||||||
|
window_item.width.set(existing_size.width as _);
|
||||||
|
size.width = existing_size.width;
|
||||||
|
}
|
||||||
|
if size.height == 0 {
|
||||||
|
window_item.height.set(existing_size.height as _);
|
||||||
|
size.height = existing_size.height;
|
||||||
|
}
|
||||||
|
}
|
||||||
let background: u32 = window_item.background().as_argb_encoded();
|
let background: u32 = window_item.background().as_argb_encoded();
|
||||||
cpp! {unsafe [widget_ptr as "QWidget*", title as "QString", size as "QSize", background as "QRgb"] {
|
cpp! {unsafe [widget_ptr as "QWidget*", title as "QString", size as "QSize", background as "QRgb"] {
|
||||||
if (!size.isEmpty())
|
widget_ptr->resize(size);
|
||||||
widget_ptr->resize(size);
|
|
||||||
widget_ptr->setWindowTitle(title);
|
widget_ptr->setWindowTitle(title);
|
||||||
auto pal = widget_ptr->palette();
|
auto pal = widget_ptr->palette();
|
||||||
pal.setColor(QPalette::Window, QColor::fromRgba(background));
|
pal.setColor(QPalette::Window, QColor::fromRgba(background));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue