Don't draw scene elements if their size is zero

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Antonio Scandurra 2022-03-14 15:29:18 +01:00
parent e7d0bf1c36
commit 47b40e3839

View file

@ -279,32 +279,40 @@ impl Layer {
}
fn push_quad(&mut self, quad: Quad) {
if can_draw(quad.bounds) {
self.quads.push(quad);
}
}
pub fn quads(&self) -> &[Quad] {
self.quads.as_slice()
}
fn push_underline(&mut self, underline: Underline) {
if underline.width > 0. {
self.underlines.push(underline);
}
}
pub fn underlines(&self) -> &[Underline] {
self.underlines.as_slice()
}
fn push_image(&mut self, image: Image) {
if can_draw(image.bounds) {
self.images.push(image);
}
}
pub fn images(&self) -> &[Image] {
self.images.as_slice()
}
fn push_shadow(&mut self, shadow: Shadow) {
if can_draw(shadow.bounds) {
self.shadows.push(shadow);
}
}
pub fn shadows(&self) -> &[Shadow] {
self.shadows.as_slice()
@ -319,15 +327,17 @@ impl Layer {
}
pub fn push_icon(&mut self, icon: Icon) {
if can_draw(icon.bounds) {
self.icons.push(icon);
}
}
pub fn icons(&self) -> &[Icon] {
self.icons.as_slice()
}
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.
}