Skip to content

Commit

Permalink
correctly implement resize_to for tuples
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonDanisch committed Jul 4, 2024
1 parent 225d0ae commit 721649d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 10 deletions.
30 changes: 23 additions & 7 deletions WGLMakie/src/wglmakie.bundled.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
24 changes: 21 additions & 3 deletions WGLMakie/src/wglmakie.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
}
}

Expand Down

0 comments on commit 721649d

Please sign in to comment.