diff --git a/Sources/OpenSwiftUICore/View/Text/Text/Text+Encapsulation.swift b/Sources/OpenSwiftUICore/View/Text/Text/Text+Encapsulation.swift new file mode 100644 index 000000000..399f44c94 --- /dev/null +++ b/Sources/OpenSwiftUICore/View/Text/Text/Text+Encapsulation.swift @@ -0,0 +1,96 @@ +// +// Text+Encapsulation.swift +// OpenSwiftUICore +// +// Audited for 6.5.4 +// Status: Complete + +public import OpenCoreGraphicsShims +import UIFoundation_Private + +@_spi(Private) +@available(OpenSwiftUI_v4_0, *) +extension Text { + public struct Encapsulation: Hashable, Sendable { + var scale: Scale? + var shape: Shape? + var style: Style? + var lineWeight: CGFloat? + var color: Color? + var minimumWidth: CGFloat? + var platterSize: PlatterSize? + + @_disfavoredOverload + public init( + scale: Text.Encapsulation.Scale? = nil, + shape: Text.Encapsulation.Shape? = nil, + style: Text.Encapsulation.Style? = nil, + lineWeight: CGFloat? = nil, + color: Color? = nil, + minimumWidth: CGFloat? = nil + ) { + self.scale = scale + self.shape = shape + self.style = style + self.lineWeight = lineWeight + self.color = color + self.minimumWidth = minimumWidth + } + + @available(OpenSwiftUI_v5_0, *) + public init( + scale: Text.Encapsulation.Scale? = nil, + shape: Text.Encapsulation.Shape? = nil, + style: Text.Encapsulation.Style? = nil, + platterSize: Text.Encapsulation.PlatterSize? = nil, + lineWeight: CGFloat? = nil, + color: Color? = nil, + minimumWidth: CGFloat? = nil + ) { + self.scale = scale + self.shape = shape + self.style = style + self.platterSize = platterSize + self.lineWeight = lineWeight + self.color = color + self.minimumWidth = minimumWidth + } + + public struct Scale: Hashable, Sendable { + let nsScale: NSTextEncapsulationScale + + public static let small: Text.Encapsulation.Scale = .init(nsScale: .small) + + public static let medium: Text.Encapsulation.Scale = .init(nsScale: .medium) + + public static let large: Text.Encapsulation.Scale = .init(nsScale: .large) + } + + public struct Shape: Hashable, Sendable { + let nsShape: NSTextEncapsulationShape + + public static let rectangle: Text.Encapsulation.Shape = .init(nsShape: .rectangle) + + public static let roundedRectangle: Text.Encapsulation.Shape = .init(nsShape: .roundedRectangle) + + public static let capsule: Text.Encapsulation.Shape = .init(nsShape: .capsule) + } + + public struct Style: Hashable, Sendable { + let nsStyle: NSTextEncapsulationStyle + + public static let outline: Text.Encapsulation.Style = .init(nsStyle: .outline) + + public static let fill: Text.Encapsulation.Style = .init(nsStyle: .fill) + } + + @available(OpenSwiftUI_v5_0, *) + public struct PlatterSize: Hashable, Sendable { + let nsPlatterSize: NSTextEncapsulationPlatterSize + + public static let regular: Text.Encapsulation.PlatterSize = .init(nsPlatterSize: .regular) + + public static let large: Text.Encapsulation.PlatterSize = .init(nsPlatterSize: .large) + } + } +} diff --git a/Sources/OpenSwiftUI_SPI/Shims/UIFoundation/NSTextEncapsulation.h b/Sources/OpenSwiftUI_SPI/Shims/UIFoundation/NSTextEncapsulation.h new file mode 100644 index 000000000..4d49e16e2 --- /dev/null +++ b/Sources/OpenSwiftUI_SPI/Shims/UIFoundation/NSTextEncapsulation.h @@ -0,0 +1,31 @@ +// +// NSTextEncapsulation.h +// OpenSwiftUI_SPI + +#pragma once + +#include "OpenSwiftUIBase.h" + +typedef unsigned long NSUInteger; + +typedef OPENSWIFTUI_CLOSED_ENUM(NSUInteger, NSTextEncapsulationScale) { + NSTextEncapsulationScaleMedium = 0x0, + NSTextEncapsulationScaleSmall = 0x1, + NSTextEncapsulationScaleLarge = 0x2, +}; + +typedef OPENSWIFTUI_CLOSED_ENUM(NSUInteger, NSTextEncapsulationShape) { + NSTextEncapsulationShapeRoundedRectangle = 0x0, + NSTextEncapsulationShapeRectangle = 0x1, + NSTextEncapsulationShapeCapsule = 0x2, +}; + +typedef OPENSWIFTUI_CLOSED_ENUM(NSUInteger, NSTextEncapsulationStyle) { + NSTextEncapsulationStyleOutline = 0x0, + NSTextEncapsulationStyleFill = 0x1, +}; + +typedef OPENSWIFTUI_CLOSED_ENUM(NSUInteger, NSTextEncapsulationPlatterSize) { + NSTextEncapsulationPlatterSizeRegular = 0x0, + NSTextEncapsulationPlatterSizeLarge = 0x1, +};