144 lines
5.9 KiB
Swift
144 lines
5.9 KiB
Swift
import SwiftUI
|
|
|
|
struct FeatureCard: View {
|
|
let title: String
|
|
let systemImage: String
|
|
let detail: String
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading, spacing: 10) {
|
|
Label(title, systemImage: systemImage)
|
|
.font(.headline)
|
|
Text(detail)
|
|
.font(.subheadline)
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
.padding()
|
|
.background(.quaternary.opacity(0.45), in: RoundedRectangle(cornerRadius: 14, style: .continuous))
|
|
}
|
|
}
|
|
|
|
struct ContentView: View {
|
|
@Environment(\.openWindow) private var openWindow
|
|
|
|
@State private var documentTitle = "Swift Window Demo"
|
|
@State private var width: Double = 980
|
|
@State private var height: Double = 640
|
|
@State private var showSheet = false
|
|
@State private var showDialog = false
|
|
|
|
var body: some View {
|
|
NavigationSplitView {
|
|
List {
|
|
Label("Overview", systemImage: "macwindow")
|
|
Label("Window Controls", systemImage: "slider.horizontal.3")
|
|
Label("Secondary Window", systemImage: "uiwindow.split.2x1")
|
|
Label("Dialogs", systemImage: "square.and.pencil")
|
|
}
|
|
.navigationTitle("Capabilities")
|
|
.listStyle(.sidebar)
|
|
} detail: {
|
|
ScrollView {
|
|
VStack(alignment: .leading, spacing: 22) {
|
|
VStack(alignment: .leading, spacing: 8) {
|
|
Text("Main Window Demo")
|
|
.font(.system(size: 34, weight: .bold))
|
|
Text("A current-style SwiftUI macOS app that exercises real desktop window behaviors instead of just rendering a static view.")
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
|
|
Grid(horizontalSpacing: 16, verticalSpacing: 16) {
|
|
GridRow {
|
|
FeatureCard(title: "Resizable", systemImage: "arrow.up.left.and.arrow.down.right", detail: "Set a target content size and apply it to the frontmost app window.")
|
|
FeatureCard(title: "Secondary Window", systemImage: "macwindow.on.rectangle", detail: "Open a separate utility-style scene to prove multi-window support.")
|
|
}
|
|
GridRow {
|
|
FeatureCard(title: "Sheet + Dialog", systemImage: "rectangle.portrait.and.arrow.right", detail: "Trigger standard macOS sheets and confirmation dialogs.")
|
|
FeatureCard(title: "Tray Integration", systemImage: "menubar.rectangle", detail: "Use the menu-bar item to reopen the main window at any time.")
|
|
}
|
|
}
|
|
|
|
GroupBox("Window controls") {
|
|
VStack(alignment: .leading, spacing: 14) {
|
|
TextField("Window title", text: $documentTitle)
|
|
.textFieldStyle(.roundedBorder)
|
|
|
|
HStack {
|
|
VStack(alignment: .leading) {
|
|
Text("Width: \(Int(width))")
|
|
Slider(value: $width, in: 700...1400, step: 10)
|
|
}
|
|
VStack(alignment: .leading) {
|
|
Text("Height: \(Int(height))")
|
|
Slider(value: $height, in: 480...960, step: 10)
|
|
}
|
|
}
|
|
|
|
HStack(spacing: 12) {
|
|
Button("Apply Size") {
|
|
WindowCommandCenter.resizeMainWindow(width: width, height: height)
|
|
}
|
|
Button("Center Window") {
|
|
WindowCommandCenter.centerMainWindow()
|
|
}
|
|
Button("Toggle Full Screen") {
|
|
WindowCommandCenter.toggleFullScreen()
|
|
}
|
|
}
|
|
}
|
|
.padding(.top, 4)
|
|
}
|
|
|
|
HStack(spacing: 12) {
|
|
Button("Open Utility Window") {
|
|
openWindow(id: "inspector")
|
|
}
|
|
Button("Show Sheet") {
|
|
showSheet = true
|
|
}
|
|
Button("Show Confirmation") {
|
|
showDialog = true
|
|
}
|
|
}
|
|
}
|
|
.padding(24)
|
|
}
|
|
.navigationTitle(documentTitle)
|
|
.sheet(isPresented: $showSheet) {
|
|
SheetDemoView()
|
|
}
|
|
.confirmationDialog("Test confirmation dialog", isPresented: $showDialog, titleVisibility: .visible) {
|
|
Button("Acknowledge") {}
|
|
Button("Cancel", role: .cancel) {}
|
|
} message: {
|
|
Text("This validates standard app-window attached dialogs on macOS.")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct SheetDemoView: View {
|
|
@Environment(\.dismiss) private var dismiss
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading, spacing: 16) {
|
|
Text("Attached Sheet")
|
|
.font(.title.bold())
|
|
Text("This sheet is attached to the main app window and demonstrates standard macOS document-style presentation.")
|
|
.foregroundStyle(.secondary)
|
|
HStack {
|
|
Spacer()
|
|
Button("Close") { dismiss() }
|
|
.keyboardShortcut(.defaultAction)
|
|
}
|
|
}
|
|
.padding(24)
|
|
.frame(minWidth: 420, minHeight: 180)
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
ContentView()
|
|
}
|