taler-ios

iOS apps for GNU Taler (wallet)
Log | Files | Refs | README | LICENSE

commit 7d32de822929ea1b846d6447cf8316c35031b9fc
parent e9e27e9f31b9d620b8b84e91b742ba71f62819b0
Author: Marc Stibane <marc@taler.net>
Date:   Sat,  2 Sep 2023 21:59:54 +0200

Font Settings

Diffstat:
MTalerWallet1/Controllers/Controller.swift | 8+++++++-
MTalerWallet1/Helper/Font+Taler.swift | 67+++++++++++++++++++++++++++++++++++++++----------------------------
MTalerWallet1/Views/Settings/SettingsItem.swift | 88++++++++++++++++++++++++++++++++++++++++++-------------------------------------
MTalerWallet1/Views/Settings/SettingsView.swift | 29++++++++++++-----------------
4 files changed, 105 insertions(+), 87 deletions(-)

diff --git a/TalerWallet1/Controllers/Controller.swift b/TalerWallet1/Controllers/Controller.swift @@ -33,13 +33,19 @@ class Controller: ObservableObject { @Published var backendState: BackendState = .none // only used for launch animation @AppStorage("playSounds") var playSounds: Int = 0 // extension mustn't define this, so it must be here - @AppStorage("talerFonts") var talerFonts: Int = 0 // extension mustn't define this, so it must be here + @AppStorage("talerFont") var talerFont: Int = 0 // extension mustn't define this, so it must be here let logger = Logger (subsystem: "net.taler.gnu", category: "Controller") let player = AVQueuePlayer() var messageForSheet: String? = nil init() { +// for family in UIFont.familyNames { +// print(family) +// for names in UIFont.fontNames(forFamilyName: family) { +// print("== \(names)") +// } +// } backendState = .instantiated } diff --git a/TalerWallet1/Helper/Font+Taler.swift b/TalerWallet1/Helper/Font+Taler.swift @@ -6,25 +6,28 @@ import SwiftUI // Use enums for multiple font types and functions for the set custom font. -fileprivate let REGULAR = "AtkinsonHyperlegible-Regular" -fileprivate let ITALIC = "AtkinsonHyperlegible-Italic" -fileprivate let BOLD = "AtkinsonHyperlegible-Bold" -fileprivate let BOLDITALIC = "AtkinsonHyperlegible-BoldItalic" +fileprivate let ATKINSON = "AtkinsonHyperlegible-" +fileprivate let NUNITO = "Nunito-" + +fileprivate let REGULAR = "Regular" +fileprivate let BOLD = "Bold" +fileprivate let BOLDITALIC = "BoldItalic" +fileprivate let ITALIC = "Italic" extension Font { enum TalerFont { case regular - case italic case bold case boldItalic + case italic case custom(String) var value: String { switch self { case .regular: return REGULAR - case .italic: return ITALIC case .bold: return BOLD case .boldItalic: return BOLDITALIC + case .italic: return ITALIC case .custom(let name): return name @@ -36,49 +39,57 @@ extension Font { return .custom(type.value, size: size) } + static func talerFontName(_ index: Int) -> String { + if index == 1 { + return ATKINSON + } else { + return NUNITO + } + } + static var talerLargeTitle: Font { - Controller.shared.talerFonts == 0 ? .largeTitle : - .custom(REGULAR, size: 38, relativeTo: .largeTitle) + Controller.shared.talerFont == 0 ? .largeTitle : + .custom(talerFontName(Controller.shared.talerFont) + REGULAR, size: 38, relativeTo: .largeTitle) } // 34 -> 38 static var talerTitle: Font { - Controller.shared.talerFonts == 0 ? .title : - .custom(REGULAR, size: 31, relativeTo: .title) + Controller.shared.talerFont == 0 ? .title : + .custom(talerFontName(Controller.shared.talerFont) + REGULAR, size: 31, relativeTo: .title) } // 28 -> 31 static var talerTitle2: Font { - Controller.shared.talerFonts == 0 ? .title2 : - .custom(REGULAR, size: 25, relativeTo: .title2) + Controller.shared.talerFont == 0 ? .title2 : + .custom(talerFontName(Controller.shared.talerFont) + REGULAR, size: 25, relativeTo: .title2) } // 22 -> 25 static var talerTitle3: Font { - Controller.shared.talerFonts == 0 ? .title3 : - .custom(REGULAR, size: 23, relativeTo: .title3) + Controller.shared.talerFont == 0 ? .title3 : + .custom(talerFontName(Controller.shared.talerFont) + REGULAR, size: 23, relativeTo: .title3) } // 20 -> 23 static var talerHeadline: Font { - Controller.shared.talerFonts == 0 ? .headline : - .custom(BOLD, size: 19, relativeTo: .headline) + Controller.shared.talerFont == 0 ? .headline : + .custom(talerFontName(Controller.shared.talerFont) + BOLD, size: 19, relativeTo: .headline) } // 17 bold -> 19 bold static var talerBody: Font { - Controller.shared.talerFonts == 0 ? .body : - .custom(REGULAR, size: 19, relativeTo: .body) + Controller.shared.talerFont == 0 ? .body : + .custom(talerFontName(Controller.shared.talerFont) + REGULAR, size: 19, relativeTo: .body) } // 17 -> 19 static var talerCallout: Font { - Controller.shared.talerFonts == 0 ? .callout : - .custom(REGULAR, size: 18, relativeTo: .callout) + Controller.shared.talerFont == 0 ? .callout : + .custom(talerFontName(Controller.shared.talerFont) + REGULAR, size: 18, relativeTo: .callout) } // 16 -> 18 static var talerSubheadline: Font { - Controller.shared.talerFonts == 0 ? .subheadline : - .custom(REGULAR, size: 17, relativeTo: .subheadline) + Controller.shared.talerFont == 0 ? .subheadline : + .custom(talerFontName(Controller.shared.talerFont) + REGULAR, size: 17, relativeTo: .subheadline) } // 15 -> 17 static var talerFootnote: Font { - Controller.shared.talerFonts == 0 ? .footnote : - .custom(REGULAR, size: 15, relativeTo: .footnote) + Controller.shared.talerFont == 0 ? .footnote : + .custom(talerFontName(Controller.shared.talerFont) + REGULAR, size: 15, relativeTo: .footnote) } // 13 -> 15 static var talerCaption: Font { - Controller.shared.talerFonts == 0 ? .caption : - .custom(REGULAR, size: 13, relativeTo: .caption) + Controller.shared.talerFont == 0 ? .caption : + .custom(talerFontName(Controller.shared.talerFont) + REGULAR, size: 13, relativeTo: .caption) } // 12 -> 13 static var talerCaption2: Font { - Controller.shared.talerFonts == 0 ? .caption2 : - .custom(REGULAR, size: 12, relativeTo: .caption2) + Controller.shared.talerFont == 0 ? .caption2 : + .custom(talerFontName(Controller.shared.talerFont) + REGULAR, size: 12, relativeTo: .caption2) } // 11 -> 12 } diff --git a/TalerWallet1/Views/Settings/SettingsItem.swift b/TalerWallet1/Views/Settings/SettingsItem.swift @@ -20,12 +20,12 @@ struct SettingsItem<Content: View>: View { VStack { Text(name) .frame(maxWidth: .infinity, alignment: .leading) - .font(.title2) + .font(.talerTitle2) .padding([.bottom], 0.01) if let desc = description { Text(desc) .frame(maxWidth: .infinity, alignment: .leading) - .font(.caption) + .font(.talerCaption) } } content() @@ -42,7 +42,7 @@ struct SettingsToggle: View { var body: some View { VStack { Toggle(name, isOn: $value.animation()) - .font(.title2) + .font(.talerTitle2) .onChange(of: value) { value in action() } @@ -50,50 +50,56 @@ struct SettingsToggle: View { if let desc = description { Text(desc) .frame(maxWidth: .infinity, alignment: .leading) - .font(.caption) + .font(.talerCaption) } }.padding([.bottom], 4) } } // MARK: - struct SettingsFont: View { - var name: String - @Binding var value: Int - var action: (_ value: Int) -> Void = {value in } + let title: String + let value: Int + let action: (Int) -> Void + + @State private var selected = 0 + let fonts = [String(localized: "Standard iOS Font"), "Atkinson-Hyperlegible", "Nunito"] - func fontName(_ value: Int) -> (String, String, String) { - return (value == 0) ? ("textformat", String(localized:"System Font"), String(localized: "Standard iOS Font")) - : (value == 1) ? ("textformat.alt", String(localized:"Taler Font"), String(localized: "Atkinson-Hyperlegible")) - : ("placeholdertext.fill", String(localized:"New Font"), String(localized:"New Font")) // Neumorphism - } var body: some View { - VStack { - let fontName = fontName(value) - HStack { - Text(name) - .font(.talerTitle2) - Text(" ") - .font(.talerLargeTitle) - Spacer() - Image(systemName: fontName.0) - .font(.talerLargeTitle) - .accessibilityLabel(fontName.1) - .onTapGesture { - if value > 0 { - value = 0 // TODO: -1 for Neumorphism - } else { - value = value + 1 - } - } + Picker(title, selection: $selected, content: { + ForEach(0..<fonts.count, id: \.self, content: { index in + Text(fonts[index]).tag(index) + }) + }) + .font(.talerTitle2) + .pickerStyle(.menu) + .onAppear() { + withAnimation { selected = value } } -// .onChange(of: value) { value in -// action(value) -// } + .onChange(of: selected) { selected in + action(selected) + } + } +} +// MARK: - +struct SettingsStyle: View { + let title: String + @Binding var myListStyle: MyListStyle - Text(fontName.2) - .frame(maxWidth: .infinity, alignment: .leading) - .font(.talerCaption) - }.padding([.bottom], 4) + var body: some View { + HStack { + Text(title) + .font(.talerTitle2) + Spacer() + Picker(selection: $myListStyle) { + ForEach(MyListStyle.allCases, id: \.self) { + Text($0.displayName.capitalized).tag($0) + .font(.talerTitle2) + } + } label: {} + .pickerStyle(.menu) +// .frame(alignment: .trailing) +// .background(WalletColors().buttonBackColor(pressed: false, disabled: false)) TODO: RoundRect + } } } // MARK: - @@ -113,12 +119,12 @@ struct SettingsSpeaker: View { let image = imageName(value) HStack { Text(name) - .font(.title2) + .font(.talerTitle2) Text(" ") - .font(.largeTitle) + .font(.talerLargeTitle) Spacer() Image(systemName: image.0) - .font(.largeTitle) + .font(.talerLargeTitle) .accessibilityLabel(image.1) .onTapGesture { if value > 0 { @@ -137,7 +143,7 @@ struct SettingsSpeaker: View { if let desc = description { Text(desc) .frame(maxWidth: .infinity, alignment: .leading) - .font(.caption) + .font(.talerCaption) } }.padding([.bottom], 4) } diff --git a/TalerWallet1/Views/Settings/SettingsView.swift b/TalerWallet1/Views/Settings/SettingsView.swift @@ -27,7 +27,7 @@ struct SettingsView: View { @AppStorage("developerMode") var developerMode: Bool = false #endif @AppStorage("playSounds") var playSounds: Int = 0 - @AppStorage("talerFonts") var talerFonts: Int = 0 + @AppStorage("talerFont") var talerFont: Int = 0 @AppStorage("developDelay") var developDelay: Bool = false @AppStorage("myListStyle") var myListStyle: MyListStyle = .automatic @@ -65,7 +65,14 @@ struct SettingsView: View { } } } + @State private var listID = UUID() + func redraw(_ newFont: Int) -> Void { + if newFont != talerFont { + talerFont = newFont + withAnimation { listID = UUID() } + } + } var body: some View { #if DEBUG let _ = Self._printChanges() @@ -74,23 +81,10 @@ struct SettingsView: View { let walletCore = WalletCore.shared Group { List { - SettingsFont(name: String(localized: "Font to use"), value: $talerFonts) SettingsSpeaker(name: String(localized: "Play Payment Sounds"), value: $playSounds, - description: String(localized: "After a transaction finished")) - HStack { - Text("Liststyle:") - .font(.title2) - Spacer() - Picker(selection: $myListStyle) { - ForEach(MyListStyle.allCases, id: \.self) { - Text($0.displayName.capitalized).tag($0) - .font(.title2) - } - } label: {} - .pickerStyle(.menu) -// .frame(alignment: .trailing) -// .background(WalletColors().buttonBackColor(pressed: false, disabled: false)) TODO: RoundRect - } + description: String(localized: "After a transaction finished")) + SettingsFont(title: String(localized: "Font:"), value: talerFont, action: redraw) + SettingsStyle(title: String(localized: "Liststyle:"), myListStyle: $myListStyle) if diagnosticModeEnabled { SettingsToggle(name: String(localized: "Developer Mode"), value: $developerMode, description: String(localized: "More information intended for debugging")) { @@ -247,6 +241,7 @@ struct SettingsView: View { } } // App version info } + .id(listID) .listStyle(myListStyle.style).anyView } .navigationTitle(navTitle)