diff --git a/ezgui/src/canvas.rs b/ezgui/src/canvas.rs index 58dcce4a76..6ad283f49d 100644 --- a/ezgui/src/canvas.rs +++ b/ezgui/src/canvas.rs @@ -30,7 +30,6 @@ pub struct Canvas { // TODO Bit weird and hacky to mutate inside of draw() calls. pub(crate) covered_areas: RefCell>, - pub(crate) covered_polygons: RefCell>, // Kind of just ezgui state awkwardly stuck here... pub(crate) lctrl_held: bool, @@ -63,7 +62,6 @@ impl Canvas { map_dims: (0.0, 0.0), covered_areas: RefCell::new(Vec::new()), - covered_polygons: RefCell::new(Vec::new()), lctrl_held: false, button_tooltip: None, @@ -127,10 +125,9 @@ impl Canvas { pub(crate) fn start_drawing(&self) { self.covered_areas.borrow_mut().clear(); - self.covered_polygons.borrow_mut().clear(); } - pub fn mark_covered_area(&self, rect: ScreenRectangle) { + pub(crate) fn mark_covered_area(&self, rect: ScreenRectangle) { self.covered_areas.borrow_mut().push(rect); } @@ -147,11 +144,6 @@ impl Canvas { return None; } } - for c in self.covered_polygons.borrow().iter() { - if c.contains_pt(pt.to_pt()) { - return None; - } - } Some(self.screen_to_map(pt)) } else { diff --git a/ezgui/src/drawing.rs b/ezgui/src/drawing.rs index 7ffa5088c0..bf0466e803 100644 --- a/ezgui/src/drawing.rs +++ b/ezgui/src/drawing.rs @@ -242,6 +242,12 @@ impl<'a> GfxCtx<'a> { .mark_covered_area(text::draw_text_bubble(self, top_left, txt, dims, true)); } + pub(crate) fn draw_blocking_text_at_screenspace_topleft(&mut self, txt: &Text, pt: ScreenPt) { + let dims = self.text_dims(&txt); + self.canvas + .mark_covered_area(text::draw_text_bubble(self, pt, txt, dims, true)); + } + pub fn get_screen_bounds(&self) -> Bounds { self.canvas.get_screen_bounds() } @@ -272,12 +278,6 @@ impl<'a> GfxCtx<'a> { ); } - pub fn draw_text_at_screenspace_topleft(&mut self, txt: &Text, pt: ScreenPt) { - let dims = self.text_dims(&txt); - self.canvas - .mark_covered_area(text::draw_text_bubble(self, pt, txt, dims, true)); - } - pub fn draw_mouse_tooltip(&mut self, txt: &Text) { let dims = self.text_dims(&txt); // TODO Maybe also consider the cursor as a valid center @@ -590,9 +590,13 @@ impl DrawBoth { g.redraw(&self.geom); g.unfork(); for (txt, pt) in &self.txt { - g.draw_text_at_screenspace_topleft( - txt, + let dims = g.text_dims(&txt); + text::draw_text_bubble( + g, ScreenPt::new(top_left.x + pt.x, top_left.y + pt.y), + txt, + dims, + true, ); } } diff --git a/ezgui/src/managed.rs b/ezgui/src/managed.rs index 68a6298533..ff1195e7e2 100644 --- a/ezgui/src/managed.rs +++ b/ezgui/src/managed.rs @@ -707,9 +707,11 @@ impl Composite { } pub fn draw(&self, g: &mut GfxCtx) { - g.canvas.mark_covered_area(self.top_level.rect.clone()); - if self.scrollable_x || self.scrollable_y { - g.enable_clipping(self.clip_rect.clone().unwrap()); + if let Some(ref rect) = self.clip_rect { + g.enable_clipping(rect.clone()); + g.canvas.mark_covered_area(rect.clone()); + } else { + g.canvas.mark_covered_area(self.top_level.rect.clone()); } self.top_level.draw(g, &self.sliders, &self.menus); if self.scrollable_x || self.scrollable_y { diff --git a/ezgui/src/widgets/button.rs b/ezgui/src/widgets/button.rs index 36a850e191..04afbbba1e 100644 --- a/ezgui/src/widgets/button.rs +++ b/ezgui/src/widgets/button.rs @@ -105,11 +105,6 @@ impl Button { } else { self.draw_normal.redraw(self.top_left, g); } - - g.canvas - .covered_polygons - .borrow_mut() - .push(self.get_hitbox()); } } diff --git a/ezgui/src/widgets/modal_menu.rs b/ezgui/src/widgets/modal_menu.rs index cfd5af3e68..53fec21907 100644 --- a/ezgui/src/widgets/modal_menu.rs +++ b/ezgui/src/widgets/modal_menu.rs @@ -196,7 +196,7 @@ impl ModalMenu { } pub fn draw(&self, g: &mut GfxCtx) { - g.draw_text_at_screenspace_topleft(&self.calculate_txt(), self.top_left); + g.draw_blocking_text_at_screenspace_topleft(&self.calculate_txt(), self.top_left); } fn recalculate_dims(&mut self, ctx: &EventCtx) { diff --git a/ezgui/src/widgets/popup_menu.rs b/ezgui/src/widgets/popup_menu.rs index 43b9fdc982..94a27a5af0 100644 --- a/ezgui/src/widgets/popup_menu.rs +++ b/ezgui/src/widgets/popup_menu.rs @@ -114,7 +114,7 @@ impl PopupMenu { } pub fn draw(&self, g: &mut GfxCtx) { - g.draw_text_at_screenspace_topleft(&self.calculate_txt(), self.top_left); + g.draw_blocking_text_at_screenspace_topleft(&self.calculate_txt(), self.top_left); } pub fn current_choice(&self) -> &T { diff --git a/ezgui/src/widgets/slider.rs b/ezgui/src/widgets/slider.rs index 45ce4d6a62..4a46518ab3 100644 --- a/ezgui/src/widgets/slider.rs +++ b/ezgui/src/widgets/slider.rs @@ -215,6 +215,8 @@ impl Slider { pub fn draw(&self, g: &mut GfxCtx) { self.draw.redraw(self.top_left, g); + // TODO Since the sliders in Composites are scrollbars outside of the clipping rectangle, + // this stays for now. g.canvas .mark_covered_area(ScreenRectangle::top_left(self.top_left, self.dims)); } diff --git a/ezgui/src/widgets/text_box.rs b/ezgui/src/widgets/text_box.rs index ba8f9beb3a..4383abcf06 100644 --- a/ezgui/src/widgets/text_box.rs +++ b/ezgui/src/widgets/text_box.rs @@ -94,7 +94,7 @@ impl TextBox { } pub fn draw(&self, g: &mut GfxCtx) { - g.draw_text_at_screenspace_topleft(&self.get_text(), self.top_left); + g.draw_blocking_text_at_screenspace_topleft(&self.get_text(), self.top_left); } }