Skip to content
Merged
73 changes: 63 additions & 10 deletions src/frontend/swiftui/EmulationToolbarItems.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ struct EmulationToolbarItems: ToolbarContent {
@EnvironmentObject var globalState: GlobalState

@State private var isRunning: Bool = false
@State private var isFramerateUnlocked = false

var body: some ToolbarContent {
#if os(macOS)
Expand All @@ -30,22 +31,74 @@ struct EmulationToolbarItems: ToolbarContent {
}

ToolbarItemGroup(placement: .confirmationAction) {
Button("Console Mode", systemImage: "inset.filled.tv") {
globalState.isHandheldMode.toggle()
if isFramerateUnlocked {
Button{
isFramerateUnlocked.toggle()
} label: {
ZStack {
Image(systemName: "square.stack.3d.down.forward")
Image(systemName: "lock")
.symbolVariant(.none)
.font(.footnote)
.offset(x: 10, y: 5)
}
}
.help("Lock Framerate to 60fps")
} else {
Button{
isFramerateUnlocked.toggle()
} label: {
ZStack {
Image(systemName: "square.stack.3d.down.forward")
Image(systemName: "lock.open")
.symbolVariant(.none)
.font(.footnote)
.offset(x: 10, y: 5)
}
}
.help("Unlock Framerate")
}
}

// This compiler check is only needed when compiling on a macOS version earlier than 26
#if compiler(>=6.2.3)
if #available(macOS 26.0, *) {
ToolbarSpacer(.fixed)
}
.disabled(!globalState.isHandheldMode)
.help("Change to Console mode")

Button("Handheld Mode", systemImage: "formfitting.gamecontroller.fill") {
globalState.isHandheldMode.toggle()
#endif

if #available(macOS 26.0, *) {
ToolbarItemGroup(placement: .confirmationAction) {
Button("Console Mode", systemImage: "inset.filled.tv") {
globalState.isHandheldMode.toggle()
}
.disabled(!globalState.isHandheldMode)
.help("Change to Console mode")

Button("Handheld Mode", systemImage: "formfitting.gamecontroller.fill") {
globalState.isHandheldMode.toggle()
}
.disabled(globalState.isHandheldMode)
.help("Change to Handheld mode")
}
} else {
ToolbarItemGroup(placement: .confirmationAction) {
if globalState.isHandheldMode {
Button("Console Mode", systemImage: "inset.filled.tv") {
globalState.isHandheldMode.toggle()
}
.help("Change to Console mode")
} else {
Button("Handheld Mode", systemImage: "formfitting.gamecontroller.fill") {
globalState.isHandheldMode.toggle()
}
.help("Change to Handheld mode")
}
}
.disabled(globalState.isHandheldMode)
.help("Change to Handheld mode")
}
#else
// TODO: options
ToolbarItemGroup(placement: .principal) {}
#endif
}

}