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
+5 -1
View File
@@ -21,7 +21,7 @@ public class Tool: NSObject, ObservableObject {
// MARK: - Photo // MARK: - Photo
@Published var selectedPhotoItem: PhotoItem? @Published var selectedPhotoItem: PhotoItem?
@Published var selection: ToolSelection = .none @Published var selection: ToolSelection = .hand
let scrollPublisher = PassthroughSubject<String, Never>() let scrollPublisher = PassthroughSubject<String, Never>()
var markers: [Pen] { var markers: [Pen] {
@@ -32,6 +32,10 @@ public class Tool: NSObject, ObservableObject {
self.object = object self.object = object
} }
func selectTool(_ selection: ToolSelection) {
self.selection = selection
}
func load() { func load() {
DispatchQueue.main.async { [weak self] in DispatchQueue.main.async { [weak self] in
guard let self else { return } guard let self else { return }
+1 -1
View File
@@ -8,7 +8,7 @@
import Foundation import Foundation
enum ToolSelection: Equatable { enum ToolSelection: Equatable {
case none case hand
case pen case pen
case photo case photo
} }
@@ -335,7 +335,7 @@ extension CanvasViewController {
let enablesDrawing: Bool let enablesDrawing: Bool
let enablesPhotoInsertion: Bool let enablesPhotoInsertion: Bool
switch selection { switch selection {
case .none: case .hand:
enablesScrolling = true enablesScrolling = true
enablesDrawing = false enablesDrawing = false
enablesPhotoInsertion = false enablesPhotoInsertion = false
+15 -2
View File
@@ -133,7 +133,20 @@ struct Toolbar: View {
HStack(spacing: 0) { HStack(spacing: 0) {
Button { Button {
withAnimation { 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: { } label: {
Image(systemName: "pencil") Image(systemName: "pencil")
@@ -148,7 +161,7 @@ struct Toolbar: View {
HStack(spacing: 0) { HStack(spacing: 0) {
Button { Button {
withAnimation { withAnimation {
tool.selection = tool.selection == .photo ? .none : .photo tool.selectTool(.photo)
} }
} label: { } label: {
Image(systemName: "photo") Image(systemName: "photo")