Skip to content

Commit

Permalink
Avoid rounding errors in canvas resolution (enso-org/ide#1820)
Browse files Browse the repository at this point in the history
Original commit: enso-org/ide@e64a6ab
  • Loading branch information
s9ferech authored Sep 16, 2021
1 parent fd0387f commit 9c4d03d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
10 changes: 10 additions & 0 deletions ide/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@

[1755]: https://github.com/enso-org/ide/pull/1755

<br/>![Bug Fixes](/docs/assets/tags/bug_fixes.svg)

#### Visual Environment

- [Sharp rendering on screens with fractional pixel ratios.][1820]

[1820]: https://github.com/enso-org/ide/pull/1820

<br/>

# Enso 2.0.0-alpha.15 (2021-09-09)

<br/>![Bug Fixes](/docs/assets/tags/bug_fixes.svg)
Expand Down
16 changes: 11 additions & 5 deletions ide/src/rust/ensogl/lib/core/src/display/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,10 @@ impl Renderer {
/// Reload the composer after scene shape change.
fn resize_composer(&self) {
let shape = self.dom.shape().device_pixels();
let width = shape.width as i32;
let height = shape.height as i32;
// The width and height in device pixels should be integers. If they are not then this is
// due to rounding errors. We round to the nearest integer to compensate for those errors.
let width = shape.width.round() as i32;
let height = shape.height.round() as i32;
self.composer.borrow_mut().resize(width,height);
}

Expand Down Expand Up @@ -899,10 +901,14 @@ impl SceneData {
/// set the dirty flag.
fn resize_canvas(&self, screen:Shape) {
let canvas = screen.device_pixels();
// The width and height in device pixels should be integers. If they are not then this is
// due to rounding errors. We round to the nearest integer to compensate for those errors.
let width = canvas.width.round() as i32;
let height = canvas.height.round() as i32;
debug!(self.logger,"Resized to {screen.width}px x {screen.height}px.", || {
self.dom.layers.canvas.set_attribute("width", &canvas.width.to_string()).unwrap();
self.dom.layers.canvas.set_attribute("height", &canvas.height.to_string()).unwrap();
self.context.viewport(0,0,canvas.width as i32, canvas.height as i32);
self.dom.layers.canvas.set_attribute("width", &width.to_string()).unwrap();
self.dom.layers.canvas.set_attribute("height", &height.to_string()).unwrap();
self.context.viewport(0,0,width, height);
});
}

Expand Down

0 comments on commit 9c4d03d

Please sign in to comment.