164 lines
8.6 KiB
Swift
164 lines
8.6 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.SwitchRow
|
|
/// A [class`Gtk`.ListBoxRow] used to represent two states.
|
|
///
|
|
/// <picture>
|
|
/// <source srcset="switch-row-dark.png" media="(prefers-color-scheme: dark)">
|
|
/// <img src="switch-row.png" alt="switch-row">
|
|
/// </picture>
|
|
///
|
|
/// The `AdwSwitchRow` widget contains a [class`Gtk`.Switch] that allows the user
|
|
/// to select between two states: "on" or "off". When activated, the row will
|
|
/// invert its active state.
|
|
///
|
|
/// The user can control the switch by activating the row or by dragging on the
|
|
/// switch handle.
|
|
///
|
|
/// See [class`Gtk`.Switch] for details.
|
|
///
|
|
/// Example of an `AdwSwitchRow` UI definition:
|
|
/// ```xml
|
|
/// <object class="AdwSwitchRow">
|
|
/// <property name="title" translatable="yes">Switch Row</property>
|
|
/// <signal name="notify::active" handler="switch_row_notify_active_cb"/>
|
|
/// </object>
|
|
/// ```
|
|
///
|
|
/// The [property`SwitchRow`:active] property should be connected to in order to
|
|
/// monitor changes to the active state.
|
|
///
|
|
/// ## Accessibility
|
|
///
|
|
/// `AdwSwitchRow` uses the [enum`Gtk`.AccessibleRole.switch] role.
|
|
///
|
|
/// A Portico view that mounts a `Adw.SwitchRow`.
|
|
@MainActor public struct SwitchRow: View {
|
|
private let make: (MountContext) -> Adw.SwitchRow
|
|
private var configure: [(Adw.SwitchRow, MountContext) -> Void] = []
|
|
|
|
public var body: Never { fatalError() }
|
|
|
|
// PorticoGen: generateInits(static) | source: Adw.SwitchRow.init()
|
|
/// Creates a new `AdwSwitchRow`.
|
|
///
|
|
/// Applied once at mount; use the `Binding` or closure overload for values that change.
|
|
/// Each closure is evaluated once; children are added in order and slot closures mount their first view.
|
|
/// An empty closure adds no children and leaves slots unset.
|
|
/// 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 active: Whether the switch row is in the "on" or "off" position.
|
|
/// - Parameter iconName: The icon name for this row.
|
|
/// - Parameter subtitle: The subtitle for this row.
|
|
/// - Parameter subtitleLines: The number of lines at the end of which the subtitle label will be ellipsized.
|
|
/// - Parameter subtitleSelectable: Whether the user can copy the subtitle from the label.
|
|
/// - Parameter titleLines: The number of lines at the end of which the title label will be ellipsized.
|
|
/// - Parameter title: The title of the preference represented by this row.
|
|
/// - Parameter titleSelectable: Whether the user can copy the title from the label.
|
|
/// - Parameter useMarkup: Whether to use Pango markup for the title label.
|
|
/// - Parameter useUnderline: Whether an embedded underline in the title indicates a mnemonic.
|
|
/// - Parameter activatable: Determines whether the ::row-activated signal will be emitted for this row.
|
|
/// - Parameter selectable: Determines whether this row can be selected.
|
|
/// - Parameter child: A `ViewBuilder` closure whose first view is mounted into the `child` slot.
|
|
/// - Parameter activatableWidget: A `ViewBuilder` closure whose first view is mounted into the `activatableWidget` slot.
|
|
/// - Parameter onActivated: Invoked when the widget emits the `activated` signal.
|
|
/// - Parameter onActivate: Invoked when the widget emits the `activate` signal.
|
|
public init(active: Bool? = nil, iconName: String? = nil, subtitle: String? = nil, subtitleLines: Int32? = nil, subtitleSelectable: Bool? = nil, titleLines: Int32? = nil, title: String? = nil, titleSelectable: Bool? = nil, useMarkup: Bool? = nil, useUnderline: Bool? = nil, activatable: Bool? = nil, selectable: Bool? = nil, @ViewBuilder child: @escaping () -> [AnyView] = { [] }, @ViewBuilder activatableWidget: @escaping () -> [AnyView] = { [] }, onActivated: (() -> Void)? = nil, onActivate: (() -> Void)? = nil) {
|
|
make = { _ in Adw.SwitchRow() }
|
|
configure.append { w, ctx in
|
|
if let active { w.setActive(isActive: active) }
|
|
if let iconName { w.setIconName(iconName: iconName) }
|
|
if let subtitle { w.setSubtitle(subtitle: subtitle) }
|
|
if let subtitleLines { w.setSubtitleLines(subtitleLines: subtitleLines) }
|
|
if let subtitleSelectable { w.setSubtitleSelectable(subtitleSelectable: subtitleSelectable) }
|
|
if let titleLines { w.setTitleLines(titleLines: titleLines) }
|
|
if let title { w.setTitle(title: title) }
|
|
if let titleSelectable { w.setTitleSelectable(titleSelectable: titleSelectable) }
|
|
if let useMarkup { w.setUseMarkup(useMarkup: useMarkup) }
|
|
if let useUnderline { w.setUseUnderline(useUnderline: useUnderline) }
|
|
if let activatable { w.setActivatable(activatable: activatable) }
|
|
if let selectable { w.setSelectable(selectable: selectable) }
|
|
if let v = Portico.mountSlotChild(child, ctx, onUpdate: { v in w.setChild(child: v) }) { w.setChild(child: v) }
|
|
if let v = Portico.mountSlotChild(activatableWidget, ctx, onUpdate: { v in w.setActivatableWidget(widget: v) }) { w.setActivatableWidget(widget: v) }
|
|
if let onActivated { ctx.registry.add(w.connectActivated { _ in onActivated() }) }
|
|
if let onActivate { ctx.registry.add(w.connectActivate { _ in onActivate() }) }
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
extension SwitchRow: WidgetView {
|
|
public typealias Target = Adw.SwitchRow
|
|
|
|
@_spi(Portico) public func appending(
|
|
_ step: @escaping (Adw.SwitchRow, MountContext) -> Void
|
|
) -> Self {
|
|
var c = self
|
|
c.configure.append(step)
|
|
return c
|
|
}
|
|
}
|
|
|
|
@_spi(Portico) extension SwitchRow: 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.SwitchRow
|
|
/// Modifiers for `Adw.SwitchRow`, available on every Portico view whose
|
|
/// backing widget is `Adw.SwitchRow` or one of its subclasses.
|
|
extension WidgetView where Target: Adw.SwitchRow {
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.SwitchRow.setActive(isActive:)
|
|
/// Sets whether `self` is in its "on" or "off" position
|
|
///
|
|
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
|
|
///
|
|
/// - Parameter active: Whether the switch row is in the "on" or "off" position.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func active(_ active: Bool) -> Self {
|
|
appending { w, _ in
|
|
w.setActive(isActive: active)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.SwitchRow.setActive(isActive:), GObject.Object.connectNotify(detail:_:), Adw.SwitchRow.getActive()
|
|
/// Sets whether `self` is in its "on" or "off" position
|
|
///
|
|
/// 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 active(_ active: Portico.Binding<Bool>) -> Self {
|
|
appending { w, ctx in
|
|
Portico.bindProperty(
|
|
w, active, registry: ctx.registry, notifyDetail: "active",
|
|
read: { [w] in w.getActive() },
|
|
write: { [w] v in w.setActive(isActive: v) }
|
|
)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.SwitchRow.setActive(isActive:)
|
|
/// Sets whether `self` is in its "on" or "off" position
|
|
///
|
|
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.SwitchRow.setActive(isActive:)`.
|
|
///
|
|
/// - Parameter active: Whether the switch row is in the "on" or "off" position.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func active(_ active: @escaping () -> Bool) -> Self {
|
|
appending { w, ctx in
|
|
let tracker = DependencyTracker { [w] in w.setActive(isActive: active()) }
|
|
tracker.run()
|
|
ctx.registry.add(tracker)
|
|
}
|
|
}
|
|
|
|
}
|