Skip to content

Commit d873fd6

Browse files
committed
WinUIBackend: Show menu bar when non-empty, hide when empty
1 parent 1833a1a commit d873fd6

File tree

12 files changed

+720
-376
lines changed

12 files changed

+720
-376
lines changed

Sources/SwiftCrossUI/Scenes/AlertScene.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,21 @@ public final class AlertSceneNode: SceneGraphNode {
4747
self.scene = scene
4848
}
4949

50-
public func update<Backend: AppBackend>(
51-
_ newScene: AlertScene?,
52-
backend: Backend,
50+
public func updateNode(
51+
_ newScene: NodeScene?,
5352
environment: EnvironmentValues
54-
) -> SceneUpdateResult {
53+
) -> SceneNodeUpdateResult {
5554
if let newScene {
5655
self.scene = newScene
5756
}
5857

58+
return .leafScene()
59+
}
60+
61+
public func update<Backend: AppBackend>(
62+
backend: Backend,
63+
environment: EnvironmentValues
64+
) {
5965
if scene.isPresented, alert == nil {
6066
let alert = backend.createAlert()
6167
backend.updateAlert(
@@ -75,7 +81,5 @@ public final class AlertSceneNode: SceneGraphNode {
7581
backend.dismissAlert(alert as! Backend.Alert, window: nil)
7682
self.alert = nil
7783
}
78-
79-
return .leafScene()
8084
}
8185
}

Sources/SwiftCrossUI/Scenes/Graph/SceneGraphNode.swift

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,29 @@ public protocol SceneGraphNode: AnyObject {
2626
environment: EnvironmentValues
2727
)
2828

29+
/// Updates the scene's node without committing anything to screen or
30+
/// propagating the update to child views.
31+
///
32+
/// - Parameters:
33+
/// - newScene: The recomputed scene if the update is due to it being
34+
/// recomputed.
35+
/// - environment: The current root-level environment.
36+
/// - Returns: The result of updating the scene node.
37+
func updateNode(
38+
_ newScene: NodeScene?,
39+
environment: EnvironmentValues
40+
) -> SceneNodeUpdateResult
41+
2942
/// Updates the scene.
3043
///
3144
/// Unlike views (which have state), scenes are only ever updated when
3245
/// they're recomputed or immediately after they're created.
3346
///
3447
/// - Parameters:
35-
/// - newScene: The recomputed scene if the update is due to it being
36-
/// recomputed.
3748
/// - backend: The app's backend.
38-
/// - environment: The current root-level environment.
39-
/// - Returns: The result of updating the scene.
49+
/// - environment: The current environment.
4050
func update<Backend: AppBackend>(
41-
_ newScene: NodeScene?,
4251
backend: Backend,
4352
environment: EnvironmentValues
44-
) -> SceneUpdateResult
53+
)
4554
}

Sources/SwiftCrossUI/Scenes/Graph/SceneUpdateResult.swift renamed to Sources/SwiftCrossUI/Scenes/Graph/SceneNodeUpdateResult.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/// The result of updating a scene.
2-
public struct SceneUpdateResult: Sendable {
1+
/// The result of updating a scene graph node.
2+
public struct SceneNodeUpdateResult: Sendable {
33
/// The preference values produced by the scene and its children.
44
public var preferences: ScenePreferenceValues
55

@@ -9,13 +9,13 @@ public struct SceneUpdateResult: Sendable {
99

1010
/// Creates an update result by combining the preference values of a scene's
1111
/// children.
12-
public init(childResults: [SceneUpdateResult]) {
12+
public init(childResults: [SceneNodeUpdateResult]) {
1313
preferences = ScenePreferenceValues(merging: childResults.map(\.preferences))
1414
}
1515

1616
/// Creates the layout result of a leaf scene (one with no children and no
1717
/// special preference behaviour). Uses ``ScenePreferenceValues/default``.
1818
public static func leafScene() -> Self {
19-
SceneUpdateResult(preferences: .default)
19+
SceneNodeUpdateResult(preferences: .default)
2020
}
2121
}

Sources/SwiftCrossUI/Scenes/Modifiers/CommandsModifier.swift

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,26 @@ final class CommandsModifierNode<Content: Scene>: SceneGraphNode {
4141
)
4242
}
4343

44-
func update<Backend: AppBackend>(
44+
func updateNode(
4545
_ newScene: NodeScene?,
46-
backend: Backend,
4746
environment: EnvironmentValues
48-
) -> SceneUpdateResult {
47+
) -> SceneNodeUpdateResult {
4948
if let newScene {
5049
self.commands = newScene.commands
5150
}
5251

53-
var result = contentNode.update(
54-
newScene?.content,
52+
var result = contentNode.updateNode(newScene?.content, environment: environment)
53+
result.preferences.commands = result.preferences.commands.overlayed(with: commands)
54+
return result
55+
}
56+
57+
func update<Backend: AppBackend>(
58+
backend: Backend,
59+
environment: EnvironmentValues
60+
) {
61+
contentNode.update(
5562
backend: backend,
5663
environment: environment
5764
)
58-
result.preferences.commands = result.preferences.commands.overlayed(with: commands)
59-
return result
6065
}
6166
}

Sources/SwiftCrossUI/Scenes/Modifiers/SceneEnvironmentModifier.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,25 @@ final class SceneEnvironmentModifierNode<Content: Scene>: SceneGraphNode {
6464
)
6565
}
6666

67-
func update<Backend: AppBackend>(
67+
func updateNode(
6868
_ newScene: NodeScene?,
69-
backend: Backend,
7069
environment: EnvironmentValues
71-
) -> SceneUpdateResult {
70+
) -> SceneNodeUpdateResult {
7271
if let newScene {
7372
self.modification = newScene.modification
7473
}
7574

76-
return contentNode.update(
75+
return contentNode.updateNode(
7776
newScene?.content,
77+
environment: modification(environment)
78+
)
79+
}
80+
81+
func update<Backend: AppBackend>(
82+
backend: Backend,
83+
environment: EnvironmentValues
84+
) {
85+
contentNode.update(
7886
backend: backend,
7987
environment: modification(environment)
8088
)

0 commit comments

Comments
 (0)