portico/Sources/Portico/Generated/TreeExpander.swift

421 lines
24 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: Gtk.TreeExpander
/// Provides an expander for a tree-like list.
///
/// It is typically placed as a bottommost child into a `GtkListView`
/// to allow users to expand and collapse children in a list with a
/// [class`Gtk`.TreeListModel]. `GtkTreeExpander` provides the common UI
/// elements, gestures and keybindings for this purpose.
///
/// On top of this, the "listitem.expand", "listitem.collapse" and
/// "listitem.toggle-expand" actions are provided to allow adding custom
/// UI for managing expanded state.
///
/// It is important to mention that you want to set the
/// [property`Gtk`.ListItem:focusable] property to FALSE when using this
/// widget, as you want the keyboard focus to be in the treexpander, and not
/// inside the list to make use of the keybindings.
///
/// The `GtkTreeListModel` must be set to not be passthrough. Then it
/// will provide [class`Gtk`.TreeListRow] items which can be set via
/// [method`Gtk`.TreeExpander.set_list_row] on the expander.
/// The expander will then watch that row item automatically.
/// [method`Gtk`.TreeExpander.set_child] sets the widget that displays
/// the actual row contents.
///
/// `GtkTreeExpander` can be modified with properties such as
/// [property`Gtk`.TreeExpander:indent-for-icon],
/// [property`Gtk`.TreeExpander:indent-for-depth], and
/// [property`Gtk`.TreeExpander:hide-expander] to achieve a different appearance.
/// This can even be done to influence individual rows, for example by binding
/// the [property`Gtk`.TreeExpander:hide-expander] property to the item count of
/// the model of the treelistrow, to hide the expander for rows without children,
/// even if the row is expandable.
///
/// ## Shortcuts and Gestures
///
/// `GtkTreeExpander` supports the following keyboard shortcuts:
///
/// - <kbd>+</kbd> or <kbd>*</kbd> expands the expander.
/// - <kbd>-</kbd> or <kbd>/</kbd> collapses the expander.
/// - Left and right arrow keys, when combined with <kbd>Shift</kbd> or
/// <kbd>Ctrl</kbd>+<kbd>Shift</kbd>, will expand or collapse, depending on
/// the locale's text direction.
/// - <kbd>Ctrl</kbd>+<kbd></kbd> toggles the expander state.
///
/// The row can also expand on drag gestures.
///
/// ## Actions
///
/// `GtkTreeExpander` defines a set of built-in actions:
///
/// - `listitem.expand` expands the expander if it can be expanded.
/// - `listitem.collapse` collapses the expander.
/// - `listitem.toggle-expand` tries to expand the expander if it was collapsed
/// or collapses it if it was expanded.
///
/// ## CSS nodes
///
/// ```
/// treeexpander
/// [indent]*
/// [expander]
/// <child>
/// ```
///
/// `GtkTreeExpander` has zero or one CSS nodes with the name "expander" that
/// should display the expander icon. The node will be `:checked` when it
/// is expanded. If the node is not expandable, an "indent" node will be
/// displayed instead.
///
/// For every level of depth, another "indent" node is prepended.
///
/// ## Accessibility
///
/// Until GTK 4.10, `GtkTreeExpander` used the [enum`Gtk`.AccessibleRole.group] role.
///
/// Since GTK 4.12, `GtkTreeExpander` uses the [enum`Gtk`.AccessibleRole.button] role.
/// Toggling it will change the `GTK_ACCESSIBLE_STATE_EXPANDED` state.
///
/// A Portico view that mounts a `Gtk.TreeExpander`.
@MainActor public struct TreeExpander: View {
private let make: (MountContext) -> Gtk.TreeExpander
private var configure: [(Gtk.TreeExpander, MountContext) -> Void] = []
public var body: Never { fatalError() }
// PorticoGen: generateInits(static) | source: Gtk.TreeExpander.init()
/// Creates a new `GtkTreeExpander`
///
/// 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 hideExpander: Whether the expander icon should be hidden in a GtkTreeListRow. Note that this property simply hides the icon. The actions and keybinding (i.e. collapse and expand) are not affected by this property.
/// - Parameter indentForDepth: TreeExpander indents the child according to its depth.
/// - Parameter indentForIcon: TreeExpander indents the child by the width of an expander-icon if it is not expandable.
/// - Parameter listRow: The list row to track for expander state.
/// - Parameter child: A `ViewBuilder` closure whose first view is mounted into the `child` slot.
public init(hideExpander: Bool? = nil, indentForDepth: Bool? = nil, indentForIcon: Bool? = nil, listRow: Gtk.TreeListRow? = nil, @ViewBuilder child: @escaping () -> [AnyView] = { [] }) {
make = { _ in Gtk.TreeExpander() }
configure.append { w, ctx in
if let hideExpander { w.setHideExpander(hideExpander: hideExpander) }
if let indentForDepth { w.setIndentForDepth(indentForDepth: indentForDepth) }
if let indentForIcon { w.setIndentForIcon(indentForIcon: indentForIcon) }
if let listRow { w.setListRow(listRow: listRow) }
if let v = Portico.mountSlotChild(child, ctx, onUpdate: { v in w.setChild(child: v) }) { w.setChild(child: v) }
}
}
}
extension TreeExpander: WidgetView {
public typealias Target = Gtk.TreeExpander
@_spi(Portico) public func appending(
_ step: @escaping (Gtk.TreeExpander, MountContext) -> Void
) -> Self {
var c = self
c.configure.append(step)
return c
}
}
@_spi(Portico) extension TreeExpander: 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: Gtk.TreeExpander
/// Modifiers for `Gtk.TreeExpander`, available on every Portico view whose
/// backing widget is `Gtk.TreeExpander` or one of its subclasses.
extension WidgetView where Target: Gtk.TreeExpander {
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.TreeExpander.setChild(child:)
/// Sets the content widget to display.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter child: The child widget with the actual contents.
/// - Returns: A copy of this view with the modifier applied.
public func child(_ child: Gtk.Widget?) -> Self {
appending { w, _ in
w.setChild(child: child)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(viewBuilder) | source: Gtk.TreeExpander.setChild(child:)
/// Sets the content widget to display.
///
/// The closure is evaluated once when the modifier is applied. Its first view is mounted into the slot.
/// Additional views are ignored; an empty closure leaves the slot unset.
///
/// - Parameter child: The child widget with the actual contents.
/// - Returns: A copy of this view with the modifier applied.
public func child(@ViewBuilder _ child: () -> [AnyView]) -> Self {
let childViews = child()
return appending { w, ctx in
guard let v = childViews.first else { return }
w.setChild(child: v.makeWidget(ctx))
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.TreeExpander.setChild(child:), GObject.Object.connectNotify(detail:_:), Gtk.TreeExpander.getChild()
/// Sets the content widget to display.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Gtk.Widget?` 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 child<W: Gtk.Widget>(_ child: Portico.Binding<W?>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, child, registry: ctx.registry, notifyDetail: "child",
read: { [w] in w.getChild() as? W },
write: { [w] v in w.setChild(child: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(lifted,twoWay) | source: Gtk.TreeExpander.setChild(child:), GObject.Object.connectNotify(detail:_:), Gtk.TreeExpander.getChild()
/// Sets the content widget to display.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// `Binding` is invariant, so a `Binding<Gtk.Widget>` is not accepted by the nullable overload; this one takes it and promotes each value. Pass a `Binding<Gtk.Widget?>` to be able to clear the property.
/// When `Gtk.Widget` 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 child<W: Gtk.Widget>(_ child: Portico.Binding<W>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, child, registry: ctx.registry, notifyDetail: "child",
read: { [w] in w.getChild() as? W },
write: { [w] v in w.setChild(child: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.TreeExpander.setChild(child:)
/// Sets the content widget to display.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.TreeExpander.setChild(child:)`.
///
/// - Parameter child: The child widget with the actual contents.
/// - Returns: A copy of this view with the modifier applied.
public func child(_ child: @escaping () -> Gtk.Widget?) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setChild(child: child()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.TreeExpander.setHideExpander(hideExpander:)
/// Sets whether the expander icon should be visible in a GtkTreeListRow.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter hideExpander: Whether the expander icon should be hidden in a GtkTreeListRow. Note that this property simply hides the icon. The actions and keybinding (i.e. collapse and expand) are not affected by this property.
/// - Returns: A copy of this view with the modifier applied.
public func hideExpander(_ hideExpander: Bool) -> Self {
appending { w, _ in
w.setHideExpander(hideExpander: hideExpander)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.TreeExpander.setHideExpander(hideExpander:), GObject.Object.connectNotify(detail:_:), Gtk.TreeExpander.getHideExpander()
/// Sets whether the expander icon should be visible in a GtkTreeListRow.
///
/// 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 hideExpander(_ hideExpander: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, hideExpander, registry: ctx.registry, notifyDetail: "hide-expander",
read: { [w] in w.getHideExpander() },
write: { [w] v in w.setHideExpander(hideExpander: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.TreeExpander.setHideExpander(hideExpander:)
/// Sets whether the expander icon should be visible in a GtkTreeListRow.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.TreeExpander.setHideExpander(hideExpander:)`.
///
/// - Parameter hideExpander: Whether the expander icon should be hidden in a GtkTreeListRow. Note that this property simply hides the icon. The actions and keybinding (i.e. collapse and expand) are not affected by this property.
/// - Returns: A copy of this view with the modifier applied.
public func hideExpander(_ hideExpander: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setHideExpander(hideExpander: hideExpander()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.TreeExpander.setIndentForDepth(indentForDepth:)
/// Sets if the TreeExpander should indent the child according to its depth.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter indentForDepth: TreeExpander indents the child according to its depth.
/// - Returns: A copy of this view with the modifier applied.
public func indentForDepth(_ indentForDepth: Bool) -> Self {
appending { w, _ in
w.setIndentForDepth(indentForDepth: indentForDepth)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.TreeExpander.setIndentForDepth(indentForDepth:), GObject.Object.connectNotify(detail:_:), Gtk.TreeExpander.getIndentForDepth()
/// Sets if the TreeExpander should indent the child according to its depth.
///
/// 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 indentForDepth(_ indentForDepth: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, indentForDepth, registry: ctx.registry, notifyDetail: "indent-for-depth",
read: { [w] in w.getIndentForDepth() },
write: { [w] v in w.setIndentForDepth(indentForDepth: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.TreeExpander.setIndentForDepth(indentForDepth:)
/// Sets if the TreeExpander should indent the child according to its depth.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.TreeExpander.setIndentForDepth(indentForDepth:)`.
///
/// - Parameter indentForDepth: TreeExpander indents the child according to its depth.
/// - Returns: A copy of this view with the modifier applied.
public func indentForDepth(_ indentForDepth: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setIndentForDepth(indentForDepth: indentForDepth()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.TreeExpander.setIndentForIcon(indentForIcon:)
/// Sets if the TreeExpander should indent the child by the width of an expander-icon when it is not expandable.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter indentForIcon: TreeExpander indents the child by the width of an expander-icon if it is not expandable.
/// - Returns: A copy of this view with the modifier applied.
public func indentForIcon(_ indentForIcon: Bool) -> Self {
appending { w, _ in
w.setIndentForIcon(indentForIcon: indentForIcon)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.TreeExpander.setIndentForIcon(indentForIcon:), GObject.Object.connectNotify(detail:_:), Gtk.TreeExpander.getIndentForIcon()
/// Sets if the TreeExpander should indent the child by the width of an expander-icon when it is not expandable.
///
/// 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 indentForIcon(_ indentForIcon: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, indentForIcon, registry: ctx.registry, notifyDetail: "indent-for-icon",
read: { [w] in w.getIndentForIcon() },
write: { [w] v in w.setIndentForIcon(indentForIcon: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.TreeExpander.setIndentForIcon(indentForIcon:)
/// Sets if the TreeExpander should indent the child by the width of an expander-icon when it is not expandable.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.TreeExpander.setIndentForIcon(indentForIcon:)`.
///
/// - Parameter indentForIcon: TreeExpander indents the child by the width of an expander-icon if it is not expandable.
/// - Returns: A copy of this view with the modifier applied.
public func indentForIcon(_ indentForIcon: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setIndentForIcon(indentForIcon: indentForIcon()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.TreeExpander.setListRow(listRow:)
/// Sets the tree list row that this expander should manage.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter listRow: The list row to track for expander state.
/// - Returns: A copy of this view with the modifier applied.
public func listRow(_ listRow: Gtk.TreeListRow?) -> Self {
appending { w, _ in
w.setListRow(listRow: listRow)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.TreeExpander.setListRow(listRow:), GObject.Object.connectNotify(detail:_:), Gtk.TreeExpander.getListRow()
/// Sets the tree list row that this expander should manage.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Gtk.TreeListRow?` 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 listRow(_ listRow: Portico.Binding<Gtk.TreeListRow?>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, listRow, registry: ctx.registry, notifyDetail: "list-row",
read: { [w] in w.getListRow() },
write: { [w] v in w.setListRow(listRow: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(lifted,twoWay) | source: Gtk.TreeExpander.setListRow(listRow:), GObject.Object.connectNotify(detail:_:), Gtk.TreeExpander.getListRow()
/// Sets the tree list row that this expander should manage.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// `Binding` is invariant, so a `Binding<Gtk.TreeListRow>` is not accepted by the nullable overload; this one takes it and promotes each value. Pass a `Binding<Gtk.TreeListRow?>` to be able to clear the property.
/// When `Gtk.TreeListRow` 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 listRow(_ listRow: Portico.Binding<Gtk.TreeListRow>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, listRow, registry: ctx.registry, notifyDetail: "list-row",
read: { [w] in w.getListRow() },
write: { [w] v in w.setListRow(listRow: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.TreeExpander.setListRow(listRow:)
/// Sets the tree list row that this expander should manage.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.TreeExpander.setListRow(listRow:)`.
///
/// - Parameter listRow: The list row to track for expander state.
/// - Returns: A copy of this view with the modifier applied.
public func listRow(_ listRow: @escaping () -> Gtk.TreeListRow?) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setListRow(listRow: listRow()) }
tracker.run()
ctx.registry.add(tracker)
}
}
}