Skip to content

Commit

Permalink
Swift UI audio engine settings
Browse files Browse the repository at this point in the history
Signed-off-by: Joseph Mattiello <[email protected]>
  • Loading branch information
JoeMatt committed Nov 9, 2024
1 parent 615d54d commit 3e81bab
Show file tree
Hide file tree
Showing 6 changed files with 282 additions and 212 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// CollapsibleSection.swift
// PVUI
//
// Created by Joseph Mattiello on 11/9/24.
//

import SwiftUI
import PVSettings
import Defaults

internal struct CollapsibleSection<Content: View>: View {
let title: String
let content: Content
@Default(.collapsedSections) var collapsedSections
@State private var isExpanded: Bool

init(title: String, @ViewBuilder content: () -> Content) {
self.title = title
self.content = content()
self._isExpanded = State(initialValue: !Defaults[.collapsedSections].contains(title))
print("Init CollapsibleSection '\(title)' - collapsed sections: \(Defaults[.collapsedSections])")
}

var body: some View {
Section {
if isExpanded {
content
}
} header: {
Button(action: {
withAnimation {
isExpanded.toggle()
print("Setting isExpanded for '\(title)' to \(isExpanded)")
print("Before - collapsed sections: \(collapsedSections)")
if isExpanded {
collapsedSections.remove(title)
} else {
collapsedSections.insert(title)
}
print("After - collapsed sections: \(collapsedSections)")
}
}) {
HStack {
Text(title)
Spacer()
Image(systemName: isExpanded ? "chevron.up" : "chevron.down")
.foregroundColor(.accentColor)
}
}
}
}
}
Loading

0 comments on commit 3e81bab

Please sign in to comment.