Skip to content

Commit

Permalink
Font optionality support
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Apr 4, 2024
1 parent e447d19 commit e756ac2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ Color(nsuiColor: NSUIColor)
Image(nsuiImage: NSUIImage)

// AppKit/UIKit
NSUIFont.init(nsuiDescriptor:, size:)
NSUIFontDescriptor.nsuiWithSymbolicTraits(_:)
NSUITextView.nsuiLayoutManager
```

Expand Down
30 changes: 30 additions & 0 deletions Sources/NSUI/Font.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#if canImport(AppKit) && !targetEnvironment(macCatalyst)
import AppKit

extension NSUIFontDescriptor.SymbolicTraits {
public static let traitItalic = Self.italic
public static let traitBold = Self.bold
public static let traitExpanded = Self.expanded
public static let traitCondensed = Self.condensed
public static let traitMonoSpace = Self.monoSpace
}

#endif

extension NSUIFontDescriptor {
/// NSUI wrapper around `withSymbolicTraits`.
///
/// This can return a nil value on iOS/visionOS.
public func nsuiWithSymbolicTraits(_ symbolicTraits: NSUIFontDescriptor.SymbolicTraits) -> NSUIFontDescriptor? {

Check warning on line 18 in Sources/NSUI/Font.swift

View workflow job for this annotation

GitHub Actions / Test (platform=macOS,variant=Mac Catalyst)

cannot use struct 'SymbolicTraits' here; 'UIKit' was not imported by this file

Check warning on line 18 in Sources/NSUI/Font.swift

View workflow job for this annotation

GitHub Actions / Test (platform=tvOS Simulator,name=Apple TV)

cannot use struct 'SymbolicTraits' here; 'UIKit' was not imported by this file

Check warning on line 18 in Sources/NSUI/Font.swift

View workflow job for this annotation

GitHub Actions / Test (platform=tvOS Simulator,name=Apple TV)

cannot use struct 'SymbolicTraits' here; 'UIKit' was not imported by this file
withSymbolicTraits(symbolicTraits)
}
}

extension NSUIFont {
/// NSUI wrapper around `init`.
///
/// This initializer can fail on macOS.
public convenience init?(nsuiDescriptor: NSUIFontDescriptor, size: CGFloat) {

Check failure on line 27 in Sources/NSUI/Font.swift

View workflow job for this annotation

GitHub Actions / Test (platform=macOS,variant=Mac Catalyst)

cannot find type 'CGFloat' in scope; did you mean to use 'CGFloat'?

Check warning on line 27 in Sources/NSUI/Font.swift

View workflow job for this annotation

GitHub Actions / Test (platform=macOS,variant=Mac Catalyst)

cannot use struct 'CGFloat' here; 'CoreFoundation' was not imported by this file

Check failure on line 27 in Sources/NSUI/Font.swift

View workflow job for this annotation

GitHub Actions / Test (platform=tvOS Simulator,name=Apple TV)

cannot find type 'CGFloat' in scope; did you mean to use 'CGFloat'?

Check warning on line 27 in Sources/NSUI/Font.swift

View workflow job for this annotation

GitHub Actions / Test (platform=tvOS Simulator,name=Apple TV)

cannot use struct 'CGFloat' here; 'CoreFoundation' was not imported by this file

Check failure on line 27 in Sources/NSUI/Font.swift

View workflow job for this annotation

GitHub Actions / Test (platform=tvOS Simulator,name=Apple TV)

cannot find type 'CGFloat' in scope; did you mean to use 'CGFloat'?

Check warning on line 27 in Sources/NSUI/Font.swift

View workflow job for this annotation

GitHub Actions / Test (platform=tvOS Simulator,name=Apple TV)

cannot use struct 'CGFloat' here; 'CoreFoundation' was not imported by this file
self.init(descriptor: nsuiDescriptor, size: size)
}
}
12 changes: 0 additions & 12 deletions Sources/NSUI/FontDescriptor.swift

This file was deleted.

0 comments on commit e756ac2

Please sign in to comment.