143 lines
5.1 KiB
Swift
143 lines
5.1 KiB
Swift
// The Swift Programming Language
|
|
// https://docs.swift.org/swift-book
|
|
|
|
import Adwaita
|
|
import CMath
|
|
|
|
@main
|
|
struct PMCalc: App {
|
|
let app = AdwaitaApp(id: "me.thealgorithm476.PMCalc.PMCalc")
|
|
@State
|
|
var vm = ViewModel()
|
|
|
|
var scene: Scene {
|
|
Window(id: "main") { window in
|
|
VStack(spacing: 8) {
|
|
Text(vm.display)
|
|
.selectable(false)
|
|
.title2()
|
|
.halign(.end)
|
|
VStack(spacing: 8) {
|
|
HStack(spacing: 8) {
|
|
Button("AC") {
|
|
vm.clear()
|
|
}
|
|
.keyboardShortcut("c", app: app)
|
|
.hexpand()
|
|
.destructive()
|
|
Button("^") {
|
|
vm.operation(.pow)
|
|
}
|
|
.hexpand()
|
|
Button("%") {}
|
|
.keyboardShortcut("percent", app: app)
|
|
.hexpand()
|
|
Button("/") {
|
|
vm.operation(.div)
|
|
}
|
|
.keyboardShortcut("slash", app: app)
|
|
.hexpand()
|
|
}
|
|
.vexpand()
|
|
HStack(spacing: 8) {
|
|
Button("7") {
|
|
vm.addNumber(7)
|
|
}
|
|
.keyboardShortcut("7", app: app)
|
|
.hexpand()
|
|
Button("8") {
|
|
vm.addNumber(8)
|
|
}
|
|
.keyboardShortcut("8", app: app)
|
|
.hexpand()
|
|
Button("9") {
|
|
vm.addNumber(9)
|
|
}
|
|
.keyboardShortcut("9", app: app)
|
|
.hexpand()
|
|
Button("*") {
|
|
vm.operation(.mul)
|
|
}
|
|
.keyboardShortcut("asterisk", app: app)
|
|
.hexpand()
|
|
}
|
|
.vexpand()
|
|
HStack(spacing: 8) {
|
|
Button("4") {
|
|
vm.addNumber(4)
|
|
}
|
|
.keyboardShortcut("4", app: app)
|
|
.hexpand()
|
|
Button("5") {
|
|
vm.addNumber(5)
|
|
}
|
|
.keyboardShortcut("5", app: app)
|
|
.hexpand()
|
|
Button("6") {
|
|
vm.addNumber(6)
|
|
}
|
|
.keyboardShortcut("6", app: app)
|
|
.hexpand()
|
|
Button("-") {
|
|
vm.operation(.sub)
|
|
}
|
|
.keyboardShortcut("minus", app: app)
|
|
.hexpand()
|
|
}
|
|
.vexpand()
|
|
HStack(spacing: 8) {
|
|
Button("1") {
|
|
vm.addNumber(1)
|
|
}
|
|
.keyboardShortcut("1", app: app)
|
|
.hexpand()
|
|
Button("2") {
|
|
vm.addNumber(2)
|
|
}
|
|
.keyboardShortcut("2", app: app)
|
|
.hexpand()
|
|
Button("3") {
|
|
vm.addNumber(3)
|
|
}
|
|
.keyboardShortcut("3", app: app)
|
|
.hexpand()
|
|
Button("+") {
|
|
vm.operation(.add)
|
|
}
|
|
.keyboardShortcut("plus", app: app)
|
|
.hexpand()
|
|
}
|
|
.vexpand()
|
|
HStack(spacing: 8) {
|
|
Button("0") {
|
|
vm.addNumber(0)
|
|
}
|
|
.keyboardShortcut("0", app: app)
|
|
.hexpand()
|
|
Button("sq") {
|
|
vm.operation(.sqrt)
|
|
}
|
|
.hexpand()
|
|
Button(",") {
|
|
vm.addComma()
|
|
}
|
|
.keyboardShortcut("comma", app: app)
|
|
.hexpand()
|
|
Button("=") {
|
|
vm.calculate()
|
|
}
|
|
.keyboardShortcut("equal", app: app)
|
|
.hexpand()
|
|
}
|
|
.vexpand()
|
|
}
|
|
}
|
|
.padding()
|
|
.topToolbar {
|
|
ToolbarView(app: app, window: window)
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|