portico/Sources/Portico/Generated/PasswordEntry.swift

231 lines
11 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.PasswordEntry
/// A single-line text entry widget for entering passwords and other secrets.
///
/// <picture>
/// <source srcset="password-entry-dark.png" media="(prefers-color-scheme: dark)">
/// <img alt="An example GtkPasswordEntry" src="password-entry.png">
/// </picture>
///
/// It does not show its contents in clear text, does not allow to copy it
/// to the clipboard, and it shows a warning when Caps Lock is engaged. If
/// the underlying platform allows it, `GtkPasswordEntry` will also place
/// the text in a non-pageable memory area, to avoid it being written out
/// to disk by the operating system.
///
/// Optionally, it can offer a way to reveal the contents in clear text.
///
/// `GtkPasswordEntry` provides only minimal API and should be used with
/// the [iface`Gtk`.Editable] API.
///
/// # CSS Nodes
///
/// ```
/// entry.password
/// text
/// image.caps-lock-indicator
///
/// ```
///
/// `GtkPasswordEntry` has a single CSS node with name entry that carries
/// a .passwordstyle class. The text Css node below it has a child with
/// name image and style class .caps-lock-indicator for the Caps Lock
/// icon, and possibly other children.
///
/// # Accessibility
///
/// `GtkPasswordEntry` uses the [enum`Gtk`.AccessibleRole.text_box] role.
///
/// A Portico view that mounts a `Gtk.PasswordEntry`.
@MainActor public struct PasswordEntry: View {
private let make: (MountContext) -> Gtk.PasswordEntry
private var configure: [(Gtk.PasswordEntry, MountContext) -> Void] = []
public var body: Never { fatalError() }
// PorticoGen: generateInits(static) | source: Gtk.PasswordEntry.init()
/// Creates a `GtkPasswordEntry`.
///
/// 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 extraMenu: A menu model whose contents will be appended to the context menu.
/// - Parameter showPeekIcon: Whether to show an icon for revealing the content.
/// - Parameter onActivate: Invoked when the widget emits the `activate` signal.
public init(extraMenu: Gtk.MenuModel? = nil, showPeekIcon: Bool? = nil, onActivate: (() -> Void)? = nil) {
make = { _ in Gtk.PasswordEntry() }
configure.append { w, ctx in
if let extraMenu { w.setExtraMenu(model: extraMenu) }
if let showPeekIcon { w.setShowPeekIcon(showPeekIcon: showPeekIcon) }
if let onActivate { ctx.registry.add(w.connectActivate { _ in onActivate() }) }
}
}
}
extension PasswordEntry: WidgetView {
public typealias Target = Gtk.PasswordEntry
@_spi(Portico) public func appending(
_ step: @escaping (Gtk.PasswordEntry, MountContext) -> Void
) -> Self {
var c = self
c.configure.append(step)
return c
}
}
@_spi(Portico) extension PasswordEntry: 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.PasswordEntry
/// Modifiers for `Gtk.PasswordEntry`, available on every Portico view whose
/// backing widget is `Gtk.PasswordEntry` or one of its subclasses.
extension WidgetView where Target: Gtk.PasswordEntry {
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.PasswordEntry.setExtraMenu(model:)
/// Sets a menu model to add when constructing
/// the context menu for `entry`.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter extraMenu: A menu model whose contents will be appended to the context menu.
/// - Returns: A copy of this view with the modifier applied.
public func extraMenu(_ extraMenu: Gtk.MenuModel?) -> Self {
appending { w, _ in
w.setExtraMenu(model: extraMenu)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.PasswordEntry.setExtraMenu(model:), GObject.Object.connectNotify(detail:_:), Gtk.PasswordEntry.getExtraMenu()
/// Sets a menu model to add when constructing
/// the context menu for `entry`.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Gtk.MenuModel?` 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 extraMenu(_ extraMenu: Portico.Binding<Gtk.MenuModel?>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, extraMenu, registry: ctx.registry, notifyDetail: "extra-menu",
read: { [w] in w.getExtraMenu() },
write: { [w] v in w.setExtraMenu(model: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(lifted,twoWay) | source: Gtk.PasswordEntry.setExtraMenu(model:), GObject.Object.connectNotify(detail:_:), Gtk.PasswordEntry.getExtraMenu()
/// Sets a menu model to add when constructing
/// the context menu for `entry`.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// `Binding` is invariant, so a `Binding<Gtk.MenuModel>` is not accepted by the nullable overload; this one takes it and promotes each value. Pass a `Binding<Gtk.MenuModel?>` to be able to clear the property.
/// When `Gtk.MenuModel` 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 extraMenu(_ extraMenu: Portico.Binding<Gtk.MenuModel>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, extraMenu, registry: ctx.registry, notifyDetail: "extra-menu",
read: { [w] in w.getExtraMenu() },
write: { [w] v in w.setExtraMenu(model: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.PasswordEntry.setExtraMenu(model:)
/// Sets a menu model to add when constructing
/// the context menu for `entry`.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.PasswordEntry.setExtraMenu(model:)`.
///
/// - Parameter extraMenu: A menu model whose contents will be appended to the context menu.
/// - Returns: A copy of this view with the modifier applied.
public func extraMenu(_ extraMenu: @escaping () -> Gtk.MenuModel?) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setExtraMenu(model: extraMenu()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.PasswordEntry.setShowPeekIcon(showPeekIcon:)
/// Sets whether the entry should have a clickable icon
/// to reveal the contents.
///
/// Setting this to `false` also hides the text again.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter showPeekIcon: Whether to show an icon for revealing the content.
/// - Returns: A copy of this view with the modifier applied.
public func showPeekIcon(_ showPeekIcon: Bool) -> Self {
appending { w, _ in
w.setShowPeekIcon(showPeekIcon: showPeekIcon)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.PasswordEntry.setShowPeekIcon(showPeekIcon:), GObject.Object.connectNotify(detail:_:), Gtk.PasswordEntry.getShowPeekIcon()
/// Sets whether the entry should have a clickable icon
/// to reveal the contents.
///
/// Setting this to `false` also hides the text again.
///
/// 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 showPeekIcon(_ showPeekIcon: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, showPeekIcon, registry: ctx.registry, notifyDetail: "show-peek-icon",
read: { [w] in w.getShowPeekIcon() },
write: { [w] v in w.setShowPeekIcon(showPeekIcon: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.PasswordEntry.setShowPeekIcon(showPeekIcon:)
/// Sets whether the entry should have a clickable icon
/// to reveal the contents.
///
/// Setting this to `false` also hides the text again.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.PasswordEntry.setShowPeekIcon(showPeekIcon:)`.
///
/// - Parameter showPeekIcon: Whether to show an icon for revealing the content.
/// - Returns: A copy of this view with the modifier applied.
public func showPeekIcon(_ showPeekIcon: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setShowPeekIcon(showPeekIcon: showPeekIcon()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Gtk.PasswordEntry.connectActivate(_:)
/// Emitted when the entry is activated.
///
/// The keybindings for this signal are all forms of the Enter key.
///
/// - 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() })
}
}
}