-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathEmojiProperties.swift
More file actions
37 lines (32 loc) · 1.17 KB
/
Copy pathEmojiProperties.swift
File metadata and controls
37 lines (32 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import SwiftUI
/// Properties that control how Textual renders custom emoji.
///
/// Use `EmojiProperties` to control the emoji’s size and baseline alignment relative to the
/// surrounding text.
///
/// Values are font-relative, so they scale with the current font size.
///
/// You can set these properties using the ``TextualNamespace/emojiProperties(_:)`` modifier.
public struct EmojiProperties: Sendable, Hashable {
/// The emoji size, expressed as a font-relative value.
public var size: FontScaled<CGSize>
/// The emoji baseline offset, expressed as a font-relative value.
public var baselineOffset: FontScaled<CGFloat>
/// Creates emoji properties with a custom size and baseline offset.
public init(
size: FontScaled<CGSize> = .fontScaled(width: 1, height: 1),
baselineOffset: FontScaled<CGFloat> = .fontScaled(-0.1)
) {
self.size = size
self.baselineOffset = baselineOffset
}
}
private struct EmojiPropertiesKey: EnvironmentKey {
static let defaultValue = EmojiProperties()
}
extension EnvironmentValues {
var emojiProperties: EmojiProperties {
get { self[EmojiPropertiesKey.self] }
set { self[EmojiPropertiesKey.self] = newValue }
}
}