264 lines
16 KiB
Swift
264 lines
16 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.LockButton
|
|
/// `GtkLockButton` is a widget to obtain and revoke authorizations
|
|
/// needed to operate the controls.
|
|
///
|
|
/// <picture>
|
|
/// <source srcset="lockbutton-dark.png" media="(prefers-color-scheme: dark)">
|
|
/// <img alt="An example GtkLockButton" src="lockbutton.png">
|
|
/// </picture>
|
|
///
|
|
/// It is typically used in preference dialogs or control panels.
|
|
///
|
|
/// The required authorization is represented by a `GPermission` object.
|
|
/// Concrete implementations of `GPermission` may use PolicyKit or some
|
|
/// other authorization framework. To obtain a PolicyKit-based
|
|
/// `GPermission`, use `polkit_permission_new()`.
|
|
///
|
|
/// If the user is not currently allowed to perform the action, but can
|
|
/// obtain the permission, the widget looks like this:
|
|
///
|
|
/// <picture>
|
|
/// <source srcset="lockbutton-dark.png" media="(prefers-color-scheme: dark)">
|
|
/// <img alt="An locked GtkLockButton" src="lockbutton.png">
|
|
/// </picture>
|
|
///
|
|
/// and the user can click the button to request the permission. Depending
|
|
/// on the platform, this may pop up an authentication dialog or ask the user
|
|
/// to authenticate in some other way. Once the user has obtained the permission,
|
|
/// the widget changes to this:
|
|
///
|
|
/// <picture>
|
|
/// <source srcset="lockbutton-unlocked-dark.png" media="(prefers-color-scheme: dark)">
|
|
/// <img alt="An unlocked GtkLockButton" src="lockbutton-unlocked.png">
|
|
/// </picture>
|
|
///
|
|
/// and the permission can be dropped again by clicking the button. If the user
|
|
/// is not able to obtain the permission at all, the widget looks like this:
|
|
///
|
|
/// <picture>
|
|
/// <source srcset="lockbutton-sorry-dark.png" media="(prefers-color-scheme: dark)">
|
|
/// <img alt="An unobtainable GtkLockButton" src="lockbutton-sorry.png">
|
|
/// </picture>
|
|
///
|
|
/// If the user has the permission and cannot drop it, the button is hidden.
|
|
///
|
|
/// The text (and tooltips) that are shown in the various cases can be adjusted
|
|
/// with the [property`Gtk`.LockButton:text-lock],
|
|
/// [property`Gtk`.LockButton:text-unlock],
|
|
/// [property`Gtk`.LockButton:tooltip-lock],
|
|
/// [property`Gtk`.LockButton:tooltip-unlock] and
|
|
/// [property`Gtk`.LockButton:tooltip-not-authorized] properties.
|
|
///
|
|
/// A Portico view that mounts a `Gtk.LockButton`.
|
|
@MainActor public struct LockButton: View {
|
|
private let make: (MountContext) -> Gtk.LockButton
|
|
private var configure: [(Gtk.LockButton, MountContext) -> Void] = []
|
|
|
|
public var body: Never { fatalError() }
|
|
|
|
// PorticoGen: generateInits(static) | source: Gtk.LockButton.init(permission:)
|
|
/// Creates a new lock button which reflects the `permission`.
|
|
///
|
|
/// 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 permission: The `GPermission object controlling this button.
|
|
/// - Parameter canShrink: Whether the size of the button can be made smaller than the natural size of its contents.
|
|
/// - Parameter hasFrame: Whether the button has a frame.
|
|
/// - Parameter iconName: The name of the icon used to automatically populate the button.
|
|
/// - Parameter label: Text of the label inside the button, if the button contains a label widget.
|
|
/// - Parameter useUnderline: If set, an underline in the text indicates that the following character is to be used as mnemonic.
|
|
/// - 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 onClicked: Invoked when the widget emits the `clicked` signal.
|
|
public init(permission: Gtk.Permission?, canShrink: Bool? = nil, hasFrame: Bool? = nil, iconName: String? = nil, label: String? = nil, useUnderline: Bool? = nil, @ViewBuilder child: @escaping () -> [AnyView] = { [] }, onActivate: (() -> Void)? = nil, onClicked: (() -> Void)? = nil) {
|
|
make = { _ in Gtk.LockButton(permission: permission) }
|
|
configure.append { w, ctx in
|
|
if let canShrink { w.setCanShrink(canShrink: canShrink) }
|
|
if let hasFrame { w.setHasFrame(hasFrame: hasFrame) }
|
|
if let iconName { w.setIconName(iconName: iconName) }
|
|
if let label { w.setLabel(label: label) }
|
|
if let useUnderline { w.setUseUnderline(useUnderline: useUnderline) }
|
|
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 onClicked { ctx.registry.add(w.connectClicked { _ in onClicked() }) }
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateInits(binding) | source: Gtk.LockButton.init(permission:), Gtk.LockButton.setPermission(permission:)
|
|
/// Creates a new lock button which reflects the `permission`.
|
|
///
|
|
/// The initial value is the binding's current value; every later change is pushed into the widget through `Gtk.LockButton.setPermission(permission:)` without rebuilding the view.
|
|
/// 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.
|
|
/// Optional `Binding` parameters bind through `Portico.bindProperty`, so they are two-way wherever the wrapper exposes a safe getter.
|
|
///
|
|
/// - Parameter permission: The `GPermission object controlling this button.
|
|
/// - Parameter canShrink: Whether the size of the button can be made smaller than the natural size of its contents.
|
|
/// - Parameter hasFrame: Whether the button has a frame.
|
|
/// - Parameter iconName: The name of the icon used to automatically populate the button.
|
|
/// - Parameter label: Text of the label inside the button, if the button contains a label widget.
|
|
/// - Parameter useUnderline: If set, an underline in the text indicates that the following character is to be used as mnemonic.
|
|
/// - 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 onClicked: Invoked when the widget emits the `clicked` signal.
|
|
public init(permission: Portico.Binding<Gtk.Permission?>, canShrink: Portico.Binding<Bool>? = nil, hasFrame: Portico.Binding<Bool>? = nil, iconName: Portico.Binding<String>? = nil, label: Portico.Binding<String>? = nil, useUnderline: Portico.Binding<Bool>? = nil, @ViewBuilder child: @escaping () -> [AnyView] = { [] }, onActivate: (() -> Void)? = nil, onClicked: (() -> Void)? = nil) {
|
|
make = { _ in Gtk.LockButton(permission: permission.wrappedValue) }
|
|
configure.append { w, ctx in
|
|
ctx.registry.add(permission.subscribe { [w] v in w.setPermission(permission: v) })
|
|
if let canShrink {
|
|
Portico.bindProperty(w, canShrink, registry: ctx.registry, notifyDetail: "can-shrink", read: { [w] in w.getCanShrink() }, write: { [w] v in w.setCanShrink(canShrink: v) })
|
|
}
|
|
if let hasFrame {
|
|
Portico.bindProperty(w, hasFrame, registry: ctx.registry, notifyDetail: "has-frame", read: { [w] in w.getHasFrame() }, write: { [w] v in w.setHasFrame(hasFrame: v) })
|
|
}
|
|
if let iconName {
|
|
Portico.bindProperty(w, iconName, registry: ctx.registry, notifyDetail: "icon-name", read: { [w] in w.getIconName() }, write: { [w] v in w.setIconName(iconName: v) })
|
|
}
|
|
if let label {
|
|
Portico.bindProperty(w, label, registry: ctx.registry, notifyDetail: "label", read: { [w] in w.getLabel() }, write: { [w] v in w.setLabel(label: v) })
|
|
}
|
|
if let useUnderline {
|
|
Portico.bindProperty(w, useUnderline, registry: ctx.registry, notifyDetail: "use-underline", read: { [w] in w.getUseUnderline() }, write: { [w] v in w.setUseUnderline(useUnderline: v) })
|
|
}
|
|
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 onClicked { ctx.registry.add(w.connectClicked { _ in onClicked() }) }
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateInits(closure) | source: Gtk.LockButton.init(permission:), Gtk.LockButton.setPermission(permission:)
|
|
/// Creates a new lock button which reflects the `permission`.
|
|
///
|
|
/// Each closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.LockButton.setPermission(permission:)`.
|
|
/// 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 permission: The `GPermission object controlling this button.
|
|
/// - Parameter canShrink: Whether the size of the button can be made smaller than the natural size of its contents.
|
|
/// - Parameter hasFrame: Whether the button has a frame.
|
|
/// - Parameter iconName: The name of the icon used to automatically populate the button.
|
|
/// - Parameter label: Text of the label inside the button, if the button contains a label widget.
|
|
/// - Parameter useUnderline: If set, an underline in the text indicates that the following character is to be used as mnemonic.
|
|
/// - 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 onClicked: Invoked when the widget emits the `clicked` signal.
|
|
public init(permission: @escaping () -> Gtk.Permission?, canShrink: Bool? = nil, hasFrame: Bool? = nil, iconName: String? = nil, label: String? = nil, useUnderline: Bool? = nil, @ViewBuilder child: @escaping () -> [AnyView] = { [] }, onActivate: (() -> Void)? = nil, onClicked: (() -> Void)? = nil) {
|
|
make = { _ in Gtk.LockButton(permission: permission()) }
|
|
configure.append { w, ctx in
|
|
let t0 = DependencyTracker { [w] in w.setPermission(permission: permission()) }
|
|
t0.run()
|
|
ctx.registry.add(t0)
|
|
if let canShrink { w.setCanShrink(canShrink: canShrink) }
|
|
if let hasFrame { w.setHasFrame(hasFrame: hasFrame) }
|
|
if let iconName { w.setIconName(iconName: iconName) }
|
|
if let label { w.setLabel(label: label) }
|
|
if let useUnderline { w.setUseUnderline(useUnderline: useUnderline) }
|
|
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 onClicked { ctx.registry.add(w.connectClicked { _ in onClicked() }) }
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
extension LockButton: WidgetView {
|
|
public typealias Target = Gtk.LockButton
|
|
|
|
@_spi(Portico) public func appending(
|
|
_ step: @escaping (Gtk.LockButton, MountContext) -> Void
|
|
) -> Self {
|
|
var c = self
|
|
c.configure.append(step)
|
|
return c
|
|
}
|
|
}
|
|
|
|
@_spi(Portico) extension LockButton: 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.LockButton
|
|
/// Modifiers for `Gtk.LockButton`, available on every Portico view whose
|
|
/// backing widget is `Gtk.LockButton` or one of its subclasses.
|
|
extension WidgetView where Target: Gtk.LockButton {
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.LockButton.setPermission(permission:)
|
|
/// Sets the `GPermission` object that controls `button`.
|
|
///
|
|
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
|
|
///
|
|
/// - Parameter permission: The `GPermission object controlling this button.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func permission(_ permission: Gtk.Permission?) -> Self {
|
|
appending { w, _ in
|
|
w.setPermission(permission: permission)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.LockButton.setPermission(permission:), GObject.Object.connectNotify(detail:_:), Gtk.LockButton.getPermission()
|
|
/// Sets the `GPermission` object that controls `button`.
|
|
///
|
|
/// Applied at mount and re-applied on every change the binding publishes.
|
|
/// When `Gtk.Permission?` 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 permission(_ permission: Portico.Binding<Gtk.Permission?>) -> Self {
|
|
appending { w, ctx in
|
|
Portico.bindProperty(
|
|
w, permission, registry: ctx.registry, notifyDetail: "permission",
|
|
read: { [w] in w.getPermission() },
|
|
write: { [w] v in w.setPermission(permission: v) }
|
|
)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(lifted,twoWay) | source: Gtk.LockButton.setPermission(permission:), GObject.Object.connectNotify(detail:_:), Gtk.LockButton.getPermission()
|
|
/// Sets the `GPermission` object that controls `button`.
|
|
///
|
|
/// Applied at mount and re-applied on every change the binding publishes.
|
|
/// `Binding` is invariant, so a `Binding<Gtk.Permission>` is not accepted by the nullable overload; this one takes it and promotes each value. Pass a `Binding<Gtk.Permission?>` to be able to clear the property.
|
|
/// When `Gtk.Permission` 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 permission(_ permission: Portico.Binding<Gtk.Permission>) -> Self {
|
|
appending { w, ctx in
|
|
Portico.bindProperty(
|
|
w, permission, registry: ctx.registry, notifyDetail: "permission",
|
|
read: { [w] in w.getPermission() },
|
|
write: { [w] v in w.setPermission(permission: v) }
|
|
)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.LockButton.setPermission(permission:)
|
|
/// Sets the `GPermission` object that controls `button`.
|
|
///
|
|
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.LockButton.setPermission(permission:)`.
|
|
///
|
|
/// - Parameter permission: The `GPermission object controlling this button.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func permission(_ permission: @escaping () -> Gtk.Permission?) -> Self {
|
|
appending { w, ctx in
|
|
let tracker = DependencyTracker { [w] in w.setPermission(permission: permission()) }
|
|
tracker.run()
|
|
ctx.registry.add(tracker)
|
|
}
|
|
}
|
|
|
|
}
|