portico/Sources/Portico/Generated/LevelBar.swift

479 lines
24 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Generated by PorticoGen. DO NOT EDIT. See Sources/PorticoGen to make changes.
import Adw
import Gtk
import Gio
import Gdk
// PorticoGen: generateStruct | source: Gtk.LevelBar
/// Shows a level indicator.
///
/// Typical use cases are displaying the strength of a password, or
/// showing the charge level of a battery.
///
/// <picture>
/// <source srcset="levelbar-dark.png" media="(prefers-color-scheme: dark)">
/// <img alt="An example GtkLevelBar" src="levelbar.png">
/// </picture>
///
/// Use [method`Gtk`.LevelBar.set_value] to set the current value, and
/// [method`Gtk`.LevelBar.add_offset_value] to set the value offsets at which
/// the bar will be considered in a different state. GTK will add a few
/// offsets by default on the level bar: `GTK_LEVEL_BAR_OFFSET_LOW`,
/// `GTK_LEVEL_BAR_OFFSET_HIGH` and `GTK_LEVEL_BAR_OFFSET_FULL`, with
/// values 0.25, 0.75 and 1.0 respectively.
///
/// Note that it is your responsibility to update preexisting offsets
/// when changing the minimum or maximum value. GTK will simply clamp
/// them to the new range.
///
/// ## Adding a custom offset on the bar
///
/// ```c
/// static GtkWidget *
/// create_level_bar (void)
/// {
/// GtkWidget *widget;
/// GtkLevelBar *bar;
///
/// widget = gtk_level_bar_new ();
/// bar = GTK_LEVEL_BAR (widget);
///
/// // This changes the value of the default low offset
///
/// gtk_level_bar_add_offset_value (bar,
/// GTK_LEVEL_BAR_OFFSET_LOW,
/// 0.10);
///
/// // This adds a new offset to the bar; the application will
/// // be able to change its color CSS like this:
/// //
/// // levelbar block.my-offset {
/// // background-color: magenta;
/// // border-style: solid;
/// // border-color: black;
/// // border-width: 1px;
/// // }
///
/// gtk_level_bar_add_offset_value (bar, "my-offset", 0.60);
///
/// return widget;
/// }
/// ```
///
/// The default interval of values is between zero and one, but its possible
/// to modify the interval using [method`Gtk`.LevelBar.set_min_value] and
/// [method`Gtk`.LevelBar.set_max_value]. The value will be always drawn in
/// proportion to the admissible interval, i.e. a value of 15 with a specified
/// interval between 10 and 20 is equivalent to a value of 0.5 with an interval
/// between 0 and 1. When `GTK_LEVEL_BAR_MODE_DISCRETE` is used, the bar level
/// is rendered as a finite number of separated blocks instead of a single one.
/// The number of blocks that will be rendered is equal to the number of units
/// specified by the admissible interval.
///
/// For instance, to build a bar rendered with five blocks, its sufficient to
/// set the minimum value to 0 and the maximum value to 5 after changing the
/// indicator mode to discrete.
///
/// # GtkLevelBar as GtkBuildable
///
/// The `GtkLevelBar` implementation of the `GtkBuildable` interface supports a
/// custom `<offsets>` element, which can contain any number of `<offset>` elements,
/// each of which must have "name" and "value" attributes.
///
/// # CSS nodes
///
/// ```
/// levelbar[.discrete]
/// trough
/// block.filled.level-name
///
/// block.empty
///
/// ```
///
/// `GtkLevelBar` has a main CSS node with name levelbar and one of the style
/// classes .discrete or .continuous and a subnode with name trough. Below the
/// trough node are a number of nodes with name block and style class .filled
/// or .empty. In continuous mode, there is exactly one node of each, in discrete
/// mode, the number of filled and unfilled nodes corresponds to blocks that are
/// drawn. The block.filled nodes also get a style class .level-name corresponding
/// to the level for the current value.
///
/// In horizontal orientation, the nodes are always arranged from left to right,
/// regardless of text direction.
///
/// # Accessibility
///
/// `GtkLevelBar` uses the [enum`Gtk`.AccessibleRole.meter] role.
///
/// A Portico view that mounts a `Gtk.LevelBar`.
@MainActor public struct LevelBar: View {
private let make: (MountContext) -> Gtk.LevelBar
private var configure: [(Gtk.LevelBar, MountContext) -> Void] = []
public var body: Never { fatalError() }
// PorticoGen: generateInits(static) | source: Gtk.LevelBar.init()
/// Creates a new `GtkLevelBar`.
///
/// 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 inverted: Whether the `GtkLeveBar` is inverted.
/// - Parameter mode: Determines the way `GtkLevelBar` interprets the value properties to draw the level fill area.
/// - Parameter value: Determines the currently filled value of the level bar.
public init(inverted: Bool? = nil, mode: Gtk.LevelBarMode? = nil, value: Double? = nil) {
make = { _ in Gtk.LevelBar() }
configure.append { w, _ in
if let inverted { w.setInverted(inverted: inverted) }
if let mode { w.setMode(mode: mode) }
if let value { w.setValue(value: value) }
}
}
// PorticoGen: generateInits(static) | source: Gtk.LevelBar.init(minValue:maxValue:)
/// Creates a new `GtkLevelBar` for the specified interval.
///
/// 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 minValue: Determines the minimum value of the interval that can be displayed by the bar.
/// - Parameter maxValue: Determines the maximum value of the interval that can be displayed by the bar.
/// - Parameter inverted: Whether the `GtkLeveBar` is inverted.
/// - Parameter mode: Determines the way `GtkLevelBar` interprets the value properties to draw the level fill area.
/// - Parameter value: Determines the currently filled value of the level bar.
public init(minValue: Double, maxValue: Double, inverted: Bool? = nil, mode: Gtk.LevelBarMode? = nil, value: Double? = nil) {
make = { _ in Gtk.LevelBar(minValue: minValue, maxValue: maxValue) }
configure.append { w, _ in
if let inverted { w.setInverted(inverted: inverted) }
if let mode { w.setMode(mode: mode) }
if let value { w.setValue(value: value) }
}
}
// PorticoGen: generateInits(binding) | source: Gtk.LevelBar.init(minValue:maxValue:), Gtk.LevelBar.setMinValue(value:), Gtk.LevelBar.setMaxValue(value:)
/// Creates a new `GtkLevelBar` for the specified interval.
///
/// The initial value is the binding's current value; every later change is pushed into the widget through `Gtk.LevelBar.setMinValue(value:), Gtk.LevelBar.setMaxValue(value:)` without rebuilding the view.
/// 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 minValue: Determines the minimum value of the interval that can be displayed by the bar.
/// - Parameter maxValue: Determines the maximum value of the interval that can be displayed by the bar.
/// - Parameter inverted: Whether the `GtkLeveBar` is inverted.
/// - Parameter mode: Determines the way `GtkLevelBar` interprets the value properties to draw the level fill area.
/// - Parameter value: Determines the currently filled value of the level bar.
public init(minValue: Portico.Binding<Double>, maxValue: Portico.Binding<Double>, inverted: Portico.Binding<Bool>? = nil, mode: Portico.Binding<Gtk.LevelBarMode>? = nil, value: Portico.Binding<Double>? = nil) {
make = { _ in Gtk.LevelBar(minValue: minValue.wrappedValue, maxValue: maxValue.wrappedValue) }
configure.append { w, ctx in
ctx.registry.add(minValue.subscribe { [w] v in w.setMinValue(value: v) })
ctx.registry.add(maxValue.subscribe { [w] v in w.setMaxValue(value: v) })
if let inverted {
Portico.bindProperty(w, inverted, registry: ctx.registry, notifyDetail: "inverted", read: { [w] in w.getInverted() }, write: { [w] v in w.setInverted(inverted: v) })
}
if let mode {
Portico.bindProperty(w, mode, registry: ctx.registry, notifyDetail: "mode", read: { [w] in w.getMode() }, write: { [w] v in w.setMode(mode: v) })
}
if let value {
Portico.bindProperty(w, value, registry: ctx.registry, notifyDetail: "value", read: { [w] in w.getValue() }, write: { [w] v in w.setValue(value: v) })
}
}
}
// PorticoGen: generateInits(closure) | source: Gtk.LevelBar.init(minValue:maxValue:), Gtk.LevelBar.setMinValue(value:), Gtk.LevelBar.setMaxValue(value:)
/// Creates a new `GtkLevelBar` for the specified interval.
///
/// Each closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.LevelBar.setMinValue(value:), Gtk.LevelBar.setMaxValue(value:)`.
/// 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 minValue: Determines the minimum value of the interval that can be displayed by the bar.
/// - Parameter maxValue: Determines the maximum value of the interval that can be displayed by the bar.
/// - Parameter inverted: Whether the `GtkLeveBar` is inverted.
/// - Parameter mode: Determines the way `GtkLevelBar` interprets the value properties to draw the level fill area.
/// - Parameter value: Determines the currently filled value of the level bar.
public init(minValue: @escaping () -> Double, maxValue: @escaping () -> Double, inverted: Bool? = nil, mode: Gtk.LevelBarMode? = nil, value: Double? = nil) {
make = { _ in Gtk.LevelBar(minValue: minValue(), maxValue: maxValue()) }
configure.append { w, ctx in
let t0 = DependencyTracker { [w] in w.setMinValue(value: minValue()) }
t0.run()
ctx.registry.add(t0)
let t1 = DependencyTracker { [w] in w.setMaxValue(value: maxValue()) }
t1.run()
ctx.registry.add(t1)
if let inverted { w.setInverted(inverted: inverted) }
if let mode { w.setMode(mode: mode) }
if let value { w.setValue(value: value) }
}
}
}
extension LevelBar: WidgetView {
public typealias Target = Gtk.LevelBar
@_spi(Portico) public func appending(
_ step: @escaping (Gtk.LevelBar, MountContext) -> Void
) -> Self {
var c = self
c.configure.append(step)
return c
}
}
@_spi(Portico) extension LevelBar: 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.LevelBar
/// Modifiers for `Gtk.LevelBar`, available on every Portico view whose
/// backing widget is `Gtk.LevelBar` or one of its subclasses.
extension WidgetView where Target: Gtk.LevelBar {
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.LevelBar.setInverted(inverted:)
/// Sets whether the `GtkLevelBar` is inverted.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter inverted: Whether the `GtkLeveBar` is inverted.
/// - Returns: A copy of this view with the modifier applied.
public func inverted(_ inverted: Bool) -> Self {
appending { w, _ in
w.setInverted(inverted: inverted)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.LevelBar.setInverted(inverted:), GObject.Object.connectNotify(detail:_:), Gtk.LevelBar.getInverted()
/// Sets whether the `GtkLevelBar` is inverted.
///
/// 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 inverted(_ inverted: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, inverted, registry: ctx.registry, notifyDetail: "inverted",
read: { [w] in w.getInverted() },
write: { [w] v in w.setInverted(inverted: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.LevelBar.setInverted(inverted:)
/// Sets whether the `GtkLevelBar` is inverted.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.LevelBar.setInverted(inverted:)`.
///
/// - Parameter inverted: Whether the `GtkLeveBar` is inverted.
/// - Returns: A copy of this view with the modifier applied.
public func inverted(_ inverted: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setInverted(inverted: inverted()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.LevelBar.setMaxValue(value:)
/// Sets the `max-value` of the `GtkLevelBar`.
///
/// You probably want to update preexisting level offsets after calling
/// this function.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter maxValue: Determines the maximum value of the interval that can be displayed by the bar.
/// - Returns: A copy of this view with the modifier applied.
public func maxValue(_ maxValue: Double) -> Self {
appending { w, _ in
w.setMaxValue(value: maxValue)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.LevelBar.setMaxValue(value:), GObject.Object.connectNotify(detail:_:), Gtk.LevelBar.getMaxValue()
/// Sets the `max-value` of the `GtkLevelBar`.
///
/// You probably want to update preexisting level offsets after calling
/// this function.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Double` 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 maxValue(_ maxValue: Portico.Binding<Double>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, maxValue, registry: ctx.registry, notifyDetail: "max-value",
read: { [w] in w.getMaxValue() },
write: { [w] v in w.setMaxValue(value: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.LevelBar.setMaxValue(value:)
/// Sets the `max-value` of the `GtkLevelBar`.
///
/// You probably want to update preexisting level offsets after calling
/// this function.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.LevelBar.setMaxValue(value:)`.
///
/// - Parameter maxValue: Determines the maximum value of the interval that can be displayed by the bar.
/// - Returns: A copy of this view with the modifier applied.
public func maxValue(_ maxValue: @escaping () -> Double) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setMaxValue(value: maxValue()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.LevelBar.setMinValue(value:)
/// Sets the `min-value` of the `GtkLevelBar`.
///
/// You probably want to update preexisting level offsets after calling
/// this function.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter minValue: Determines the minimum value of the interval that can be displayed by the bar.
/// - Returns: A copy of this view with the modifier applied.
public func minValue(_ minValue: Double) -> Self {
appending { w, _ in
w.setMinValue(value: minValue)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.LevelBar.setMinValue(value:), GObject.Object.connectNotify(detail:_:), Gtk.LevelBar.getMinValue()
/// Sets the `min-value` of the `GtkLevelBar`.
///
/// You probably want to update preexisting level offsets after calling
/// this function.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Double` 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 minValue(_ minValue: Portico.Binding<Double>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, minValue, registry: ctx.registry, notifyDetail: "min-value",
read: { [w] in w.getMinValue() },
write: { [w] v in w.setMinValue(value: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.LevelBar.setMinValue(value:)
/// Sets the `min-value` of the `GtkLevelBar`.
///
/// You probably want to update preexisting level offsets after calling
/// this function.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.LevelBar.setMinValue(value:)`.
///
/// - Parameter minValue: Determines the minimum value of the interval that can be displayed by the bar.
/// - Returns: A copy of this view with the modifier applied.
public func minValue(_ minValue: @escaping () -> Double) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setMinValue(value: minValue()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.LevelBar.setMode(mode:)
/// Sets the `mode` of the `GtkLevelBar`.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter mode: Determines the way `GtkLevelBar` interprets the value properties to draw the level fill area.
/// - Returns: A copy of this view with the modifier applied.
public func mode(_ mode: Gtk.LevelBarMode) -> Self {
appending { w, _ in
w.setMode(mode: mode)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.LevelBar.setMode(mode:), GObject.Object.connectNotify(detail:_:), Gtk.LevelBar.getMode()
/// Sets the `mode` of the `GtkLevelBar`.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Gtk.LevelBarMode` 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 mode(_ mode: Portico.Binding<Gtk.LevelBarMode>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, mode, registry: ctx.registry, notifyDetail: "mode",
read: { [w] in w.getMode() },
write: { [w] v in w.setMode(mode: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.LevelBar.setMode(mode:)
/// Sets the `mode` of the `GtkLevelBar`.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.LevelBar.setMode(mode:)`.
///
/// - Parameter mode: Determines the way `GtkLevelBar` interprets the value properties to draw the level fill area.
/// - Returns: A copy of this view with the modifier applied.
public func mode(_ mode: @escaping () -> Gtk.LevelBarMode) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setMode(mode: mode()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.LevelBar.setValue(value:)
/// Sets the value of the `GtkLevelBar`.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter value: Determines the currently filled value of the level bar.
/// - Returns: A copy of this view with the modifier applied.
public func value(_ value: Double) -> Self {
appending { w, _ in
w.setValue(value: value)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.LevelBar.setValue(value:), GObject.Object.connectNotify(detail:_:), Gtk.LevelBar.getValue()
/// Sets the value of the `GtkLevelBar`.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Double` 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 value(_ value: Portico.Binding<Double>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, value, registry: ctx.registry, notifyDetail: "value",
read: { [w] in w.getValue() },
write: { [w] v in w.setValue(value: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.LevelBar.setValue(value:)
/// Sets the value of the `GtkLevelBar`.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.LevelBar.setValue(value:)`.
///
/// - Parameter value: Determines the currently filled value of the level bar.
/// - Returns: A copy of this view with the modifier applied.
public func value(_ value: @escaping () -> Double) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setValue(value: value()) }
tracker.run()
ctx.registry.add(tracker)
}
}
}