Skip to content

Commit

Permalink
VGSL sources update
Browse files Browse the repository at this point in the history
38cd55c2b239bba6ecbf56b9c6970e62b3ef817a
  • Loading branch information
booster committed Mar 22, 2024
1 parent 721da42 commit 8524dcc
Show file tree
Hide file tree
Showing 19 changed files with 205 additions and 123 deletions.
30 changes: 16 additions & 14 deletions BasePublic/CGSizeExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ extension CGSize {
let selfRatio = aspectRatio else {
return nil
}
let multiplier: CGFloat = if sizeRatio > selfRatio {
// rect is "wider", so we cut top and bottom of self
size.width / width
} else {
// rect is "higher", so we cut left and right of self
size.height / height
}
let multiplier: CGFloat =
if sizeRatio > selfRatio {
// rect is "wider", so we cut top and bottom of self
size.width / width
} else {
// rect is "higher", so we cut left and right of self
size.height / height
}

return (self * multiplier).rounded()
}
Expand All @@ -52,13 +53,14 @@ extension CGSize {
return nil
}

let multiplier: CGFloat = if sizeRatio > selfRatio {
size.height / height
// rect is "wider", so we leave empty sides
} else {
// rect is "higher", so we leave empty top and bottom
size.width / width
}
let multiplier: CGFloat =
if sizeRatio > selfRatio {
size.height / height
// rect is "wider", so we leave empty sides
} else {
// rect is "higher", so we leave empty top and bottom
size.width / width
}

return (self * multiplier).rounded()
}
Expand Down
11 changes: 6 additions & 5 deletions BasePublic/ImageContentMode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,12 @@ extension ImageContentMode {

extension ImageContentMode: CustomDebugStringConvertible {
public var debugDescription: String {
let alignmentDescription = if verticalAlignment == .center, horizontalAlignment == .center {
"\(verticalAlignment)"
} else {
"\(verticalAlignment)-\(horizontalAlignment)"
}
let alignmentDescription =
if verticalAlignment == .center, horizontalAlignment == .center {
"\(verticalAlignment)"
} else {
"\(verticalAlignment)-\(horizontalAlignment)"
}
return "Scale: \(scale), Alignment: \(alignmentDescription)"
}
}
11 changes: 6 additions & 5 deletions BasePublic/LinkedListOrderedDictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ public final class LinkedListOrderedDictionary<T>: OrderedDictionary {
keyToNode: [key: newNode]
)
case let .nonEmpty(head: head, tail: tail, keyToNode: keyToNode):
let newTail = if newNode.key == tail.key {
tail.previous ?? tail
} else {
tail
}
let newTail =
if newNode.key == tail.key {
tail.previous ?? tail
} else {
tail
}
if newNode.key != head.key {
newNode.previous?.next = newNode.next
newNode.next?.previous = newNode.previous
Expand Down
1 change: 0 additions & 1 deletion BasePublic/ParameterizedDiskCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ private enum State<Storage> {
case loaded(storage: Storage)
}


enum ParameterizedDiskCacheErrors: Error {
case keyNotFound
}
21 changes: 11 additions & 10 deletions BasePublic/RGBAColorExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@ extension RGBAColor {
let colorValue = hexString.dropFirst()
guard let format = HexStringFormat(rawValue: colorValue.count) else { return nil }
do {
let argb: UInt32 = switch format {
case .rgb:
try colorValueForShortFormat(colorValue) | 0xFF_00_00_00
case .argb:
try colorValueForShortFormat(colorValue)
case .rrggbb:
try colorValueForFullFormat(colorValue) | 0xFF_00_00_00
case .aarrggbb:
try colorValueForFullFormat(colorValue)
}
let argb: UInt32 =
switch format {
case .rgb:
try colorValueForShortFormat(colorValue) | 0xFF_00_00_00
case .argb:
try colorValueForShortFormat(colorValue)
case .rrggbb:
try colorValueForFullFormat(colorValue) | 0xFF_00_00_00
case .aarrggbb:
try colorValueForFullFormat(colorValue)
}
return colorWithARGBHexCode(argb)
} catch {
return nil
Expand Down
26 changes: 14 additions & 12 deletions BasePublic/RadialGradientView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,20 @@ public final class RadialGradientView: UIView {
}

private var startPoint: CGPoint {
let centerX: CGFloat = switch gradient.centerX {
case let .relative(x):
x
case let .absolute(x):
CGFloat(x) / bounds.width
}
let centerY: CGFloat = switch gradient.centerY {
case let .relative(y):
y
case let .absolute(y):
CGFloat(y) / bounds.height
}
let centerX: CGFloat =
switch gradient.centerX {
case let .relative(x):
x
case let .absolute(x):
CGFloat(x) / bounds.width
}
let centerY: CGFloat =
switch gradient.centerY {
case let .relative(y):
y
case let .absolute(y):
CGFloat(y) / bounds.height
}
return CGPoint(x: centerX, y: centerY)
}

Expand Down
21 changes: 11 additions & 10 deletions BasePublic/SettingProperty.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,17 @@ extension SettingProperty where T: Archivable {
}, setter: {
if let newValue = $0 {
// Exported with minimal iOS version 9.0.
let encodedValue = if #available(iOS 11, tvOS 11, *) {
try? NSKeyedArchiver.archivedData(
withRootObject: newValue,
requiringSecureCoding: false
)
} else {
NSKeyedArchiver.archivedData(
withRootObject: newValue
)
}
let encodedValue =
if #available(iOS 11, tvOS 11, *) {
try? NSKeyedArchiver.archivedData(
withRootObject: newValue,
requiringSecureCoding: false
)
} else {
NSKeyedArchiver.archivedData(
withRootObject: newValue
)
}
storage.set(encodedValue, forKey: key)
} else {
storage.removeObject(forKey: key)
Expand Down
11 changes: 6 additions & 5 deletions BasePublic/SingleValueCoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,12 @@ extension FixedWidthInteger {
var bytes: [Base] = []
for i in 0..<(Self.bitWidth / Base.bitWidth) {
let shifted = self >> (i * SignedBase.bitWidth)
let result = if Self.isSigned, i == (Self.bitWidth / Base.bitWidth) - 1 {
Base(bitPattern: SignedBase(truncatingIfNeeded: shifted))
} else {
Base(truncatingIfNeeded: shifted)
}
let result =
if Self.isSigned, i == (Self.bitWidth / Base.bitWidth) - 1 {
Base(bitPattern: SignedBase(truncatingIfNeeded: shifted))
} else {
Base(truncatingIfNeeded: shifted)
}
bytes.append(result)
}
return Data(bytes)
Expand Down
11 changes: 6 additions & 5 deletions BaseUIPublic/AlertButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ public struct AlertButton {
isEnabled: Bool = true,
action customAction: Action.CustomAction?
) {
let action: Action = if let customAction {
.custom(customAction)
} else {
.none
}
let action: Action =
if let customAction {
.custom(customAction)
} else {
.none
}
self.init(
title: title,
actionStyle: actionStyle,
Expand Down
7 changes: 6 additions & 1 deletion BaseUIPublic/BackgroundAttribute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@
import CoreGraphics
import Foundation

import BaseTinyPublic

public final class BackgroundAttribute {
public static let Key = NSAttributedString.Key("RangeBackground")

public let color: CGColor
public let range: CFRange
public let padding: EdgeInsets?

public init(
color: CGColor,
range: CFRange
range: CFRange,
padding: EdgeInsets? = nil
) {
self.color = color
self.range = range
self.padding = padding
}

public func apply(to str: CFMutableAttributedString, at range: CFRange) {
Expand Down
4 changes: 2 additions & 2 deletions BaseUIPublic/Label.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ public final class Label: UIView {
inContext: context,
rect: rect,
actionKey: .link,
backgroundKey: nil,
borderKey: nil,
backgroundKey: BackgroundAttribute.Key,
borderKey: BorderAttribute.Key,
selectedRange: nil
)
}
Expand Down
26 changes: 14 additions & 12 deletions BaseUIPublic/NSAttributedStringExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,7 @@ extension CTLine {
}

let borderWidth = border?.width ?? 0
let padding = background?.padding ?? .zero

let scaleX = (run.typographicBounds.width - borderWidth) / run.typographicBounds.width
let scaleY = (run.typographicBounds.height - borderWidth) / run.typographicBounds.height
Expand All @@ -1034,17 +1035,17 @@ extension CTLine {
roundedRect: CGRect(
origin: .zero,
size: CGSize(
width: run.typographicBounds.width,
height: run.typographicBounds.height
width: run.typographicBounds.width + padding.horizontalInsets.sum,
height: run.typographicBounds.height + padding.verticalInsets.sum
)
),
byRoundingCorners: corners,
cornerRadii: CGSize(squareDimension: border?.cornerRadius ?? 0)
)
path.apply(CGAffineTransform(scaleX: scaleX, y: scaleY))
path.apply(CGAffineTransform(
translationX: runPosition.x + borderWidth / 2,
y: runPosition.y + borderWidth / 2 - run.typographicBounds.descent
translationX: runPosition.x + borderWidth / 2 - padding.left,
y: runPosition.y + borderWidth / 2 - run.typographicBounds.descent - padding.bottom
))

context.saveGState()
Expand Down Expand Up @@ -1272,14 +1273,15 @@ extension CGContext {
return
}
// fix for UIKit compatibility
let offsetToUse: CGSize = if #available(iOS 14, *) {
shadow.shadowOffset
} else {
CGSize(
width: shadow.shadowOffset.width,
height: -shadow.shadowOffset.height
)
}
let offsetToUse: CGSize =
if #available(iOS 14, *) {
shadow.shadowOffset
} else {
CGSize(
width: shadow.shadowOffset.width,
height: -shadow.shadowOffset.height
)
}
setShadow(
offset: offsetToUse,
blur: shadow.shadowBlurRadius,
Expand Down
34 changes: 18 additions & 16 deletions CommonCorePublic/ImageLayerLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,23 +114,25 @@ private func makeOrigin(
contentSize: CGSize,
bounds: CGSize
) -> CGPoint {
let x: CGFloat = switch contentMode.horizontalAlignment {
case .left:
0
case .center:
(bounds.width - contentSize.width) / 2
case .right:
bounds.width - contentSize.width
}
let x: CGFloat =
switch contentMode.horizontalAlignment {
case .left:
0
case .center:
(bounds.width - contentSize.width) / 2
case .right:
bounds.width - contentSize.width
}

let y: CGFloat = switch contentMode.verticalAlignment {
case .top:
0
case .center:
(bounds.height - contentSize.height) / 2
case .bottom:
bounds.height - contentSize.height
}
let y: CGFloat =
switch contentMode.verticalAlignment {
case .top:
0
case .center:
(bounds.height - contentSize.height) / 2
case .bottom:
bounds.height - contentSize.height
}

return CGPoint(x: x, y: y)
}
11 changes: 6 additions & 5 deletions CommonCorePublic/Property+Storage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ extension Property where T: Codable {
if let currentValue = value {
return currentValue
}
let storedValue: T? = if fileManager.fileExists(atPath: fileURL.value.path) {
read(url: fileURL.value, onError: onError)
} else {
nil
}
let storedValue: T? =
if fileManager.fileExists(atPath: fileURL.value.path) {
read(url: fileURL.value, onError: onError)
} else {
nil
}
let currentValue = storedValue ?? initialValue
value = currentValue
return currentValue
Expand Down
Loading

0 comments on commit 8524dcc

Please sign in to comment.