Skip to content

Commit

Permalink
Improve quick measurement overlays across all possible arrangement sc…
Browse files Browse the repository at this point in the history
…enarios (#2147)

* setup single edge crossing handling for quick measure tool

* Setup quick measure functionality for intersecting objects and handle centerline cases for non intersecting objects.

* setup single edge crossing handling for quick measure tool

* Setup quick measure functionality for intersecting objects and handle centerline cases for non intersecting objects.

* Setup quick measure functionality for intersecting objects and handle centerline cases for non intersecting objects.

* Setup quick measure functionality for intersecting objects and handle centerline cases for non intersecting objects.

* Setup quick measure functionality for intersecting objects and handle centerline cases for non intersecting objects. Add a dashed_line_with_pattern function that gives more granular control over dash_width and gap_width.

* Setup quick measure functionality for intersecting objects and handle centerline cases for non intersecting objects. Add a dashed_line_with_pattern function that gives more granular control over dash_width and gap_width.

* Setup quick measure functionality for intersecting objects and handle centerline cases for non intersecting objects. Add a dashed_line_with_pattern function that gives more granular control over dash_width and gap_width.

* Setup quick measure functionality for intersecting objects and handle centerline cases for non intersecting objects. Add a dashed_line_with_pattern function that gives more granular control over dash_width and gap_width.

* Nit picks

* Define wrapper for Overlay_context line method

* Comments and consolidating lines of code

---------

Co-authored-by: Keavon Chambers <[email protected]>
  • Loading branch information
singhutsav5502 and Keavon authored Dec 23, 2024
1 parent bc47d06 commit a1dc955
Show file tree
Hide file tree
Showing 3 changed files with 412 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
}
Expand Down
13 changes: 10 additions & 3 deletions editor/src/messages/portfolio/document/overlays/utility_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<f64>) {
pub fn dashed_line(&mut self, start: DVec2, end: DVec2, color: Option<&str>, dash_width: Option<f64>, gap_width: Option<f64>) {
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.);
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))
Expand All @@ -72,6 +73,12 @@ impl OverlayContext {
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 to solid after drawing
self.render_context
.set_line_dash(&JsValue::from(js_sys::Array::new()))
.map_err(|error| log::warn!("Error drawing dashed line: {:?}", error))
.ok();
}

pub fn manipulator_handle(&mut self, position: DVec2, selected: bool) {
Expand Down
Loading

0 comments on commit a1dc955

Please sign in to comment.