mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-04 12:13:34 +00:00
Preserve macOS chat typography scaling
This commit is contained in:
@@ -155,6 +155,11 @@ struct OpenClawTypographyTests {
|
||||
contentsOf: Self.sourceURL("Design/SettingsChannelsDestination.swift"),
|
||||
encoding: .utf8)
|
||||
let docs = try String(contentsOf: Self.sourceURL("Design/OpenClawDocsScreen.swift"), encoding: .utf8)
|
||||
let chatTypography = try String(
|
||||
contentsOf: Self.iosRootURL()
|
||||
.deletingLastPathComponent()
|
||||
.appendingPathComponent("shared/OpenClawKit/Sources/OpenClawChatUI/ChatTypography.swift"),
|
||||
encoding: .utf8)
|
||||
let chatMessageViews = try String(
|
||||
contentsOf: Self.iosRootURL()
|
||||
.deletingLastPathComponent()
|
||||
@@ -232,6 +237,12 @@ struct OpenClawTypographyTests {
|
||||
#expect(!chatMessageViews.contains("font: .body"))
|
||||
#expect(!chatMessageViews.contains("Font.body"))
|
||||
#expect(!chatMessageViews.contains("Font.callout"))
|
||||
#expect(chatTypography
|
||||
.contains("Font.custom(self.macSystemFontName(size: size), size: size, relativeTo: textStyle)"))
|
||||
#expect(chatTypography.contains(
|
||||
"Font.custom(self.macMonospacedSystemFontName(size: size), size: size, relativeTo: textStyle)"))
|
||||
#expect(!chatTypography.contains("Font.system(textStyle, design: .default)"))
|
||||
#expect(!chatTypography.contains("Font.system(textStyle, design: .monospaced)"))
|
||||
}
|
||||
|
||||
@Test func `iOS app text and control calls keep branded font boundaries`() throws {
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
#if os(macOS)
|
||||
import AppKit
|
||||
#endif
|
||||
|
||||
enum OpenClawChatTypography {
|
||||
static var title3: Font {
|
||||
@@ -43,12 +46,14 @@ enum OpenClawChatTypography {
|
||||
}
|
||||
|
||||
static func avatar(size: CGFloat) -> Font {
|
||||
body(size: size, weight: .bold, relativeTo: .caption)
|
||||
self.body(size: size, weight: .bold, relativeTo: .caption)
|
||||
}
|
||||
|
||||
static func body(size: CGFloat, weight: Font.Weight, relativeTo textStyle: Font.TextStyle) -> Font {
|
||||
#if os(iOS)
|
||||
Font.custom(Self.bodyPostScriptName, size: size, relativeTo: textStyle).weight(weight)
|
||||
Font.custom(self.bodyPostScriptName, size: size, relativeTo: textStyle).weight(weight)
|
||||
#elseif os(macOS)
|
||||
Font.custom(self.macSystemFontName(size: size), size: size, relativeTo: textStyle).weight(weight)
|
||||
#else
|
||||
Font.system(size: size, weight: weight)
|
||||
#endif
|
||||
@@ -56,7 +61,9 @@ enum OpenClawChatTypography {
|
||||
|
||||
static func display(size: CGFloat, weight: Font.Weight, relativeTo textStyle: Font.TextStyle) -> Font {
|
||||
#if os(iOS)
|
||||
Font.custom(Self.displayPostScriptName, size: size, relativeTo: textStyle).weight(weight)
|
||||
Font.custom(self.displayPostScriptName, size: size, relativeTo: textStyle).weight(weight)
|
||||
#elseif os(macOS)
|
||||
Font.custom(self.macSystemFontName(size: size), size: size, relativeTo: textStyle).weight(weight)
|
||||
#else
|
||||
Font.system(size: size, weight: weight)
|
||||
#endif
|
||||
@@ -66,6 +73,9 @@ enum OpenClawChatTypography {
|
||||
#if os(iOS)
|
||||
let name = weight == .semibold ? Self.monoSemiBoldPostScriptName : Self.monoPostScriptName
|
||||
return Font.custom(name, size: size, relativeTo: textStyle)
|
||||
#elseif os(macOS)
|
||||
return Font.custom(self.macMonospacedSystemFontName(size: size), size: size, relativeTo: textStyle)
|
||||
.weight(weight)
|
||||
#else
|
||||
return Font.system(size: size, weight: weight, design: .monospaced)
|
||||
#endif
|
||||
@@ -75,4 +85,14 @@ enum OpenClawChatTypography {
|
||||
private static let bodyPostScriptName = "Inter-Regular"
|
||||
private static let monoPostScriptName = "JetBrainsMono-Regular"
|
||||
private static let monoSemiBoldPostScriptName = "JetBrainsMono-SemiBold"
|
||||
|
||||
#if os(macOS)
|
||||
private static func macSystemFontName(size: CGFloat) -> String {
|
||||
NSFont.systemFont(ofSize: size).fontName
|
||||
}
|
||||
|
||||
private static func macMonospacedSystemFontName(size: CGFloat) -> String {
|
||||
NSFont.monospacedSystemFont(ofSize: size, weight: .regular).fontName
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user