feat: add hand button in element tool bar

This commit is contained in:
dscyrescotti
2024-06-24 20:16:02 +07:00
parent 7946253b60
commit bd1196ec41
4 changed files with 22 additions and 5 deletions

View File

@@ -21,7 +21,7 @@ public class Tool: NSObject, ObservableObject {
// MARK: - Photo
@Published var selectedPhotoItem: PhotoItem?
@Published var selection: ToolSelection = .none
@Published var selection: ToolSelection = .hand
let scrollPublisher = PassthroughSubject<String, Never>()
var markers: [Pen] {
@@ -32,6 +32,10 @@ public class Tool: NSObject, ObservableObject {
self.object = object
}
func selectTool(_ selection: ToolSelection) {
self.selection = selection
}
func load() {
DispatchQueue.main.async { [weak self] in
guard let self else { return }

View File

@@ -8,7 +8,7 @@
import Foundation
enum ToolSelection: Equatable {
case none
case hand
case pen
case photo
}

View File

@@ -335,7 +335,7 @@ extension CanvasViewController {
let enablesDrawing: Bool
let enablesPhotoInsertion: Bool
switch selection {
case .none:
case .hand:
enablesScrolling = true
enablesDrawing = false
enablesPhotoInsertion = false

View File

@@ -133,7 +133,20 @@ struct Toolbar: View {
HStack(spacing: 0) {
Button {
withAnimation {
tool.selection = tool.selection == .pen ? .none : .pen
tool.selectTool(.hand)
}
} label: {
Image(systemName: "hand.draw.fill")
.fontWeight(.heavy)
.contentShape(.circle)
.frame(width: size, height: size)
.background(tool.selection == .hand ? Color.accentColor : Color.clear)
.foregroundStyle(tool.selection == .hand ? Color.white : Color.accentColor)
.clipShape(.rect(cornerRadius: 8))
}
Button {
withAnimation {
tool.selectTool(.pen)
}
} label: {
Image(systemName: "pencil")
@@ -148,7 +161,7 @@ struct Toolbar: View {
HStack(spacing: 0) {
Button {
withAnimation {
tool.selection = tool.selection == .photo ? .none : .photo
tool.selectTool(.photo)
}
} label: {
Image(systemName: "photo")