Skip to content

Commit d894936

Browse files
committed
Remove non vertex tools.
1 parent e2a262c commit d894936

File tree

2 files changed

+26
-82
lines changed

2 files changed

+26
-82
lines changed

Shared/Samples/Snap geometry edits/SnapGeometryEditsView.GeometryEditorMenu.swift

Lines changed: 7 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,6 @@ extension SnapGeometryEditsView {
2727
/// The current geometry of the geometry editor.
2828
@State private var geometry: Geometry?
2929

30-
/// The geometry editor tool used to edit geometries for the most optimal
31-
/// snapping experience based on the device type.
32-
private var adaptiveVertexTool: GeometryEditorTool {
33-
#if targetEnvironment(macCatalyst)
34-
VertexTool()
35-
#else
36-
ReticleVertexTool()
37-
#endif
38-
}
39-
4030
/// A Boolean value indicating if the geometry editor can perform an undo.
4131
private var canUndo: Bool {
4232
return model.geometryEditor.canUndo
@@ -96,61 +86,19 @@ extension SnapGeometryEditsView {
9686
private var mainMenuContent: some View {
9787
VStack {
9888
Button("New Point", systemImage: "smallcircle.filled.circle") {
99-
model.startEditing(with: adaptiveVertexTool, geometryType: Point.self)
89+
model.startEditing(withType: Point.self)
10090
}
10191

10292
Button("New Line", systemImage: "line.diagonal") {
103-
model.startEditing(with: adaptiveVertexTool, geometryType: Polyline.self)
93+
model.startEditing(withType: Polyline.self)
10494
}
10595

10696
Button("New Area", systemImage: "skew") {
107-
model.startEditing(with: adaptiveVertexTool, geometryType: Polygon.self)
97+
model.startEditing(withType: Polygon.self)
10898
}
10999

110100
Button("New Multipoint", systemImage: "hand.point.up.braille") {
111-
model.startEditing(with: adaptiveVertexTool, geometryType: Multipoint.self)
112-
}
113-
114-
Button("New Freehand Line", systemImage: "scribble") {
115-
model.startEditing(with: FreehandTool(), geometryType: Polyline.self)
116-
}
117-
118-
Button("New Freehand Area", systemImage: "lasso") {
119-
model.startEditing(with: FreehandTool(), geometryType: Polygon.self)
120-
}
121-
122-
Menu("Shapes") {
123-
Button("New Line Arrow", systemImage: "arrowshape.right") {
124-
model.startEditing(with: ShapeTool(kind: .arrow), geometryType: Polyline.self)
125-
}
126-
127-
Button("New Polygon Arrow", systemImage: "arrowshape.right.fill") {
128-
model.startEditing(with: ShapeTool(kind: .arrow), geometryType: Polygon.self)
129-
}
130-
131-
Button("New Line Rectangle", systemImage: "rectangle") {
132-
model.startEditing(with: ShapeTool(kind: .rectangle), geometryType: Polyline.self)
133-
}
134-
135-
Button("New Polygon Rectangle", systemImage: "rectangle.fill") {
136-
model.startEditing(with: ShapeTool(kind: .rectangle), geometryType: Polygon.self)
137-
}
138-
139-
Button("New Line Ellipse", systemImage: "circle") {
140-
model.startEditing(with: ShapeTool(kind: .ellipse), geometryType: Polyline.self)
141-
}
142-
143-
Button("New Polygon Ellipse", systemImage: "circle.fill") {
144-
model.startEditing(with: ShapeTool(kind: .ellipse), geometryType: Polygon.self)
145-
}
146-
147-
Button("New Line Triangle", systemImage: "triangle") {
148-
model.startEditing(with: ShapeTool(kind: .triangle), geometryType: Polyline.self)
149-
}
150-
151-
Button("New Polygon Triangle", systemImage: "triangle.fill") {
152-
model.startEditing(with: ShapeTool(kind: .triangle), geometryType: Polygon.self)
153-
}
101+
model.startEditing(withType: Multipoint.self)
154102
}
155103

156104
Divider()
@@ -180,7 +128,9 @@ extension SnapGeometryEditsView {
180128
}
181129
.disabled(deleteButtonIsDisabled)
182130

183-
Toggle("Uniform Scale", isOn: $model.isUniformScale)
131+
if model.adaptiveVertexTool is VertexTool {
132+
Toggle("Uniform Scale", isOn: $model.isUniformScale)
133+
}
184134

185135
Button("Clear Current Sketch", systemImage: "trash", role: .destructive) {
186136
model.geometryEditor.clearGeometry()

Shared/Samples/Snap geometry edits/SnapGeometryEditsView.GeometryEditorModel.swift

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ extension SnapGeometryEditsView {
2727
return geometryEditor
2828
}()
2929

30+
/// The geometry editor tool used to edit geometries for the most optimal
31+
/// snapping experience based on the device type.
32+
let adaptiveVertexTool: GeometryEditorTool = {
33+
#if targetEnvironment(macCatalyst)
34+
VertexTool()
35+
#else
36+
ReticleVertexTool()
37+
#endif
38+
}()
39+
3040
/// The graphics overlay used to save geometries to.
3141
let geometryOverlay: GraphicsOverlay = {
3242
let overlay = GraphicsOverlay(renderingMode: .dynamic)
@@ -43,7 +53,9 @@ extension SnapGeometryEditsView {
4353
/// A Boolean value indicating if the scale mode is uniform.
4454
@Published var isUniformScale = false {
4555
didSet {
46-
configureGeometryEditorTool(geometryEditor.tool, scaleMode: scaleMode)
56+
if let vertexTool = adaptiveVertexTool as? VertexTool {
57+
vertexTool.configuration.scaleMode = scaleMode
58+
}
4759
}
4860
}
4961

@@ -52,6 +64,10 @@ extension SnapGeometryEditsView {
5264
isUniformScale ? .uniform : .stretch
5365
}
5466

67+
init() {
68+
geometryEditor.tool = adaptiveVertexTool
69+
}
70+
5571
/// Saves the current geometry to the graphics overlay and stops editing.
5672
/// - Precondition: Geometry's sketch must be valid.
5773
func save() {
@@ -94,32 +110,10 @@ extension SnapGeometryEditsView {
94110
}
95111
}
96112

97-
/// Configures the scale mode for the geometry editor tool.
98-
/// - Parameters:
99-
/// - tool: The geometry editor tool.
100-
/// - scaleMode: Preserve the original aspect ratio or scale freely.
101-
private func configureGeometryEditorTool(_ tool: GeometryEditorTool, scaleMode: GeometryEditorScaleMode) {
102-
switch tool {
103-
case let tool as FreehandTool:
104-
tool.configuration.scaleMode = scaleMode
105-
case let tool as ShapeTool:
106-
tool.configuration.scaleMode = scaleMode
107-
case let tool as VertexTool:
108-
tool.configuration.scaleMode = scaleMode
109-
case _ as ReticleVertexTool:
110-
break
111-
default:
112-
fatalError("Unexpected tool type")
113-
}
114-
}
115-
116-
/// Starts editing with the specified tool and geometry type.
113+
/// Starts editing with the specified geometry type.
117114
/// - Parameters:
118-
/// - tool: The tool to draw with.
119115
/// - geometryType: The type of geometry to draw.
120-
func startEditing(with tool: GeometryEditorTool, geometryType: Geometry.Type) {
121-
configureGeometryEditorTool(tool, scaleMode: scaleMode)
122-
geometryEditor.tool = tool
116+
func startEditing(withType geometryType: Geometry.Type) {
123117
geometryEditor.start(withType: geometryType)
124118
isStarted = true
125119
}

0 commit comments

Comments
 (0)