Browse Source

Tesselator: ignore zero-sized clip rects

Improves https://github.com/emilk/egui/issues/328
pull/333/head
Emil Ernerfeldt 4 years ago
parent
commit
58ebb217dc
  1. 4
      egui/src/layout.rs
  2. 13
      emath/src/rect.rs
  3. 2
      epaint/src/tessellator.rs

4
egui/src/layout.rs

@ -333,7 +333,7 @@ impl Layout {
impl Layout { impl Layout {
pub fn align_size_within_rect(&self, size: Vec2, outer: Rect) -> Rect { pub fn align_size_within_rect(&self, size: Vec2, outer: Rect) -> Rect {
debug_assert!(size.x >= 0.0 && size.y >= 0.0); debug_assert!(size.x >= 0.0 && size.y >= 0.0);
debug_assert!(outer.is_non_negative()); debug_assert!(!outer.is_negative());
self.align2().align_size_within_rect(size, outer) self.align2().align_size_within_rect(size, outer)
} }
@ -571,7 +571,7 @@ impl Layout {
/// Apply justify (fill width/height) and/or alignment after calling `next_space`. /// Apply justify (fill width/height) and/or alignment after calling `next_space`.
pub(crate) fn justify_and_align(&self, frame: Rect, mut child_size: Vec2) -> Rect { pub(crate) fn justify_and_align(&self, frame: Rect, mut child_size: Vec2) -> Rect {
debug_assert!(child_size.x >= 0.0 && child_size.y >= 0.0); debug_assert!(child_size.x >= 0.0 && child_size.y >= 0.0);
debug_assert!(frame.is_non_negative()); debug_assert!(!frame.is_negative());
if self.horizontal_justify() { if self.horizontal_justify() {
child_size.x = child_size.x.at_least(frame.width()); // fill full width child_size.x = child_size.x.at_least(frame.width()); // fill full width

13
emath/src/rect.rs

@ -297,16 +297,21 @@ impl Rect {
self.max.x < self.min.x || self.max.y < self.min.y self.max.x < self.min.x || self.max.y < self.min.y
} }
/// `max.x < min.x` or `max.y < min.y`. /// `width < 0 || height < 0`
#[inline(always)] #[inline(always)]
pub fn is_negative(&self) -> bool { pub fn is_negative(&self) -> bool {
self.max.x < self.min.x || self.max.y < self.min.y self.max.x < self.min.x || self.max.y < self.min.y
} }
/// `min.x <= max.x && min.y <= max.y`. #[deprecated = "Use !is_negative() instead"]
#[inline(always)]
pub fn is_non_negative(&self) -> bool { pub fn is_non_negative(&self) -> bool {
self.min.x <= self.max.x && self.min.y <= self.max.y !self.is_negative()
}
/// `width > 0 && height > 0`
#[inline(always)]
pub fn is_positive(&self) -> bool {
self.min.x < self.max.x && self.min.y < self.max.y
} }
/// True if all members are also finite. /// True if all members are also finite.

2
epaint/src/tessellator.rs

@ -742,7 +742,7 @@ pub fn tessellate_shapes(
let mut clipped_meshes: Vec<ClippedMesh> = Vec::default(); let mut clipped_meshes: Vec<ClippedMesh> = Vec::default();
for ClippedShape(clip_rect, shape) in shapes { for ClippedShape(clip_rect, shape) in shapes {
if !clip_rect.is_non_negative() { if !clip_rect.is_positive() {
continue; // skip empty clip rectangles continue; // skip empty clip rectangles
} }

Loading…
Cancel
Save