Skip to content

Commit d320e6e

Browse files
committed
Fix incorrect size of several wasm demos
Commit 1c73144 (famous resume protocol) change the overal timing and sequence of window creation. As it happens now, when we set_visibility() is called and we try to preserve a "browser" assigned canvas size, we do so even for windows where we decided we want to go with the preferred size. This restores the todo/underlay/etc. demos. With commit bcfa1ea we now end up computing current_size as (10, 10) for the slide puzzle (which has no min-width in Slint), which differs from (0, 0). But we really shouldn't try to assign a size in the first place.
1 parent bd02c22 commit d320e6e

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

internal/backends/winit/winitwindowadapter.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,9 @@ impl WinitWindowAdapter {
906906
);
907907

908908
#[cfg(target_arch = "wasm32")]
909-
if let Some(html_canvas) = winit_window.canvas() {
909+
if let Some(html_canvas) =
910+
winit_window.canvas().filter(|html_canvas| !is_preferred_sized_canvas(html_canvas))
911+
{
910912
let existing_canvas_size = winit::dpi::LogicalSize::new(
911913
html_canvas.client_width() as f32,
912914
html_canvas.client_height() as f32,
@@ -1226,12 +1228,7 @@ impl WindowAdapter for WinitWindowAdapter {
12261228
if let Some(canvas) =
12271229
winit_window_or_none.as_window().and_then(|winit_window| winit_window.canvas())
12281230
{
1229-
if canvas
1230-
.dataset()
1231-
.get("slintAutoResizeToPreferred")
1232-
.and_then(|val_str| val_str.parse().ok())
1233-
.unwrap_or_default()
1234-
{
1231+
if is_preferred_sized_canvas(&canvas) {
12351232
let pref = new_constraints.preferred;
12361233
if pref.width > 0 as Coord || pref.height > 0 as Coord {
12371234
// TODO: don't ignore error, propgate to caller
@@ -1489,11 +1486,18 @@ fn adjust_window_size_to_satisfy_constraints(
14891486
max_size: Option<winit::dpi::LogicalSize<f64>>,
14901487
) {
14911488
let sf = adapter.window().scale_factor() as f64;
1492-
let current_size = adapter
1489+
let Some(current_size) = adapter
14931490
.pending_requested_size
14941491
.get()
1492+
.or_else(|| {
1493+
let existing_adapter_size = adapter.size.get();
1494+
(existing_adapter_size.width != 0 && existing_adapter_size.height != 0)
1495+
.then(|| physical_size_to_winit(existing_adapter_size).into())
1496+
})
14951497
.map(|s| s.to_logical::<f64>(sf))
1496-
.unwrap_or_else(|| physical_size_to_winit(adapter.size.get()).to_logical(sf));
1498+
else {
1499+
return;
1500+
};
14971501

14981502
let mut window_size = current_size;
14991503
if let Some(min_size) = min_size {
@@ -1513,3 +1517,12 @@ fn adjust_window_size_to_satisfy_constraints(
15131517
adapter.resize_window(window_size.into()).ok();
15141518
}
15151519
}
1520+
1521+
#[cfg(target_family = "wasm")]
1522+
fn is_preferred_sized_canvas(canvas: &web_sys::HtmlCanvasElement) -> bool {
1523+
canvas
1524+
.dataset()
1525+
.get("slintAutoResizeToPreferred")
1526+
.and_then(|val_str| val_str.parse::<bool>().ok())
1527+
.unwrap_or_default()
1528+
}

0 commit comments

Comments
 (0)