You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
162 lines
5.8 KiB
162 lines
5.8 KiB
//
|
|
// Created by Marco Schmickler on 12.11.21.
|
|
// Copyright (c) 2021 Marco Schmickler. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import SwiftUI
|
|
|
|
protocol EditItemDelegate {
|
|
func captureZoom()
|
|
func setStart()
|
|
func setEnd()
|
|
func cancelEdit()
|
|
func okEdit()
|
|
func seek(_ : Double)
|
|
}
|
|
|
|
struct TagEditor: View {
|
|
@ObservedObject
|
|
var item: MediaItem
|
|
var completionHandler: ((MediaItem) -> Void)?
|
|
var data = DatabaseManager.sharedInstance.allTags[""]!
|
|
|
|
init(item: MediaItem, completionHandler: ((MediaItem) -> Void)? = nil) {
|
|
self.item = item
|
|
self.completionHandler = completionHandler
|
|
data.sort()
|
|
}
|
|
|
|
var body: some View {
|
|
FlexibleView(
|
|
data: data,
|
|
spacing: 15,
|
|
alignment: .leading
|
|
) { tag in
|
|
Button(action: {
|
|
if item.tags.contains(tag) {
|
|
item.tags.removeAll(where: { toRemove in toRemove == tag })
|
|
}
|
|
else {
|
|
item.tags.append(tag)
|
|
}
|
|
if let c = self.completionHandler {
|
|
c(item)
|
|
}
|
|
print(tag)
|
|
}, label: {
|
|
Text(verbatim: tag)
|
|
.padding(8)
|
|
.background(
|
|
RoundedRectangle(cornerRadius: 8)
|
|
.fill( item.tags.contains(tag) ?
|
|
Color.yellow.opacity(0.4) :
|
|
Color.gray.opacity(0.4)
|
|
)
|
|
)
|
|
}).buttonStyle(BorderlessButtonStyle())
|
|
}
|
|
}
|
|
}
|
|
|
|
struct EditItemView: View {
|
|
@ObservedObject
|
|
var item: MediaItem
|
|
|
|
@State
|
|
var scrubber = 0.0
|
|
|
|
var len: Double
|
|
|
|
var delegate: EditItemDelegate
|
|
|
|
var body: some View {
|
|
Form {
|
|
Section(header: Text("K Settings")) {
|
|
VStack() {
|
|
HStack() {
|
|
Slider(value: Binding<Double>(
|
|
get: { scrubber },
|
|
set: {
|
|
scrubber = $0
|
|
delegate.seek($0)
|
|
print ($0)
|
|
}
|
|
), in: item.time...(item.time + item.length))
|
|
|
|
}
|
|
Text("Start \(EditItemView.formatSecondsToString(item.time)) End \(EditItemView.formatSecondsToString(item.time + item.length)) Length \(item.length, specifier: "%.1f")")
|
|
HStack {
|
|
Stepper(value: Binding<Double>(
|
|
get: { item.time },
|
|
set: { s in
|
|
item.time = s
|
|
delegate.seek(item.time)
|
|
}), in: 0...len){
|
|
Button(action: delegate.setStart, label: {
|
|
Text("Start")
|
|
}).buttonStyle(BorderlessButtonStyle());
|
|
}
|
|
Stepper(value:Binding<Double>(
|
|
get: { item.length },
|
|
set: { l in
|
|
item.length = l
|
|
delegate.seek(item.time + item.length)
|
|
}
|
|
), in: 1...500){
|
|
Text("Len")
|
|
}
|
|
Button(action: delegate.setEnd, label: {
|
|
Text("End")
|
|
}).buttonStyle(BorderlessButtonStyle());
|
|
}
|
|
Text("Zoom \(item.scale, specifier: "%.1f") X \(item.offset.x, specifier: "%.1f") Y \(item.offset.y, specifier: "%.1f") ")
|
|
HStack {
|
|
Button(action: delegate.captureZoom, label: {
|
|
Text("Zoom")
|
|
}).padding(5).buttonStyle(BorderlessButtonStyle());
|
|
Button(action: {
|
|
item.scale = 1.0
|
|
item.offset = CGPoint(x: 0,y: 0)
|
|
item.objectWillChange.send()
|
|
}, label: {
|
|
Text("Reset")
|
|
}).padding(5).buttonStyle(BorderlessButtonStyle());
|
|
Stepper(value:$item.rating, in: -1...5){
|
|
Text("*\(item.rating)").frame(width: 25)
|
|
}
|
|
Button(action: {
|
|
delegate.okEdit()
|
|
}, label: {
|
|
Text("ok")
|
|
}).padding(5).buttonStyle(BorderlessButtonStyle());Button(action: {
|
|
delegate.cancelEdit()
|
|
}, label: {
|
|
Text("cancel")
|
|
}).padding(5).buttonStyle(BorderlessButtonStyle());
|
|
}
|
|
TagEditor(item: item)
|
|
|
|
}.background(Color.clear)
|
|
}.background(Color.clear)
|
|
}
|
|
.onAppear {
|
|
UITableView.appearance().backgroundColor = .clear
|
|
}
|
|
.onDisappear {
|
|
UITableView.appearance().backgroundColor = .systemBackground
|
|
}
|
|
.frame(height: 800, alignment: .top)
|
|
//Spacer()
|
|
}
|
|
|
|
static func formatSecondsToString(_ seconds: TimeInterval) -> String {
|
|
if seconds.isNaN {
|
|
return "00:00"
|
|
}
|
|
let min = Int(seconds / 60)
|
|
let sec = seconds.truncatingRemainder(dividingBy: 60)
|
|
return String(format: "%02d:%.1f", min, sec)
|
|
}
|
|
}
|
|
|