Skip to content

Commit 4e75cc4

Browse files
committed
clean-up and comments
1 parent cab43f3 commit 4e75cc4

File tree

2 files changed

+40
-61
lines changed

2 files changed

+40
-61
lines changed

editor/src/messages/portfolio/document/overlays/utility_types.rs

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -368,45 +368,12 @@ impl OverlayContext {
368368
self.end_dpi_aware_transform();
369369
}
370370

371-
pub fn dashed_circle(
372-
&mut self,
373-
position: DVec2,
374-
radius: f64,
375-
color_fill: Option<&str>,
376-
color_stroke: Option<&str>,
377-
dash_width: Option<f64>,
378-
dash_gap_width: Option<f64>,
379-
dash_offset: Option<f64>,
380-
transform: Option<DAffine2>,
381-
) {
371+
pub fn circle(&mut self, position: DVec2, radius: f64, color_fill: Option<&str>, color_stroke: Option<&str>) {
382372
let color_stroke = color_stroke.unwrap_or(COLOR_OVERLAY_BLUE);
383373
let position = position.round();
384374

385375
self.start_dpi_aware_transform();
386376

387-
if let Some(transform) = transform {
388-
let [a, b, c, d, e, f] = transform.to_cols_array();
389-
self.render_context.transform(a, b, c, d, e, f).expect("Failed to transform circle");
390-
}
391-
392-
if let Some(dash_width) = dash_width {
393-
let dash_gap_width = dash_gap_width.unwrap_or(1.);
394-
let array = js_sys::Array::new();
395-
array.push(&JsValue::from(dash_width));
396-
array.push(&JsValue::from(dash_gap_width));
397-
398-
if let Some(dash_offset) = dash_offset {
399-
if dash_offset != 0. {
400-
self.render_context.set_line_dash_offset(dash_offset);
401-
}
402-
}
403-
404-
self.render_context
405-
.set_line_dash(&JsValue::from(array))
406-
.map_err(|error| log::warn!("Error drawing dashed line: {:?}", error))
407-
.ok();
408-
}
409-
410377
self.render_context.begin_path();
411378
self.render_context.arc(position.x, position.y, radius, 0., TAU).expect("Failed to draw the circle");
412379
self.render_context.set_stroke_style_str(color_stroke);
@@ -417,24 +384,9 @@ impl OverlayContext {
417384
}
418385
self.render_context.stroke();
419386

420-
// Reset the dash pattern back to solid
421-
if dash_width.is_some() {
422-
self.render_context
423-
.set_line_dash(&JsValue::from(js_sys::Array::new()))
424-
.map_err(|error| log::warn!("Error drawing dashed line: {:?}", error))
425-
.ok();
426-
}
427-
if dash_offset.is_some() && dash_offset != Some(0.) {
428-
self.render_context.set_line_dash_offset(0.);
429-
}
430-
431387
self.end_dpi_aware_transform();
432388
}
433389

434-
pub fn circle(&mut self, position: DVec2, radius: f64, color_fill: Option<&str>, color_stroke: Option<&str>) {
435-
self.dashed_circle(position, radius, color_fill, color_stroke, None, None, None, None);
436-
}
437-
438390
pub fn manipulator_handle(&mut self, position: DVec2, selected: bool, color: Option<&str>) {
439391
self.start_dpi_aware_transform();
440392

editor/src/messages/tool/common_functionality/gizmos/shape_gizmos/circle_arc_radius_handle.rs

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,15 @@ pub enum RadiusHandleState {
2323

2424
#[derive(Clone, Debug, Default, PartialEq)]
2525
pub struct RadiusHandle {
26+
/// The layer this handle is currently attached to
2627
pub layer: Option<LayerNodeIdentifier>,
28+
/// Original radius value when drag operation started (for delta calculations)
2729
initial_radius: f64,
30+
/// Current interaction state (inactive/hover/dragging)
2831
handle_state: RadiusHandleState,
32+
/// Angle at which the handle appears on the circle (in radians)
2933
angle: f64,
34+
/// Previous mouse position (used for calculating movement deltas)
3035
previous_mouse_position: DVec2,
3136
}
3237

@@ -48,13 +53,24 @@ impl RadiusHandle {
4853
self.handle_state = state;
4954
}
5055

56+
/// Determines if the mouse position is within the interactive area of the radius handle
57+
/// The interactive area is a "dashed line" region around the circle/arc perimeter
58+
///
59+
/// For shapes with stroke: Creates a band around the radius (stroke_width + spacing)
60+
/// For shapes without stroke: Uses simple distance-from-center comparison
5161
pub fn check_if_inside_dash_lines(angle: f64, mouse_position: DVec2, viewport: DAffine2, radius: f64, document: &DocumentMessageHandler, layer: LayerNodeIdentifier) -> bool {
5262
let center = viewport.transform_point2(DVec2::ZERO);
63+
5364
if let Some(stroke_width) = get_stroke_width(layer, &document.network_interface) {
65+
// For stroked shapes: Create interaction band based on stroke width
5466
let layer_mouse = viewport.inverse().transform_point2(mouse_position);
55-
let spacing = 3. * stroke_width;
56-
layer_mouse.distance(DVec2::ZERO) >= (radius - spacing) && layer_mouse.distance(DVec2::ZERO) <= (radius + spacing)
67+
let spacing = 3.0 * stroke_width; // 3x stroke width for comfortable interaction area
68+
let mouse_distance = layer_mouse.distance(DVec2::ZERO);
69+
70+
// Mouse must be within the stroke band around the radius
71+
mouse_distance >= (radius - spacing) && mouse_distance <= (radius + spacing)
5772
} else {
73+
// For non-stroked shapes: Simple radial distance check
5874
let point_position = viewport.transform_point2(calculate_circle_point_position(angle, radius.abs()));
5975
mouse_position.distance(center) <= point_position.distance(center)
6076
}
@@ -89,45 +105,56 @@ impl RadiusHandle {
89105
}
90106
}
91107

108+
/// Renders visual overlay indicators for the radius handle
109+
/// Shows dashed ellipses to indicate the interactive area around the shape
92110
pub fn overlays(&self, document: &DocumentMessageHandler, overlay_context: &mut OverlayContext) {
93111
match &self.handle_state {
94-
RadiusHandleState::Inactive => {}
112+
RadiusHandleState::Inactive => {
113+
// No visual feedback when inactive
114+
}
95115

96116
RadiusHandleState::Dragging | RadiusHandleState::Hover => {
97117
let Some(layer) = self.layer else { return };
118+
119+
// Extract radius from the shape (circle or arc)
98120
let Some(radius) = extract_circle_radius(layer, document).or(extract_arc_parameters(Some(layer), document).map(|(r, _, _, _)| r)) else {
99121
return;
100122
};
123+
101124
let viewport = document.metadata().transform_to_viewport(layer);
102125
let center = viewport.transform_point2(DVec2::ZERO);
103126

104-
let start_point = viewport.transform_point2(calculate_circle_point_position(0., radius)).distance(center);
127+
// Calculate radii at different angles to handle elliptical transformations
128+
let start_point = viewport.transform_point2(calculate_circle_point_position(0.0, radius)).distance(center);
105129
let end_point = viewport.transform_point2(calculate_circle_point_position(FRAC_PI_2, radius)).distance(center);
106130

107131
if let Some(stroke_width) = get_stroke_width(layer, &document.network_interface) {
132+
// For stroked shapes: Show inner and outer interaction boundaries
108133
let threshold = 15.0;
109134
let min_radius = start_point.min(end_point);
110135

111-
let extra_spacing = if min_radius < threshold {
112-
10.0 * (min_radius / threshold) // smoothly scales from 0 → 10
113-
} else {
114-
10.0
115-
};
136+
// Dynamic spacing that scales down for very small radii (prevents visual overlap)
137+
let extra_spacing = if min_radius < threshold { 10.0 * (min_radius / threshold) } else { 10.0 };
116138

117139
let spacing = stroke_width + extra_spacing;
140+
141+
// Inner boundary (closer to center)
118142
let smaller_radius_x = (start_point - spacing).abs();
119143
let smaller_radius_y = (end_point - spacing).abs();
120144

145+
// Outer boundary (further from center)
121146
let larger_radius_x = (start_point + spacing).abs();
122147
let larger_radius_y = (end_point + spacing).abs();
123148

124-
overlay_context.dashed_ellipse(center, smaller_radius_x, smaller_radius_y, None, None, None, None, None, None, Some(4.), Some(4.), Some(0.5));
125-
overlay_context.dashed_ellipse(center, larger_radius_x, larger_radius_y, None, None, None, None, None, None, Some(4.), Some(4.), Some(0.5));
149+
// Render both inner and outer dashed ellipses
150+
overlay_context.dashed_ellipse(center, smaller_radius_x, smaller_radius_y, None, None, None, None, None, None, Some(4.0), Some(4.0), Some(0.5));
151+
overlay_context.dashed_ellipse(center, larger_radius_x, larger_radius_y, None, None, None, None, None, None, Some(4.0), Some(4.0), Some(0.5));
126152

127153
return;
128154
}
129155

130-
overlay_context.dashed_ellipse(center, start_point, end_point, None, None, None, None, None, None, Some(4.), Some(4.), Some(0.5));
156+
// For non-stroked shapes: Show single dashed ellipse at the radius
157+
overlay_context.dashed_ellipse(center, start_point, end_point, None, None, None, None, None, None, Some(4.0), Some(4.0), Some(0.5));
131158
}
132159
}
133160
}

0 commit comments

Comments
 (0)