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

@@ -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()))
}
}

View File

@@ -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)

View File

@@ -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)
}
}
}