Updated add project screen to use the theme colour if none selected
This commit is contained in:
parent
71806c9ca4
commit
a4302ef65d
@ -18,6 +18,8 @@ struct MainView: View {
|
||||
|
||||
@State private var searchText = ""
|
||||
|
||||
@AppStorage(Preferences.themeColour) var themeColor = Color.blue.toHex()!
|
||||
|
||||
var body: some View {
|
||||
NavigationSplitView {
|
||||
List {
|
||||
@ -52,7 +54,13 @@ struct MainView: View {
|
||||
|
||||
private func addItem(name: String, color: String) {
|
||||
withAnimation {
|
||||
let newProject = OCProject(name: name, color: color)
|
||||
var newProject: OCProject
|
||||
|
||||
if color == Color.clear.toHex()! {
|
||||
newProject = OCProject(name: name, color: themeColor)
|
||||
} else {
|
||||
newProject = OCProject(name: name, color: color)
|
||||
}
|
||||
modelContext.insert(newProject)
|
||||
}
|
||||
}
|
||||
|
@ -10,28 +10,41 @@ import SwiftUI
|
||||
struct NewProjectForm: View {
|
||||
|
||||
@State private var newProjectName = ""
|
||||
@State private var chosenColor: Color = .blue
|
||||
@State private var chosenColor = Color.clear
|
||||
@Environment(\.dismiss) var dismiss
|
||||
|
||||
let completionHandler: (String, String) -> Void
|
||||
|
||||
let availColours: [String] = {
|
||||
var c = Constants.colors.map { $0.toHex()! }
|
||||
c.insert("Theme", at: 0)
|
||||
return c
|
||||
}()
|
||||
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
Form {
|
||||
TextField("Project Name", text: $newProjectName)
|
||||
Section(header: Text("Project Colour")) {
|
||||
Section {
|
||||
HStack {
|
||||
ForEach(Constants.colors, id: \.self) { clr in
|
||||
ColorChooserCircle(color: clr)
|
||||
.padding(.vertical)
|
||||
.onTapGesture {
|
||||
self.chosenColor = clr
|
||||
ForEach(Constants.colors, id: \.self) { color in
|
||||
if chosenColor == color {
|
||||
ZStack {
|
||||
Circle()
|
||||
.foregroundStyle(color)
|
||||
Image(systemName: "checkmark")
|
||||
}
|
||||
.onTapGesture { chooseColour(color) }
|
||||
} else {
|
||||
Circle()
|
||||
.foregroundStyle(color)
|
||||
.onTapGesture { chooseColour(color) }
|
||||
}
|
||||
}
|
||||
}
|
||||
} header: { Text("Project Colour") } footer: { Text("Leave unselected to use theme colour in settings" )}
|
||||
}
|
||||
}
|
||||
.navigationTitle("Add New Project").foregroundStyle(chosenColor)
|
||||
.navigationTitle("Add New Project")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .topBarLeading) {
|
||||
@ -47,16 +60,13 @@ struct NewProjectForm: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func chooseColour(_ color: Color) {
|
||||
if color == chosenColor {
|
||||
chosenColor = .clear
|
||||
} else {
|
||||
chosenColor = color
|
||||
}
|
||||
|
||||
struct ColorChooserCircle: View {
|
||||
var color: Color
|
||||
|
||||
var body: some View {
|
||||
Circle()
|
||||
.strokeBorder(Color.gray,lineWidth: 2)
|
||||
.background(Circle().foregroundColor(color))
|
||||
.frame(minHeight: 25)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,5 +9,4 @@ import SwiftUI
|
||||
|
||||
public struct Constants {
|
||||
static let colors: [Color] = [.red, .orange, .yellow, .green, .blue, .indigo]
|
||||
static let colorText = ["None", "Red", "Orange", "Yellow", "Green", "Blue", "Indigo"]
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user