From 6da01eac9b50a8987edbea070d498d86adedf436 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 31 Jan 2022 13:06:59 -0800 Subject: [PATCH] Make editor element's paint and layout states non-optional Co-Authored-By: Nathan Sobo --- crates/editor/src/element.rs | 57 ++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 512c6325f9d7d250eac41bc4619498903c49fa1d..5acd46b0f8db6bab25f5a0c0c6a4018cfe32bb35 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -689,8 +689,8 @@ impl EditorElement { } impl Element for EditorElement { - type LayoutState = Option; - type PaintState = Option; + type LayoutState = LayoutState; + type PaintState = PaintState; fn layout( &mut self, @@ -918,7 +918,7 @@ impl Element for EditorElement { ( size, - Some(LayoutState { + LayoutState { size, scroll_max, gutter_size, @@ -937,7 +937,7 @@ impl Element for EditorElement { em_advance, selections, completions, - }), + }, ) } @@ -948,7 +948,6 @@ impl Element for EditorElement { layout: &mut Self::LayoutState, cx: &mut PaintContext, ) -> Self::PaintState { - let layout = layout.as_mut()?; cx.scene.push_layer(Some(bounds)); let gutter_bounds = RectF::new(bounds.origin(), layout.gutter_size); @@ -971,11 +970,11 @@ impl Element for EditorElement { cx.scene.pop_layer(); - Some(PaintState { + PaintState { bounds, gutter_bounds, text_bounds, - }) + } } fn dispatch_event( @@ -986,31 +985,27 @@ impl Element for EditorElement { paint: &mut Self::PaintState, cx: &mut EventContext, ) -> bool { - if let (Some(layout), Some(paint)) = (layout, paint) { - match event { - Event::LeftMouseDown { - position, - alt, - shift, - click_count, - .. - } => self.mouse_down(*position, *alt, *shift, *click_count, layout, paint, cx), - Event::LeftMouseUp { position } => self.mouse_up(*position, cx), - Event::LeftMouseDragged { position } => { - self.mouse_dragged(*position, layout, paint, cx) - } - Event::ScrollWheel { - position, - delta, - precise, - } => self.scroll(*position, *delta, *precise, layout, paint, cx), - Event::KeyDown { - chars, keystroke, .. - } => self.key_down(chars, keystroke, cx), - _ => false, + match event { + Event::LeftMouseDown { + position, + alt, + shift, + click_count, + .. + } => self.mouse_down(*position, *alt, *shift, *click_count, layout, paint, cx), + Event::LeftMouseUp { position } => self.mouse_up(*position, cx), + Event::LeftMouseDragged { position } => { + self.mouse_dragged(*position, layout, paint, cx) } - } else { - false + Event::ScrollWheel { + position, + delta, + precise, + } => self.scroll(*position, *delta, *precise, layout, paint, cx), + Event::KeyDown { + chars, keystroke, .. + } => self.key_down(chars, keystroke, cx), + _ => false, } }