| 1 | import SwiftUI |
| 2 | |
| 3 | struct SheetFormatMenu: View { |
| 4 | @Bindable var model: SheetModel |
| 5 | @State private var columnWidth = 110 |
| 6 | @State private var rowHeight = 32 |
| 7 | var body: some View { |
| 8 | Menu("Format", systemImage: "textformat") { |
| 9 | Button("Bold") { |
| 10 | Task { |
| 11 | await model.format([ |
| 12 | "bold": !model.selection.coordinates.allSatisfy { |
| 13 | model.styles[model.cells[$0]?.f ?? ""]?.b == true |
| 14 | } |
| 15 | ]) |
| 16 | } |
| 17 | }.keyboardShortcut("b") |
| 18 | Button("Italic") { |
| 19 | Task { |
| 20 | await model.format([ |
| 21 | "italic": !model.selection.coordinates.allSatisfy { |
| 22 | model.styles[model.cells[$0]?.f ?? ""]?.i == true |
| 23 | } |
| 24 | ]) |
| 25 | } |
| 26 | }.keyboardShortcut("i") |
| 27 | Menu("Alignment") { |
| 28 | Button("Automatic") { Task { await model.format(["align": ""]) } } |
| 29 | ForEach(["left", "center", "right"], id: \.self) { value in |
| 30 | Button(value.capitalized) { Task { await model.format(["align": value]) } } |
| 31 | } |
| 32 | } |
| 33 | Menu("Number format") { |
| 34 | ForEach(model.page?.NumberFormats ?? []) { value in |
| 35 | Button(value.Label) { Task { await model.format(["numfmt": value.Code]) } } |
| 36 | } |
| 37 | } |
| 38 | Menu("Fill colour") { |
| 39 | Button("No fill") { Task { await model.format(["fill": "none"]) } } |
| 40 | ForEach(model.page?.FillSwatches ?? []) { value in |
| 41 | Button(value.Label) { Task { await model.format(["fill": value.Name]) } } |
| 42 | } |
| 43 | } |
| 44 | Menu("Text colour") { |
| 45 | Button("Default") { Task { await model.format(["ink": "none"]) } } |
| 46 | ForEach(model.page?.InkSwatches ?? []) { value in |
| 47 | Button(value.Label) { Task { await model.format(["ink": value.Name]) } } |
| 48 | } |
| 49 | } |
| 50 | Button("Clear formatting") { |
| 51 | Task { |
| 52 | await model.format([ |
| 53 | "bold": false, "italic": false, "align": "", "numfmt": "", "fill": "none", |
| 54 | "ink": "none", |
| 55 | ]) |
| 56 | } |
| 57 | } |
| 58 | }.disabled(!model.mayWrite || model.hasUnconfirmedChanges || model.busy) |
| 59 | } |
| 60 | } |
| 61 | |