Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions Sources/OpenSwiftUICore/View/Text/Text/Text+Encapsulation.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
31 changes: 31 additions & 0 deletions Sources/OpenSwiftUI_SPI/Shims/UIFoundation/NSTextEncapsulation.h
Original file line number Diff line number Diff line change
@@ -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,
};
Loading