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

48 lines
1.8 KiB
Swift

import Adw
public extension EntryRow {
/// Creates an EntryRow with static text and optional entry contents.
///
/// Values are applied once when the widget mounts.
/// - Parameter title: The row title.
/// - Parameter text: The optional entry text.
@_disfavoredOverload
init<S: StringProtocol>(_ title: S, text: String? = nil) {
self.init()
self = self.title(String(title))
if let text { self = self.text(text) }
}
/// Creates an EntryRow whose title and text follow bindings.
///
/// Binding modifiers update the widget in place and write widget changes back.
/// - Parameter title: The title binding.
/// - Parameter text: The optional text binding.
init(_ title: Portico.Binding<String>, text: Portico.Binding<String>? = nil) {
self.init()
self = self.title(title)
if let text { self = self.text(text) }
}
/// Creates an EntryRow with live interpolated text values.
///
/// Interpolated segments are re-evaluated when their dependencies change.
/// - Parameter title: The interpolated title.
/// - Parameter text: The optional interpolated entry text.
init(_ title: Portico.InterpolatedText, text: Portico.InterpolatedText? = nil) {
self.init()
self = self.title(title)
if let text { self = self.text(text) }
}
/// Creates an EntryRow with a static title and bound text.
///
/// Use `EntryRow("Name: \(value)").text(binding)` when both values are reactive.
/// - Parameter title: The row title.
/// - Parameter text: The required text binding.
init<S: StringProtocol>(_ title: S, text: Portico.Binding<String>) {
self.init()
self = self.title(String(title))
self = self.text(text)
}
}