416 lines
20 KiB
Swift
416 lines
20 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.ToggleGroup
|
|
/// A group of exclusive toggles.
|
|
///
|
|
/// <picture>
|
|
/// <source srcset="toggle-group-dark.png" media="(prefers-color-scheme: dark)">
|
|
/// <img src="toggle-group.png" alt="toggle-group">
|
|
/// </picture>
|
|
///
|
|
/// `AdwToggleGroup` presents a set of exclusive toggles, represented as
|
|
/// [class`Toggle`] objects. Each toggle can display an icon, a label, an icon
|
|
/// and a label, or a custom child.
|
|
///
|
|
/// Toggles are indexed by their position, with the first toggle being equivalent
|
|
/// to 0, and so on. Use the [property`ToggleGroup`:active] to get that position.
|
|
///
|
|
/// Toggles can also have optional names, set via the [property`Toggle`:name]
|
|
/// property. The name of the active toggle can be accessed via the
|
|
/// [property`ToggleGroup`:active-name] property.
|
|
///
|
|
/// `AdwToggle` objects can be retrieved via their index or name, using
|
|
/// [method`ToggleGroup`.get_toggle] or [method`ToggleGroup`.get_toggle_by_name]
|
|
/// respectively. `AdwToggleGroup` also provides a [iface`Gtk`.SelectionModel] of
|
|
/// its toggles via the [property`ToggleGroup`:toggles] property.
|
|
///
|
|
/// `AdwToggleGroup` is orientable, and the toggles can be displayed horizontally
|
|
/// or vertically. This is mostly useful for icon-only toggles.
|
|
///
|
|
/// Use the [property`ToggleGroup`:homogeneous] property to make the toggles take
|
|
/// the same size, and the [property`ToggleGroup`:can-shrink] to control whether
|
|
/// the toggles can ellipsize.
|
|
///
|
|
/// Example of an `AdwToggleGroup` UI definition:
|
|
///
|
|
/// ```xml
|
|
/// <object class="AdwToggleGroup">
|
|
/// <property name="active-name">picture</property>
|
|
/// <child>
|
|
/// <object class="AdwToggle">
|
|
/// <property name="icon-name">camera-photo-symbolic</property>
|
|
/// <property name="tooltip" translatable="yes">Picture Mode</property>
|
|
/// <property name="name">picture</property>
|
|
/// </object>
|
|
/// </child>
|
|
/// <child>
|
|
/// <object class="AdwToggle">
|
|
/// <property name="icon-name">camera-video-symbolic</property>
|
|
/// <property name="tooltip" translatable="yes">Recording Mode</property>
|
|
/// <property name="name">recording</property>
|
|
/// </object>
|
|
/// </child>
|
|
/// </object>
|
|
/// ```
|
|
///
|
|
/// See also: [class`InlineViewSwitcher`].
|
|
///
|
|
/// ## CSS nodes
|
|
///
|
|
/// `AdwToggleGroup` has a main CSS node with the name `toggle-group`.
|
|
///
|
|
/// Its toggles have CSS nodes with the name `toggle`, and its separators have nodes
|
|
/// with the name `separator`.
|
|
///
|
|
/// Toggle nodes will have a different style classes depending on their content:
|
|
/// `.text-button` for labels, `.image-button` for icons, `.image-text-button`
|
|
/// for both or no style class for custom children.
|
|
///
|
|
/// The hidden separators use the `.hidden` style class.
|
|
///
|
|
/// ## Style classes
|
|
///
|
|
/// `AdwToggleGroup` can use the [`.flat`](style-classes.html`flat_1`) style class
|
|
/// to remove its background and make it look like a group of buttons.
|
|
///
|
|
/// <picture>
|
|
/// <source srcset="toggle-group-flat-dark.png" media="(prefers-color-scheme: dark)">
|
|
/// <img src="toggle-group-flat.png" alt="toggle-group-flat">
|
|
/// </picture>
|
|
///
|
|
/// It can also use the [`.round`](style-classes.html`round`) style class to make
|
|
/// its toggles and the group itself rounded.
|
|
///
|
|
/// <picture>
|
|
/// <source srcset="toggle-group-round-dark.png" media="(prefers-color-scheme: dark)">
|
|
/// <img src="toggle-group-round.png" alt="toggle-group-round">
|
|
/// </picture>
|
|
///
|
|
/// They can also be combined with each other.
|
|
///
|
|
/// <picture>
|
|
/// <source srcset="toggle-group-flat-round-dark.png" media="(prefers-color-scheme: dark)">
|
|
/// <img src="toggle-group-flat-round.png" alt="toggle-group-flat-round">
|
|
/// </picture>
|
|
///
|
|
/// ## Accessibility
|
|
///
|
|
/// `AdwToggleGroup` uses the [enum`Gtk`.AccessibleRole.radio-group] role. Its
|
|
/// toggles use the [enum`Gtk`.AccessibleRole.radio] role.
|
|
///
|
|
/// A Portico view that mounts a `Adw.ToggleGroup`.
|
|
@MainActor public struct ToggleGroup: View {
|
|
private let make: (MountContext) -> Adw.ToggleGroup
|
|
private var configure: [(Adw.ToggleGroup, MountContext) -> Void] = []
|
|
|
|
public var body: Never { fatalError() }
|
|
|
|
// PorticoGen: generateInits(static) | source: Adw.ToggleGroup.init()
|
|
/// Creates a new `AdwToggleGroup`.
|
|
///
|
|
/// 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 active: The index of the active toggle.
|
|
/// - Parameter activeName: The name of the active toggle.
|
|
/// - Parameter canShrink: Whether the toggles can be smaller than the natural size of their contents.
|
|
/// - Parameter homogeneous: Whether all toggles take the same size.
|
|
public init(active: UInt32? = nil, activeName: String? = nil, canShrink: Bool? = nil, homogeneous: Bool? = nil) {
|
|
make = { _ in Adw.ToggleGroup() }
|
|
configure.append { w, _ in
|
|
if let active { w.setActive(active: active) }
|
|
if let activeName { w.setActiveName(name: activeName) }
|
|
if let canShrink { w.setCanShrink(canShrink: canShrink) }
|
|
if let homogeneous { w.setHomogeneous(homogeneous: homogeneous) }
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
extension ToggleGroup: WidgetView {
|
|
public typealias Target = Adw.ToggleGroup
|
|
|
|
@_spi(Portico) public func appending(
|
|
_ step: @escaping (Adw.ToggleGroup, MountContext) -> Void
|
|
) -> Self {
|
|
var c = self
|
|
c.configure.append(step)
|
|
return c
|
|
}
|
|
}
|
|
|
|
@_spi(Portico) extension ToggleGroup: 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.ToggleGroup
|
|
/// Modifiers for `Adw.ToggleGroup`, available on every Portico view whose
|
|
/// backing widget is `Adw.ToggleGroup` or one of its subclasses.
|
|
extension WidgetView where Target: Adw.ToggleGroup {
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.ToggleGroup.setActive(active:)
|
|
/// Sets the active toggle for `self`.
|
|
///
|
|
/// If the index is larger than the number of toggles in `self`, unsets the
|
|
/// current active toggle.
|
|
///
|
|
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
|
|
///
|
|
/// - Parameter active: The index of the active toggle.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func active(_ active: UInt32) -> Self {
|
|
appending { w, _ in
|
|
w.setActive(active: active)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.ToggleGroup.setActive(active:), GObject.Object.connectNotify(detail:_:), Adw.ToggleGroup.getActive()
|
|
/// Sets the active toggle for `self`.
|
|
///
|
|
/// If the index is larger than the number of toggles in `self`, unsets the
|
|
/// current active toggle.
|
|
///
|
|
/// Applied at mount and re-applied on every change the binding publishes.
|
|
/// When `UInt32` 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<UInt32>) -> 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(active: v) }
|
|
)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.ToggleGroup.setActive(active:)
|
|
/// Sets the active toggle for `self`.
|
|
///
|
|
/// If the index is larger than the number of toggles in `self`, unsets the
|
|
/// current active toggle.
|
|
///
|
|
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.ToggleGroup.setActive(active:)`.
|
|
///
|
|
/// - Parameter active: The index of the active toggle.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func active(_ active: @escaping () -> UInt32) -> Self {
|
|
appending { w, ctx in
|
|
let tracker = DependencyTracker { [w] in w.setActive(active: active()) }
|
|
tracker.run()
|
|
ctx.registry.add(tracker)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.ToggleGroup.setActiveName(name:)
|
|
/// Sets the active toggle for `self`.
|
|
///
|
|
/// The name can be set via [property`Toggle`:name].
|
|
///
|
|
/// If `name` is `NULL`, unset the current active toggle instead.
|
|
///
|
|
/// 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 activeName: The name of the active toggle.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
@_disfavoredOverload
|
|
public func activeName<S: StringProtocol>(_ activeName: S?) -> Self {
|
|
appending { w, _ in
|
|
w.setActiveName(name: activeName.map { String($0) })
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.ToggleGroup.setActiveName(name:), GObject.Object.connectNotify(detail:_:), Adw.ToggleGroup.getActiveName()
|
|
/// Sets the active toggle for `self`.
|
|
///
|
|
/// The name can be set via [property`Toggle`:name].
|
|
///
|
|
/// If `name` is `NULL`, unset the current active toggle instead.
|
|
///
|
|
/// 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 activeName(_ activeName: Portico.Binding<String?>) -> Self {
|
|
appending { w, ctx in
|
|
Portico.bindProperty(
|
|
w, activeName, registry: ctx.registry, notifyDetail: "active-name",
|
|
read: { [w] in w.getActiveName() },
|
|
write: { [w] v in w.setActiveName(name: v) }
|
|
)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(lifted,twoWay) | source: Adw.ToggleGroup.setActiveName(name:), GObject.Object.connectNotify(detail:_:), Adw.ToggleGroup.getActiveName()
|
|
/// Sets the active toggle for `self`.
|
|
///
|
|
/// The name can be set via [property`Toggle`:name].
|
|
///
|
|
/// If `name` is `NULL`, unset the current active toggle instead.
|
|
///
|
|
/// 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 activeName(_ activeName: Portico.Binding<String>) -> Self {
|
|
appending { w, ctx in
|
|
Portico.bindProperty(
|
|
w, activeName, registry: ctx.registry, notifyDetail: "active-name",
|
|
read: { [w] in w.getActiveName() },
|
|
write: { [w] v in w.setActiveName(name: v) }
|
|
)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.ToggleGroup.setActiveName(name:)
|
|
/// Sets the active toggle for `self`.
|
|
///
|
|
/// The name can be set via [property`Toggle`:name].
|
|
///
|
|
/// If `name` is `NULL`, unset the current active toggle instead.
|
|
///
|
|
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.ToggleGroup.setActiveName(name:)`.
|
|
///
|
|
/// - Parameter activeName: The name of the active toggle.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func activeName(_ activeName: @escaping () -> String?) -> Self {
|
|
appending { w, ctx in
|
|
let tracker = DependencyTracker { [w] in w.setActiveName(name: activeName()) }
|
|
tracker.run()
|
|
ctx.registry.add(tracker)
|
|
}
|
|
}
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(interpolation) | source: Adw.ToggleGroup.setActiveName(name:)
|
|
/// Sets the active toggle for `self`.
|
|
///
|
|
/// The name can be set via [property`Toggle`:name].
|
|
///
|
|
/// If `name` is `NULL`, unset the current active toggle instead.
|
|
///
|
|
/// Interpolated segments are captured unevaluated and re-read inside a `DependencyTracker`, so any `@State` they read pushes a new value through `Adw.ToggleGroup.setActiveName(name:)`. A literal with no interpolation is applied once, with no subscription.
|
|
///
|
|
/// - Parameter activeName: The name of the active toggle.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func activeName(_ activeName: Portico.InterpolatedText?) -> Self {
|
|
appending { w, ctx in
|
|
Portico.bindOptionalInterpolation(activeName, registry: ctx.registry) { [w] v in w.setActiveName(name: v) }
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.ToggleGroup.setCanShrink(canShrink:)
|
|
/// Sets whether the toggles can be smaller than the natural size of their
|
|
/// contents.
|
|
///
|
|
/// If `can_shrink` is `TRUE`, the toggle labels will ellipsize.
|
|
///
|
|
/// See [property`Gtk`.Button:can-shrink].
|
|
///
|
|
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
|
|
///
|
|
/// - Parameter canShrink: Whether the toggles can be smaller than the natural size of their 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.ToggleGroup.setCanShrink(canShrink:), GObject.Object.connectNotify(detail:_:), Adw.ToggleGroup.getCanShrink()
|
|
/// Sets whether the toggles can be smaller than the natural size of their
|
|
/// contents.
|
|
///
|
|
/// If `can_shrink` is `TRUE`, the toggle labels will ellipsize.
|
|
///
|
|
/// See [property`Gtk`.Button: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.ToggleGroup.setCanShrink(canShrink:)
|
|
/// Sets whether the toggles can be smaller than the natural size of their
|
|
/// contents.
|
|
///
|
|
/// If `can_shrink` is `TRUE`, the toggle labels will ellipsize.
|
|
///
|
|
/// See [property`Gtk`.Button:can-shrink].
|
|
///
|
|
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.ToggleGroup.setCanShrink(canShrink:)`.
|
|
///
|
|
/// - Parameter canShrink: Whether the toggles can be smaller than the natural size of their 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.ToggleGroup.setHomogeneous(homogeneous:)
|
|
/// Sets whether all toggles take the same size.
|
|
///
|
|
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
|
|
///
|
|
/// - Parameter homogeneous: Whether all toggles take the same size.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func homogeneous(_ homogeneous: Bool) -> Self {
|
|
appending { w, _ in
|
|
w.setHomogeneous(homogeneous: homogeneous)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.ToggleGroup.setHomogeneous(homogeneous:), GObject.Object.connectNotify(detail:_:), Adw.ToggleGroup.getHomogeneous()
|
|
/// Sets whether all toggles take the same size.
|
|
///
|
|
/// 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 homogeneous(_ homogeneous: Portico.Binding<Bool>) -> Self {
|
|
appending { w, ctx in
|
|
Portico.bindProperty(
|
|
w, homogeneous, registry: ctx.registry, notifyDetail: "homogeneous",
|
|
read: { [w] in w.getHomogeneous() },
|
|
write: { [w] v in w.setHomogeneous(homogeneous: v) }
|
|
)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.ToggleGroup.setHomogeneous(homogeneous:)
|
|
/// Sets whether all toggles take the same size.
|
|
///
|
|
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.ToggleGroup.setHomogeneous(homogeneous:)`.
|
|
///
|
|
/// - Parameter homogeneous: Whether all toggles take the same size.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func homogeneous(_ homogeneous: @escaping () -> Bool) -> Self {
|
|
appending { w, ctx in
|
|
let tracker = DependencyTracker { [w] in w.setHomogeneous(homogeneous: homogeneous()) }
|
|
tracker.run()
|
|
ctx.registry.add(tracker)
|
|
}
|
|
}
|
|
|
|
}
|