Refactor and enhance GUI components
- Improved code readability by formatting function parameters and conditionals. - Updated tooltip implementations to use a consistent style across various components. - Added vector angle property to tool settings and integrated it into the vector shape rendering logic. - Enhanced the rendering of shapes such as Cross, Bolt, and Arrow4 to improve visual fidelity. - Refactored dock and sidebar components for better organization and clarity. - Fixed various minor issues and improved logging for better debugging.
This commit is contained in:
+84
-26
@@ -564,27 +564,34 @@ fn render_shape(layer: &mut Layer, shape: &VectorShape) {
|
||||
}
|
||||
}
|
||||
Cross { x1, y1, x2, y2, stroke, color, fill_color, fill, opacity, angle, .. } => {
|
||||
// Plus sign: four narrow arms extending from center.
|
||||
let (left, top, right, bottom) = normalized_rect(*x1, *y1, *x2, *y2);
|
||||
let cx = (left + right) / 2.0;
|
||||
let cy = (top + bottom) / 2.0;
|
||||
let hw = (right - left) * 0.3;
|
||||
let hh = (bottom - top) * 0.3;
|
||||
let bw = right - left;
|
||||
let bh = bottom - top;
|
||||
// Arm width = 25% of the shorter dimension for a balanced plus.
|
||||
let arm = bw.min(bh) * 0.25;
|
||||
let alpha = (color[3] as f32 * opacity).round() as u8;
|
||||
let px_color = [color[0], color[1], color[2], alpha];
|
||||
|
||||
let mut pts = vec![
|
||||
(cx - hw, top),
|
||||
(cx + hw, top),
|
||||
(cx + hw, cy - hh),
|
||||
(right, cy - hh),
|
||||
(right, cy + hh),
|
||||
(cx + hw, cy + hh),
|
||||
(cx + hw, bottom),
|
||||
(cx - hw, bottom),
|
||||
(cx - hw, cy + hh),
|
||||
(left, cy + hh),
|
||||
(left, cy - hh),
|
||||
(cx - hw, cy - hh),
|
||||
// Top arm
|
||||
(cx - arm, top),
|
||||
(cx + arm, top),
|
||||
(cx + arm, cy - arm),
|
||||
// Right arm
|
||||
(right, cy - arm),
|
||||
(right, cy + arm),
|
||||
// Bottom arm
|
||||
(cx + arm, cy + arm),
|
||||
(cx + arm, bottom),
|
||||
(cx - arm, bottom),
|
||||
// Left arm
|
||||
(cx - arm, cy + arm),
|
||||
(left, cy + arm),
|
||||
(left, cy - arm),
|
||||
(cx - arm, cy - arm),
|
||||
];
|
||||
|
||||
for p in &mut pts {
|
||||
@@ -633,14 +640,33 @@ fn render_shape(layer: &mut Layer, shape: &VectorShape) {
|
||||
}
|
||||
|
||||
Bolt { x1, y1, x2, y2, stroke, color, fill_color, fill, opacity, angle, .. } => {
|
||||
// Lightning bolt: classic top-right to bottom-left zigzag.
|
||||
// Points flow: top tip → right shoulder → center notch → left notch → bottom tip
|
||||
let alpha = (color[3] as f32 * opacity).round() as u8;
|
||||
let px_color = [color[0], color[1], color[2], alpha];
|
||||
let cx = (*x1 + *x2) / 2.0;
|
||||
let cy = (*y1 + *y2) / 2.0;
|
||||
let mid_x = (*x1 + *x2) / 2.0;
|
||||
|
||||
let left = *x1;
|
||||
let right = *x2;
|
||||
let top = *y1;
|
||||
let bottom = *y2;
|
||||
let w = right - left;
|
||||
let h = bottom - top;
|
||||
// Notch offset from center — creates the zigzag cut.
|
||||
let nx = w * 0.18;
|
||||
let mut pts = vec![
|
||||
(*x1, *y1), (mid_x, *y2 * 0.7 + *y1 * 0.3), (*x2, *y1 * 0.3 + *y2 * 0.7), (*x2, *y2),
|
||||
// Top tip (slightly right of center)
|
||||
(cx + nx, top),
|
||||
// Right shoulder (top-right corner area)
|
||||
(right, top + h * 0.28),
|
||||
// Zigzag inward to center-left
|
||||
(cx - nx, cy - h * 0.05),
|
||||
// Zigzag back to center-right
|
||||
(cx + nx, cy + h * 0.05),
|
||||
// Left shoulder (bottom-left corner area)
|
||||
(left, bottom - h * 0.28),
|
||||
// Bottom tip (slightly left of center)
|
||||
(cx - nx, bottom),
|
||||
];
|
||||
|
||||
for p in &mut pts {
|
||||
@@ -654,19 +680,51 @@ fn render_shape(layer: &mut Layer, shape: &VectorShape) {
|
||||
let px_fill = [fill_color[0], fill_color[1], fill_color[2], fill_alpha];
|
||||
fill_polygon(layer, &pts, px_fill);
|
||||
}
|
||||
draw_line(layer, pts[0].0, pts[0].1, pts[1].0, pts[1].1, px_color, *stroke, None);
|
||||
draw_line(layer, pts[1].0, pts[1].1, pts[2].0, pts[2].1, px_color, *stroke, None);
|
||||
draw_line(layer, pts[2].0, pts[2].1, pts[3].0, pts[3].1, px_color, *stroke, None);
|
||||
for i in 0..pts.len() {
|
||||
let j = (i + 1) % pts.len();
|
||||
draw_line(layer, pts[i].0, pts[i].1, pts[j].0, pts[j].1, px_color, *stroke, None);
|
||||
}
|
||||
}
|
||||
Arrow4 { x1, y1, x2, y2, stroke, color, fill_color, fill, opacity, angle, .. } => {
|
||||
// 4-way arrow: cross-shaped body with triangular arrowheads at each end.
|
||||
let (left, top, right, bottom) = normalized_rect(*x1, *y1, *x2, *y2);
|
||||
let cx = (left + right) / 2.0;
|
||||
let cy = (top + bottom) / 2.0;
|
||||
let alpha = (color[3] as f32 * opacity).round() as u8;
|
||||
let px_color = [color[0], color[1], color[2], alpha];
|
||||
|
||||
// Arm width is 25% of each half-dimension.
|
||||
let arm_w = (right - left) * 0.125;
|
||||
let arm_h = (bottom - top) * 0.125;
|
||||
// Arrowhead extends 30% inward from the tip.
|
||||
let head_extend_x = (right - cx) * 0.3;
|
||||
let head_extend_y = (bottom - cy) * 0.3;
|
||||
|
||||
// Full 12-point cross+arrowhead polygon:
|
||||
// Up arm with arrowhead
|
||||
let mut pts = vec![
|
||||
(cx, top), (right, cy), (cx, bottom), (left, cy),
|
||||
(cx - arm_w, cy - arm_h), // inner left of up arm
|
||||
(cx - arm_w, top + head_extend_y), // left side near tip
|
||||
(cx, top), // up tip
|
||||
(cx + arm_w, top + head_extend_y), // right side near tip
|
||||
(cx + arm_w, cy - arm_h), // inner right of up arm
|
||||
// Right arm with arrowhead
|
||||
(cx + arm_w, cy - arm_h), // shared
|
||||
(right - head_extend_x, cy - arm_h), // top side near tip
|
||||
(right, cy), // right tip
|
||||
(right - head_extend_x, cy + arm_h), // bottom side near tip
|
||||
(cx + arm_w, cy + arm_h), // inner bottom of right arm
|
||||
// Down arm with arrowhead
|
||||
(cx + arm_w, cy + arm_h), // shared
|
||||
(cx + arm_w, bottom - head_extend_y), // right side near tip
|
||||
(cx, bottom), // down tip
|
||||
(cx - arm_w, bottom - head_extend_y), // left side near tip
|
||||
(cx - arm_w, cy + arm_h), // inner left of down arm
|
||||
// Left arm with arrowhead
|
||||
(cx - arm_w, cy + arm_h), // shared
|
||||
(left + head_extend_x, cy + arm_h), // bottom side near tip
|
||||
(left, cy), // left tip
|
||||
(left + head_extend_x, cy - arm_h), // top side near tip
|
||||
(cx - arm_w, cy - arm_h), // inner top of left arm (closes)
|
||||
];
|
||||
|
||||
for p in &mut pts {
|
||||
@@ -680,10 +738,10 @@ fn render_shape(layer: &mut Layer, shape: &VectorShape) {
|
||||
let px_fill = [fill_color[0], fill_color[1], fill_color[2], fill_alpha];
|
||||
fill_polygon(layer, &pts, px_fill);
|
||||
}
|
||||
draw_line(layer, pts[0].0, pts[0].1, pts[1].0, pts[1].1, px_color, *stroke, None);
|
||||
draw_line(layer, pts[1].0, pts[1].1, pts[2].0, pts[2].1, px_color, *stroke, None);
|
||||
draw_line(layer, pts[2].0, pts[2].1, pts[3].0, pts[3].1, px_color, *stroke, None);
|
||||
draw_line(layer, pts[3].0, pts[3].1, pts[0].0, pts[0].1, px_color, *stroke, None);
|
||||
for i in 0..pts.len() {
|
||||
let j = (i + 1) % pts.len();
|
||||
draw_line(layer, pts[i].0, pts[i].1, pts[j].0, pts[j].1, px_color, *stroke, None);
|
||||
}
|
||||
}
|
||||
FreePath { pts, stroke, color, fill, fill_color, opacity, .. } => {
|
||||
let alpha = (color[3] as f32 * opacity).round() as u8;
|
||||
|
||||
Reference in New Issue
Block a user