Added a font scale slider on macOS

This commit is contained in:
Thomas Ricouard 2023-01-17 21:08:05 +01:00
parent 504f93fab0
commit c7a832e110
6 changed files with 44 additions and 25 deletions

View file

@ -49,7 +49,7 @@ struct SideBarView<Content: View>: View {
.fill(.red)
Text(String(badge))
.foregroundColor(.white)
.font(.caption)
.font(.caption2)
}
.frame(width: 20, height: 20)
.offset(x: 10, y: -10)

View file

@ -2,9 +2,11 @@ import DesignSystem
import Models
import Status
import SwiftUI
import Env
struct DisplaySettingsView: View {
@EnvironmentObject private var theme: Theme
@EnvironmentObject private var userPreferences: UserPreferences
@State private var isThemeSelectorPresented = false
@ -40,6 +42,13 @@ struct DisplaySettingsView: View {
Text(buttonStyle.description).tag(buttonStyle)
}
}
if ProcessInfo.processInfo.isiOSAppOnMac {
VStack {
Slider(value: $userPreferences.fontSizeScale, in: 0.5...1.5, step: 0.1)
Text("Font scaling: \(String(format: "%.1f", userPreferences.fontSizeScale))")
.font(.scaledBody)
}
}
}
.listRowBackground(theme.primaryBackgroundColor)

View file

@ -109,15 +109,17 @@ struct SettingsTabs: View {
private var appSection: some View {
Section("App") {
NavigationLink(destination: IconSelectorView()) {
Label {
Text("App Icon")
} icon: {
if let icon = IconSelectorView.Icon(string: UIApplication.shared.alternateIconName ?? "AppIcon") {
Image(uiImage: .init(named: icon.iconName)!)
.resizable()
.frame(width: 25, height: 25)
.cornerRadius(4)
if !ProcessInfo.processInfo.isiOSAppOnMac {
NavigationLink(destination: IconSelectorView()) {
Label {
Text("App Icon")
} icon: {
if let icon = IconSelectorView.Icon(string: UIApplication.shared.alternateIconName ?? "AppIcon") {
Image(uiImage: .init(named: icon.iconName)!)
.resizable()
.frame(width: 25, height: 25)
.cornerRadius(4)
}
}
}
}

View file

@ -82,16 +82,16 @@ public struct AccountDetailView: View {
viewModel.isCurrentUser = isCurrentUser
viewModel.client = client
Task {
await viewModel.fetchAccount()
}
Task {
if viewModel.statuses.isEmpty {
await viewModel.fetchStatuses()
await withTaskGroup(of: Void.self) { group in
group.addTask { await viewModel.fetchAccount() }
group.addTask {
if await viewModel.statuses.isEmpty {
await viewModel.fetchStatuses()
}
}
group.addTask { await viewModel.fetchFamilliarFollowers() }
}
}
Task {
await viewModel.fetchFamilliarFollowers()
}
}
.refreshable {
Task {

View file

@ -1,9 +1,16 @@
import SwiftUI
import Env
@MainActor
extension Font {
public static func userScaledFontSize(baseSize: CGFloat) -> CGFloat {
UIFontMetrics.default.scaledValue(for: baseSize * UserPreferences.shared.fontSizeScale)
}
public static var scaledTitle: Font {
if ProcessInfo.processInfo.isiOSAppOnMac {
return .system(size: UIFontMetrics.default.scaledValue(for: 28))
return .system(size: userScaledFontSize(baseSize: 28))
} else {
return .title
}
@ -11,7 +18,7 @@ extension Font {
public static var scaledHeadline: Font {
if ProcessInfo.processInfo.isiOSAppOnMac {
return .system(size: UIFontMetrics.default.scaledValue(for: 19), weight: .semibold)
return .system(size: userScaledFontSize(baseSize: 20), weight: .semibold)
} else {
return .headline
}
@ -19,7 +26,7 @@ extension Font {
public static var scaledBody: Font {
if ProcessInfo.processInfo.isiOSAppOnMac {
return .system(size: UIFontMetrics.default.scaledValue(for: 19))
return .system(size: userScaledFontSize(baseSize: 19))
} else {
return .body
}
@ -27,7 +34,7 @@ extension Font {
public static var scaledCallout: Font {
if ProcessInfo.processInfo.isiOSAppOnMac {
return .system(size: UIFontMetrics.default.scaledValue(for: 17))
return .system(size: userScaledFontSize(baseSize: 17))
} else {
return .callout
}
@ -35,7 +42,7 @@ extension Font {
public static var scaledSubheadline: Font {
if ProcessInfo.processInfo.isiOSAppOnMac {
return .system(size: UIFontMetrics.default.scaledValue(for: 16))
return .system(size: userScaledFontSize(baseSize: 16))
} else {
return .subheadline
}
@ -44,7 +51,7 @@ extension Font {
public static var scaledFootnote: Font {
if ProcessInfo.processInfo.isiOSAppOnMac {
return .system(size: UIFontMetrics.default.scaledValue(for: 15))
return .system(size: userScaledFontSize(baseSize: 15))
} else {
return .footnote
}
@ -52,7 +59,7 @@ extension Font {
public static var scaledCaption: Font {
if ProcessInfo.processInfo.isiOSAppOnMac {
return .system(size: UIFontMetrics.default.scaledValue(for: 14))
return .system(size: userScaledFontSize(baseSize: 14))
} else {
return .caption
}

View file

@ -13,6 +13,7 @@ public class UserPreferences: ObservableObject {
@AppStorage("remote_local_timeline") public var remoteLocalTimelines: [String] = []
@AppStorage("preferred_browser") public var preferredBrowser: PreferredBrowser = .inAppSafari
@AppStorage("draft_posts") public var draftsPosts: [String] = []
@AppStorage("font_size_scale") public var fontSizeScale: Double = 1
public var pushNotificationsCount: Int {
get {