Document dialog property sources
This commit is contained in:
parent
c4818604c4
commit
789d35b090
1 changed files with 16 additions and 0 deletions
|
|
@ -2,37 +2,53 @@ import Adw
|
|||
|
||||
/// The source of a dialog property, either a fixed value or a live binding.
|
||||
public enum DialogPropertyValue<Value> {
|
||||
/// A fixed property value applied once when the dialog mounts.
|
||||
case constant(Value)
|
||||
/// A live property binding reapplied when its value changes.
|
||||
case binding(Binding<Value>)
|
||||
}
|
||||
|
||||
/// Supplies a dialog property as a fixed value or a live binding.
|
||||
public protocol DialogPropertySource<Value> {
|
||||
/// The value type accepted by this property source.
|
||||
associatedtype Value
|
||||
/// Returns the fixed value or binding represented by this source.
|
||||
var _dialogPropertyValue: DialogPropertyValue<Value> { get }
|
||||
}
|
||||
|
||||
/// Provides a fixed string dialog property value.
|
||||
extension String: DialogPropertySource {
|
||||
/// Returns this string as a fixed dialog property value.
|
||||
public var _dialogPropertyValue: DialogPropertyValue<String> { .constant(self) }
|
||||
}
|
||||
|
||||
/// Provides a fixed Boolean dialog property value.
|
||||
extension Bool: DialogPropertySource {
|
||||
/// Returns this Boolean as a fixed dialog property value.
|
||||
public var _dialogPropertyValue: DialogPropertyValue<Bool> { .constant(self) }
|
||||
}
|
||||
|
||||
/// Provides an integer literal as an `Int32` dialog property value.
|
||||
extension Int: DialogPropertySource {
|
||||
/// Returns this integer converted to a fixed `Int32` dialog property value.
|
||||
public var _dialogPropertyValue: DialogPropertyValue<Int32> { .constant(Int32(self)) }
|
||||
}
|
||||
|
||||
/// Provides a fixed `Int32` dialog property value.
|
||||
extension Int32: DialogPropertySource {
|
||||
/// Returns this value as a fixed dialog property value.
|
||||
public var _dialogPropertyValue: DialogPropertyValue<Int32> { .constant(self) }
|
||||
}
|
||||
|
||||
/// Provides a fixed dialog presentation mode.
|
||||
extension DialogPresentationMode: DialogPropertySource {
|
||||
/// Returns this mode as a fixed dialog property value.
|
||||
public var _dialogPropertyValue: DialogPropertyValue<DialogPresentationMode> { .constant(self) }
|
||||
}
|
||||
|
||||
/// Provides a live dialog property value through a Portico binding.
|
||||
extension Binding: DialogPropertySource {
|
||||
/// Returns this binding as a live dialog property value.
|
||||
public var _dialogPropertyValue: DialogPropertyValue<Value> { .binding(self) }
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue