re-do the way a custom icon is generated / stored

fix small roll up header text going outside of circle view
This commit is contained in:
Trey t
2022-02-14 17:02:56 -06:00
parent 0ca2e9b1be
commit fce13af84e
4 changed files with 71 additions and 59 deletions

View File

@@ -9,11 +9,24 @@ import SwiftUI
class CustomIcon: ObservableObject { class CustomIcon: ObservableObject {
static let numberOfBGItems = 99 static let numberOfBGItems = 99
init(leftEye: Image, static let defaultCustomIcon = CustomIcon(leftEye: EyeOptions.defaultOption,
rightEye: Image, rightEye: EyeOptions.defaultOption,
mouth: Image, mouth: MouthOptions.defaultOption,
background: [(Image, UUID)], 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, bgColor: Color,
innerColor: Color, innerColor: Color,
bgOverlayColor: Color, bgOverlayColor: Color,
@@ -35,11 +48,11 @@ class CustomIcon: ObservableObject {
self.circleStrokeColor = circleStrokeColor self.circleStrokeColor = circleStrokeColor
} }
@Published var leftEye: Image @Published var leftEye: EyeOptions
@Published var rightEye: Image @Published var rightEye: EyeOptions
@Published var mouth: Image @Published var mouth: MouthOptions
@Published var background: [(Image, UUID)] @Published var background: [(BackGroundOptions, UUID)]
@Published var bgColor: Color @Published var bgColor: Color
@Published var innerColor: Color @Published var innerColor: Color
@Published var bgOverlayColor: Color @Published var bgOverlayColor: Color
@@ -51,7 +64,7 @@ class CustomIcon: ObservableObject {
@Published var circleStrokeColor: Color @Published var circleStrokeColor: Color
} }
enum BackGroundOptions: String, CaseIterable { enum BackGroundOptions: String, CaseIterable, Codable {
case horrible case horrible
case bad case bad
case average case average
@@ -62,14 +75,22 @@ enum BackGroundOptions: String, CaseIterable {
static var selectable: [BackGroundOptions] { static var selectable: [BackGroundOptions] {
return [.great, .good, .average, .bad, .horrible] 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 left
case right case right
} }
enum EyeOptions: String, CaseIterable { enum EyeOptions: String, CaseIterable, Codable {
case fire = "fire" case fire = "fire"
case bolt = "bolt2" case bolt = "bolt2"
case dollar = "dollar" case dollar = "dollar"
@@ -88,13 +109,16 @@ enum EyeOptions: String, CaseIterable {
case skull2 = "skull2" case skull2 = "skull2"
case poo = "poo" case poo = "poo"
static public var defaultOption: Image { static public var defaultOption: EyeOptions {
let image = Image(EyeOptions.fire.rawValue, bundle: .main) EyeOptions.fire
return image }
public var image: Image {
return Image(self.rawValue, bundle: .main)
} }
} }
enum MouthOptions: String, CaseIterable { enum MouthOptions: String, CaseIterable, Codable {
case fire = "fire" case fire = "fire"
case bolt = "bolt2" case bolt = "bolt2"
case dollar = "dollar" case dollar = "dollar"
@@ -113,8 +137,11 @@ enum MouthOptions: String, CaseIterable {
case skull2 = "skull2" case skull2 = "skull2"
case poo = "poo" case poo = "poo"
static public var defaultOption: Image { static public var defaultOption: MouthOptions {
let image = Image(MouthOptions.bomb.rawValue, bundle: .main) MouthOptions.bomb
return image }
public var image: Image {
return Image(self.rawValue, bundle: .main)
} }
} }

View File

@@ -12,16 +12,15 @@ struct CreateIconView: View {
@AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system @AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system
static var iconViewBGs: [(Image, UUID)] = { static var iconViewBGs: [(BackGroundOptions, UUID)] = {
var blah = [(Image, UUID)]() var blah = [(BackGroundOptions, UUID)]()
for _ in 0...99 { for _ in 0...99 {
let image = Image(BackGroundOptions.selectable.randomElement()!.rawValue, bundle: .main) blah.append((BackGroundOptions.selectable.randomElement()!, UUID()))
blah.append((image, UUID()))
} }
return blah return blah
}() }()
@State private var mouth: Image = MouthOptions.defaultOption @State private var mouth: MouthOptions = MouthOptions.defaultOption
@StateObject private var customIcon = CustomIcon(leftEye: EyeOptions.defaultOption, @StateObject private var customIcon = CustomIcon(leftEye: EyeOptions.defaultOption,
rightEye: EyeOptions.defaultOption, rightEye: EyeOptions.defaultOption,
mouth: MouthOptions.defaultOption, mouth: MouthOptions.defaultOption,
@@ -49,12 +48,11 @@ struct CreateIconView: View {
] ]
func update(eye: Eyes, eyeOption: EyeOptions) { func update(eye: Eyes, eyeOption: EyeOptions) {
let image = Image(eyeOption.rawValue, bundle: .main)
switch eye { switch eye {
case .left: case .left:
customIcon.leftEye = image customIcon.leftEye = eyeOption
case .right: case .right:
customIcon.rightEye = image customIcon.rightEye = eyeOption
} }
} }
@@ -75,8 +73,7 @@ struct CreateIconView: View {
} }
func update(mouthOption: MouthOptions) { func update(mouthOption: MouthOptions) {
let image = Image(mouthOption.rawValue, bundle: .main) customIcon.mouth = mouthOption
customIcon.mouth = image
} }
func update(background: BackGroundOptions) { func update(background: BackGroundOptions) {
@@ -84,14 +81,12 @@ struct CreateIconView: View {
if background == .random { if background == .random {
for _ in 0...CustomIcon.numberOfBGItems { for _ in 0...CustomIcon.numberOfBGItems {
let image = Image(BackGroundOptions.selectable.randomElement()!.rawValue, bundle: .main) customIcon.background.append((BackGroundOptions.selectable.randomElement()!, UUID()))
customIcon.background.append((image, UUID()))
} }
return return
} }
let image = Image(background.rawValue, bundle: .main)
for _ in 0...CustomIcon.numberOfBGItems { for _ in 0...CustomIcon.numberOfBGItems {
customIcon.background.append((image, UUID())) customIcon.background.append((background, UUID()))
} }
} }

View File

@@ -57,8 +57,8 @@ struct IconView: View {
.frame(maxWidth: .infinity, maxHeight: .infinity) .frame(maxWidth: .infinity, maxHeight: .infinity)
LazyVGrid(columns: columns, alignment: .leading, spacing: 0) { LazyVGrid(columns: columns, alignment: .leading, spacing: 0) {
ForEach(customIcon.background, id: \.self.1) { (image, uuid) in ForEach(customIcon.background, id: \.self.1) { (bgOption, uuid) in
image bgOption.image
.resizable() .resizable()
.aspectRatio(1, contentMode: .fill) .aspectRatio(1, contentMode: .fill)
.foregroundColor(customIcon.bgOverlayColor) .foregroundColor(customIcon.bgOverlayColor)
@@ -68,7 +68,7 @@ struct IconView: View {
.background( .background(
.clear .clear
) )
Circle() Circle()
.strokeBorder(customIcon.circleStrokeColor, lineWidth: geo.size.width * 0.045) .strokeBorder(customIcon.circleStrokeColor, lineWidth: geo.size.width * 0.045)
.background(Circle().fill(customIcon.innerColor)) .background(Circle().fill(customIcon.innerColor))
@@ -76,8 +76,8 @@ struct IconView: View {
height: geo.size.height*facePercSize, height: geo.size.height*facePercSize,
alignment: .center) alignment: .center)
.position(x: geo.size.width/2, y: geo.size.height/2) .position(x: geo.size.width/2, y: geo.size.height/2)
customIcon.leftEye customIcon.leftEye.image
.resizable() .resizable()
.aspectRatio(contentMode: .fit) .aspectRatio(contentMode: .fit)
.frame(width: geo.size.width*0.12, .frame(width: geo.size.width*0.12,
@@ -86,8 +86,8 @@ struct IconView: View {
.position(x: geo.size.width*0.4, .position(x: geo.size.width*0.4,
y: geo.size.height*0.4) y: geo.size.height*0.4)
.foregroundColor(customIcon.leftEyeColor) .foregroundColor(customIcon.leftEyeColor)
customIcon.rightEye customIcon.rightEye.image
.resizable() .resizable()
.aspectRatio(contentMode: .fit) .aspectRatio(contentMode: .fit)
.frame(width: geo.size.width*0.12, .frame(width: geo.size.width*0.12,
@@ -96,8 +96,8 @@ struct IconView: View {
.position(x: geo.size.width*0.6, .position(x: geo.size.width*0.6,
y: geo.size.height*0.4) y: geo.size.height*0.4)
.foregroundColor(customIcon.rightEyeColor) .foregroundColor(customIcon.rightEyeColor)
customIcon.mouth customIcon.mouth.image
.resizable() .resizable()
.aspectRatio(contentMode: .fit) .aspectRatio(contentMode: .fit)
.frame(width: geo.size.width*0.12, .frame(width: geo.size.width*0.12,
@@ -114,27 +114,16 @@ struct IconView: View {
} }
struct IconView_Previews: PreviewProvider { struct IconView_Previews: PreviewProvider {
static var backgrounds: [(Image, UUID)] = { static var backgrounds: [(BackGroundOptions, UUID)] = {
var blah = [(Image, UUID)]() var blah = [(BackGroundOptions, UUID)]()
for _ in 0...CustomIcon.numberOfBGItems { for _ in 0...CustomIcon.numberOfBGItems {
let image = Image(BackGroundOptions.selectable.randomElement()!.rawValue, bundle: .main) blah.append((BackGroundOptions.selectable.randomElement()!, UUID()))
blah.append((image, UUID()))
} }
return blah return blah
}() }()
static var previews: some View { static var previews: some View {
IconView(customIcon: CustomIcon(leftEye: EyeOptions.defaultOption, IconView(customIcon: CustomIcon.defaultCustomIcon,
rightEye: EyeOptions.defaultOption,
mouth: MouthOptions.defaultOption,
background: IconView_Previews.backgrounds,
bgColor: .red,
innerColor: .green,
bgOverlayColor: .orange,
rightEyeColor: .orange,
leftEyeColor: .yellow,
mouthColor: .green,
circleStrokeColor: .pink),
isPreview: true) isPreview: true)
.frame(width: 256, height: 256, alignment: .center) .frame(width: 256, height: 256, alignment: .center)

View File

@@ -76,14 +76,15 @@ struct SmallRollUpHeaderView: View {
.frame(width: 50, height: 50) .frame(width: 50, height: 50)
textView(forModel: model) textView(forModel: model)
.font(.title) .font(.title3)
.fontWeight(.bold) .fontWeight(.bold)
.frame(width: 40, height: 40)
.scaledToFill() .scaledToFill()
.minimumScaleFactor(0.5) .minimumScaleFactor(0.5)
.lineLimit(1) .lineLimit(1)
.foregroundColor(Color(UIColor.white)) .foregroundColor(Color(UIColor.white))
} }
.frame(maxWidth: .infinity, alignment: .center) .padding([.leading, .trailing], 5)
} }
} }
} }