From 47b40e38395d149b32a27960cbf914c30c653616 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Mon, 14 Mar 2022 15:29:18 +0100 Subject: [PATCH] Don't draw scene elements if their size is zero Co-Authored-By: Nathan Sobo --- crates/gpui/src/scene.rs | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/crates/gpui/src/scene.rs b/crates/gpui/src/scene.rs index a5b2f6c8b8..450edc6d8f 100644 --- a/crates/gpui/src/scene.rs +++ b/crates/gpui/src/scene.rs @@ -279,7 +279,9 @@ impl Layer { } fn push_quad(&mut self, quad: Quad) { - self.quads.push(quad); + if can_draw(quad.bounds) { + self.quads.push(quad); + } } pub fn quads(&self) -> &[Quad] { @@ -287,7 +289,9 @@ impl Layer { } fn push_underline(&mut self, underline: Underline) { - self.underlines.push(underline); + if underline.width > 0. { + self.underlines.push(underline); + } } pub fn underlines(&self) -> &[Underline] { @@ -295,7 +299,9 @@ impl Layer { } fn push_image(&mut self, image: Image) { - self.images.push(image); + if can_draw(image.bounds) { + self.images.push(image); + } } pub fn images(&self) -> &[Image] { @@ -303,7 +309,9 @@ impl Layer { } fn push_shadow(&mut self, shadow: Shadow) { - self.shadows.push(shadow); + if can_draw(shadow.bounds) { + self.shadows.push(shadow); + } } pub fn shadows(&self) -> &[Shadow] { @@ -319,7 +327,9 @@ impl Layer { } pub fn push_icon(&mut self, icon: Icon) { - self.icons.push(icon); + if can_draw(icon.bounds) { + self.icons.push(icon); + } } pub fn icons(&self) -> &[Icon] { @@ -327,7 +337,7 @@ impl Layer { } fn push_path(&mut self, path: Path) { - if !path.bounds.is_empty() { + if can_draw(path.bounds) { self.paths.push(path); } } @@ -429,3 +439,8 @@ impl ToJson for Border { value } } + +fn can_draw(bounds: RectF) -> bool { + let size = bounds.size(); + size.x() > 0. && size.y() > 0. +}