mirror of
https://github.com/insidegui/VirtualBuddy.git
synced 2026-12-02 09:59:25 +08:00
117 lines
3.3 KiB
Swift
117 lines
3.3 KiB
Swift
//
|
|
// VMConfigurationView.swift
|
|
// VirtualBuddy
|
|
//
|
|
// Created by Guilherme Rambo on 17/07/22.
|
|
//
|
|
|
|
import SwiftUI
|
|
import VirtualCore
|
|
|
|
public struct VMConfigurationView: View {
|
|
@EnvironmentObject var controller: VMController
|
|
|
|
@Binding var configuration: VBMacConfiguration
|
|
@Binding var hardware: VBMacDevice
|
|
|
|
private var unfocusActiveField = VoidSubject()
|
|
|
|
public init(configuration: Binding<VBMacConfiguration>, hardware: Binding<VBMacDevice>) {
|
|
self._configuration = configuration
|
|
self._hardware = hardware
|
|
}
|
|
|
|
public var body: some View {
|
|
VStack(alignment: .leading, spacing: 16) {
|
|
ConfigurationSection {
|
|
NumericPropertyControl(
|
|
value: $hardware.cpuCount,
|
|
range: VBMacDevice.virtualCPUCountRange,
|
|
step: 1,
|
|
label: "Virtual CPUs",
|
|
formatter: NumberFormatter.numericPropertyControlDefault,
|
|
unfocus: unfocusActiveField
|
|
)
|
|
|
|
NumericPropertyControl(
|
|
value: $hardware.memorySize.gbValue,
|
|
range: VBMacDevice.memorySizeRangeInGigabytes,
|
|
step: VBMacDevice.memorySizeRangeInGigabytes.upperBound / 16,
|
|
label: "Memory (GB)",
|
|
formatter: NumberFormatter.numericPropertyControlDefault,
|
|
unfocus: unfocusActiveField
|
|
)
|
|
} header: {
|
|
HStack {
|
|
Text("General")
|
|
Spacer()
|
|
Image(systemName: "memorychip.fill")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct ConfigurationSection<Header: View, Content: View>: View {
|
|
|
|
@State private var isCollapsed = false
|
|
|
|
var content: () -> Content
|
|
var header: () -> Header
|
|
|
|
init(@ViewBuilder _ content: @escaping () -> Content, @ViewBuilder header: @escaping () -> Header) {
|
|
self.header = header
|
|
self.content = content
|
|
}
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading, spacing: 0) {
|
|
styledHeader
|
|
|
|
if !isCollapsed {
|
|
content()
|
|
.padding()
|
|
.transition(.opacity)
|
|
}
|
|
}
|
|
.controlGroup()
|
|
}
|
|
|
|
@ViewBuilder
|
|
private var styledHeader: some View {
|
|
header()
|
|
.font(.system(size: 14, weight: .medium, design: .rounded))
|
|
.padding(.horizontal)
|
|
.padding(.vertical, 8)
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
.background(Material.ultraThick, in: Rectangle())
|
|
.onTapGesture {
|
|
withAnimation(.default) {
|
|
isCollapsed.toggle()
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
#if DEBUG
|
|
struct VMConfigurationView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
_Template()
|
|
}
|
|
|
|
struct _Template: View {
|
|
@StateObject var controller = VMController(with: .preview)
|
|
|
|
var body: some View {
|
|
VMConfigurationView(configuration: $controller.virtualMachineModel.configuration, hardware: $controller.virtualMachineModel.configuration.hardware)
|
|
.environmentObject(controller)
|
|
.frame(width: 320, height: 400, alignment: .top)
|
|
.padding()
|
|
.padding(100)
|
|
}
|
|
}
|
|
}
|
|
|
|
#endif
|