From b8e1198c5b2b4b6759be6e1a6624122816f9f634 Mon Sep 17 00:00:00 2001 From: Trey t Date: Sun, 13 Feb 2022 23:23:58 -0600 Subject: [PATCH] spacing on custom icon widget create color extension for random widget 512x512 ... 1024x1024 didn't work clean up Icon Widget View --- Shared/Random.swift | 10 ++++++++++ Shared/views/CreateIconView.swift | 18 +++++------------- Shared/views/IconView.swift | 19 ++++++++++--------- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/Shared/Random.swift b/Shared/Random.swift index c069b55..dfcb245 100644 --- a/Shared/Random.swift +++ b/Shared/Random.swift @@ -145,3 +145,13 @@ extension Date { return dates } } + +extension Color { + static func random() -> Self { + Self( + red: .random(in: 0...1), + green: .random(in: 0...1), + blue: .random(in: 0...1) + ) + } +} diff --git a/Shared/views/CreateIconView.swift b/Shared/views/CreateIconView.swift index 7d93a0c..ca96d52 100644 --- a/Shared/views/CreateIconView.swift +++ b/Shared/views/CreateIconView.swift @@ -55,17 +55,9 @@ struct CreateIconView: View { } func createRandom() { - customIcon.bgColor = Color( - red: .random(in: 0...1), - green: .random(in: 0...1), - blue: .random(in: 0...1) - ) - - customIcon.innerColor = Color( - red: .random(in: 0...1), - green: .random(in: 0...1), - blue: .random(in: 0...1) - ) + customIcon.bgColor = Color.random() + customIcon.innerColor = Color.random() + customIcon.bgOverlayColor = Color.random() update(eye: .left, eyeOption: EyeOptions.allCases.randomElement()!) update(eye: .right, eyeOption: EyeOptions.allCases.randomElement()!) @@ -214,8 +206,8 @@ struct CreateIconView: View { Button(action: { let bigIconView = IconView(customIcon: customIcon, isPreview: false) - .frame(width: 1024, height: 1024, alignment: .center) - .aspectRatio(contentMode: .fit) + .frame(width: 512, height: 512, alignment: .center) + .aspectRatio(contentMode: .fill) let icon = bigIconView.snapshot() if let data = icon.pngData() { savedCustomIcon = data diff --git a/Shared/views/IconView.swift b/Shared/views/IconView.swift index 05b94ee..c8da9f0 100644 --- a/Shared/views/IconView.swift +++ b/Shared/views/IconView.swift @@ -27,6 +27,13 @@ struct IconView: View { return CGFloat(-8) } + private var entireFuckingViewOffset: CGFloat { + if isPreview { + return CGFloat(0) + } + return CGFloat(25) + } + let columns = [ GridItem(.flexible(minimum: 1, maximum: 100), spacing: 1), GridItem(.flexible(minimum: 1, maximum: 100), spacing: 1), @@ -47,8 +54,7 @@ struct IconView: View { .fill( customIcon.bgColor ) - .frame(width: geo.size.width, height: geo.size.height, alignment: .center) - .position(x: geo.size.width/2, y: geo.size.height/2) + .frame(maxWidth: .infinity, maxHeight: .infinity) LazyVGrid(columns: columns, alignment: .leading, spacing: 0) { ForEach(customIcon.background, id: \.self.1) { (image, uuid) in @@ -58,12 +64,7 @@ struct IconView: View { .foregroundColor(customIcon.bgOverlayColor) } } - .frame(width: geo.size.width, - height: geo.size.height, - alignment: .center) - .position(x: geo.size.width/2 + gridXOffset, - y: geo.size.height/2 + gridYOffset) - + .frame(maxWidth: .infinity, maxHeight: .infinity) .background( .clear ) @@ -104,7 +105,7 @@ struct IconView: View { y: geo.size.height*0.59) } .position(x: geo.size.width/2, - y: geo.size.height/2) + y: geo.size.height/2 - entireFuckingViewOffset) } } }