TechnologiesSwiftUI

WindowLayoutRoot struct

iOSmacOStvOSwatchOSvisionOS✓ renders

A proxy which represents the root contents of a window.

How it works

A WindowLayoutRoot is the proxy that stands in for a window's root content while you arrange that window inside a custom WindowLayout. Rather than holding a view you build yourself, it represents the scene's own root — the content SwiftUI has already produced — so you can place, size, and position it within a layout container of your choosing. Reach for WindowLayoutRoot when a standard window presentation isn't enough and you need to drive where the root content lands, for example when composing utility panels or a bespoke document-window arrangement around the same root view you would otherwise show on its own.

  1. Treat the root view as the laid-out content

    WindowLayoutRoot wraps whatever a scene declares as its root — here the VStack containing the macwindow Image, the "Document Window" Text, and its "Root content for a window scene" subtitle. You don't reconstruct that hierarchy inside the layout; the proxy already carries it, and your job is to decide where it sits.

  2. Place the proxy inside a layout container

    Because WindowLayoutRoot conforms to View, you embed it in any container — a VStack, an HStack, or a frame — exactly where you want the window's content to appear. The example's own VStack(spacing: 16) is the kind of arrangement the proxy plugs into, letting the surrounding layout drive ordering and spacing.

  3. Stretch the content to fill the window

    Apply standard sizing modifiers to the root so it grows to occupy the window's bounds. The example reaches the window edges with .frame(maxWidth: .infinity, maxHeight: .infinity); applied to a WindowLayoutRoot, the same modifier makes the root content expand to fill the area the layout assigns it rather than hugging its intrinsic size.

  4. Inset the root with padding

    Layout modifiers compose around the proxy just as they would around any view, so you can give the root breathing room before it meets the window chrome. The .padding() in the example demonstrates that final inset — the root content is positioned, sized, and then padded within the window the layout produces.

Try it — Wrap the body in an HStack and add a second copy of the content beside it, then change .frame(maxWidth: .infinity, maxHeight: .infinity) to .frame(maxWidth: 240) to watch the root content stop filling the window and instead claim a fixed share of the layout.

Example & preview

Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.

WindowLayoutRoot.swift
struct WindowLayoutRootDemo: View {
    var body: some View {
        VStack(spacing: 16) {
            Image(systemName: "macwindow")
                .font(.system(size: 44))
                .foregroundStyle(.tint)
            Text("Document Window")
                .font(.title2.bold())
            Text("Root content for a window scene")
                .font(.subheadline)
                .foregroundStyle(.secondary)
        }
        .frame(maxWidth: .infinity, maxHeight: .infinity)
        .padding()
    }
}
Live preview
Document Window Root content for a window scene
Document Window Root content for a window scene
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →