portico/Sources/Portico/Generated/Expander.swift

509 lines
22 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.Expander
/// Allows the user to reveal or conceal a child widget.
///
/// <picture>
/// <source srcset="expander-dark.png" media="(prefers-color-scheme: dark)">
/// <img alt="An example GtkExpander" src="expander.png">
/// </picture>
///
/// This is similar to the triangles used in a `GtkTreeView`.
///
/// Normally you use an expander as you would use a frame; you create
/// the child widget and use [method`Gtk`.Expander.set_child] to add it
/// to the expander. When the expander is toggled, it will take care of
/// showing and hiding the child automatically.
///
/// # Special Usage
///
/// There are situations in which you may prefer to show and hide the
/// expanded widget yourself, such as when you want to actually create
/// the widget at expansion time. In this case, create a `GtkExpander`
/// but do not add a child to it. The expander widget has an
/// [property`Gtk`.Expander:expanded] property which can be used to
/// monitor its expansion state. You should watch this property with
/// a signal connection as follows:
///
/// ```c
/// static void
/// expander_callback (GObject *object,
/// GParamSpec *param_spec,
/// gpointer user_data)
/// {
/// GtkExpander *expander;
///
/// expander = GTK_EXPANDER (object);
///
/// if (gtk_expander_get_expanded (expander))
/// {
/// // Show or create widgets
/// }
/// else
/// {
/// // Hide or destroy widgets
/// }
/// }
///
/// static void
/// create_expander (void)
/// {
/// GtkWidget *expander = gtk_expander_new_with_mnemonic ("_More Options");
/// g_signal_connect (expander, "notify::expanded",
/// G_CALLBACK (expander_callback), NULL);
///
/// // ...
/// }
/// ```
///
/// # GtkExpander as GtkBuildable
///
/// An example of a UI definition fragment with GtkExpander:
///
/// ```xml
/// <object class="GtkExpander">
/// <property name="label-widget">
/// <object class="GtkLabel" id="expander-label"/>
/// </property>
/// <property name="child">
/// <object class="GtkEntry" id="expander-content"/>
/// </property>
/// </object>
/// ```
///
/// # CSS nodes
///
/// ```
/// expander-widget
/// box
/// title
/// expander
/// <label widget>
/// <child>
/// ```
///
/// `GtkExpander` has a main node `expander-widget`, and subnode `box` containing
/// the title and child widget. The box subnode `title` contains node `expander`,
/// i.e. the expand/collapse arrow; then the label widget if any. The arrow of an
/// expander that is showing its child gets the `:checked` pseudoclass set on it.
///
/// # Accessibility
///
/// `GtkExpander` uses the [enum`Gtk`.AccessibleRole.button] role.
///
/// A Portico view that mounts a `Gtk.Expander`.
@MainActor public struct Expander: View {
private let make: (MountContext) -> Gtk.Expander
private var configure: [(Gtk.Expander, MountContext) -> Void] = []
public var body: Never { fatalError() }
// PorticoGen: generateInits(static) | source: Gtk.Expander.init(label:)
/// Creates a new expander using `label` as the text of the label.
///
/// Applied once at mount; use the `Binding` or closure overload for values that change.
///
/// - Parameter label: The text of the expanders label.
public init(label: String?) {
make = { _ in Gtk.Expander(label: label) }
}
// PorticoGen: generateInits(binding) | source: Gtk.Expander.init(label:), Gtk.Expander.setLabel(label:)
/// Creates a new expander using `label` as the text of the label.
///
/// The initial value is the binding's current value; every later change is pushed into the widget through `Gtk.Expander.setLabel(label:)` without rebuilding the view.
///
/// - Parameter label: The text of the expanders label.
public init(label: Portico.Binding<String?>) {
make = { _ in Gtk.Expander(label: label.wrappedValue) }
configure.append { w, ctx in
ctx.registry.add(label.subscribe { [w] v in w.setLabel(label: v) })
}
}
// PorticoGen: generateInits(closure) | source: Gtk.Expander.init(label:), Gtk.Expander.setLabel(label:)
/// Creates a new expander using `label` as the text of the label.
///
/// Each closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.Expander.setLabel(label:)`.
///
/// - Parameter label: The text of the expanders label.
public init(label: @escaping () -> String?) {
make = { _ in Gtk.Expander(label: label()) }
configure.append { w, ctx in
let t0 = DependencyTracker { [w] in w.setLabel(label: label()) }
t0.run()
ctx.registry.add(t0)
}
}
// PorticoGen: generateContentInit | source: Gtk.Expander.setChild(child:), Gtk.Expander.setLabelWidget(labelWidget:)
/// Creates a Expander with child widgets supplied by `ViewBuilder` closures.
///
/// Each closure is evaluated once; its first view is mounted into the matching slot.
/// Additional views are ignored; an empty closure leaves that slot unset.
///
/// - Parameter label: The text of the expanders label.
/// - Parameter child: A `ViewBuilder` closure whose first view is mounted into the `child` slot.
/// - Parameter labelWidget: A `ViewBuilder` closure whose first view is mounted into the `labelWidget` slot.
public init(label: String?, @ViewBuilder child: () -> [AnyView], @ViewBuilder labelWidget: () -> [AnyView]) {
let childViews = child()
let labelWidgetViews = labelWidget()
make = { _ in Gtk.Expander(label: label) }
configure.append { w, ctx in
if let v = childViews.first { w.setChild(child: v.makeWidget(ctx)) }
if let v = labelWidgetViews.first { w.setLabelWidget(labelWidget: v.makeWidget(ctx)) }
}
}
}
extension Expander: WidgetView {
public typealias Target = Gtk.Expander
@_spi(Portico) public func appending(
_ step: @escaping (Gtk.Expander, MountContext) -> Void
) -> Self {
var c = self
c.configure.append(step)
return c
}
}
@_spi(Portico) extension Expander: 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.Expander
/// Modifiers for `Gtk.Expander`, available on every Portico view whose
/// backing widget is `Gtk.Expander` or one of its subclasses.
extension WidgetView where Target: Gtk.Expander {
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.Expander.setChild(child:)
/// Sets the child widget of `expander`.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter child: The child widget.
/// - 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.Expander.setChild(child:)
/// Sets the child widget of `expander`.
///
/// 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.
/// - 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(static) | source: Gtk.Expander.setExpanded(expanded:)
/// Sets the state of the expander.
///
/// Set to `true`, if you want the child widget to be revealed,
/// and `false` if you want the child widget to be hidden.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter expanded: Whether the expander has been opened to reveal the child.
/// - Returns: A copy of this view with the modifier applied.
public func expanded(_ expanded: Bool) -> Self {
appending { w, _ in
w.setExpanded(expanded: expanded)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(oneWay) | source: Gtk.Expander.setExpanded(expanded:)
/// Sets the state of the expander.
///
/// Set to `true`, if you want the child widget to be revealed,
/// and `false` if you want the child widget to be hidden.
///
/// Applied at mount and re-applied on every change the binding publishes.
///
/// - Parameter expanded: Whether the expander has been opened to reveal the child.
/// - Returns: A copy of this view with the modifier applied.
public func expanded(_ expanded: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
w.setExpanded(expanded: expanded.wrappedValue)
ctx.registry.add(expanded.subscribe { [w] v in w.setExpanded(expanded: v) })
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.Expander.setExpanded(expanded:)
/// Sets the state of the expander.
///
/// Set to `true`, if you want the child widget to be revealed,
/// and `false` if you want the child widget to be hidden.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.Expander.setExpanded(expanded:)`.
///
/// - Parameter expanded: Whether the expander has been opened to reveal the child.
/// - Returns: A copy of this view with the modifier applied.
public func expanded(_ expanded: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setExpanded(expanded: expanded()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.Expander.setLabel(label:)
/// Sets the text of the label of the expander to `label`.
///
/// This will also clear any previously set labels.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter label: The text of the expanders label.
/// - Returns: A copy of this view with the modifier applied.
public func label(_ label: String?) -> Self {
appending { w, _ in
w.setLabel(label: label)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(oneWay) | source: Gtk.Expander.setLabel(label:)
/// Sets the text of the label of the expander to `label`.
///
/// This will also clear any previously set labels.
///
/// Applied at mount and re-applied on every change the binding publishes.
///
/// - Parameter label: The text of the expanders label.
/// - Returns: A copy of this view with the modifier applied.
public func label(_ label: Portico.Binding<String?>) -> Self {
appending { w, ctx in
w.setLabel(label: label.wrappedValue)
ctx.registry.add(label.subscribe { [w] v in w.setLabel(label: v) })
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(lifted) | source: Gtk.Expander.setLabel(label:)
/// Sets the text of the label of the expander to `label`.
///
/// This will also clear any previously set labels.
///
/// 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.
///
/// - Parameter label: The text of the expanders label.
/// - Returns: A copy of this view with the modifier applied.
public func label(_ label: Portico.Binding<String>) -> Self {
appending { w, ctx in
w.setLabel(label: label.wrappedValue)
ctx.registry.add(label.subscribe { [w] v in w.setLabel(label: v) })
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.Expander.setLabel(label:)
/// Sets the text of the label of the expander to `label`.
///
/// This will also clear any previously set labels.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.Expander.setLabel(label:)`.
///
/// - Parameter label: The text of the expanders 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(static) | source: Gtk.Expander.setLabelWidget(labelWidget:)
/// Set the label widget for the expander.
///
/// This is the widget that will appear embedded alongside
/// the expander arrow.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter labelWidget: A widget to display instead of the usual expander label.
/// - Returns: A copy of this view with the modifier applied.
public func labelWidget(_ labelWidget: Gtk.Widget?) -> Self {
appending { w, _ in
w.setLabelWidget(labelWidget: labelWidget)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(viewBuilder) | source: Gtk.Expander.setLabelWidget(labelWidget:)
/// Set the label widget for the expander.
///
/// This is the widget that will appear embedded alongside
/// the expander arrow.
///
/// 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 labelWidget: A widget to display instead of the usual expander label.
/// - Returns: A copy of this view with the modifier applied.
public func labelWidget(@ViewBuilder _ labelWidget: () -> [AnyView]) -> Self {
let labelWidgetViews = labelWidget()
return appending { w, ctx in
guard let v = labelWidgetViews.first else { return }
w.setLabelWidget(labelWidget: v.makeWidget(ctx))
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.Expander.setResizeToplevel(resizeToplevel:)
/// Sets whether the expander will resize the toplevel widget
/// containing the expander upon resizing and collapsing.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter resizeToplevel: When this property is `true`, the expander will resize the toplevel widget containing the expander upon expanding and collapsing.
/// - Returns: A copy of this view with the modifier applied.
public func resizeToplevel(_ resizeToplevel: Bool) -> Self {
appending { w, _ in
w.setResizeToplevel(resizeToplevel: resizeToplevel)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(oneWay) | source: Gtk.Expander.setResizeToplevel(resizeToplevel:)
/// Sets whether the expander will resize the toplevel widget
/// containing the expander upon resizing and collapsing.
///
/// Applied at mount and re-applied on every change the binding publishes.
///
/// - Parameter resizeToplevel: When this property is `true`, the expander will resize the toplevel widget containing the expander upon expanding and collapsing.
/// - Returns: A copy of this view with the modifier applied.
public func resizeToplevel(_ resizeToplevel: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
w.setResizeToplevel(resizeToplevel: resizeToplevel.wrappedValue)
ctx.registry.add(resizeToplevel.subscribe { [w] v in w.setResizeToplevel(resizeToplevel: v) })
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.Expander.setResizeToplevel(resizeToplevel:)
/// Sets whether the expander will resize the toplevel widget
/// containing the expander upon resizing and collapsing.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.Expander.setResizeToplevel(resizeToplevel:)`.
///
/// - Parameter resizeToplevel: When this property is `true`, the expander will resize the toplevel widget containing the expander upon expanding and collapsing.
/// - Returns: A copy of this view with the modifier applied.
public func resizeToplevel(_ resizeToplevel: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setResizeToplevel(resizeToplevel: resizeToplevel()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.Expander.setUseMarkup(useMarkup:)
/// Sets whether the text of the label contains Pango markup.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter useMarkup: Whether the text in the label is Pango markup.
/// - Returns: A copy of this view with the modifier applied.
public func useMarkup(_ useMarkup: Bool) -> Self {
appending { w, _ in
w.setUseMarkup(useMarkup: useMarkup)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(oneWay) | source: Gtk.Expander.setUseMarkup(useMarkup:)
/// Sets whether the text of the label contains Pango markup.
///
/// Applied at mount and re-applied on every change the binding publishes.
///
/// - Parameter useMarkup: Whether the text in the label is Pango markup.
/// - Returns: A copy of this view with the modifier applied.
public func useMarkup(_ useMarkup: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
w.setUseMarkup(useMarkup: useMarkup.wrappedValue)
ctx.registry.add(useMarkup.subscribe { [w] v in w.setUseMarkup(useMarkup: v) })
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.Expander.setUseMarkup(useMarkup:)
/// Sets whether the text of the label contains Pango markup.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.Expander.setUseMarkup(useMarkup:)`.
///
/// - Parameter useMarkup: Whether the text in the label is Pango markup.
/// - Returns: A copy of this view with the modifier applied.
public func useMarkup(_ useMarkup: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setUseMarkup(useMarkup: useMarkup()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.Expander.setUseUnderline(useUnderline:)
/// If true, an underline in the text indicates a mnemonic.
///
/// 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(oneWay) | source: Gtk.Expander.setUseUnderline(useUnderline:)
/// If true, an underline in the text indicates a mnemonic.
///
/// Applied at mount and re-applied on every change the binding publishes.
///
/// - 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: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
w.setUseUnderline(useUnderline: useUnderline.wrappedValue)
ctx.registry.add(useUnderline.subscribe { [w] v in w.setUseUnderline(useUnderline: v) })
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.Expander.setUseUnderline(useUnderline:)
/// If true, an underline in the text indicates a mnemonic.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.Expander.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)
}
}
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Gtk.Expander.connectActivate(_:)
/// Activates the `GtkExpander`.
///
/// - Parameter handler: Invoked when the widget emits the `activate` signal.
/// - Returns: A copy of this view with the modifier applied.
public func onActivate(_ handler: @escaping () -> Void) -> Self {
appending { w, ctx in
ctx.registry.add(w.connectActivate { _ in handler() })
}
}
}