Set the size to the Window element when it is shown, when the size would otherwise be empty

This commit is contained in:
Olivier Goffart 2021-04-08 08:26:51 +02:00
parent 8a08e06ee0
commit cdcf0faa5f
2 changed files with 29 additions and 7 deletions

View file

@ -424,10 +424,20 @@ impl PlatformWindow for GraphicsWindow {
let backend = window.backend.borrow();
let winit_window = backend.window();
winit_window.set_title(&window_item.title());
let size: winit::dpi::PhysicalSize<u32> =
(window_item.width(), window_item.height()).into();
if size.width > 0 && size.height > 0 {
let mut size = winit_window.inner_size();
let mut must_resize = false;
let mut apply = |r: &mut u32, v| {
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 _)
}
}
}

View file

@ -933,13 +933,25 @@ impl PlatformWindow for QtWindow {
fn apply_window_properties(&self, window_item: Pin<&items::Window>) {
let widget_ptr = self.widget_ptr();
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 _,
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();
cpp! {unsafe [widget_ptr as "QWidget*", title as "QString", size as "QSize", background as "QRgb"] {
if (!size.isEmpty())
widget_ptr->resize(size);
widget_ptr->setWindowTitle(title);
auto pal = widget_ptr->palette();