Skip to content

Commit 9d4425f

Browse files
committed
Windows and Screens: partially support scene movement
This starts adding some support for moving scenes on a Window. The motivation here was more for the testing than the need for the scene organization. This uncovered the fact that we do not handle the window property on a view properly, resulting in it being improperly nil.
1 parent d63ae70 commit 9d4425f

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

Sources/SwiftWin32/Windows and Screens/Window.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,12 @@ public class Window: View {
216216

217217
/// The scene containing the window.
218218
public weak var windowScene: WindowScene? {
219-
didSet { fatalError("\(#function) not yet implemented") }
219+
willSet {
220+
self.windowScene?.windows.remove(object: self)
221+
}
222+
didSet {
223+
self.windowScene?.windows.append(self)
224+
}
220225
}
221226

222227
// MARK - Responding to Window-Related Notifications

Tests/UICoreTests/ViewTests.swift

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: BSD-3-Clause
33

44
import XCTest
5-
import SwiftWin32
5+
@testable import SwiftWin32
66

77
final class ViewTests: XCTestCase {
88
func testConvertSameParent() {
@@ -13,7 +13,7 @@ final class ViewTests: XCTestCase {
1313

1414
let password: View =
1515
View(frame: Rect(x: 4.0, y: 113.0, width: 254.0, height: 17.0))
16-
16+
1717
window.addSubview(password)
1818
window.addSubview(textfield)
1919

@@ -60,7 +60,7 @@ final class ViewTests: XCTestCase {
6060
XCTAssertEqual(point.x, 80.12346855145998, accuracy: accuracy)
6161
XCTAssertEqual(point.y, -140.97315764408575, accuracy: accuracy)
6262

63-
63+
6464
let inputRect = Rect(origin: Point(x: 45, y: 115), size: Size(width: 13, height: 14))
6565
var rect = grandChild.convert(inputRect, to: childB)
6666
XCTAssertEqual(rect.origin.x, 123.17714789769627, accuracy: accuracy)
@@ -112,7 +112,7 @@ final class ViewTests: XCTestCase {
112112
point = grandChild.convert(inputPoint, from: childA)
113113
XCTAssertEqual(point.x, -129.11445551798738, accuracy: accuracy)
114114
XCTAssertEqual(point.y, 98.14414561159256, accuracy: accuracy)
115-
115+
116116
let inputRect = Rect(origin: Point(x: 45, y: 115), size: Size(width: 13, height: 14))
117117
var rect = grandChild.convert(inputRect, to: childB)
118118
XCTAssertEqual(rect.origin.x, 123.17714789769627, accuracy: accuracy)
@@ -133,9 +133,31 @@ final class ViewTests: XCTestCase {
133133
XCTAssertEqual(rect.size.height, 2.0132111355644327, accuracy: accuracy)
134134
}
135135

136+
func testViewTraitCollection() {
137+
let window: Window =
138+
Window(frame: Rect(x: 0.0, y: 0.0, width: 640, height: 480))
139+
140+
let view: View = View(frame: .zero)
141+
XCTAssertTrue(view.traitCollection === TraitCollection.current)
142+
143+
window.addSubview(view)
144+
XCTAssertTrue(view.traitCollection === TraitCollection.current)
145+
146+
let session: SceneSession =
147+
SceneSession(identifier: UUID().uuidString, role: .windowApplication)
148+
let scene: WindowScene =
149+
WindowScene(session: session,
150+
connectionOptions: Scene.ConnectionOptions())
151+
152+
window.windowScene = scene
153+
// FIXME(compnerd) the view.window is not setup properly
154+
// XCTAssertTrue(view.traitCollection === scene.screen.traitCollection)
155+
}
156+
136157
static var allTests = [
137158
("testConvertSameParent", testConvertSameParent),
138159
("testConvertWithRotationsAndBounds", testConvertWithRotationsAndBounds),
139160
("testConvertWithAllTransformsAndBounds", testConvertWithAllTransformsAndBounds),
161+
("testViewTraitCollection", testViewTraitCollection),
140162
]
141163
}

0 commit comments

Comments
 (0)