add shape picker for backgrounds
This commit is contained in:
31
Shared/Models/DiamondView.swift
Normal file
31
Shared/Models/DiamondView.swift
Normal file
@@ -0,0 +1,31 @@
|
||||
//
|
||||
// DiamondView.swift
|
||||
// Feels
|
||||
//
|
||||
// Created by Trey Tartt on 3/20/22.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct Diamond:Shape {
|
||||
|
||||
func path(in rect: CGRect) -> Path {
|
||||
var path = Path()
|
||||
// get the center of the rect
|
||||
let center = CGPoint(x: rect.midX, y: rect.midY)
|
||||
// get the starting of our drawing the right side of our diamond
|
||||
let startingPoint = CGPoint(x: rect.maxX, y: center.y)
|
||||
// move our start of drawing to the beggining point
|
||||
path.move(to: startingPoint)
|
||||
// distance / 2 is our height
|
||||
// create all our points
|
||||
let secondPoint = CGPoint(x: center.x, y: rect.maxY)
|
||||
let thirdPoint = CGPoint(x: rect.minX , y: center.y)
|
||||
let fourthPoint = CGPoint(x: center.x, y: rect.minY)
|
||||
path.addLine(to: secondPoint)
|
||||
path.addLine(to: thirdPoint)
|
||||
path.addLine(to: fourthPoint)
|
||||
path.addLine(to: startingPoint)
|
||||
return path
|
||||
}
|
||||
}
|
||||
65
Shared/Models/Shapes.swift
Normal file
65
Shared/Models/Shapes.swift
Normal file
@@ -0,0 +1,65 @@
|
||||
//
|
||||
// Shapes.swift
|
||||
// Feels
|
||||
//
|
||||
// Created by Trey Tartt on 3/20/22.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
enum BGShape: Int, CaseIterable {
|
||||
case circle
|
||||
case diamond
|
||||
case rectangle
|
||||
case roundedRectangle
|
||||
|
||||
func view(withText text: Text, bgColor: Color, textColor: Color) -> some View{
|
||||
return AnyView(
|
||||
ZStack {
|
||||
switch self {
|
||||
case .circle:
|
||||
Circle()
|
||||
.fill(bgColor)
|
||||
.frame(minWidth: 5,
|
||||
maxWidth: 500,
|
||||
minHeight: 5,
|
||||
maxHeight: 500,
|
||||
alignment: .center)
|
||||
|
||||
case .diamond:
|
||||
Diamond()
|
||||
.fill(bgColor)
|
||||
.frame(minWidth: 5,
|
||||
maxWidth: 500,
|
||||
minHeight: 5,
|
||||
maxHeight: 500)
|
||||
.aspectRatio(contentMode: .fit)
|
||||
|
||||
case .rectangle:
|
||||
Rectangle()
|
||||
.fill(bgColor)
|
||||
.frame(minWidth: 5,
|
||||
maxWidth: 500,
|
||||
minHeight: 5,
|
||||
maxHeight: 500,
|
||||
alignment: .center)
|
||||
case .roundedRectangle:
|
||||
RoundedRectangle(cornerRadius: 8, style: .continuous)
|
||||
.fill(bgColor)
|
||||
.frame(minWidth: 5,
|
||||
maxWidth: 500,
|
||||
minHeight: 5,
|
||||
maxHeight: 500,
|
||||
alignment: .center)
|
||||
}
|
||||
text
|
||||
.font(.title2)
|
||||
.fontWeight(.bold)
|
||||
.lineLimit(1)
|
||||
.foregroundColor(textColor)
|
||||
.minimumScaleFactor(0.7)
|
||||
.padding(10)
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ class UserDefaultsStore {
|
||||
case customMoodTintUpdateNumber
|
||||
case textColor
|
||||
case showNSFW
|
||||
case shape
|
||||
|
||||
case contentViewCurrentSelectedHeaderViewBackDays
|
||||
case contentViewHeaderTag
|
||||
@@ -190,6 +191,15 @@ class UserDefaultsStore {
|
||||
return SavedMoodTint()
|
||||
}
|
||||
|
||||
static func getCustomBGShape() -> BGShape {
|
||||
if let data = GroupUserDefaults.groupDefaults.object(forKey: UserDefaultsStore.Keys.shape.rawValue) as? Int,
|
||||
let model = BGShape.init(rawValue: data) {
|
||||
return model
|
||||
} else {
|
||||
return BGShape.circle
|
||||
}
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
static func saveCustomMoodTint(customTint: SavedMoodTint) -> SavedMoodTint {
|
||||
do {
|
||||
|
||||
Reference in New Issue
Block a user