This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ScanSequence<Base: Sequence, Result>: Sequence { | |
let base: Base | |
let first: Result | |
let next: (Result, Base.Element) -> Result | |
func makeIterator() -> PrependIterator<ScanIterator<Base.Iterator, Result>> { | |
.init(base: .init(base: base.makeIterator(), previous: first, combine: next), first: first) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
import simd | |
struct Rotation3DEffect: GeometryEffect { | |
var angle: Angle | |
var axis: (x: CGFloat, y: CGFloat, z: CGFloat) | |
var anchor: UnitPoint = .center | |
var anchorZ: CGFloat = 0 | |
var focalLength: CGFloat | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// import https://gist.github.com/JadenGeller/2cdcc441f936b4b0a7b331ccf13a78ac#file-monitorevents-swift | |
import SwiftUI | |
enum ScrollPhase: Hashable, Sendable { | |
case interactive | |
case momentum | |
case ended | |
} | |
struct ScrollAreaModifier: ViewModifier { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct HFold3DEffectModifier: ViewModifier { | |
var angle: Angle | |
var perspective: Double | |
var anchor: UnitPoint { | |
angle.radians >= 0 ? .leading : .trailing | |
} | |
func visualWidth(width: CGFloat) -> CGFloat { | |
width * cos(angle.radians) / (perspective * sin(abs(angle.radians)) + 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
// FIXME: Is there value to defining this DynamicProperty vs. inlining all this into LazyBindingView? | |
@propertyWrapper | |
struct LazyBinding<Value>: DynamicProperty { | |
var initialValue: Value | |
var makeBinding: () -> Binding<Value> | |
@State var binding: Binding<Value>? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct DynamicWidthTextEditor: View { | |
@Binding var text: String | |
// add spacing after each line to prevent flexible width text editor from reflowing before SwiftUI rerenders | |
var textWithTrailingBlocks: String { | |
text | |
.split(separator: "\n") | |
.map({ $0 + "█." }) | |
.joined(separator: "\n") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension NSEvent { | |
static func keyPress(_ keyPress: KeyPress) -> NSEvent? { | |
guard let eventType = EventType(keyPress.phase) else { return nil } | |
return .keyEvent( | |
with: eventType, | |
location: .zero, | |
modifierFlags: .init(keyPress.modifiers), | |
timestamp: ProcessInfo.processInfo.systemUptime, | |
windowNumber: 0, // TODO: Does it matter that this isn't accurate? | |
context: nil, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct BoundsLayout: Layout { | |
var bounds: (ProposedViewSize, LayoutSubview) -> CGRect | |
func makeCache(subviews: Subviews) -> CGRect { | |
.zero | |
} | |
func sizeThatFits( |