From 721649dd8c50067486d1e06b7e558de18f14f295 Mon Sep 17 00:00:00 2001 From: SimonDanisch Date: Thu, 4 Jul 2024 20:59:02 +0200 Subject: [PATCH] correctly implement resize_to for tuples --- WGLMakie/src/wglmakie.bundled.js | 30 +++++++++++++++++++++++------- WGLMakie/src/wglmakie.js | 24 +++++++++++++++++++++--- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/WGLMakie/src/wglmakie.bundled.js b/WGLMakie/src/wglmakie.bundled.js index d0668a19b6a..4274cdd63ad 100644 --- a/WGLMakie/src/wglmakie.bundled.js +++ b/WGLMakie/src/wglmakie.bundled.js @@ -22932,18 +22932,34 @@ function add_canvas_events(screen, comm, resize_to) { [width, height] = get_body_size(); } else if (resize_to == "parent") { [width, height] = get_parent_size(canvas); + } else if (resize_to.length == 2) { + [width, height] = get_parent_size(canvas); + const [_width, _height] = resize_to; + const [f_width, f_height] = [ + screen.renderer._width, + screen.renderer._height + ]; + console.log(`rwidht: ${_width}, rheight: ${_height}`); + width = _width == "parent" ? width : f_width; + height = _height == "parent" ? height : f_height; + console.log(`widht: ${width}, height: ${height}`); + } else { + console.warn("Invalid resize_to option"); + return; + } + if (height > 0 && width > 0) { + comm.notify({ + resize: [ + width / winscale, + height / winscale + ] + }); } - comm.notify({ - resize: [ - width / winscale, - height / winscale - ] - }); } if (resize_to) { const resize_callback_throttled = throttle_function(resize_callback, 100); window.addEventListener("resize", (event)=>resize_callback_throttled()); - resize_callback_throttled(); + setTimeout(resize_callback, 50); } } function threejs_module(canvas) { diff --git a/WGLMakie/src/wglmakie.js b/WGLMakie/src/wglmakie.js index 110273d7883..8a44b4449d3 100644 --- a/WGLMakie/src/wglmakie.js +++ b/WGLMakie/src/wglmakie.js @@ -313,9 +313,25 @@ function add_canvas_events(screen, comm, resize_to) { [width, height] = get_body_size(); } else if (resize_to == "parent") { [width, height] = get_parent_size(canvas); + } else if (resize_to.length == 2) { + [width, height] = get_parent_size(canvas); + const [_width, _height] = resize_to; + const [f_width, f_height] = [ + screen.renderer._width, + screen.renderer._height, + ]; + console.log(`rwidht: ${_width}, rheight: ${_height}`); + width = _width == "parent" ? width : f_width; + height = _height == "parent" ? height : f_height; + console.log(`widht: ${width}, height: ${height}`); + } else { + console.warn("Invalid resize_to option"); + return; + } + if (height > 0 && width > 0) { + // Send the resize event to Julia + comm.notify({ resize: [width / winscale, height / winscale] }); } - // Send the resize event to Julia - comm.notify({ resize: [width / winscale, height / winscale] }); } if (resize_to) { const resize_callback_throttled = throttle_function( @@ -326,7 +342,9 @@ function add_canvas_events(screen, comm, resize_to) { resize_callback_throttled() ); // Fire the resize event once at the start to auto-size our window - resize_callback_throttled(); + // Without setTimeout, the parent doesn't have the right size yet? + // TODO, there should be a way to do this cleanly + setTimeout(resize_callback, 50); } }