[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-taler-ios] 19/19: Font Settings
From: |
gnunet |
Subject: |
[taler-taler-ios] 19/19: Font Settings |
Date: |
Sat, 02 Sep 2023 22:01:20 +0200 |
This is an automated email from the git hooks/post-receive script.
marc-stibane pushed a commit to branch master
in repository taler-ios.
commit 7d32de822929ea1b846d6447cf8316c35031b9fc
Author: Marc Stibane <marc@taler.net>
AuthorDate: Sat Sep 2 21:59:54 2023 +0200
Font Settings
---
TalerWallet1/Controllers/Controller.swift | 8 ++-
TalerWallet1/Helper/Font+Taler.swift | 67 ++++++++++++--------
TalerWallet1/Views/Settings/SettingsItem.swift | 88 ++++++++++++++------------
TalerWallet1/Views/Settings/SettingsView.swift | 29 ++++-----
4 files changed, 105 insertions(+), 87 deletions(-)
diff --git a/TalerWallet1/Controllers/Controller.swift
b/TalerWallet1/Controllers/Controller.swift
index 90de1d4..0dbd42c 100644
--- 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
index 1f0317e..bc0511a 100644
--- 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
index bda253f..919ea48 100644
--- 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
index 4457dd7..6394d07 100644
--- 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)
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [taler-taler-ios] 02/19: Changed "Invoice" to "Request" (private mode - "Invoice" will be used in business mode post 1.0), roundedBorder for input fields, (continued)
- [taler-taler-ios] 02/19: Changed "Invoice" to "Request" (private mode - "Invoice" will be used in business mode post 1.0), roundedBorder for input fields, gnunet, 2023/09/02
- [taler-taler-ios] 08/19: IntegrationTest on test, gnunet, 2023/09/02
- [taler-taler-ios] 13/19: ScopedCurrencyInfo, SuperScriptDigit, gnunet, 2023/09/02
- [taler-taler-ios] 05/19: Comment, gnunet, 2023/09/02
- [taler-taler-ios] 18/19: Nunito Font, gnunet, 2023/09/02
- [taler-taler-ios] 16/19: Rename, fix, gnunet, 2023/09/02
- [taler-taler-ios] 14/19: CurrencyFormatter, gnunet, 2023/09/02
- [taler-taler-ios] 09/19: Accessibility String for Payment Sounds, gnunet, 2023/09/02
- [taler-taler-ios] 12/19: CachePath for data not to be backed up, gnunet, 2023/09/02
- [taler-taler-ios] 11/19: Settings: Font: AtkinsonHyperlegible, gnunet, 2023/09/02
- [taler-taler-ios] 19/19: Font Settings,
gnunet <=
- [taler-taler-ios] 10/19: Comment, gnunet, 2023/09/02
- [taler-taler-ios] 06/19: Rename, gnunet, 2023/09/02
- [taler-taler-ios] 15/19: group, gnunet, 2023/09/02
- [taler-taler-ios] 07/19: secret-token:secret, gnunet, 2023/09/02
- [taler-taler-ios] 17/19: GNU Taler, Taler Wallet, gnunet, 2023/09/02