Skip to content

Commit

Permalink
correctly implement resize_to for tuples (#4009)
Browse files Browse the repository at this point in the history
* correctly implement resize_to for tuples

* add changelog entry
  • Loading branch information
SimonDanisch authored Jul 7, 2024
1 parent de1dfc3 commit 682ae88
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [Unreleased]

- Fixed tuple argument for `WGLMakie.activate!(resize_to=(:parent, nothing))` [#4009](https://github.com/MakieOrg/Makie.jl/pull/4009).
- validate plot attributes later, for axis specific plot attributes [#3974](https://github.com/MakieOrg/Makie.jl/pull/3974).

## [0.21.4] - 2024-07-02
Expand Down
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 682ae88

Please sign in to comment.