portico/Sources/Portico/Generated/ButtonContent.swift

350 lines
17 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.ButtonContent
/// A helper widget for creating buttons.
///
/// <picture>
/// <source srcset="button-content-dark.png" media="(prefers-color-scheme: dark)">
/// <img src="button-content.png" alt="button-content">
/// </picture>
///
/// `AdwButtonContent` is a box-like widget with an icon and a label.
///
/// It's intended to be used as a direct child of [class`Gtk`.Button],
/// [class`Gtk`.MenuButton] or [class`SplitButton`], when they need to have both an
/// icon and a label, as follows:
///
/// ```xml
/// <object class="GtkButton">
/// <property name="child">
/// <object class="AdwButtonContent">
/// <property name="icon-name">document-open-symbolic</property>
/// <property name="label" translatable="yes">_Open</property>
/// <property name="use-underline">True</property>
/// </object>
/// </property>
/// </object>
/// ```
///
/// `AdwButtonContent` handles style classes and connecting the mnemonic to the
/// button automatically.
///
/// ## CSS nodes
///
/// ```
/// buttoncontent
/// box
/// image
/// label
/// ```
///
/// `AdwButtonContent`'s CSS node is called `buttoncontent`. It contains a `box`
/// subnode that serves as a container for the `image` and `label` nodes.
///
/// When inside a `GtkButton` or `AdwSplitButton`, the button will receive the
/// `.image-text-button` style class. When inside a `GtkMenuButton`, the
/// internal `GtkButton` will receive it instead.
///
/// ## Accessibility
///
/// `AdwButtonContent` uses the [enum`Gtk`.AccessibleRole.group] role.
///
/// A Portico view that mounts a `Adw.ButtonContent`.
@MainActor public struct ButtonContent: View {
private let make: (MountContext) -> Adw.ButtonContent
private var configure: [(Adw.ButtonContent, MountContext) -> Void] = []
public var body: Never { fatalError() }
// PorticoGen: generateInits(static) | source: Adw.ButtonContent.init()
/// Creates a new `AdwButtonContent`.
///
/// Applied once at mount; use the `Binding` or closure overload for values that change.
/// 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 canShrink: Whether the button can be smaller than the natural size of its contents.
/// - Parameter iconName: The name of the displayed icon.
/// - Parameter label: The displayed label.
/// - Parameter useUnderline: Whether an underline in the text indicates a mnemonic.
public init(canShrink: Bool? = nil, iconName: String? = nil, label: String? = nil, useUnderline: Bool? = nil) {
make = { _ in Adw.ButtonContent() }
configure.append { w, _ in
if let canShrink { w.setCanShrink(canShrink: canShrink) }
if let iconName { w.setIconName(iconName: iconName) }
if let label { w.setLabel(label: label) }
if let useUnderline { w.setUseUnderline(useUnderline: useUnderline) }
}
}
}
extension ButtonContent: WidgetView {
public typealias Target = Adw.ButtonContent
@_spi(Portico) public func appending(
_ step: @escaping (Adw.ButtonContent, MountContext) -> Void
) -> Self {
var c = self
c.configure.append(step)
return c
}
}
@_spi(Portico) extension ButtonContent: 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.ButtonContent
/// Modifiers for `Adw.ButtonContent`, available on every Portico view whose
/// backing widget is `Adw.ButtonContent` or one of its subclasses.
extension WidgetView where Target: Adw.ButtonContent {
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.ButtonContent.setCanShrink(canShrink:)
/// Sets whether the button can be smaller than the natural size of its contents.
///
/// If set to `TRUE`, the label will ellipsize.
///
/// See [method`Gtk`.Button.set_can_shrink].
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter canShrink: Whether the button can be smaller than the natural size of its contents.
/// - Returns: A copy of this view with the modifier applied.
public func canShrink(_ canShrink: Bool) -> Self {
appending { w, _ in
w.setCanShrink(canShrink: canShrink)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.ButtonContent.setCanShrink(canShrink:), GObject.Object.connectNotify(detail:_:), Adw.ButtonContent.getCanShrink()
/// Sets whether the button can be smaller than the natural size of its contents.
///
/// If set to `TRUE`, the label will ellipsize.
///
/// See [method`Gtk`.Button.set_can_shrink].
///
/// 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 canShrink(_ canShrink: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, canShrink, registry: ctx.registry, notifyDetail: "can-shrink",
read: { [w] in w.getCanShrink() },
write: { [w] v in w.setCanShrink(canShrink: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.ButtonContent.setCanShrink(canShrink:)
/// Sets whether the button can be smaller than the natural size of its contents.
///
/// If set to `TRUE`, the label will ellipsize.
///
/// See [method`Gtk`.Button.set_can_shrink].
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.ButtonContent.setCanShrink(canShrink:)`.
///
/// - Parameter canShrink: Whether the button can be smaller than the natural size of its contents.
/// - Returns: A copy of this view with the modifier applied.
public func canShrink(_ canShrink: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setCanShrink(canShrink: canShrink()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.ButtonContent.setIconName(iconName:)
/// Sets the name of the displayed icon.
///
/// If empty, the icon is not shown.
///
/// 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 the displayed icon.
/// - 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: String(iconName))
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.ButtonContent.setIconName(iconName:), GObject.Object.connectNotify(detail:_:), Adw.ButtonContent.getIconName()
/// Sets the name of the displayed icon.
///
/// If empty, the icon is not shown.
///
/// 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(closure) | source: Adw.ButtonContent.setIconName(iconName:)
/// Sets the name of the displayed icon.
///
/// If empty, the icon is not shown.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.ButtonContent.setIconName(iconName:)`.
///
/// - Parameter iconName: The name of the displayed icon.
/// - 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.ButtonContent.setIconName(iconName:)
/// Sets the name of the displayed icon.
///
/// If empty, the icon is not shown.
///
/// Interpolated segments are captured unevaluated and re-read inside a `DependencyTracker`, so any `@State` they read pushes a new value through `Adw.ButtonContent.setIconName(iconName:)`. A literal with no interpolation is applied once, with no subscription.
///
/// - Parameter iconName: The name of the displayed icon.
/// - Returns: A copy of this view with the modifier applied.
public func iconName(_ iconName: Portico.InterpolatedText) -> Self {
appending { w, ctx in
Portico.bindInterpolation(iconName, registry: ctx.registry) { [w] v in w.setIconName(iconName: v) }
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.ButtonContent.setLabel(label:)
/// Sets the displayed label.
///
/// 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 label: The displayed label.
/// - Returns: A copy of this view with the modifier applied.
@_disfavoredOverload
public func label<S: StringProtocol>(_ label: S) -> Self {
appending { w, _ in
w.setLabel(label: String(label))
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.ButtonContent.setLabel(label:), GObject.Object.connectNotify(detail:_:), Adw.ButtonContent.getLabel()
/// Sets the displayed label.
///
/// 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 label(_ label: Portico.Binding<String>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, label, registry: ctx.registry, notifyDetail: "label",
read: { [w] in w.getLabel() },
write: { [w] v in w.setLabel(label: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.ButtonContent.setLabel(label:)
/// Sets the displayed label.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.ButtonContent.setLabel(label:)`.
///
/// - Parameter label: The displayed label.
/// - Returns: A copy of this view with the modifier applied.
public func label(_ label: @escaping () -> String) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setLabel(label: label()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(interpolation) | source: Adw.ButtonContent.setLabel(label:)
/// Sets the displayed label.
///
/// Interpolated segments are captured unevaluated and re-read inside a `DependencyTracker`, so any `@State` they read pushes a new value through `Adw.ButtonContent.setLabel(label:)`. A literal with no interpolation is applied once, with no subscription.
///
/// - Parameter label: The displayed label.
/// - Returns: A copy of this view with the modifier applied.
public func label(_ label: Portico.InterpolatedText) -> Self {
appending { w, ctx in
Portico.bindInterpolation(label, registry: ctx.registry) { [w] v in w.setLabel(label: v) }
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.ButtonContent.setUseUnderline(useUnderline:)
/// Sets whether an underline in the text indicates a mnemonic.
///
/// The mnemonic can be used to activate the parent button.
///
/// See [property`ButtonContent`:label].
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter useUnderline: Whether an underline in the text indicates a mnemonic.
/// - Returns: A copy of this view with the modifier applied.
public func useUnderline(_ useUnderline: Bool) -> Self {
appending { w, _ in
w.setUseUnderline(useUnderline: useUnderline)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.ButtonContent.setUseUnderline(useUnderline:), GObject.Object.connectNotify(detail:_:), Adw.ButtonContent.getUseUnderline()
/// Sets whether an underline in the text indicates a mnemonic.
///
/// The mnemonic can be used to activate the parent button.
///
/// See [property`ButtonContent`:label].
///
/// 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 useUnderline(_ useUnderline: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, useUnderline, registry: ctx.registry, notifyDetail: "use-underline",
read: { [w] in w.getUseUnderline() },
write: { [w] v in w.setUseUnderline(useUnderline: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.ButtonContent.setUseUnderline(useUnderline:)
/// Sets whether an underline in the text indicates a mnemonic.
///
/// The mnemonic can be used to activate the parent button.
///
/// See [property`ButtonContent`:label].
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.ButtonContent.setUseUnderline(useUnderline:)`.
///
/// - Parameter useUnderline: Whether an underline in the text indicates a mnemonic.
/// - Returns: A copy of this view with the modifier applied.
public func useUnderline(_ useUnderline: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setUseUnderline(useUnderline: useUnderline()) }
tracker.run()
ctx.registry.add(tracker)
}
}
}