portico/Sources/Portico/Generated/Avatar.swift

515 lines
29 KiB
Swift

// Generated by PorticoGen. DO NOT EDIT. See Sources/PorticoGen to make changes.
import Adw
import Gtk
import Gio
import Gdk
// PorticoGen: generateStruct | source: Adw.Avatar
/// A widget displaying an image, with a generated fallback.
///
/// <picture>
/// <source srcset="avatar-dark.png" media="(prefers-color-scheme: dark)">
/// <img src="avatar.png" alt="avatar">
/// </picture>
///
/// `AdwAvatar` is a widget that shows a round avatar.
///
/// `AdwAvatar` generates an avatar with the initials of the
/// [property`Avatar`:text] on top of a colored background.
///
/// The color is picked based on the hash of the [property`Avatar`:text].
///
/// If [property`Avatar`:show-initials] is set to `FALSE`,
/// [property`Avatar`:icon-name] or `adw-avatar-default-symbolic` is shown instead
/// of the initials.
///
/// Use [property`Avatar`:custom-image] to set a custom image.
///
/// ## CSS nodes
///
/// `AdwAvatar` has a single CSS node with name `avatar`.
///
/// ## Accessibility
///
/// `AdwAvatar` uses the [enum`Gtk`.AccessibleRole.img] role.
///
/// A Portico view that mounts a `Adw.Avatar`.
@MainActor public struct Avatar: View {
private let make: (MountContext) -> Adw.Avatar
private var configure: [(Adw.Avatar, MountContext) -> Void] = []
public var body: Never { fatalError() }
// PorticoGen: generateInits(static) | source: Adw.Avatar.init(size:text:showInitials:)
/// Creates a new `AdwAvatar`.
///
/// Applied once at mount; use the `Binding`, closure, or `InterpolatedText` overload for values that change.
/// A string literal containing interpolation selects the `InterpolatedText` overload instead, which updates live.
/// Optional value parameters are applied only when non-`nil`; a `nil` argument leaves the widget's own default in place and cannot clear a nullable property - use the matching modifier for that.
///
/// - Parameter size: The size of the avatar.
/// - Parameter text: Sets the text used to generate the fallback initials and color.
/// - Parameter showInitials: Whether initials are used instead of an icon on the fallback avatar.
/// - Parameter customImage: A custom image paintable.
/// - Parameter iconName: The name of an icon to use as a fallback.
@_disfavoredOverload
public init<S: StringProtocol>(size: Int32, text: S?, showInitials: Bool, customImage: Adw.Paintable? = nil, iconName: String? = nil) {
make = { _ in Adw.Avatar(size: size, text: text.map { String($0) }, showInitials: showInitials) }
configure.append { w, _ in
if let customImage { w.setCustomImage(customImage: customImage) }
if let iconName { w.setIconName(iconName: iconName) }
}
}
// PorticoGen: generateInits(binding) | source: Adw.Avatar.init(size:text:showInitials:), Adw.Avatar.setSize(size:), Adw.Avatar.setText(text:), Adw.Avatar.setShowInitials(showInitials:)
/// Creates a new `AdwAvatar`.
///
/// The initial value is the binding's current value; every later change is pushed into the widget through `Adw.Avatar.setSize(size:), Adw.Avatar.setText(text:), Adw.Avatar.setShowInitials(showInitials:)` without rebuilding the view.
/// Optional value parameters are applied only when non-`nil`; a `nil` argument leaves the widget's own default in place and cannot clear a nullable property - use the matching modifier for that.
/// Optional `Binding` parameters bind through `Portico.bindProperty`, so they are two-way wherever the wrapper exposes a safe getter.
///
/// - Parameter size: The size of the avatar.
/// - Parameter text: Sets the text used to generate the fallback initials and color.
/// - Parameter showInitials: Whether initials are used instead of an icon on the fallback avatar.
/// - Parameter customImage: A custom image paintable.
/// - Parameter iconName: The name of an icon to use as a fallback.
public init(size: Portico.Binding<Int32>, text: Portico.Binding<String?>, showInitials: Portico.Binding<Bool>, customImage: Portico.Binding<Adw.Paintable?>? = nil, iconName: Portico.Binding<String?>? = nil) {
make = { _ in Adw.Avatar(size: size.wrappedValue, text: text.wrappedValue, showInitials: showInitials.wrappedValue) }
configure.append { w, ctx in
ctx.registry.add(size.subscribe { [w] v in w.setSize(size: v) })
ctx.registry.add(text.subscribe { [w] v in w.setText(text: v) })
ctx.registry.add(showInitials.subscribe { [w] v in w.setShowInitials(showInitials: v) })
if let customImage {
Portico.bindProperty(w, customImage, registry: ctx.registry, notifyDetail: "custom-image", read: { [w] in w.getCustomImage() }, write: { [w] v in w.setCustomImage(customImage: v) })
}
if let iconName {
Portico.bindProperty(w, iconName, registry: ctx.registry, notifyDetail: "icon-name", read: { [w] in w.getIconName() }, write: { [w] v in w.setIconName(iconName: v) })
}
}
}
// PorticoGen: generateInits(closure) | source: Adw.Avatar.init(size:text:showInitials:), Adw.Avatar.setSize(size:), Adw.Avatar.setText(text:), Adw.Avatar.setShowInitials(showInitials:)
/// Creates a new `AdwAvatar`.
///
/// Each closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.Avatar.setSize(size:), Adw.Avatar.setText(text:), Adw.Avatar.setShowInitials(showInitials:)`.
/// Optional value parameters are applied only when non-`nil`; a `nil` argument leaves the widget's own default in place and cannot clear a nullable property - use the matching modifier for that.
///
/// - Parameter size: The size of the avatar.
/// - Parameter text: Sets the text used to generate the fallback initials and color.
/// - Parameter showInitials: Whether initials are used instead of an icon on the fallback avatar.
/// - Parameter customImage: A custom image paintable.
/// - Parameter iconName: The name of an icon to use as a fallback.
public init(size: @escaping () -> Int32, text: @escaping () -> String?, showInitials: @escaping () -> Bool, customImage: Adw.Paintable? = nil, iconName: String? = nil) {
make = { _ in Adw.Avatar(size: size(), text: text(), showInitials: showInitials()) }
configure.append { w, ctx in
let t0 = DependencyTracker { [w] in w.setSize(size: size()) }
t0.run()
ctx.registry.add(t0)
let t1 = DependencyTracker { [w] in w.setText(text: text()) }
t1.run()
ctx.registry.add(t1)
let t2 = DependencyTracker { [w] in w.setShowInitials(showInitials: showInitials()) }
t2.run()
ctx.registry.add(t2)
if let customImage { w.setCustomImage(customImage: customImage) }
if let iconName { w.setIconName(iconName: iconName) }
}
}
// PorticoGen: generateInits(interpolation) | source: Adw.Avatar.init(size:text:showInitials:), Adw.Avatar.setText(text:)
/// Creates a new `AdwAvatar`.
///
/// Interpolated segments are captured unevaluated and re-read inside a `DependencyTracker`, so any `@State` they read pushes a new value through `Adw.Avatar.setText(text:)`. A literal with no interpolation is applied once, with no subscription.
/// Optional value parameters are applied only when non-`nil`; a `nil` argument leaves the widget's own default in place and cannot clear a nullable property - use the matching modifier for that.
///
/// - Parameter size: The size of the avatar.
/// - Parameter text: Sets the text used to generate the fallback initials and color.
/// - Parameter showInitials: Whether initials are used instead of an icon on the fallback avatar.
/// - Parameter customImage: A custom image paintable.
/// - Parameter iconName: The name of an icon to use as a fallback.
public init(size: Int32, text: Portico.InterpolatedText?, showInitials: Bool, customImage: Adw.Paintable? = nil, iconName: String? = nil) {
make = { _ in Adw.Avatar(size: size, text: text?.untrackedText, showInitials: showInitials) }
configure.append { w, ctx in
Portico.bindOptionalInterpolation(text, registry: ctx.registry) { [w] v in w.setText(text: v) }
if let customImage { w.setCustomImage(customImage: customImage) }
if let iconName { w.setIconName(iconName: iconName) }
}
}
}
extension Avatar: WidgetView {
public typealias Target = Adw.Avatar
@_spi(Portico) public func appending(
_ step: @escaping (Adw.Avatar, MountContext) -> Void
) -> Self {
var c = self
c.configure.append(step)
return c
}
}
@_spi(Portico) extension Avatar: Mountable {
@_spi(Portico) public func mount(_ ctx: MountContext) -> Gtk.Widget {
let w = make(ctx)
for step in configure { step(w, ctx) }
return w
}
}
// PorticoGen: generateModifierExtension | source: Adw.Avatar
/// Modifiers for `Adw.Avatar`, available on every Portico view whose
/// backing widget is `Adw.Avatar` or one of its subclasses.
extension WidgetView where Target: Adw.Avatar {
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.Avatar.setCustomImage(customImage:)
/// Sets the custom image paintable.
///
/// Custom image is displayed instead of initials or icon.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter customImage: A custom image paintable.
/// - Returns: A copy of this view with the modifier applied.
public func customImage(_ customImage: Adw.Paintable?) -> Self {
appending { w, _ in
w.setCustomImage(customImage: customImage)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.Avatar.setCustomImage(customImage:), GObject.Object.connectNotify(detail:_:), Adw.Avatar.getCustomImage()
/// Sets the custom image paintable.
///
/// Custom image is displayed instead of initials or icon.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Adw.Paintable?` conforms to `Equatable` this binds in both directions: the widget's `notify` signal writes its current value back into the binding, so changes made in the UI propagate to the bound state. Each direction compares before writing, which terminates the echo after one hop. A value type that is not `Equatable` binds one way only, because the echo cannot be broken.
///
/// - Returns: A copy of this view with the modifier applied.
public func customImage(_ customImage: Portico.Binding<Adw.Paintable?>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, customImage, registry: ctx.registry, notifyDetail: "custom-image",
read: { [w] in w.getCustomImage() },
write: { [w] v in w.setCustomImage(customImage: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(lifted,twoWay) | source: Adw.Avatar.setCustomImage(customImage:), GObject.Object.connectNotify(detail:_:), Adw.Avatar.getCustomImage()
/// Sets the custom image paintable.
///
/// Custom image is displayed instead of initials or icon.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// `Binding` is invariant, so a `Binding<Adw.Paintable>` is not accepted by the nullable overload; this one takes it and promotes each value. Pass a `Binding<Adw.Paintable?>` to be able to clear the property.
/// When `Adw.Paintable` conforms to `Equatable` this binds in both directions: the widget's `notify` signal writes its current value back into the binding, so changes made in the UI propagate to the bound state. Each direction compares before writing, which terminates the echo after one hop. A value type that is not `Equatable` binds one way only, because the echo cannot be broken.
/// A `nil` widget value is never written back into the binding.
///
/// - Returns: A copy of this view with the modifier applied.
public func customImage(_ customImage: Portico.Binding<Adw.Paintable>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, customImage, registry: ctx.registry, notifyDetail: "custom-image",
read: { [w] in w.getCustomImage() },
write: { [w] v in w.setCustomImage(customImage: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.Avatar.setCustomImage(customImage:)
/// Sets the custom image paintable.
///
/// Custom image is displayed instead of initials or icon.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.Avatar.setCustomImage(customImage:)`.
///
/// - Parameter customImage: A custom image paintable.
/// - Returns: A copy of this view with the modifier applied.
public func customImage(_ customImage: @escaping () -> Adw.Paintable?) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setCustomImage(customImage: customImage()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.Avatar.setIconName(iconName:)
/// Sets the name of an icon to use as a fallback.
///
/// If no name is set, `adw-avatar-default-symbolic` will be used.
///
/// Applied once at mount; use the `Binding`, closure, or `InterpolatedText` overload for a value that changes.
/// A string literal containing interpolation selects the `InterpolatedText` overload instead, which updates live.
///
/// - Parameter iconName: The name of an icon to use as a fallback.
/// - Returns: A copy of this view with the modifier applied.
@_disfavoredOverload
public func iconName<S: StringProtocol>(_ iconName: S?) -> Self {
appending { w, _ in
w.setIconName(iconName: iconName.map { String($0) })
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.Avatar.setIconName(iconName:), GObject.Object.connectNotify(detail:_:), Adw.Avatar.getIconName()
/// Sets the name of an icon to use as a fallback.
///
/// If no name is set, `adw-avatar-default-symbolic` will be used.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `String?` conforms to `Equatable` this binds in both directions: the widget's `notify` signal writes its current value back into the binding, so changes made in the UI propagate to the bound state. Each direction compares before writing, which terminates the echo after one hop. A value type that is not `Equatable` binds one way only, because the echo cannot be broken.
///
/// - Returns: A copy of this view with the modifier applied.
public func iconName(_ iconName: Portico.Binding<String?>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, iconName, registry: ctx.registry, notifyDetail: "icon-name",
read: { [w] in w.getIconName() },
write: { [w] v in w.setIconName(iconName: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(lifted,twoWay) | source: Adw.Avatar.setIconName(iconName:), GObject.Object.connectNotify(detail:_:), Adw.Avatar.getIconName()
/// Sets the name of an icon to use as a fallback.
///
/// If no name is set, `adw-avatar-default-symbolic` will be used.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// `Binding` is invariant, so a `Binding<String>` is not accepted by the nullable overload; this one takes it and promotes each value. Pass a `Binding<String?>` to be able to clear the property.
/// When `String` conforms to `Equatable` this binds in both directions: the widget's `notify` signal writes its current value back into the binding, so changes made in the UI propagate to the bound state. Each direction compares before writing, which terminates the echo after one hop. A value type that is not `Equatable` binds one way only, because the echo cannot be broken.
/// A `nil` widget value is never written back into the binding.
///
/// - Returns: A copy of this view with the modifier applied.
public func iconName(_ iconName: Portico.Binding<String>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, iconName, registry: ctx.registry, notifyDetail: "icon-name",
read: { [w] in w.getIconName() },
write: { [w] v in w.setIconName(iconName: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.Avatar.setIconName(iconName:)
/// Sets the name of an icon to use as a fallback.
///
/// If no name is set, `adw-avatar-default-symbolic` will be used.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.Avatar.setIconName(iconName:)`.
///
/// - Parameter iconName: The name of an icon to use as a fallback.
/// - Returns: A copy of this view with the modifier applied.
public func iconName(_ iconName: @escaping () -> String?) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setIconName(iconName: iconName()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(interpolation) | source: Adw.Avatar.setIconName(iconName:)
/// Sets the name of an icon to use as a fallback.
///
/// If no name is set, `adw-avatar-default-symbolic` will be used.
///
/// Interpolated segments are captured unevaluated and re-read inside a `DependencyTracker`, so any `@State` they read pushes a new value through `Adw.Avatar.setIconName(iconName:)`. A literal with no interpolation is applied once, with no subscription.
///
/// - Parameter iconName: The name of an icon to use as a fallback.
/// - Returns: A copy of this view with the modifier applied.
public func iconName(_ iconName: Portico.InterpolatedText?) -> Self {
appending { w, ctx in
Portico.bindOptionalInterpolation(iconName, registry: ctx.registry) { [w] v in w.setIconName(iconName: v) }
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.Avatar.setShowInitials(showInitials:)
/// Sets whether to use initials instead of an icon on the fallback avatar.
///
/// See [property`Avatar`:icon-name] for how to change the fallback icon.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter showInitials: Whether initials are used instead of an icon on the fallback avatar.
/// - Returns: A copy of this view with the modifier applied.
public func showInitials(_ showInitials: Bool) -> Self {
appending { w, _ in
w.setShowInitials(showInitials: showInitials)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.Avatar.setShowInitials(showInitials:), GObject.Object.connectNotify(detail:_:), Adw.Avatar.getShowInitials()
/// Sets whether to use initials instead of an icon on the fallback avatar.
///
/// See [property`Avatar`:icon-name] for how to change the fallback icon.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Bool` conforms to `Equatable` this binds in both directions: the widget's `notify` signal writes its current value back into the binding, so changes made in the UI propagate to the bound state. Each direction compares before writing, which terminates the echo after one hop. A value type that is not `Equatable` binds one way only, because the echo cannot be broken.
///
/// - Returns: A copy of this view with the modifier applied.
public func showInitials(_ showInitials: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, showInitials, registry: ctx.registry, notifyDetail: "show-initials",
read: { [w] in w.getShowInitials() },
write: { [w] v in w.setShowInitials(showInitials: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.Avatar.setShowInitials(showInitials:)
/// Sets whether to use initials instead of an icon on the fallback avatar.
///
/// See [property`Avatar`:icon-name] for how to change the fallback icon.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.Avatar.setShowInitials(showInitials:)`.
///
/// - Parameter showInitials: Whether initials are used instead of an icon on the fallback avatar.
/// - Returns: A copy of this view with the modifier applied.
public func showInitials(_ showInitials: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setShowInitials(showInitials: showInitials()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.Avatar.setSize(size:)
/// Sets the size of the avatar.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter size: The size of the avatar.
/// - Returns: A copy of this view with the modifier applied.
public func size(_ size: Int32) -> Self {
appending { w, _ in
w.setSize(size: size)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.Avatar.setSize(size:), GObject.Object.connectNotify(detail:_:), Adw.Avatar.getSize()
/// Sets the size of the avatar.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Int32` conforms to `Equatable` this binds in both directions: the widget's `notify` signal writes its current value back into the binding, so changes made in the UI propagate to the bound state. Each direction compares before writing, which terminates the echo after one hop. A value type that is not `Equatable` binds one way only, because the echo cannot be broken.
///
/// - Returns: A copy of this view with the modifier applied.
public func size(_ size: Portico.Binding<Int32>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, size, registry: ctx.registry, notifyDetail: "size",
read: { [w] in w.getSize() },
write: { [w] v in w.setSize(size: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.Avatar.setSize(size:)
/// Sets the size of the avatar.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.Avatar.setSize(size:)`.
///
/// - Parameter size: The size of the avatar.
/// - Returns: A copy of this view with the modifier applied.
public func size(_ size: @escaping () -> Int32) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setSize(size: size()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.Avatar.setText(text:)
/// Sets the text used to generate the fallback initials and color.
///
/// It's only used to generate the color if [property`Avatar`:show-initials] is
/// `FALSE`.
///
/// Applied once at mount; use the `Binding`, closure, or `InterpolatedText` overload for a value that changes.
/// A string literal containing interpolation selects the `InterpolatedText` overload instead, which updates live.
///
/// - Parameter text: Sets the text used to generate the fallback initials and color.
/// - Returns: A copy of this view with the modifier applied.
@_disfavoredOverload
public func text<S: StringProtocol>(_ text: S?) -> Self {
appending { w, _ in
w.setText(text: text.map { String($0) })
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.Avatar.setText(text:), GObject.Object.connectNotify(detail:_:), Adw.Avatar.getText()
/// Sets the text used to generate the fallback initials and color.
///
/// It's only used to generate the color if [property`Avatar`:show-initials] is
/// `FALSE`.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `String?` conforms to `Equatable` this binds in both directions: the widget's `notify` signal writes its current value back into the binding, so changes made in the UI propagate to the bound state. Each direction compares before writing, which terminates the echo after one hop. A value type that is not `Equatable` binds one way only, because the echo cannot be broken.
///
/// - Returns: A copy of this view with the modifier applied.
public func text(_ text: Portico.Binding<String?>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, text, registry: ctx.registry, notifyDetail: "text",
read: { [w] in w.getText() },
write: { [w] v in w.setText(text: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(lifted,twoWay) | source: Adw.Avatar.setText(text:), GObject.Object.connectNotify(detail:_:), Adw.Avatar.getText()
/// Sets the text used to generate the fallback initials and color.
///
/// It's only used to generate the color if [property`Avatar`:show-initials] is
/// `FALSE`.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// `Binding` is invariant, so a `Binding<String>` is not accepted by the nullable overload; this one takes it and promotes each value. Pass a `Binding<String?>` to be able to clear the property.
/// When `String` conforms to `Equatable` this binds in both directions: the widget's `notify` signal writes its current value back into the binding, so changes made in the UI propagate to the bound state. Each direction compares before writing, which terminates the echo after one hop. A value type that is not `Equatable` binds one way only, because the echo cannot be broken.
/// A `nil` widget value is never written back into the binding.
///
/// - Returns: A copy of this view with the modifier applied.
public func text(_ text: Portico.Binding<String>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, text, registry: ctx.registry, notifyDetail: "text",
read: { [w] in w.getText() },
write: { [w] v in w.setText(text: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.Avatar.setText(text:)
/// Sets the text used to generate the fallback initials and color.
///
/// It's only used to generate the color if [property`Avatar`:show-initials] is
/// `FALSE`.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.Avatar.setText(text:)`.
///
/// - Parameter text: Sets the text used to generate the fallback initials and color.
/// - Returns: A copy of this view with the modifier applied.
public func text(_ text: @escaping () -> String?) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setText(text: text()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(interpolation) | source: Adw.Avatar.setText(text:)
/// Sets the text used to generate the fallback initials and color.
///
/// It's only used to generate the color if [property`Avatar`:show-initials] is
/// `FALSE`.
///
/// Interpolated segments are captured unevaluated and re-read inside a `DependencyTracker`, so any `@State` they read pushes a new value through `Adw.Avatar.setText(text:)`. A literal with no interpolation is applied once, with no subscription.
///
/// - Parameter text: Sets the text used to generate the fallback initials and color.
/// - Returns: A copy of this view with the modifier applied.
public func text(_ text: Portico.InterpolatedText?) -> Self {
appending { w, ctx in
Portico.bindOptionalInterpolation(text, registry: ctx.registry) { [w] v in w.setText(text: v) }
}
}
}