Skip to content

Commit b0c5e9d

Browse files
authored
Add Text+Encapsulation (#651)
1 parent a68507a commit b0c5e9d

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
//
2+
// Text+Encapsulation.swift
3+
// OpenSwiftUICore
4+
//
5+
// Audited for 6.5.4
6+
// Status: Complete
7+
8+
public import OpenCoreGraphicsShims
9+
import UIFoundation_Private
10+
11+
@_spi(Private)
12+
@available(OpenSwiftUI_v4_0, *)
13+
extension Text {
14+
public struct Encapsulation: Hashable, Sendable {
15+
var scale: Scale?
16+
var shape: Shape?
17+
var style: Style?
18+
var lineWeight: CGFloat?
19+
var color: Color?
20+
var minimumWidth: CGFloat?
21+
var platterSize: PlatterSize?
22+
23+
@_disfavoredOverload
24+
public init(
25+
scale: Text.Encapsulation.Scale? = nil,
26+
shape: Text.Encapsulation.Shape? = nil,
27+
style: Text.Encapsulation.Style? = nil,
28+
lineWeight: CGFloat? = nil,
29+
color: Color? = nil,
30+
minimumWidth: CGFloat? = nil
31+
) {
32+
self.scale = scale
33+
self.shape = shape
34+
self.style = style
35+
self.lineWeight = lineWeight
36+
self.color = color
37+
self.minimumWidth = minimumWidth
38+
}
39+
40+
@available(OpenSwiftUI_v5_0, *)
41+
public init(
42+
scale: Text.Encapsulation.Scale? = nil,
43+
shape: Text.Encapsulation.Shape? = nil,
44+
style: Text.Encapsulation.Style? = nil,
45+
platterSize: Text.Encapsulation.PlatterSize? = nil,
46+
lineWeight: CGFloat? = nil,
47+
color: Color? = nil,
48+
minimumWidth: CGFloat? = nil
49+
) {
50+
self.scale = scale
51+
self.shape = shape
52+
self.style = style
53+
self.platterSize = platterSize
54+
self.lineWeight = lineWeight
55+
self.color = color
56+
self.minimumWidth = minimumWidth
57+
}
58+
59+
public struct Scale: Hashable, Sendable {
60+
let nsScale: NSTextEncapsulationScale
61+
62+
public static let small: Text.Encapsulation.Scale = .init(nsScale: .small)
63+
64+
public static let medium: Text.Encapsulation.Scale = .init(nsScale: .medium)
65+
66+
public static let large: Text.Encapsulation.Scale = .init(nsScale: .large)
67+
}
68+
69+
public struct Shape: Hashable, Sendable {
70+
let nsShape: NSTextEncapsulationShape
71+
72+
public static let rectangle: Text.Encapsulation.Shape = .init(nsShape: .rectangle)
73+
74+
public static let roundedRectangle: Text.Encapsulation.Shape = .init(nsShape: .roundedRectangle)
75+
76+
public static let capsule: Text.Encapsulation.Shape = .init(nsShape: .capsule)
77+
}
78+
79+
public struct Style: Hashable, Sendable {
80+
let nsStyle: NSTextEncapsulationStyle
81+
82+
public static let outline: Text.Encapsulation.Style = .init(nsStyle: .outline)
83+
84+
public static let fill: Text.Encapsulation.Style = .init(nsStyle: .fill)
85+
}
86+
87+
@available(OpenSwiftUI_v5_0, *)
88+
public struct PlatterSize: Hashable, Sendable {
89+
let nsPlatterSize: NSTextEncapsulationPlatterSize
90+
91+
public static let regular: Text.Encapsulation.PlatterSize = .init(nsPlatterSize: .regular)
92+
93+
public static let large: Text.Encapsulation.PlatterSize = .init(nsPlatterSize: .large)
94+
}
95+
}
96+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//
2+
// NSTextEncapsulation.h
3+
// OpenSwiftUI_SPI
4+
5+
#pragma once
6+
7+
#include "OpenSwiftUIBase.h"
8+
9+
typedef unsigned long NSUInteger;
10+
11+
typedef OPENSWIFTUI_CLOSED_ENUM(NSUInteger, NSTextEncapsulationScale) {
12+
NSTextEncapsulationScaleMedium = 0x0,
13+
NSTextEncapsulationScaleSmall = 0x1,
14+
NSTextEncapsulationScaleLarge = 0x2,
15+
};
16+
17+
typedef OPENSWIFTUI_CLOSED_ENUM(NSUInteger, NSTextEncapsulationShape) {
18+
NSTextEncapsulationShapeRoundedRectangle = 0x0,
19+
NSTextEncapsulationShapeRectangle = 0x1,
20+
NSTextEncapsulationShapeCapsule = 0x2,
21+
};
22+
23+
typedef OPENSWIFTUI_CLOSED_ENUM(NSUInteger, NSTextEncapsulationStyle) {
24+
NSTextEncapsulationStyleOutline = 0x0,
25+
NSTextEncapsulationStyleFill = 0x1,
26+
};
27+
28+
typedef OPENSWIFTUI_CLOSED_ENUM(NSUInteger, NSTextEncapsulationPlatterSize) {
29+
NSTextEncapsulationPlatterSizeRegular = 0x0,
30+
NSTextEncapsulationPlatterSizeLarge = 0x1,
31+
};

0 commit comments

Comments
 (0)