diff --git a/editor/src/messages/portfolio/document/overlays/grid_overlays.rs b/editor/src/messages/portfolio/document/overlays/grid_overlays.rs index dbed875dcd..3c3c05309c 100644 --- a/editor/src/messages/portfolio/document/overlays/grid_overlays.rs +++ b/editor/src/messages/portfolio/document/overlays/grid_overlays.rs @@ -184,6 +184,7 @@ fn grid_overlay_isometric_dot(document: &DocumentMessageHandler, overlay_context document_to_viewport.transform_point2(end), Some(&("#".to_string() + &grid_color.rgba_hex())), Some((spacing_x / cos_a) * document_to_viewport.matrix2.x_axis.length()), + None, ); } } diff --git a/editor/src/messages/portfolio/document/overlays/utility_types.rs b/editor/src/messages/portfolio/document/overlays/utility_types.rs index c0dbecbb6c..24859f382f 100644 --- a/editor/src/messages/portfolio/document/overlays/utility_types.rs +++ b/editor/src/messages/portfolio/document/overlays/utility_types.rs @@ -46,16 +46,17 @@ impl OverlayContext { } pub fn line(&mut self, start: DVec2, end: DVec2, color: Option<&str>) { - self.dashed_line(start, end, color, None) + self.dashed_line(start, end, color, None, None) } - pub fn dashed_line(&mut self, start: DVec2, end: DVec2, color: Option<&str>, dash_width: Option) { + pub fn dashed_line(&mut self, start: DVec2, end: DVec2, color: Option<&str>, dash_width: Option, gap_width: Option) { let start = start.round() - DVec2::splat(0.5); let end = end.round() - DVec2::splat(0.5); if let Some(dash_width) = dash_width { + let gap_width = gap_width.unwrap_or(1.0); let array = js_sys::Array::new(); - array.push(&JsValue::from(1)); array.push(&JsValue::from(dash_width - 1.)); + array.push(&JsValue::from(gap_width)); self.render_context .set_line_dash(&JsValue::from(array)) .map_err(|error| log::warn!("Error drawing dashed line: {:?}", error)) @@ -80,32 +81,6 @@ impl OverlayContext { .ok(); } - pub fn dashed_line_with_pattern(&mut self, start: DVec2, end: DVec2, color: Option<&str>, dash_width: f64, gap_width: f64) { - let start = start.round() - DVec2::splat(0.5); - let end = end.round() - DVec2::splat(0.5); - - // Set the dash and gap pattern - let array = js_sys::Array::new(); - array.push(&JsValue::from(dash_width)); - array.push(&JsValue::from(gap_width)); - self.render_context - .set_line_dash(&JsValue::from(array)) - .map_err(|error| log::warn!("Error setting line dash: {:?}", error)) - .ok(); - - self.render_context.begin_path(); - self.render_context.move_to(start.x, start.y); - self.render_context.line_to(end.x, end.y); - self.render_context.set_stroke_style_str(color.unwrap_or(COLOR_OVERLAY_BLUE)); - self.render_context.stroke(); - - // Reset the dash pattern after drawing - self.render_context - .set_line_dash(&JsValue::from(js_sys::Array::new())) - .map_err(|error| log::warn!("Error resetting line dash: {:?}", error)) - .ok(); - } - pub fn manipulator_handle(&mut self, position: DVec2, selected: bool) { let position = position.round() - DVec2::splat(0.5); diff --git a/editor/src/messages/tool/common_functionality/measure.rs b/editor/src/messages/tool/common_functionality/measure.rs index 29d13974b0..0ca912862c 100644 --- a/editor/src/messages/tool/common_functionality/measure.rs +++ b/editor/src/messages/tool/common_functionality/measure.rs @@ -39,7 +39,7 @@ fn draw_zero_axis_crossings(selected_bounds: Rect, hovered_bounds: Rect, transfo let min_viewport = transform.transform_point2(line_start); let max_viewport = transform.transform_point2(line_end); - overlay_context.dashed_line_with_pattern(min_viewport, max_viewport, None, 2.0, 2.0); + overlay_context.dashed_line(min_viewport, max_viewport, None, Some(2.0), Some(2.0)); let min_viewport_y_selected = transform.transform_point2(DVec2::new(selected_x, selected_y)); let max_viewport_y_selected = transform.transform_point2(DVec2::new(selected_x, hovered_y)); @@ -56,7 +56,7 @@ fn draw_zero_axis_crossings(selected_bounds: Rect, hovered_bounds: Rect, transfo let min_viewport_y_hovered = transform.transform_point2(DVec2::new(hovered_x, selected_y)); let max_viewport_y_hovered = transform.transform_point2(DVec2::new(hovered_x, hovered_y)); - overlay_context.dashed_line_with_pattern(min_viewport_y_hovered, max_viewport_y_hovered, None, 2.0, 2.0); + overlay_context.dashed_line(min_viewport_y_hovered, max_viewport_y_hovered, None, Some(2.0), Some(2.0)); } fn draw_single_axis_zero_crossings(selected_bounds: Rect, hovered_bounds: Rect, transform: DAffine2, document_to_viewport: DAffine2, overlay_context: &mut OverlayContext) { let transform_to_document = document_to_viewport.inverse() * transform; @@ -123,7 +123,7 @@ fn draw_single_axis_zero_crossings(selected_bounds: Rect, hovered_bounds: Rect, let min_viewport = transform.transform_point2(dashed_line_start); let max_viewport = transform.transform_point2(dashed_line_end); - overlay_context.dashed_line_with_pattern(min_viewport, max_viewport, None, 2.0, 2.0); + overlay_context.dashed_line(min_viewport, max_viewport, None, Some(2.0), Some(2.0)); } else if overlap_x { let selected_facing_edge = if hovered_bounds.max().x < selected_bounds.min().x { selected_bounds.min().x @@ -182,7 +182,7 @@ fn draw_single_axis_zero_crossings(selected_bounds: Rect, hovered_bounds: Rect, let min_viewport = transform.transform_point2(dashed_line_start); let max_viewport = transform.transform_point2(dashed_line_end); - overlay_context.dashed_line_with_pattern(min_viewport, max_viewport, None, 2.0, 2.0); + overlay_context.dashed_line(min_viewport, max_viewport, None, Some(2.0), Some(2.0)); } } fn draw_single_axis_one_crossings(selected_bounds: Rect, hovered_bounds: Rect, transform: DAffine2, document_to_viewport: DAffine2, overlay_context: &mut OverlayContext) {