Consolidate images and files
This commit is contained in:
@ -1,49 +0,0 @@
|
||||
import SwiftUI
|
||||
|
||||
struct FlexibleColumnView<Content, Inner>: View where Content: Identifiable, Inner: View {
|
||||
|
||||
@Binding
|
||||
var items: [Content]
|
||||
|
||||
let maximumItemWidth: CGFloat
|
||||
|
||||
let spacing: CGFloat
|
||||
|
||||
private let content: (_ item: Content, _ width: CGFloat) -> Inner
|
||||
|
||||
init(items: Binding<[Content]>, maximumItemWidth: CGFloat = 300, spacing: CGFloat = 20, content: @escaping (_ item: Content, _ width: CGFloat) -> Inner) {
|
||||
self._items = items
|
||||
self.maximumItemWidth = maximumItemWidth
|
||||
self.spacing = spacing
|
||||
self.content = content
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
GeometryReader { geometry in
|
||||
let totalWidth = geometry.size.width
|
||||
let columnCount = max(Int((totalWidth + spacing) / (maximumItemWidth + spacing)), 1)
|
||||
let totalSpacing = spacing * CGFloat(columnCount + 1)
|
||||
let trueItemWidth = (totalWidth - totalSpacing) / CGFloat(columnCount)
|
||||
|
||||
let columns = Array(repeating: GridItem(.flexible(), spacing: spacing), count: columnCount)
|
||||
|
||||
ScrollView {
|
||||
LazyVGrid(columns: columns, spacing: spacing) {
|
||||
ForEach(items) { item in
|
||||
content(item, trueItemWidth)
|
||||
}
|
||||
}
|
||||
.padding(spacing)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
FlexibleColumnView(items: .constant(MockImage.images), maximumItemWidth: 150) { image, width in
|
||||
image.imageToDisplay
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(width: width)
|
||||
}
|
||||
}
|
26
CHDataManagement/Views/Images/ImageContentView.swift
Normal file
26
CHDataManagement/Views/Images/ImageContentView.swift
Normal file
@ -0,0 +1,26 @@
|
||||
import SwiftUI
|
||||
|
||||
struct ImageContentView: View {
|
||||
|
||||
@ObservedObject
|
||||
var image: FileResource
|
||||
|
||||
var body: some View {
|
||||
image.imageToDisplay
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
}
|
||||
}
|
||||
|
||||
extension ImageContentView: MainContentView {
|
||||
|
||||
init(item: FileResource) {
|
||||
self.image = item
|
||||
}
|
||||
|
||||
static let itemDescription = "an image"
|
||||
}
|
||||
|
||||
#Preview {
|
||||
ImageContentView(image: .init(resourceImage: "image1", type: .jpg))
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
import SwiftUI
|
||||
|
||||
struct ImageDetailsView: View {
|
||||
|
||||
@Environment(\.language)
|
||||
var language
|
||||
|
||||
@ObservedObject
|
||||
var image: ImageResource
|
||||
|
||||
@State
|
||||
private var newId: String
|
||||
|
||||
init(image: ImageResource) {
|
||||
self.image = image
|
||||
self.newId = image.id
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading) {
|
||||
Text("Unique identifier")
|
||||
.font(.headline)
|
||||
HStack {
|
||||
TextField("", text: $newId)
|
||||
Button(action: setNewId) {
|
||||
Text("Update")
|
||||
}
|
||||
}
|
||||
Text("German Description")
|
||||
.font(.headline)
|
||||
TextField("", text: $image.germanDescription)
|
||||
Text("English Description")
|
||||
.font(.headline)
|
||||
TextField("", text: $image.englishDescription)
|
||||
Text("Info")
|
||||
.font(.headline)
|
||||
HStack(alignment: .top) {
|
||||
VStack(alignment: .leading) {
|
||||
Text("Original Size")
|
||||
Text("Aspect ratio")
|
||||
}
|
||||
VStack(alignment: .trailing) {
|
||||
Text("\(Int(image.size.width)) x \(Int(image.size.height))")
|
||||
Text("\(image.aspectRatio)")
|
||||
}
|
||||
}.padding(.vertical)
|
||||
Text("Versions")
|
||||
.font(.headline)
|
||||
Spacer()
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
|
||||
private func setNewId() {
|
||||
#warning("Check if ID is unique")
|
||||
// TODO: Clean id
|
||||
image.id = newId
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
ImageDetailsView(image: MockImage.images.first!)
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
import SwiftUI
|
||||
|
||||
struct ImagesContentView: View {
|
||||
|
||||
@ObservedObject
|
||||
var image: ImageResource
|
||||
|
||||
var body: some View {
|
||||
image.imageToDisplay
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
ImagesContentView(image: .init(resourceName: "image1", type: .jpg))
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
import SwiftUI
|
||||
import SFSafeSymbols
|
||||
|
||||
struct ImagesView: View {
|
||||
|
||||
@EnvironmentObject
|
||||
var content: Content
|
||||
|
||||
let maximumItemWidth: CGFloat = 300
|
||||
|
||||
let aspectRatio: CGFloat = 1.5
|
||||
|
||||
let spacing: CGFloat = 20
|
||||
|
||||
@State
|
||||
private var selectedImage: ImageResource?
|
||||
|
||||
@State
|
||||
private var showImageDetails = false
|
||||
|
||||
var body: some View {
|
||||
NavigationSplitView {
|
||||
List(content.images, selection: $selectedImage) { image in
|
||||
Text(image.id)
|
||||
.tag(image)
|
||||
}
|
||||
} content: {
|
||||
if let selectedImage {
|
||||
ImagesContentView(image: selectedImage)
|
||||
.layoutPriority(1)
|
||||
} else {
|
||||
Text("Select an image in the sidebar")
|
||||
}
|
||||
} detail: {
|
||||
if let selectedImage {
|
||||
ImageDetailsView(image: selectedImage)
|
||||
.frame(maxWidth: 350)
|
||||
} else {
|
||||
EmptyView()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
let content = Content()
|
||||
content.images = MockImage.images
|
||||
return ImagesView()
|
||||
.environmentObject(content)
|
||||
}
|
Reference in New Issue
Block a user