Scene.windowIdealSize(.fitToContent) seems not working

Hi everyone,

Something didn't work in my environment so I wrote some demo code:

import SwiftUI

@main
struct DemoApp: App {
    var body: some Scene {
        WindowGroup {
            Color.accentColor.opacity(1/4)
                .frame(idealWidth: 800, idealHeight: 800)
        }
        .windowIdealSize(.fitToContent)
    }
}

I expected a 800*800 window (then +28pt top) using .windowIdealSize(.fitToContent). Otherwise I can't control these views that use up available space such as Color, Spacer, GeometryReader, etc.

Was I missing something? Or this is a problem or intended framework design?

Environments:

  • macOS 15.4.1 (24E263) and 15.5 beta 4 (24F5068b)
  • Xcode 16.3 (16E140)

You might want to specify the minWidth, minHeight and the resizability strategy to contentSize. For example:

 var body: some Scene {
        WindowGroup {
            Color.accentColor.opacity(1/4)
                .frame(
                    minWidth: 500,
                    idealWidth: 800,
                    minHeight: 500,
                    idealHeight: 800
                )
        }
        .windowResizability(.contentSize)
    }

To learn more about window resizability, checkout Positioning and sizing windows

I did't fully read the documentation and misunderstood this API.

Scene.windowIdealSize(_:) is for zooming in macOS. (The command "Window" > "Zoom" can trigger it.) This also explains why there exists WindowIdealSize.maximum, I think.

For my needs, I used Scene.defaultSize and people would see my designed window size on first-time window presentation.

WindowGroup {
    Color.accentColor.opacity(1/4)
        .frame(minWidth: 500, minHeight: 500)
        .frame(idealWidth: 800, idealHeight: 800)
    }
    
    // For window zooming (a macOS feature),
    // which can be accessed via double-clicking the window title bar (see Settings).
    .windowIdealSize(.fitToContent)
    
    // For window size on first presentation
    .defaultSize(width: 640, height: 640)

In this example, people will see 640640 window for the first time. Also, when people zoom this window, it expands to 800800, not as large as it can.