Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
muukii committed Feb 4, 2024
1 parent 774c8ce commit f499d1b
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 49 deletions.
33 changes: 20 additions & 13 deletions Dev/Sources/SwiftUIDemo/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import BrightroomUI
import SwiftUI

struct ContentView: View {
@State private var image: SwiftUI.Image?
@State private var renderedImage: SwiftUI.Image?

@State private var sharedStack = Mocks.makeEditingStack(image: Mocks.imageHorizontal())
@State private var fullScreenView: FullscreenIdentifiableView?
Expand Down Expand Up @@ -34,7 +34,7 @@ struct ContentView: View {
NavigationView {
VStack {
Group {
if let image = image {
if let image = renderedImage {
image
.resizable()
.aspectRatio(contentMode: .fit)
Expand All @@ -49,12 +49,18 @@ struct ContentView: View {

Section {
Button("Component: Crop - keepAlive") {
fullScreenView = .init { DemoCropView(editingStack: sharedStack) }
fullScreenView = .init {
DemoCropView(
editingStack: sharedStack
)
}
}

Button("Component: Crop") {
fullScreenView = .init {
DemoCropView(editingStack: Mocks.makeEditingStack(image: Mocks.imageHorizontal()))
DemoCropView(
editingStack: Mocks.makeEditingStack(image: Mocks.imageHorizontal())
)
}
}
}
Expand All @@ -65,7 +71,8 @@ struct ContentView: View {
SwiftUIPhotosCropView(
editingStack: stackForHorizontal,
onDone: {
self.image = try! stackForHorizontal.makeRenderer().render().swiftUIImage
self.renderedImage = try! stackForHorizontal.makeRenderer().render()
.swiftUIImage
self.fullScreenView = nil
},
onCancel: {}
Expand All @@ -78,7 +85,7 @@ struct ContentView: View {
SwiftUIPhotosCropView(
editingStack: stackForVertical,
onDone: {
self.image = try! stackForVertical.makeRenderer().render().swiftUIImage
self.renderedImage = try! stackForVertical.makeRenderer().render().swiftUIImage
self.fullScreenView = nil
},
onCancel: {}
Expand All @@ -91,7 +98,7 @@ struct ContentView: View {
SwiftUIPhotosCropView(
editingStack: stackForSquare,
onDone: {
self.image = try! stackForSquare.makeRenderer().render().swiftUIImage
self.renderedImage = try! stackForSquare.makeRenderer().render().swiftUIImage
self.fullScreenView = nil
},
onCancel: {}
Expand All @@ -104,7 +111,7 @@ struct ContentView: View {
SwiftUIPhotosCropView(
editingStack: stackForNasa,
onDone: {
self.image = try! stackForNasa.makeRenderer().render().swiftUIImage
self.renderedImage = try! stackForNasa.makeRenderer().render().swiftUIImage
self.fullScreenView = nil
},
onCancel: {}
Expand All @@ -117,7 +124,7 @@ struct ContentView: View {
SwiftUIPhotosCropView(
editingStack: stackForSmall,
onDone: {
self.image = try! stackForSmall.makeRenderer().render().swiftUIImage
self.renderedImage = try! stackForSmall.makeRenderer().render().swiftUIImage
self.fullScreenView = nil
},
onCancel: {}
Expand All @@ -139,7 +146,7 @@ struct ContentView: View {
SwiftUIPhotosCropView(
editingStack: stack,
onDone: {
self.image = try! stack.makeRenderer().render().swiftUIImage
self.renderedImage = try! stack.makeRenderer().render().swiftUIImage
self.fullScreenView = nil
},
onCancel: {}
Expand All @@ -161,7 +168,7 @@ struct ContentView: View {
SwiftUIPhotosCropView(
editingStack: stack,
onDone: {
self.image = try! stack.makeRenderer().render().swiftUIImage
self.renderedImage = try! stack.makeRenderer().render().swiftUIImage
self.fullScreenView = nil
},
onCancel: {}
Expand All @@ -182,7 +189,7 @@ struct ContentView: View {
)
fullScreenView = .init {
PixelEditWrapper(editingStack: stack) {
self.image = try! stackForHorizontal.makeRenderer().render().swiftUIImage
self.renderedImage = try! stackForHorizontal.makeRenderer().render().swiftUIImage
self.fullScreenView = nil
}
}
Expand All @@ -194,7 +201,7 @@ struct ContentView: View {
)
fullScreenView = .init {
PixelEditWrapper(editingStack: stack) {
self.image = try! stackForHorizontal.makeRenderer().render().swiftUIImage
self.renderedImage = try! stackForHorizontal.makeRenderer().render().swiftUIImage
self.fullScreenView = nil
}
}
Expand Down
58 changes: 49 additions & 9 deletions Dev/Sources/SwiftUIDemo/DemoCropView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// Copyright © 2021 muukii. All rights reserved.
//

import BrightroomUI
import BrightroomEngine
import BrightroomUI
import SwiftUI
import UIKit

Expand All @@ -16,7 +16,15 @@ struct DemoCropView: View {
let editingStack: EditingStack

@State var rotation: EditingCrop.Rotation?
@State var adjustmentAngle: EditingCrop.AdjustmentAngle = .zero
@State var adjustmentAngle: EditingCrop.AdjustmentAngle?

@State var resultImage: ResultImage?

init(
editingStack: EditingStack
) {
self.editingStack = editingStack
}

var body: some View {
VStack {
Expand All @@ -35,7 +43,8 @@ struct DemoCropView: View {
Circle()
.foregroundColor(.white)
.frame(width: 50, height: 50, alignment: .center)
})
}
)
)
.rotation(rotation)
.adjustmentAngle(adjustmentAngle)
Expand All @@ -55,27 +64,60 @@ struct DemoCropView: View {
self.rotation = .angle_270
}
Button("- 10") {
self.adjustmentAngle -= .degrees(10)
if self.adjustmentAngle == nil {
self.adjustmentAngle = .zero
}
self.adjustmentAngle! -= .degrees(10)
}
Button("+ 10") {
self.adjustmentAngle += .degrees(10)
if self.adjustmentAngle == nil {
self.adjustmentAngle = .zero
}
self.adjustmentAngle! += .degrees(10)
}
}
}
}
Button("Done") {
let image = try! editingStack.makeRenderer().render().swiftUIImage
print(image)
self.resultImage = .init(image: image)
}
}
.onAppear {
editingStack.start()
}
.sheet(item: $resultImage) {
RenderedResultView(image: $0.image)
}
}
}

struct ResultImage: Identifiable {
let id: String
let image: Image

init(image: Image) {
self.id = UUID().uuidString
self.image = image
}
}

struct RenderedResultView: View {

let image: Image

var body: some View {
image
.resizable()
.aspectRatio(contentMode: .fit)
}

}

#Preview {
DemoCropView(editingStack: Mocks.makeEditingStack(image: Mocks.imageHorizontal()))
DemoCropView(
editingStack: Mocks.makeEditingStack(image: Mocks.imageHorizontal())
)
}

#Preview {
Expand All @@ -91,5 +133,3 @@ struct DemoCropView: View {
print(uiView.frame, uiView.bounds)
}
}


2 changes: 1 addition & 1 deletion Sources/BrightroomEngine/Core/EditingCrop.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public struct EditingCrop: Equatable {
return new
}

private func scaled(_ scale: CGFloat) -> Self {
private consuming func scaled(_ scale: CGFloat) -> Self {

var modified = self

Expand Down
15 changes: 14 additions & 1 deletion Sources/BrightroomEngine/Library/Geometry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ extension CGSize {
}
}

public struct PixelAspectRatio: Hashable {
public struct PixelAspectRatio: Hashable, CustomReflectable {

public static func == (lhs: Self, rhs: Self) -> Bool {
lhs._comparingValue == rhs._comparingValue
Expand Down Expand Up @@ -261,5 +261,18 @@ public struct PixelAspectRatio: Hashable {
.init(width: 1, height: 1)
}

public var customMirror: Mirror {

return Mirror(
self,
children: [
"width": width,
"height": height,
"ratio": _comparingValue
],
displayStyle:.struct
)
}

}

Loading

0 comments on commit f499d1b

Please sign in to comment.