Skip to content

Commit b3b4443

Browse files
committed
Fix scale mode issue.
1 parent 1982953 commit b3b4443

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

Shared/Samples/Create and edit geometries/CreateAndEditGeometriesView.swift

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,14 +265,15 @@ class GeometryEditorMenuModel: ObservableObject {
265265
/// A Boolean value indicating if the scale mode is uniform.
266266
@Published var shouldUniformScale = false {
267267
didSet {
268-
let scaleMode: GeometryEditorScaleMode = shouldUniformScale ? .uniform : .stretch
269-
let tool = geometryEditor.tool
270-
(tool as? FreehandTool)?.configuration.scaleMode = scaleMode
271-
(tool as? ShapeTool)?.configuration.scaleMode = scaleMode
272-
(tool as? VertexTool)?.configuration.scaleMode = scaleMode
268+
configureGeometryEditorTool(geometryEditor.tool, scaleMode: scaleMode)
273269
}
274270
}
275271

272+
/// The scale mode to be set on the geometry editor.
273+
private var scaleMode: GeometryEditorScaleMode {
274+
shouldUniformScale ? .uniform : .stretch
275+
}
276+
276277
/// Creates the geometry menu with a geometry editor.
277278
/// - Parameter geometryEditor: The geometry editor that the menu should interact with.
278279
/// - Parameter graphicsOverlay: The graphics overlay that is used to save geometries to.
@@ -334,11 +335,29 @@ class GeometryEditorMenuModel: ObservableObject {
334335
}
335336
}
336337

338+
/// Configures the scale mode for the geometry editor tool.
339+
/// - Parameters:
340+
/// - tool: The geometry editor tool
341+
/// - scaleMode: Preserve the original aspect ratio or scale freely.
342+
func configureGeometryEditorTool(_ tool: GeometryEditorTool, scaleMode: GeometryEditorScaleMode) {
343+
switch tool {
344+
case let tool as FreehandTool:
345+
tool.configuration.scaleMode = scaleMode
346+
case let tool as ShapeTool:
347+
tool.configuration.scaleMode = scaleMode
348+
case let tool as VertexTool:
349+
tool.configuration.scaleMode = scaleMode
350+
default:
351+
fatalError("Unexpected tool type")
352+
}
353+
}
354+
337355
/// Starts editing with the specified tool and geometry type.
338356
/// - Parameters:
339357
/// - tool: The tool to draw with.
340358
/// - geometryType: The type of geometry to draw.
341359
func startEditing(with tool: GeometryEditorTool, geometryType: Geometry.Type) {
360+
configureGeometryEditorTool(tool, scaleMode: scaleMode)
342361
geometryEditor.tool = tool
343362
geometryEditor.start(withType: geometryType)
344363
isStarted = true

0 commit comments

Comments
 (0)