Skip to content

Commit b8534f3

Browse files
committed
Split View.update into View.computeLayout and View.commit
1 parent 8be83ea commit b8534f3

File tree

72 files changed

+1863
-1441
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1863
-1441
lines changed

Benchmarks/LayoutPerformanceBenchmark/LayoutPerformanceBenchmark.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ struct Benchmarks {
3535

3636
@MainActor
3737
func updateNode<V: View>(_ node: ViewGraphNode<V, DummyBackend>, _ size: SIMD2<Int>) {
38-
_ = node.update(proposedSize: size, environment: environment, dryRun: true)
39-
_ = node.update(proposedSize: size, environment: environment, dryRun: false)
38+
_ = node.computeLayout(proposedSize: size, environment: environment)
39+
_ = node.commit()
4040
}
4141

4242
#if BENCHMARK_VIZ

Examples/Sources/WindowingExample/WindowingApp.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ struct WindowingApp: App {
177177
}
178178

179179
Image(Bundle.module.bundleURL.appendingPathComponent("Banner.png"))
180+
.resizable()
181+
.aspectRatio(contentMode: .fit)
180182

181183
Divider()
182184

Sources/AppKitBackend/AppKitBackend.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ public final class AppKitBackend: AppBackend {
3131
// We assume that all scrollers have their controlSize set to `.regular` by default.
3232
// The internet seems to indicate that this is true regardless of any system wide
3333
// preferences etc.
34-
Int(
34+
let result = Int(
3535
NSScroller.scrollerWidth(
3636
for: .regular,
3737
scrollerStyle: NSScroller.preferredScrollerStyle
3838
).rounded(.awayFromZero)
3939
)
40+
print(result)
41+
return result
4042
}
4143

4244
private let appDelegate = NSCustomApplicationDelegate()

Sources/AppKitBackend/NSViewRepresentable.swift

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,14 @@ extension View where Self: NSViewRepresentable {
139139
}
140140
}
141141

142-
public func update<Backend: AppBackend>(
142+
public func computeLayout<Backend: AppBackend>(
143143
_ widget: Backend.Widget,
144144
children: any ViewGraphNodeChildren,
145145
proposedSize: SIMD2<Int>,
146146
environment: EnvironmentValues,
147-
backend: Backend,
148-
dryRun: Bool
149-
) -> ViewUpdateResult {
150-
guard let backend = backend as? AppKitBackend else {
147+
backend: Backend
148+
) -> ViewLayoutResult {
149+
guard backend is AppKitBackend else {
151150
fatalError("NSViewRepresentable updated by \(Backend.self)")
152151
}
153152

@@ -160,11 +159,17 @@ extension View where Self: NSViewRepresentable {
160159
context: representingWidget.context!
161160
)
162161

163-
if !dryRun {
164-
backend.setSize(of: representingWidget, to: size.size)
165-
}
162+
return ViewLayoutResult.leafView(size: size)
163+
}
166164

167-
return ViewUpdateResult.leafView(size: size)
165+
public func commit<Backend: AppBackend>(
166+
_ widget: Backend.Widget,
167+
children: any ViewGraphNodeChildren,
168+
layout: ViewLayoutResult,
169+
environment: EnvironmentValues,
170+
backend: Backend
171+
) {
172+
backend.setSize(of: widget, to: layout.size.size)
168173
}
169174
}
170175

0 commit comments

Comments
 (0)