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

66 lines
2.8 KiB
Swift

import Adw
public extension ActionRow {
/// Creates an ActionRow with static title, subtitle, and icon values.
///
/// Values are applied once when the widget mounts.
/// - Parameter title: The row title.
/// - Parameter subtitle: The optional row subtitle.
/// - Parameter iconName: The optional icon name.
@_disfavoredOverload
init<S: StringProtocol>(_ title: S, subtitle: String? = nil, iconName: String? = nil) {
self.init()
self = self.title(String(title))
if let subtitle { self = self.subtitle(subtitle) }
if let iconName { self = self.iconName(iconName) }
}
/// Creates an ActionRow whose title, subtitle, and icon follow bindings.
///
/// Binding modifiers update the widget in place and write widget changes back.
/// - Parameter title: The title binding.
/// - Parameter subtitle: The optional subtitle binding.
/// - Parameter iconName: The optional icon binding.
init(_ title: Portico.Binding<String>, subtitle: Portico.Binding<String>? = nil, iconName: Portico.Binding<String>? = nil) {
self.init()
self = self.title(title)
if let subtitle { self = self.subtitle(subtitle) }
if let iconName { self = self.iconName(iconName) }
}
/// Creates an ActionRow with live interpolated text values.
///
/// Interpolated segments are re-evaluated when their dependencies change.
/// - Parameter title: The interpolated title.
/// - Parameter subtitle: The optional interpolated subtitle.
/// - Parameter iconName: The optional interpolated icon name.
init(_ title: Portico.InterpolatedText, subtitle: Portico.InterpolatedText? = nil, iconName: Portico.InterpolatedText? = nil) {
self.init()
self = self.title(title)
if let subtitle { self = self.subtitle(subtitle) }
if let iconName { self = self.iconName(iconName) }
}
}
extension WidgetView where Target: Adw.ActionRow {
/// Applies the `.property` style class.
///
/// De-emphasizes the row title and emphasizes the subtitle, for read-only properties; typically paired with a selectable subtitle. Since libadwaita 1.4.
///
/// - Parameter enabled: Whether the style class is applied.
/// - Returns: A copy of this view with the modifier applied.
public func property(_ enabled: Bool = true) -> Self {
styleClass("property", enabled)
}
/// Applies the `.property` style class.
///
/// De-emphasizes the row title and emphasizes the subtitle, for read-only properties; typically paired with a selectable subtitle. Since libadwaita 1.4.
///
/// - Parameter enabled: A binding that controls whether the class is applied.
/// - Returns: A copy of this view with the modifier applied.
public func property(_ enabled: Binding<Bool>) -> Self {
styleClass("property", enabled)
}
}