137 lines
3.6 KiB
Swift
137 lines
3.6 KiB
Swift
//
|
|
// Demo.swift
|
|
// MacBackend
|
|
//
|
|
// Created by david-swift on 25.09.23.
|
|
//
|
|
|
|
// swiftlint:disable missing_docs no_magic_numbers closure_body_length
|
|
|
|
import Foundation
|
|
import MacBackend
|
|
|
|
@main
|
|
struct Demo: App {
|
|
|
|
var app = MacApp(id: "dev.aparoksha.Demo")
|
|
|
|
@State("bool")
|
|
private var bool = false
|
|
@State(blockUpdates: true)
|
|
private var width = 500
|
|
@State(blockUpdates: true)
|
|
private var height = 450
|
|
@State private var elements: [Element] = [.init()]
|
|
@State private var selectedElement: String?
|
|
@State private var selection = "Hello"
|
|
@State private var path: NavigationPath<Navigation> = .init()
|
|
|
|
var scene: Scene {
|
|
Window("Main", id: "main") { _ in
|
|
NavigationSplitView {
|
|
List(elements, selection: $selectedElement) { element in
|
|
Label(element.id, icon: .system(name: "play.fill"))
|
|
}
|
|
} detail: {
|
|
NavigationStack(path: $path) { navigation in
|
|
Button(navigation.description) {
|
|
selectedElement = nil
|
|
}
|
|
} initialView: {
|
|
VStack {
|
|
Button(selectedElement ?? "World") {
|
|
let element = Element()
|
|
elements.append(element)
|
|
selectedElement = element.id
|
|
}
|
|
Button("Navigate") {
|
|
path.push(.test)
|
|
}
|
|
}
|
|
.toolbar {
|
|
Button("World", icon: .system(name: "globe")) {
|
|
print("World")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.frame(width: $width, height: $height)
|
|
MenuBar {
|
|
Menu("Test") {
|
|
MenuButton(bool.description) {
|
|
bool.toggle()
|
|
}
|
|
.keyboardShortcut("h")
|
|
.selected(bool)
|
|
Divider()
|
|
Menu("Test") {
|
|
MenuButton("Hi") {}
|
|
Menu("Hi?") { }
|
|
}
|
|
MenuButton("Hello") {
|
|
print("Hello")
|
|
}
|
|
.enabled(bool)
|
|
.keyboardShortcut("s")
|
|
MenuButton("World") {
|
|
print("World")
|
|
}
|
|
Menu("Actions") {
|
|
MenuButton("Quit") {
|
|
app.quit()
|
|
}
|
|
}
|
|
}
|
|
Menu("Quit") {
|
|
MenuButton("Quit") {
|
|
app.quit()
|
|
}
|
|
.keyboardShortcut("q")
|
|
}
|
|
} app: {
|
|
MenuButton("About Demo") {
|
|
app.showAboutWindow()
|
|
}
|
|
Divider()
|
|
ServicesMenu("Services")
|
|
Divider()
|
|
MenuButton("Hide Demo") {
|
|
app.hide()
|
|
}
|
|
.keyboardShortcut("h")
|
|
MenuButton("Hide Others") {
|
|
app.hideOthers()
|
|
}
|
|
.keyboardShortcut(.init("h", alt: true))
|
|
MenuButton("Show All") {
|
|
app.showAll()
|
|
}
|
|
Divider()
|
|
MenuButton("Quit Demo") {
|
|
app.quit()
|
|
}
|
|
.keyboardShortcut("q")
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
struct Element: Identifiable {
|
|
|
|
var id: String = UUID().uuidString
|
|
|
|
}
|
|
|
|
enum Navigation: CustomStringConvertible {
|
|
|
|
case test
|
|
|
|
var description: String {
|
|
"Test"
|
|
}
|
|
|
|
}
|
|
|
|
// swiftlint:enable missing_docs no_magic_numbers closure_body_length
|