portico/Sources/Portico/Extensions/PreferencesGroup+Extras.swift

40 lines
1.9 KiB
Swift

import Adw
public extension PreferencesGroup {
/// Creates a PreferencesGroup with static title, description, and child rows.
///
/// Values are applied once when the widget mounts.
/// - Parameter title: The group title.
/// - Parameter description: The optional group description.
/// - Parameter children: The child rows to mount.
@_disfavoredOverload
init<S: StringProtocol>(_ title: S, description: String? = nil, @ViewBuilder _ children: @escaping () -> [AnyView] = { [] }) {
self.init(children: children)
self = self.title(String(title))
if let description { self = self.description(description) }
}
/// Creates a PreferencesGroup whose text follows bindings.
///
/// Binding modifiers update the widget in place and write widget changes back.
/// - Parameter title: The title binding.
/// - Parameter description: The optional description binding.
/// - Parameter children: The child rows to mount.
init(_ title: Portico.Binding<String>, description: Portico.Binding<String>? = nil, @ViewBuilder _ children: @escaping () -> [AnyView] = { [] }) {
self.init(children: children)
self = self.title(title)
if let description { self = self.description(description) }
}
/// Creates a PreferencesGroup with live interpolated text values.
///
/// Interpolated segments are re-evaluated when their dependencies change.
/// - Parameter title: The interpolated title.
/// - Parameter description: The optional interpolated description.
/// - Parameter children: The child rows to mount.
init(_ title: Portico.InterpolatedText, description: Portico.InterpolatedText? = nil, @ViewBuilder _ children: @escaping () -> [AnyView] = { [] }) {
self.init(children: children)
self = self.title(title)
if let description { self = self.description(description) }
}
}