diff --git a/Shared/Models/CustomIcon.swift b/Shared/Models/CustomIcon.swift index 69218cf..6aac96f 100644 --- a/Shared/Models/CustomIcon.swift +++ b/Shared/Models/CustomIcon.swift @@ -9,11 +9,24 @@ import SwiftUI class CustomIcon: ObservableObject { static let numberOfBGItems = 99 - - init(leftEye: Image, - rightEye: Image, - mouth: Image, - background: [(Image, UUID)], + + static let defaultCustomIcon = CustomIcon(leftEye: EyeOptions.defaultOption, + rightEye: EyeOptions.defaultOption, + mouth: MouthOptions.defaultOption, + background: IconView_Previews.backgrounds, + bgColor: .red, + innerColor: .green, + bgOverlayColor: .orange, + rightEyeColor: .orange, + leftEyeColor: .yellow, + mouthColor: .green, + circleStrokeColor: .pink) + + + init(leftEye: EyeOptions, + rightEye: EyeOptions, + mouth: MouthOptions, + background: [(BackGroundOptions, UUID)], bgColor: Color, innerColor: Color, bgOverlayColor: Color, @@ -35,11 +48,11 @@ class CustomIcon: ObservableObject { self.circleStrokeColor = circleStrokeColor } - @Published var leftEye: Image - @Published var rightEye: Image - @Published var mouth: Image + @Published var leftEye: EyeOptions + @Published var rightEye: EyeOptions + @Published var mouth: MouthOptions - @Published var background: [(Image, UUID)] + @Published var background: [(BackGroundOptions, UUID)] @Published var bgColor: Color @Published var innerColor: Color @Published var bgOverlayColor: Color @@ -51,7 +64,7 @@ class CustomIcon: ObservableObject { @Published var circleStrokeColor: Color } -enum BackGroundOptions: String, CaseIterable { +enum BackGroundOptions: String, CaseIterable, Codable { case horrible case bad case average @@ -62,14 +75,22 @@ enum BackGroundOptions: String, CaseIterable { static var selectable: [BackGroundOptions] { return [.great, .good, .average, .bad, .horrible] } + + static public var defaultOption: BackGroundOptions { + BackGroundOptions.random + } + + public var image: Image { + return Image(self.rawValue, bundle: .main) + } } -enum Eyes { +enum Eyes: String, Codable { case left case right } -enum EyeOptions: String, CaseIterable { +enum EyeOptions: String, CaseIterable, Codable { case fire = "fire" case bolt = "bolt2" case dollar = "dollar" @@ -88,13 +109,16 @@ enum EyeOptions: String, CaseIterable { case skull2 = "skull2" case poo = "poo" - static public var defaultOption: Image { - let image = Image(EyeOptions.fire.rawValue, bundle: .main) - return image + static public var defaultOption: EyeOptions { + EyeOptions.fire + } + + public var image: Image { + return Image(self.rawValue, bundle: .main) } } -enum MouthOptions: String, CaseIterable { +enum MouthOptions: String, CaseIterable, Codable { case fire = "fire" case bolt = "bolt2" case dollar = "dollar" @@ -113,8 +137,11 @@ enum MouthOptions: String, CaseIterable { case skull2 = "skull2" case poo = "poo" - static public var defaultOption: Image { - let image = Image(MouthOptions.bomb.rawValue, bundle: .main) - return image + static public var defaultOption: MouthOptions { + MouthOptions.bomb + } + + public var image: Image { + return Image(self.rawValue, bundle: .main) } } diff --git a/Shared/views/CreateIconView.swift b/Shared/views/CreateIconView.swift index f440877..cbd93e3 100644 --- a/Shared/views/CreateIconView.swift +++ b/Shared/views/CreateIconView.swift @@ -12,16 +12,15 @@ struct CreateIconView: View { @AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system - static var iconViewBGs: [(Image, UUID)] = { - var blah = [(Image, UUID)]() + static var iconViewBGs: [(BackGroundOptions, UUID)] = { + var blah = [(BackGroundOptions, UUID)]() for _ in 0...99 { - let image = Image(BackGroundOptions.selectable.randomElement()!.rawValue, bundle: .main) - blah.append((image, UUID())) + blah.append((BackGroundOptions.selectable.randomElement()!, UUID())) } return blah }() - @State private var mouth: Image = MouthOptions.defaultOption + @State private var mouth: MouthOptions = MouthOptions.defaultOption @StateObject private var customIcon = CustomIcon(leftEye: EyeOptions.defaultOption, rightEye: EyeOptions.defaultOption, mouth: MouthOptions.defaultOption, @@ -49,12 +48,11 @@ struct CreateIconView: View { ] func update(eye: Eyes, eyeOption: EyeOptions) { - let image = Image(eyeOption.rawValue, bundle: .main) switch eye { case .left: - customIcon.leftEye = image + customIcon.leftEye = eyeOption case .right: - customIcon.rightEye = image + customIcon.rightEye = eyeOption } } @@ -75,8 +73,7 @@ struct CreateIconView: View { } func update(mouthOption: MouthOptions) { - let image = Image(mouthOption.rawValue, bundle: .main) - customIcon.mouth = image + customIcon.mouth = mouthOption } func update(background: BackGroundOptions) { @@ -84,14 +81,12 @@ struct CreateIconView: View { if background == .random { for _ in 0...CustomIcon.numberOfBGItems { - let image = Image(BackGroundOptions.selectable.randomElement()!.rawValue, bundle: .main) - customIcon.background.append((image, UUID())) + customIcon.background.append((BackGroundOptions.selectable.randomElement()!, UUID())) } return } - let image = Image(background.rawValue, bundle: .main) for _ in 0...CustomIcon.numberOfBGItems { - customIcon.background.append((image, UUID())) + customIcon.background.append((background, UUID())) } } diff --git a/Shared/views/IconView.swift b/Shared/views/IconView.swift index 36b0f37..25fa761 100644 --- a/Shared/views/IconView.swift +++ b/Shared/views/IconView.swift @@ -57,8 +57,8 @@ struct IconView: View { .frame(maxWidth: .infinity, maxHeight: .infinity) LazyVGrid(columns: columns, alignment: .leading, spacing: 0) { - ForEach(customIcon.background, id: \.self.1) { (image, uuid) in - image + ForEach(customIcon.background, id: \.self.1) { (bgOption, uuid) in + bgOption.image .resizable() .aspectRatio(1, contentMode: .fill) .foregroundColor(customIcon.bgOverlayColor) @@ -68,7 +68,7 @@ struct IconView: View { .background( .clear ) - + Circle() .strokeBorder(customIcon.circleStrokeColor, lineWidth: geo.size.width * 0.045) .background(Circle().fill(customIcon.innerColor)) @@ -76,8 +76,8 @@ struct IconView: View { height: geo.size.height*facePercSize, alignment: .center) .position(x: geo.size.width/2, y: geo.size.height/2) - - customIcon.leftEye + + customIcon.leftEye.image .resizable() .aspectRatio(contentMode: .fit) .frame(width: geo.size.width*0.12, @@ -86,8 +86,8 @@ struct IconView: View { .position(x: geo.size.width*0.4, y: geo.size.height*0.4) .foregroundColor(customIcon.leftEyeColor) - - customIcon.rightEye + + customIcon.rightEye.image .resizable() .aspectRatio(contentMode: .fit) .frame(width: geo.size.width*0.12, @@ -96,8 +96,8 @@ struct IconView: View { .position(x: geo.size.width*0.6, y: geo.size.height*0.4) .foregroundColor(customIcon.rightEyeColor) - - customIcon.mouth + + customIcon.mouth.image .resizable() .aspectRatio(contentMode: .fit) .frame(width: geo.size.width*0.12, @@ -114,27 +114,16 @@ struct IconView: View { } struct IconView_Previews: PreviewProvider { - static var backgrounds: [(Image, UUID)] = { - var blah = [(Image, UUID)]() + static var backgrounds: [(BackGroundOptions, UUID)] = { + var blah = [(BackGroundOptions, UUID)]() for _ in 0...CustomIcon.numberOfBGItems { - let image = Image(BackGroundOptions.selectable.randomElement()!.rawValue, bundle: .main) - blah.append((image, UUID())) + blah.append((BackGroundOptions.selectable.randomElement()!, UUID())) } return blah }() static var previews: some View { - IconView(customIcon: CustomIcon(leftEye: EyeOptions.defaultOption, - rightEye: EyeOptions.defaultOption, - mouth: MouthOptions.defaultOption, - background: IconView_Previews.backgrounds, - bgColor: .red, - innerColor: .green, - bgOverlayColor: .orange, - rightEyeColor: .orange, - leftEyeColor: .yellow, - mouthColor: .green, - circleStrokeColor: .pink), + IconView(customIcon: CustomIcon.defaultCustomIcon, isPreview: true) .frame(width: 256, height: 256, alignment: .center) diff --git a/Shared/views/SmallRollUpHeaderView.swift b/Shared/views/SmallRollUpHeaderView.swift index d07a4b5..23e4cce 100644 --- a/Shared/views/SmallRollUpHeaderView.swift +++ b/Shared/views/SmallRollUpHeaderView.swift @@ -76,14 +76,15 @@ struct SmallRollUpHeaderView: View { .frame(width: 50, height: 50) textView(forModel: model) - .font(.title) + .font(.title3) .fontWeight(.bold) + .frame(width: 40, height: 40) .scaledToFill() .minimumScaleFactor(0.5) .lineLimit(1) .foregroundColor(Color(UIColor.white)) } - .frame(maxWidth: .infinity, alignment: .center) + .padding([.leading, .trailing], 5) } } }