Skip to content

Grid shape & Grid Row and columns gizmos #2921

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@
"files.insertFinalNewline": true,
"files.associations": {
"*.graphite": "json"
}
},
"rust-analyzer.checkOnSave": true
}
8 changes: 8 additions & 0 deletions editor/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ pub const ARC_SNAP_THRESHOLD: f64 = 5.;
pub const ARC_SWEEP_GIZMO_RADIUS: f64 = 14.;
pub const ARC_SWEEP_GIZMO_TEXT_HEIGHT: f64 = 12.;
pub const GIZMO_HIDE_THRESHOLD: f64 = 20.;
pub const GRID_ROW_COLUMN_GIZMO_OFFSET: f64 = 15.;

// SCROLLBARS
pub const SCROLLBAR_SPACING: f64 = 0.1;
Expand All @@ -157,3 +158,10 @@ pub const AUTO_SAVE_TIMEOUT_SECONDS: u64 = 1;

// INPUT
pub const DOUBLE_CLICK_MILLISECONDS: u64 = 500;

// GRID INPUT INDICES
pub const GRID_TYPE_INDEX: usize = 1;
pub const GRID_SPACING_INDEX: usize = 2;
pub const GRID_COLUMNS_INDEX: usize = 3;
pub const GRID_ROW_INDEX: usize = 4;
pub const GRID_ANGLE_INDEX: usize = 5;
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::messages::tool::common_functionality::graph_modification_utils;
use crate::messages::tool::common_functionality::shape_editor::ShapeState;
use crate::messages::tool::common_functionality::shapes::arc_shape::ArcGizmoHandler;
use crate::messages::tool::common_functionality::shapes::circle_shape::CircleGizmoHandler;
use crate::messages::tool::common_functionality::shapes::grid_shape::GridGizmoHandler;
use crate::messages::tool::common_functionality::shapes::polygon_shape::PolygonGizmoHandler;
use crate::messages::tool::common_functionality::shapes::shape_utility::ShapeGizmoHandler;
use crate::messages::tool::common_functionality::shapes::star_shape::StarGizmoHandler;
Expand All @@ -28,6 +29,7 @@ pub enum ShapeGizmoHandlers {
Polygon(PolygonGizmoHandler),
Arc(ArcGizmoHandler),
Circle(CircleGizmoHandler),
Grid(GridGizmoHandler),
}

impl ShapeGizmoHandlers {
Expand All @@ -39,6 +41,7 @@ impl ShapeGizmoHandlers {
Self::Polygon(_) => "polygon",
Self::Arc(_) => "arc",
Self::Circle(_) => "circle",
Self::Grid(_) => "grid",
Self::None => "none",
}
}
Expand All @@ -50,6 +53,7 @@ impl ShapeGizmoHandlers {
Self::Polygon(h) => h.handle_state(layer, mouse_position, document, responses),
Self::Arc(h) => h.handle_state(layer, mouse_position, document, responses),
Self::Circle(h) => h.handle_state(layer, mouse_position, document, responses),
Self::Grid(h) => h.handle_state(layer, mouse_position, document, responses),
Self::None => {}
}
}
Expand All @@ -61,6 +65,7 @@ impl ShapeGizmoHandlers {
Self::Polygon(h) => h.is_any_gizmo_hovered(),
Self::Arc(h) => h.is_any_gizmo_hovered(),
Self::Circle(h) => h.is_any_gizmo_hovered(),
Self::Grid(h) => h.is_any_gizmo_hovered(),
Self::None => false,
}
}
Expand All @@ -72,6 +77,7 @@ impl ShapeGizmoHandlers {
Self::Polygon(h) => h.handle_click(),
Self::Arc(h) => h.handle_click(),
Self::Circle(h) => h.handle_click(),
Self::Grid(h) => h.handle_click(),
Self::None => {}
}
}
Expand All @@ -83,6 +89,7 @@ impl ShapeGizmoHandlers {
Self::Polygon(h) => h.handle_update(drag_start, document, input, responses),
Self::Arc(h) => h.handle_update(drag_start, document, input, responses),
Self::Circle(h) => h.handle_update(drag_start, document, input, responses),
Self::Grid(h) => h.handle_update(drag_start, document, input, responses),
Self::None => {}
}
}
Expand All @@ -94,6 +101,7 @@ impl ShapeGizmoHandlers {
Self::Polygon(h) => h.cleanup(),
Self::Arc(h) => h.cleanup(),
Self::Circle(h) => h.cleanup(),
Self::Grid(h) => h.cleanup(),
Self::None => {}
}
}
Expand All @@ -113,6 +121,7 @@ impl ShapeGizmoHandlers {
Self::Polygon(h) => h.overlays(document, layer, input, shape_editor, mouse_position, overlay_context),
Self::Arc(h) => h.overlays(document, layer, input, shape_editor, mouse_position, overlay_context),
Self::Circle(h) => h.overlays(document, layer, input, shape_editor, mouse_position, overlay_context),
Self::Grid(h) => h.overlays(document, layer, input, shape_editor, mouse_position, overlay_context),
Self::None => {}
}
}
Expand All @@ -131,6 +140,7 @@ impl ShapeGizmoHandlers {
Self::Polygon(h) => h.dragging_overlays(document, input, shape_editor, mouse_position, overlay_context),
Self::Arc(h) => h.dragging_overlays(document, input, shape_editor, mouse_position, overlay_context),
Self::Circle(h) => h.dragging_overlays(document, input, shape_editor, mouse_position, overlay_context),
Self::Grid(h) => h.dragging_overlays(document, input, shape_editor, mouse_position, overlay_context),
Self::None => {}
}
}
Expand All @@ -141,6 +151,7 @@ impl ShapeGizmoHandlers {
Self::Polygon(h) => h.mouse_cursor_icon(),
Self::Arc(h) => h.mouse_cursor_icon(),
Self::Circle(h) => h.mouse_cursor_icon(),
Self::Grid(h) => h.mouse_cursor_icon(),
Self::None => None,
}
}
Expand Down Expand Up @@ -185,6 +196,11 @@ impl GizmoManager {
return Some(ShapeGizmoHandlers::Circle(CircleGizmoHandler::default()));
}

// Grid
if graph_modification_utils::get_grid_id(layer, &document.network_interface).is_some() {
return Some(ShapeGizmoHandlers::Grid(GridGizmoHandler::default()));
}

None
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl RadiusHandle {
let center = viewport.transform_point2(DVec2::ZERO);
if let Some(stroke_width) = get_stroke_width(layer, &document.network_interface) {
let circle_point = calculate_circle_point_position(angle, radius.abs());
let direction = circle_point.normalize();
let Some(direction) = circle_point.try_normalize() else { return false };
let mouse_distance = mouse_position.distance(center);

let spacing = Self::calculate_extra_spacing(viewport, radius, center, stroke_width, 15.);
Expand Down
Loading