Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
parent
be3131ad7c
commit
2f85c334cb
@ -1,44 +0,0 @@
|
||||
//
|
||||
// Color+Codable.swift
|
||||
// CameraTester
|
||||
//
|
||||
// Created by Matt Bruce on 1/3/26.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
// MARK: - Color Codable Extension
|
||||
|
||||
extension Color: Codable {
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case red, green, blue, opacity
|
||||
}
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
let red = try container.decode(Double.self, forKey: .red)
|
||||
let green = try container.decode(Double.self, forKey: .green)
|
||||
let blue = try container.decode(Double.self, forKey: .blue)
|
||||
let opacity = try container.decode(Double.self, forKey: .opacity)
|
||||
|
||||
self.init(red: red, green: green, blue: blue, opacity: opacity)
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
|
||||
// Convert Color to RGB components
|
||||
let uiColor = UIColor(self)
|
||||
var red: CGFloat = 0
|
||||
var green: CGFloat = 0
|
||||
var blue: CGFloat = 0
|
||||
var alpha: CGFloat = 0
|
||||
|
||||
uiColor.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
|
||||
|
||||
try container.encode(Double(red), forKey: .red)
|
||||
try container.encode(Double(green), forKey: .green)
|
||||
try container.encode(Double(blue), forKey: .blue)
|
||||
try container.encode(Double(alpha), forKey: .opacity)
|
||||
}
|
||||
}
|
||||
@ -11,17 +11,22 @@ import SwiftUI
|
||||
struct CameraSettings: Codable {
|
||||
var photoQuality: PhotoQuality
|
||||
var isRingLightEnabled: Bool
|
||||
var ringLightColor: Color
|
||||
var ringLightColorRGB: CustomColorRGB
|
||||
var ringLightSize: CGFloat
|
||||
var ringLightOpacity: Double
|
||||
var flashMode: CameraFlashMode
|
||||
var isFlashSyncedWithRingLight: Bool
|
||||
|
||||
var ringLightColor: Color {
|
||||
get { ringLightColorRGB.color }
|
||||
set { ringLightColorRGB = CustomColorRGB(from: newValue) }
|
||||
}
|
||||
|
||||
// Default settings
|
||||
static let `default` = CameraSettings(
|
||||
photoQuality: .high,
|
||||
isRingLightEnabled: true,
|
||||
ringLightColor: .white,
|
||||
ringLightColorRGB: .defaultWhite,
|
||||
ringLightSize: 25,
|
||||
ringLightOpacity: 1.0,
|
||||
flashMode: .off,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user