portico/Sources/Portico/Generated/ComboBoxText.swift

137 lines
7 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.ComboBoxText
/// A `GtkComboBoxText` is a simple variant of `GtkComboBox` for text-only
/// use cases.
///
/// <picture>
/// <source srcset="combo-box-text-dark.png" media="(prefers-color-scheme: dark)">
/// <img alt="An example GtkComboBoxText" src="combo-box-text.png">
/// </picture>
///
/// `GtkComboBoxText` hides the model-view complexity of `GtkComboBox`.
///
/// To create a `GtkComboBoxText`, use [ctor`Gtk`.ComboBoxText.new] or
/// [ctor`Gtk`.ComboBoxText.new_with_entry].
///
/// You can add items to a `GtkComboBoxText` with
/// [method`Gtk`.ComboBoxText.append_text],
/// [method`Gtk`.ComboBoxText.insert_text] or
/// [method`Gtk`.ComboBoxText.prepend_text] and remove options with
/// [method`Gtk`.ComboBoxText.remove].
///
/// If the `GtkComboBoxText` contains an entry (via the
/// [property`Gtk`.ComboBox:has-entry] property), its contents can be retrieved
/// using [method`Gtk`.ComboBoxText.get_active_text].
///
/// You should not call [method`Gtk`.ComboBox.set_model] or attempt to pack more
/// cells into this combo box via its [iface`Gtk`.CellLayout] interface.
///
/// ## GtkComboBoxText as GtkBuildable
///
/// The `GtkComboBoxText` implementation of the `GtkBuildable` interface supports
/// adding items directly using the `<items>` element and specifying `<item>`
/// elements for each item. Each `<item>` element can specify the id
/// corresponding to the appended text and also supports the regular
/// translation attributes translatable, context and comments.
///
/// Here is a UI definition fragment specifying `GtkComboBoxText` items:
/// ```xml
/// <object class="GtkComboBoxText">
/// <items>
/// <item translatable="yes" id="factory">Factory</item>
/// <item translatable="yes" id="home">Home</item>
/// <item translatable="yes" id="subway">Subway</item>
/// </items>
/// </object>
/// ```
///
/// ## CSS nodes
///
/// ```
/// combobox
/// box.linked
/// entry.combo
/// button.combo
/// window.popup
/// ```
///
/// `GtkComboBoxText` has a single CSS node with name combobox. It adds
/// the style class .combo to the main CSS nodes of its entry and button
/// children, and the .linked class to the node of its internal box.
///
/// A Portico view that mounts a `Gtk.ComboBoxText`.
@MainActor public struct ComboBoxText: View {
private let make: (MountContext) -> Gtk.ComboBoxText
private var configure: [(Gtk.ComboBoxText, MountContext) -> Void] = []
public var body: Never { fatalError() }
// PorticoGen: generateInits(static) | source: Gtk.ComboBoxText.init()
/// Creates a new `GtkComboBoxText`.
///
/// 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: The item which is currently active.
/// - Parameter activeId: The value of the ID column of the active row.
/// - Parameter buttonSensitivity: Whether the dropdown button is sensitive when the model is empty.
/// - Parameter entryTextColumn: The model column to associate with strings from the entry.
/// - Parameter idColumn: The model column that provides string IDs for the values in the model, if != -1.
/// - Parameter model: The model from which the combo box takes its values.
/// - Parameter popupFixedWidth: Whether the popup's width should be a fixed width matching the allocated width of the combo box.
/// - Parameter child: A `ViewBuilder` closure whose first view is mounted into the `child` slot.
/// - Parameter onActivate: Invoked when the widget emits the `activate` signal.
/// - Parameter onChanged: Invoked when the widget emits the `changed` signal.
/// - Parameter onFormatEntryText: Invoked when the widget emits the `format-entry-text` signal. The closure receives the signal's arguments in order. Its return value is forwarded to GTK as the signal's result.
/// - Parameter onMoveActive: Invoked when the widget emits the `move-active` signal. The closure receives the signal's arguments in order.
/// - Parameter onPopdown: Invoked when the widget emits the `popdown` signal. Its return value is forwarded to GTK as the signal's result.
/// - Parameter onPopup: Invoked when the widget emits the `popup` signal.
public init(active: Int32? = nil, activeId: String? = nil, buttonSensitivity: Gtk.SensitivityType? = nil, entryTextColumn: Int32? = nil, idColumn: Int32? = nil, model: Gtk.TreeModel? = nil, popupFixedWidth: Bool? = nil, @ViewBuilder child: @escaping () -> [AnyView] = { [] }, onActivate: (() -> Void)? = nil, onChanged: (() -> Void)? = nil, onFormatEntryText: ((String) -> String)? = nil, onMoveActive: ((Gtk.ScrollType) -> Void)? = nil, onPopdown: (() -> Bool)? = nil, onPopup: (() -> Void)? = nil) {
make = { _ in Gtk.ComboBoxText() }
configure.append { w, ctx in
if let active { w.setActive(index: active) }
if let activeId { w.setActiveId(activeId: activeId) }
if let buttonSensitivity { w.setButtonSensitivity(sensitivity: buttonSensitivity) }
if let entryTextColumn { w.setEntryTextColumn(textColumn: entryTextColumn) }
if let idColumn { w.setIdColumn(idColumn: idColumn) }
if let model { w.setModel(model: model) }
if let popupFixedWidth { w.setPopupFixedWidth(fixed: popupFixedWidth) }
if let v = Portico.mountSlotChild(child, ctx, onUpdate: { v in w.setChild(child: v) }) { w.setChild(child: v) }
if let onActivate { ctx.registry.add(w.connectActivate { _ in onActivate() }) }
if let onChanged { ctx.registry.add(w.connectChanged { _ in onChanged() }) }
if let onFormatEntryText { ctx.registry.add(w.connectFormatEntryText { _, a0 in onFormatEntryText(a0) }) }
if let onMoveActive { ctx.registry.add(w.connectMoveActive { _, a0 in onMoveActive(a0) }) }
if let onPopdown { ctx.registry.add(w.connectPopdown { _ in onPopdown() }) }
if let onPopup { ctx.registry.add(w.connectPopup { _ in onPopup() }) }
}
}
}
extension ComboBoxText: WidgetView {
public typealias Target = Gtk.ComboBoxText
@_spi(Portico) public func appending(
_ step: @escaping (Gtk.ComboBoxText, MountContext) -> Void
) -> Self {
var c = self
c.configure.append(step)
return c
}
}
@_spi(Portico) extension ComboBoxText: Mountable {
@_spi(Portico) public func mount(_ ctx: MountContext) -> Gtk.Widget {
let w = make(ctx)
for step in configure { step(w, ctx) }
return w
}
}