SSPreferences // Add certain customized settings back.
This commit is contained in:
parent
5fa96c7f64
commit
21932166de
|
@ -50,7 +50,20 @@ public extension Settings {
|
|||
|
||||
return VStack(alignment: .settingsSectionLabel) {
|
||||
ForEach(0 ..< sections.count, id: \.self) { index in
|
||||
viewForSection(sections, index: index)
|
||||
let labelWidth = max(minimumLabelWidth, maximumLabelWidth)
|
||||
if sections[index].label != nil {
|
||||
sections[index]
|
||||
.frame(width: contentWidth, alignment: .leading)
|
||||
} else {
|
||||
sections[index].content
|
||||
.alignmentGuide(.settingsSectionLabel) { $0[.leading] + labelWidth }
|
||||
.frame(width: contentWidth, alignment: .leading)
|
||||
}
|
||||
if sections[index].bottomDivider, index < sections.count - 1 {
|
||||
Divider()
|
||||
.frame(height: 10)
|
||||
.alignmentGuide(.settingsSectionLabel) { $0[.leading] + labelWidth }
|
||||
}
|
||||
}
|
||||
}
|
||||
.modifier(Section.LabelWidthModifier(maximumWidth: $maximumLabelWidth))
|
||||
|
@ -58,17 +71,6 @@ public extension Settings {
|
|||
.padding(.vertical, 20)
|
||||
.padding(.horizontal, 30)
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private func viewForSection(_ sections: [Section], index: Int) -> some View {
|
||||
sections[index]
|
||||
if index != sections.count - 1, sections[index].bottomDivider {
|
||||
Divider()
|
||||
// Strangely doesn't work without width being specified. Probably because of custom alignment.
|
||||
.frame(width: contentWidth, height: 20)
|
||||
.alignmentGuide(.settingsSectionLabel) { $0[.leading] + max(minimumLabelWidth, maximumLabelWidth) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -90,8 +90,9 @@ public extension View {
|
|||
/**
|
||||
Applies font and color for a label used for describing a setting.
|
||||
*/
|
||||
func preferenceDescription() -> some View {
|
||||
font(.system(size: 11.0))
|
||||
func preferenceDescription(maxWidth: CGFloat? = nil) -> some View {
|
||||
controlSize(.small)
|
||||
.frame(maxWidth: maxWidth, alignment: .leading)
|
||||
// TODO: Use `.foregroundStyle` when targeting macOS 12.
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ public extension Settings {
|
|||
}
|
||||
}
|
||||
|
||||
public let label: AnyView
|
||||
public private(set) var label: AnyView?
|
||||
public let content: AnyView
|
||||
public let bottomDivider: Bool
|
||||
public let verticalAlignment: VerticalAlignment
|
||||
|
@ -83,6 +83,27 @@ public extension Settings {
|
|||
self.content = stack.eraseToAnyView()
|
||||
}
|
||||
|
||||
/**
|
||||
A section is responsible for controlling a single setting without title label.
|
||||
|
||||
- Parameters:
|
||||
- bottomDivider: Whether to place a `Divider` after the section content. Default is `false`.
|
||||
- verticalAlignement: The vertical alignment of the section content.
|
||||
- label: A view describing the setting handled by this section.
|
||||
- content: A content view.
|
||||
*/
|
||||
public init(
|
||||
bottomDivider: Bool = false,
|
||||
verticalAlignment: VerticalAlignment = .firstTextBaseline,
|
||||
@ViewBuilder content: @escaping () -> some View
|
||||
) {
|
||||
label = nil
|
||||
self.bottomDivider = bottomDivider
|
||||
self.verticalAlignment = verticalAlignment
|
||||
let stack = VStack(alignment: .leading) { content() }
|
||||
self.content = stack.eraseToAnyView()
|
||||
}
|
||||
|
||||
/**
|
||||
Creates instance of section, responsible for controling a single setting with `Text` as a `Label`.
|
||||
|
||||
|
@ -115,8 +136,9 @@ public extension Settings {
|
|||
|
||||
public var body: some View {
|
||||
HStack(alignment: verticalAlignment) {
|
||||
label
|
||||
.alignmentGuide(.settingsSectionLabel) { $0[.trailing] }
|
||||
if let label = label {
|
||||
label.alignmentGuide(.settingsSectionLabel) { $0[.trailing] }
|
||||
}
|
||||
content
|
||||
Spacer()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue