Add instrument checkbox selection
This commit is contained in:
@@ -2,6 +2,7 @@ import MusicAssistantCore
|
||||
import SwiftUI
|
||||
|
||||
struct InstrumentBrowserView: View {
|
||||
@Binding private var project: SongProject
|
||||
private let catalog: LocalInstrumentCatalog
|
||||
|
||||
@State private var searchText = ""
|
||||
@@ -9,7 +10,11 @@ struct InstrumentBrowserView: View {
|
||||
@State private var selectedRegionOrigin: String?
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
|
||||
init(catalog: LocalInstrumentCatalog = LocalInstrumentCatalog()) {
|
||||
init(
|
||||
project: Binding<SongProject>,
|
||||
catalog: LocalInstrumentCatalog = LocalInstrumentCatalog()
|
||||
) {
|
||||
_project = project
|
||||
self.catalog = catalog
|
||||
}
|
||||
|
||||
@@ -50,21 +55,24 @@ struct InstrumentBrowserView: View {
|
||||
),
|
||||
id: \.id
|
||||
) { instrument in
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text(instrument.name)
|
||||
.font(.body.weight(.medium))
|
||||
Toggle(isOn: selectionBinding(for: instrument)) {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text(instrument.name)
|
||||
.font(.body.weight(.medium))
|
||||
|
||||
HStack(spacing: 6) {
|
||||
Text(instrument.familyCategory)
|
||||
HStack(spacing: 6) {
|
||||
Text(instrument.familyCategory)
|
||||
|
||||
if let regionOrigin = instrument.regionOrigin {
|
||||
Text(regionOrigin)
|
||||
if let regionOrigin = instrument.regionOrigin {
|
||||
Text(regionOrigin)
|
||||
}
|
||||
}
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
.lineLimit(1)
|
||||
}
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
.lineLimit(1)
|
||||
}
|
||||
.toggleStyle(.checkbox)
|
||||
.padding(.vertical, 2)
|
||||
}
|
||||
}
|
||||
@@ -80,8 +88,31 @@ struct InstrumentBrowserView: View {
|
||||
}
|
||||
.frame(minWidth: 460, minHeight: 520)
|
||||
}
|
||||
|
||||
private func selectionBinding(for instrument: InstrumentCatalogItem) -> Binding<Bool> {
|
||||
Binding {
|
||||
project.isInstrumentSelected(id: instrument.id)
|
||||
} set: { isSelected in
|
||||
project.setInstrumentSelected(
|
||||
id: instrument.id,
|
||||
isSelected: isSelected,
|
||||
variant: instrument.name
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
InstrumentBrowserView()
|
||||
InstrumentBrowserPreview()
|
||||
}
|
||||
|
||||
private struct InstrumentBrowserPreview: View {
|
||||
@State private var project = SongProject(
|
||||
title: "Instrument Browser Preview",
|
||||
idea: "Browse the instrument catalog."
|
||||
)
|
||||
|
||||
var body: some View {
|
||||
InstrumentBrowserView(project: $project)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user