390 lines
20 KiB
Swift
390 lines
20 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: Adw.ViewSwitcherTitle
|
|
/// A view switcher title.
|
|
///
|
|
/// <picture>
|
|
/// <source srcset="view-switcher-title-dark.png" media="(prefers-color-scheme: dark)">
|
|
/// <img src="view-switcher-title.png" alt="view-switcher-title">
|
|
/// </picture>
|
|
///
|
|
/// A widget letting you switch between multiple views contained by a
|
|
/// [class`ViewStack`] via an [class`ViewSwitcher`].
|
|
///
|
|
/// It is designed to be used as the title widget of a [class`HeaderBar`], and
|
|
/// will display the window's title when the window is too narrow to fit the view
|
|
/// switcher e.g. on mobile phones, or if there are less than two views.
|
|
///
|
|
/// In order to center the title in narrow windows, the header bar should have
|
|
/// [property`HeaderBar`:centering-policy] set to
|
|
/// [enum`Adw`.CenteringPolicy.strict].
|
|
///
|
|
/// `AdwViewSwitcherTitle` is intended to be used together with
|
|
/// [class`ViewSwitcherBar`].
|
|
///
|
|
/// A common use case is to bind the [property`ViewSwitcherBar`:reveal] property
|
|
/// to [property`ViewSwitcherTitle`:title-visible] to automatically reveal the
|
|
/// view switcher bar when the title label is displayed in place of the view
|
|
/// switcher, as follows:
|
|
///
|
|
/// ```xml
|
|
/// <object class="AdwWindow">
|
|
/// <property name="content">
|
|
/// <object class="AdwToolbarView">
|
|
/// <child type="top">
|
|
/// <object class="AdwHeaderBar">
|
|
/// <property name="centering-policy">strict</property>
|
|
/// <property name="title-widget">
|
|
/// <object class="AdwViewSwitcherTitle" id="title">
|
|
/// <property name="stack">stack</property>
|
|
/// </object>
|
|
/// </property>
|
|
/// </object>
|
|
/// </child>
|
|
/// <property name="content">
|
|
/// <object class="AdwViewStack" id="stack"/>
|
|
/// </property>
|
|
/// <child type="bottom">
|
|
/// <object class="AdwViewSwitcherBar">
|
|
/// <property name="stack">stack</property>
|
|
/// <binding name="reveal">
|
|
/// <lookup name="title-visible">title</lookup>
|
|
/// </binding>
|
|
/// </object>
|
|
/// </child>
|
|
/// </object>
|
|
/// </property>
|
|
/// </object>
|
|
/// ```
|
|
///
|
|
/// ## CSS nodes
|
|
///
|
|
/// `AdwViewSwitcherTitle` has a single CSS node with name `viewswitchertitle`.
|
|
///
|
|
/// A Portico view that mounts a `Adw.ViewSwitcherTitle`.
|
|
@MainActor public struct ViewSwitcherTitle: View {
|
|
private let make: (MountContext) -> Adw.ViewSwitcherTitle
|
|
private var configure: [(Adw.ViewSwitcherTitle, MountContext) -> Void] = []
|
|
|
|
public var body: Never { fatalError() }
|
|
|
|
// PorticoGen: generateInits(static) | source: Adw.ViewSwitcherTitle.init()
|
|
/// Creates a new `AdwViewSwitcherTitle`.
|
|
///
|
|
/// 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 stack: The stack the view switcher controls.
|
|
/// - Parameter subtitle: The subtitle to display.
|
|
/// - Parameter title: The title to display.
|
|
/// - Parameter viewSwitcherEnabled: Whether the view switcher is enabled.
|
|
public init(stack: Adw.ViewStack? = nil, subtitle: String? = nil, title: String? = nil, viewSwitcherEnabled: Bool? = nil) {
|
|
make = { _ in Adw.ViewSwitcherTitle() }
|
|
configure.append { w, _ in
|
|
if let stack { w.setStack(stack: stack) }
|
|
if let subtitle { w.setSubtitle(subtitle: subtitle) }
|
|
if let title { w.setTitle(title: title) }
|
|
if let viewSwitcherEnabled { w.setViewSwitcherEnabled(enabled: viewSwitcherEnabled) }
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
extension ViewSwitcherTitle: WidgetView {
|
|
public typealias Target = Adw.ViewSwitcherTitle
|
|
|
|
@_spi(Portico) public func appending(
|
|
_ step: @escaping (Adw.ViewSwitcherTitle, MountContext) -> Void
|
|
) -> Self {
|
|
var c = self
|
|
c.configure.append(step)
|
|
return c
|
|
}
|
|
}
|
|
|
|
@_spi(Portico) extension ViewSwitcherTitle: 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: Adw.ViewSwitcherTitle
|
|
/// Modifiers for `Adw.ViewSwitcherTitle`, available on every Portico view whose
|
|
/// backing widget is `Adw.ViewSwitcherTitle` or one of its subclasses.
|
|
extension WidgetView where Target: Adw.ViewSwitcherTitle {
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.ViewSwitcherTitle.setStack(stack:)
|
|
/// Sets the stack controlled by `self`.
|
|
///
|
|
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
|
|
///
|
|
/// - Parameter stack: The stack the view switcher controls.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func stack(_ stack: Adw.ViewStack?) -> Self {
|
|
appending { w, _ in
|
|
w.setStack(stack: stack)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.ViewSwitcherTitle.setStack(stack:), GObject.Object.connectNotify(detail:_:), Adw.ViewSwitcherTitle.getStack()
|
|
/// Sets the stack controlled by `self`.
|
|
///
|
|
/// Applied at mount and re-applied on every change the binding publishes.
|
|
/// When `Adw.ViewStack?` 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 stack<W: Adw.ViewStack>(_ stack: Portico.Binding<W?>) -> Self {
|
|
appending { w, ctx in
|
|
Portico.bindProperty(
|
|
w, stack, registry: ctx.registry, notifyDetail: "stack",
|
|
read: { [w] in w.getStack() as? W },
|
|
write: { [w] v in w.setStack(stack: v) }
|
|
)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(lifted,twoWay) | source: Adw.ViewSwitcherTitle.setStack(stack:), GObject.Object.connectNotify(detail:_:), Adw.ViewSwitcherTitle.getStack()
|
|
/// Sets the stack controlled by `self`.
|
|
///
|
|
/// Applied at mount and re-applied on every change the binding publishes.
|
|
/// `Binding` is invariant, so a `Binding<Adw.ViewStack>` is not accepted by the nullable overload; this one takes it and promotes each value. Pass a `Binding<Adw.ViewStack?>` to be able to clear the property.
|
|
/// When `Adw.ViewStack` 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 stack<W: Adw.ViewStack>(_ stack: Portico.Binding<W>) -> Self {
|
|
appending { w, ctx in
|
|
Portico.bindProperty(
|
|
w, stack, registry: ctx.registry, notifyDetail: "stack",
|
|
read: { [w] in w.getStack() as? W },
|
|
write: { [w] v in w.setStack(stack: v) }
|
|
)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.ViewSwitcherTitle.setStack(stack:)
|
|
/// Sets the stack controlled by `self`.
|
|
///
|
|
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.ViewSwitcherTitle.setStack(stack:)`.
|
|
///
|
|
/// - Parameter stack: The stack the view switcher controls.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func stack(_ stack: @escaping () -> Adw.ViewStack?) -> Self {
|
|
appending { w, ctx in
|
|
let tracker = DependencyTracker { [w] in w.setStack(stack: stack()) }
|
|
tracker.run()
|
|
ctx.registry.add(tracker)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.ViewSwitcherTitle.setSubtitle(subtitle:)
|
|
/// Sets the subtitle of `self`.
|
|
///
|
|
/// The subtitle should give the user additional details.
|
|
///
|
|
/// Applied once at mount; use the `Binding`, closure, or `InterpolatedText` overload for a value that changes.
|
|
/// A string literal containing interpolation selects the `InterpolatedText` overload instead, which updates live.
|
|
///
|
|
/// - Parameter subtitle: The subtitle to display.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
@_disfavoredOverload
|
|
public func subtitle<S: StringProtocol>(_ subtitle: S) -> Self {
|
|
appending { w, _ in
|
|
w.setSubtitle(subtitle: String(subtitle))
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.ViewSwitcherTitle.setSubtitle(subtitle:), GObject.Object.connectNotify(detail:_:), Adw.ViewSwitcherTitle.getSubtitle()
|
|
/// Sets the subtitle of `self`.
|
|
///
|
|
/// The subtitle should give the user additional details.
|
|
///
|
|
/// Applied at mount and re-applied on every change the binding publishes.
|
|
/// When `String` 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 subtitle(_ subtitle: Portico.Binding<String>) -> Self {
|
|
appending { w, ctx in
|
|
Portico.bindProperty(
|
|
w, subtitle, registry: ctx.registry, notifyDetail: "subtitle",
|
|
read: { [w] in w.getSubtitle() },
|
|
write: { [w] v in w.setSubtitle(subtitle: v) }
|
|
)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.ViewSwitcherTitle.setSubtitle(subtitle:)
|
|
/// Sets the subtitle of `self`.
|
|
///
|
|
/// The subtitle should give the user additional details.
|
|
///
|
|
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.ViewSwitcherTitle.setSubtitle(subtitle:)`.
|
|
///
|
|
/// - Parameter subtitle: The subtitle to display.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func subtitle(_ subtitle: @escaping () -> String) -> Self {
|
|
appending { w, ctx in
|
|
let tracker = DependencyTracker { [w] in w.setSubtitle(subtitle: subtitle()) }
|
|
tracker.run()
|
|
ctx.registry.add(tracker)
|
|
}
|
|
}
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(interpolation) | source: Adw.ViewSwitcherTitle.setSubtitle(subtitle:)
|
|
/// Sets the subtitle of `self`.
|
|
///
|
|
/// The subtitle should give the user additional details.
|
|
///
|
|
/// Interpolated segments are captured unevaluated and re-read inside a `DependencyTracker`, so any `@State` they read pushes a new value through `Adw.ViewSwitcherTitle.setSubtitle(subtitle:)`. A literal with no interpolation is applied once, with no subscription.
|
|
///
|
|
/// - Parameter subtitle: The subtitle to display.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func subtitle(_ subtitle: Portico.InterpolatedText) -> Self {
|
|
appending { w, ctx in
|
|
Portico.bindInterpolation(subtitle, registry: ctx.registry) { [w] v in w.setSubtitle(subtitle: v) }
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.ViewSwitcherTitle.setTitle(title:)
|
|
/// Sets the title of `self`.
|
|
///
|
|
/// The title typically identifies the current view or content item, and
|
|
/// generally does not use the application name.
|
|
///
|
|
/// Applied once at mount; use the `Binding`, closure, or `InterpolatedText` overload for a value that changes.
|
|
/// A string literal containing interpolation selects the `InterpolatedText` overload instead, which updates live.
|
|
///
|
|
/// - Parameter title: The title to display.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
@_disfavoredOverload
|
|
public func title<S: StringProtocol>(_ title: S) -> Self {
|
|
appending { w, _ in
|
|
w.setTitle(title: String(title))
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.ViewSwitcherTitle.setTitle(title:), GObject.Object.connectNotify(detail:_:), Adw.ViewSwitcherTitle.getTitle()
|
|
/// Sets the title of `self`.
|
|
///
|
|
/// The title typically identifies the current view or content item, and
|
|
/// generally does not use the application name.
|
|
///
|
|
/// Applied at mount and re-applied on every change the binding publishes.
|
|
/// When `String` 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 title(_ title: Portico.Binding<String>) -> Self {
|
|
appending { w, ctx in
|
|
Portico.bindProperty(
|
|
w, title, registry: ctx.registry, notifyDetail: "title",
|
|
read: { [w] in w.getTitle() },
|
|
write: { [w] v in w.setTitle(title: v) }
|
|
)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.ViewSwitcherTitle.setTitle(title:)
|
|
/// Sets the title of `self`.
|
|
///
|
|
/// The title typically identifies the current view or content item, and
|
|
/// generally does not use the application name.
|
|
///
|
|
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.ViewSwitcherTitle.setTitle(title:)`.
|
|
///
|
|
/// - Parameter title: The title to display.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func title(_ title: @escaping () -> String) -> Self {
|
|
appending { w, ctx in
|
|
let tracker = DependencyTracker { [w] in w.setTitle(title: title()) }
|
|
tracker.run()
|
|
ctx.registry.add(tracker)
|
|
}
|
|
}
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(interpolation) | source: Adw.ViewSwitcherTitle.setTitle(title:)
|
|
/// Sets the title of `self`.
|
|
///
|
|
/// The title typically identifies the current view or content item, and
|
|
/// generally does not use the application name.
|
|
///
|
|
/// Interpolated segments are captured unevaluated and re-read inside a `DependencyTracker`, so any `@State` they read pushes a new value through `Adw.ViewSwitcherTitle.setTitle(title:)`. A literal with no interpolation is applied once, with no subscription.
|
|
///
|
|
/// - Parameter title: The title to display.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func title(_ title: Portico.InterpolatedText) -> Self {
|
|
appending { w, ctx in
|
|
Portico.bindInterpolation(title, registry: ctx.registry) { [w] v in w.setTitle(title: v) }
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.ViewSwitcherTitle.setViewSwitcherEnabled(enabled:)
|
|
/// Sets whether `self`'s view switcher is enabled.
|
|
///
|
|
/// If it is disabled, the title will be displayed instead. This allows to
|
|
/// programmatically hide the view switcher even if it fits in the available
|
|
/// space.
|
|
///
|
|
/// This can be used e.g. to ensure the view switcher is hidden below a certain
|
|
/// window width, or any other constraint you find suitable.
|
|
///
|
|
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
|
|
///
|
|
/// - Parameter viewSwitcherEnabled: Whether the view switcher is enabled.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func viewSwitcherEnabled(_ viewSwitcherEnabled: Bool) -> Self {
|
|
appending { w, _ in
|
|
w.setViewSwitcherEnabled(enabled: viewSwitcherEnabled)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.ViewSwitcherTitle.setViewSwitcherEnabled(enabled:), GObject.Object.connectNotify(detail:_:), Adw.ViewSwitcherTitle.getViewSwitcherEnabled()
|
|
/// Sets whether `self`'s view switcher is enabled.
|
|
///
|
|
/// If it is disabled, the title will be displayed instead. This allows to
|
|
/// programmatically hide the view switcher even if it fits in the available
|
|
/// space.
|
|
///
|
|
/// This can be used e.g. to ensure the view switcher is hidden below a certain
|
|
/// window width, or any other constraint you find suitable.
|
|
///
|
|
/// 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 viewSwitcherEnabled(_ viewSwitcherEnabled: Portico.Binding<Bool>) -> Self {
|
|
appending { w, ctx in
|
|
Portico.bindProperty(
|
|
w, viewSwitcherEnabled, registry: ctx.registry, notifyDetail: "view-switcher-enabled",
|
|
read: { [w] in w.getViewSwitcherEnabled() },
|
|
write: { [w] v in w.setViewSwitcherEnabled(enabled: v) }
|
|
)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.ViewSwitcherTitle.setViewSwitcherEnabled(enabled:)
|
|
/// Sets whether `self`'s view switcher is enabled.
|
|
///
|
|
/// If it is disabled, the title will be displayed instead. This allows to
|
|
/// programmatically hide the view switcher even if it fits in the available
|
|
/// space.
|
|
///
|
|
/// This can be used e.g. to ensure the view switcher is hidden below a certain
|
|
/// window width, or any other constraint you find suitable.
|
|
///
|
|
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.ViewSwitcherTitle.setViewSwitcherEnabled(enabled:)`.
|
|
///
|
|
/// - Parameter viewSwitcherEnabled: Whether the view switcher is enabled.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func viewSwitcherEnabled(_ viewSwitcherEnabled: @escaping () -> Bool) -> Self {
|
|
appending { w, ctx in
|
|
let tracker = DependencyTracker { [w] in w.setViewSwitcherEnabled(enabled: viewSwitcherEnabled()) }
|
|
tracker.run()
|
|
ctx.registry.add(tracker)
|
|
}
|
|
}
|
|
|
|
}
|