Created
October 19, 2021 08:19
-
-
Save odrobnik/4609ef14d560c5e69e226207a6325762 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct Modifier: Identifiable | |
{ | |
let id = UUID() | |
@State var title: String | |
} | |
struct FastnotesSettings: View | |
{ | |
@State private var rows: [Modifier] = [Modifier(title:"Brightness"), Modifier(title:"Contrast"), Modifier(title:"Detail"), Modifier(title:"Saturation"), Modifier(title:"Sharpness"), Modifier(title:"Weight")] | |
@State private var editMode = EditMode.inactive | |
var body: some View | |
{ | |
List { | |
Section { | |
ForEach(rows) { row in | |
TextField("Text", text: row.$title) | |
.disabled(editMode != .active) | |
} | |
.onMove(perform: move) | |
.onDelete(perform: delete) | |
} | |
Section { | |
HStack { | |
Spacer() | |
Button("Restore Default FastNotes Palette") { | |
withAnimation { | |
//self.model.reset() | |
} | |
} | |
Spacer() | |
} | |
} | |
} | |
.navigationBarItems(leading: addButton, trailing: EditButton()) | |
.environment(\.editMode, $editMode) | |
.listStyle(GroupedListStyle()) | |
.environment(\.horizontalSizeClass, .regular) | |
.navigationBarTitle("FastNotes", displayMode: .inline) | |
} | |
func move(from source: IndexSet, to destination: Int) | |
{ | |
rows.move(fromOffsets: source, toOffset: destination) | |
} | |
func delete(from source: IndexSet) | |
{ | |
rows.remove(atOffsets: source) | |
} | |
@ViewBuilder | |
private var addButton: some View | |
{ | |
switch editMode { | |
case .active: | |
Button(action: onAdd) | |
{ | |
Image(systemName: "plus") | |
} | |
.disabled(rows.count >= 10) | |
default: | |
EmptyView() | |
} | |
} | |
func onAdd() | |
{ | |
withAnimation { | |
rows.append(Modifier(title:"")) | |
} | |
} | |
} | |
struct FastNotesPalette_Previews: PreviewProvider { | |
static var previews: some View { | |
NavigationView { | |
FastnotesSettings() | |
} | |
.navigationViewStyle(StackNavigationViewStyle()) | |
.previewLayout(.fixed(width: 500, height: 600)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment