|
12 | 12 | import SwiftUI |
13 | 13 |
|
14 | 14 | //*============================================================================* |
15 | | -// MARK: * Environment x Font [...] |
| 15 | +// MARK: * Environment x Font |
16 | 16 | //*============================================================================* |
| 17 | +//=----------------------------------------------------------------------------= |
| 18 | +// MARK: + Keys |
| 19 | +//=----------------------------------------------------------------------------= |
17 | 20 |
|
18 | 21 | @usableFromInline enum DiffableTextViews_Font: EnvironmentKey { |
19 | 22 | @usableFromInline static let defaultValue: DiffableTextFont? = nil |
20 | 23 | } |
21 | 24 |
|
| 25 | +//=----------------------------------------------------------------------------= |
| 26 | +// MARK: + Values |
| 27 | +//=----------------------------------------------------------------------------= |
| 28 | + |
22 | 29 | extension EnvironmentValues { |
23 | 30 | @inlinable var diffableTextViews_font: DiffableTextFont? { |
24 | 31 | get { self[DiffableTextViews_Font.self] } |
25 | 32 | set { self[DiffableTextViews_Font.self] = newValue } |
26 | 33 | } |
27 | 34 | } |
28 | 35 |
|
| 36 | +//=----------------------------------------------------------------------------= |
| 37 | +// MARK: + View |
| 38 | +//=----------------------------------------------------------------------------= |
| 39 | + |
29 | 40 | public extension View { |
30 | | - @inlinable func diffableTextViews_font(_ font: DiffableTextFont?) -> some View { |
31 | | - environment(\.diffableTextViews_font, font) |
| 41 | + |
| 42 | + /// Sets the default font for text in diffable text views. |
| 43 | + /// |
| 44 | + /// It is similar to `View/font(_:)` but uses a SwiftUI-esque system font type. |
| 45 | + /// |
| 46 | + /// ``` |
| 47 | + /// DiffableTextField("Monospaced", value: $value, style: style) |
| 48 | + /// .diffableTextViews_font(.body.monospaced()) |
| 49 | + /// ``` |
| 50 | + /// |
| 51 | + /// Monospaced fonts are recommended because they make as-you-type formatting |
| 52 | + /// more visually predictable. Sometimes it does not matter much, however. As-you-type |
| 53 | + /// formatting with trailing text alignment works fine with just about any font, |
| 54 | + /// because then the caret and/or selection does not jump around as much. |
| 55 | + /// |
| 56 | + /// **Notes** |
| 57 | + /// |
| 58 | + /// - The default value is `DiffableTextFont.body`. |
| 59 | + /// - It is not yet possible to convert `SwiftUI.Font` to `UIKit.UIFont`. |
| 60 | + /// |
| 61 | + @inlinable func diffableTextViews_font(_ font: DiffableTextFont?) -> some View { |
| 62 | + self.environment(\.diffableTextViews_font, font) |
32 | 63 | } |
33 | 64 | } |
34 | 65 |
|
|
0 commit comments