portico/Sources/Portico/Generated/Calendar.swift

541 lines
27 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.Calendar
/// Displays a Gregorian calendar, one month at a time.
///
/// <picture>
/// <source srcset="calendar-dark.png" media="(prefers-color-scheme: dark)">
/// <img alt="An example GtkCalendar" src="calendar.png">
/// </picture>
///
/// A `GtkCalendar` can be created with [ctor`Gtk`.Calendar.new].
///
/// The selected date can be retrieved from a `GtkCalendar` using
/// [method`Gtk`.Calendar.get_date].
/// It can be altered with [method`Gtk`.Calendar.set_date].
///
/// To place a visual marker on a particular day, use
/// [method`Gtk`.Calendar.mark_day] and to remove the marker,
/// [method`Gtk`.Calendar.unmark_day]. Alternative, all
/// marks can be cleared with [method`Gtk`.Calendar.clear_marks].
///
/// Users should be aware that, although the Gregorian calendar is the
/// legal calendar in most countries, it was adopted progressively
/// between 1582 and 1929. Display before these dates is likely to be
/// historically incorrect.
///
/// # Shortcuts and Gestures
///
/// `GtkCalendar` supports the following gestures:
///
/// - Scrolling up or down will switch to the previous or next month.
/// - Date strings can be dropped for setting the current day.
///
/// # CSS nodes
///
/// ```
/// calendar.view
/// header
/// button
/// stack.month
/// button
/// button
/// label.year
/// button
/// grid
/// label[.day-name][.week-number][.day-number][.other-month][.today]
/// ```
///
/// `GtkCalendar` has a main node with name calendar. It contains a subnode
/// called header containing the widgets for switching between years and months.
///
/// The grid subnode contains all day labels, including week numbers on the left
/// (marked with the .week-number css class) and day names on top (marked with the
/// .day-name css class).
///
/// Day labels that belong to the previous or next month get the .other-month
/// style class. The label of the current day get the .today style class.
///
/// Marked day labels get the :selected state assigned.
///
/// A Portico view that mounts a `Gtk.Calendar`.
@MainActor public struct Calendar: View {
private let make: (MountContext) -> Gtk.Calendar
private var configure: [(Gtk.Calendar, MountContext) -> Void] = []
public var body: Never { fatalError() }
// PorticoGen: generateInits(static) | source: Gtk.Calendar.init()
/// Creates a new calendar, with the current date being selected.
///
/// 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 date: The selected date.
/// - Parameter day: The selected day (as a number between 1 and 31).
/// - Parameter month: The selected month (as a number between 0 and 11).
/// - Parameter showDayNames: Determines whether day names are displayed.
/// - Parameter showHeading: Determines whether a heading is displayed.
/// - Parameter showWeekNumbers: Determines whether week numbers are displayed.
/// - Parameter year: The selected year.
/// - Parameter onDaySelected: Invoked when the widget emits the `day-selected` signal.
/// - Parameter onNextMonth: Invoked when the widget emits the `next-month` signal.
/// - Parameter onNextYear: Invoked when the widget emits the `next-year` signal.
/// - Parameter onPrevMonth: Invoked when the widget emits the `prev-month` signal.
/// - Parameter onPrevYear: Invoked when the widget emits the `prev-year` signal.
public init(date: GLib.DateTime? = nil, day: Int32? = nil, month: Int32? = nil, showDayNames: Bool? = nil, showHeading: Bool? = nil, showWeekNumbers: Bool? = nil, year: Int32? = nil, onDaySelected: (() -> Void)? = nil, onNextMonth: (() -> Void)? = nil, onNextYear: (() -> Void)? = nil, onPrevMonth: (() -> Void)? = nil, onPrevYear: (() -> Void)? = nil) {
make = { _ in Gtk.Calendar() }
configure.append { w, ctx in
if let date { w.setDate(date: date) }
if let day { w.setDay(day: day) }
if let month { w.setMonth(month: month) }
if let showDayNames { w.setShowDayNames(value: showDayNames) }
if let showHeading { w.setShowHeading(value: showHeading) }
if let showWeekNumbers { w.setShowWeekNumbers(value: showWeekNumbers) }
if let year { w.setYear(year: year) }
if let onDaySelected { ctx.registry.add(w.connectDaySelected { _ in onDaySelected() }) }
if let onNextMonth { ctx.registry.add(w.connectNextMonth { _ in onNextMonth() }) }
if let onNextYear { ctx.registry.add(w.connectNextYear { _ in onNextYear() }) }
if let onPrevMonth { ctx.registry.add(w.connectPrevMonth { _ in onPrevMonth() }) }
if let onPrevYear { ctx.registry.add(w.connectPrevYear { _ in onPrevYear() }) }
}
}
}
extension Calendar: WidgetView {
public typealias Target = Gtk.Calendar
@_spi(Portico) public func appending(
_ step: @escaping (Gtk.Calendar, MountContext) -> Void
) -> Self {
var c = self
c.configure.append(step)
return c
}
}
@_spi(Portico) extension Calendar: 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.Calendar
/// Modifiers for `Gtk.Calendar`, available on every Portico view whose
/// backing widget is `Gtk.Calendar` or one of its subclasses.
extension WidgetView where Target: Gtk.Calendar {
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.Calendar.setDate(date:)
/// Switches to `date`'s year and month and selects its day.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter date: The selected date.
/// - Returns: A copy of this view with the modifier applied.
public func date(_ date: GLib.DateTime) -> Self {
appending { w, _ in
w.setDate(date: date)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.Calendar.setDate(date:), GObject.Object.connectNotify(detail:_:), Gtk.Calendar.getDate()
/// Switches to `date`'s year and month and selects its day.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `GLib.DateTime` 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 date(_ date: Portico.Binding<GLib.DateTime>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, date, registry: ctx.registry, notifyDetail: "date",
read: { [w] in w.getDate() },
write: { [w] v in w.setDate(date: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.Calendar.setDate(date:)
/// Switches to `date`'s year and month and selects its day.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.Calendar.setDate(date:)`.
///
/// - Parameter date: The selected date.
/// - Returns: A copy of this view with the modifier applied.
public func date(_ date: @escaping () -> GLib.DateTime) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setDate(date: date()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.Calendar.setDay(day:)
/// Sets the day for the selected date.
///
/// The new date must be valid. For example, setting the day to 31 when the
/// month is February will fail.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter day: The selected day (as a number between 1 and 31).
/// - Returns: A copy of this view with the modifier applied.
public func day(_ day: Int32) -> Self {
appending { w, _ in
w.setDay(day: day)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.Calendar.setDay(day:), GObject.Object.connectNotify(detail:_:), Gtk.Calendar.getDay()
/// Sets the day for the selected date.
///
/// The new date must be valid. For example, setting the day to 31 when the
/// month is February will fail.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Int32` 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 day(_ day: Portico.Binding<Int32>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, day, registry: ctx.registry, notifyDetail: "day",
read: { [w] in w.getDay() },
write: { [w] v in w.setDay(day: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.Calendar.setDay(day:)
/// Sets the day for the selected date.
///
/// The new date must be valid. For example, setting the day to 31 when the
/// month is February will fail.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.Calendar.setDay(day:)`.
///
/// - Parameter day: The selected day (as a number between 1 and 31).
/// - Returns: A copy of this view with the modifier applied.
public func day(_ day: @escaping () -> Int32) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setDay(day: day()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.Calendar.setMonth(month:)
/// Sets the month for the selected date.
///
/// The new date must be valid. For example, setting the month to 1 (February)
/// when the day is 31 will fail.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter month: The selected month (as a number between 0 and 11).
/// - Returns: A copy of this view with the modifier applied.
public func month(_ month: Int32) -> Self {
appending { w, _ in
w.setMonth(month: month)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.Calendar.setMonth(month:), GObject.Object.connectNotify(detail:_:), Gtk.Calendar.getMonth()
/// Sets the month for the selected date.
///
/// The new date must be valid. For example, setting the month to 1 (February)
/// when the day is 31 will fail.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Int32` 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 month(_ month: Portico.Binding<Int32>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, month, registry: ctx.registry, notifyDetail: "month",
read: { [w] in w.getMonth() },
write: { [w] v in w.setMonth(month: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.Calendar.setMonth(month:)
/// Sets the month for the selected date.
///
/// The new date must be valid. For example, setting the month to 1 (February)
/// when the day is 31 will fail.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.Calendar.setMonth(month:)`.
///
/// - Parameter month: The selected month (as a number between 0 and 11).
/// - Returns: A copy of this view with the modifier applied.
public func month(_ month: @escaping () -> Int32) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setMonth(month: month()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.Calendar.setShowDayNames(value:)
/// Sets whether the calendar shows day names.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter showDayNames: Determines whether day names are displayed.
/// - Returns: A copy of this view with the modifier applied.
public func showDayNames(_ showDayNames: Bool) -> Self {
appending { w, _ in
w.setShowDayNames(value: showDayNames)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.Calendar.setShowDayNames(value:), GObject.Object.connectNotify(detail:_:), Gtk.Calendar.getShowDayNames()
/// Sets whether the calendar shows day names.
///
/// 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 showDayNames(_ showDayNames: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, showDayNames, registry: ctx.registry, notifyDetail: "show-day-names",
read: { [w] in w.getShowDayNames() },
write: { [w] v in w.setShowDayNames(value: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.Calendar.setShowDayNames(value:)
/// Sets whether the calendar shows day names.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.Calendar.setShowDayNames(value:)`.
///
/// - Parameter showDayNames: Determines whether day names are displayed.
/// - Returns: A copy of this view with the modifier applied.
public func showDayNames(_ showDayNames: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setShowDayNames(value: showDayNames()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.Calendar.setShowHeading(value:)
/// Sets whether the calendar should show a heading.
///
/// The heading contains the current year and month as well as
/// buttons for changing both.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter showHeading: Determines whether a heading is displayed.
/// - Returns: A copy of this view with the modifier applied.
public func showHeading(_ showHeading: Bool) -> Self {
appending { w, _ in
w.setShowHeading(value: showHeading)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.Calendar.setShowHeading(value:), GObject.Object.connectNotify(detail:_:), Gtk.Calendar.getShowHeading()
/// Sets whether the calendar should show a heading.
///
/// The heading contains the current year and month as well as
/// buttons for changing both.
///
/// 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 showHeading(_ showHeading: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, showHeading, registry: ctx.registry, notifyDetail: "show-heading",
read: { [w] in w.getShowHeading() },
write: { [w] v in w.setShowHeading(value: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.Calendar.setShowHeading(value:)
/// Sets whether the calendar should show a heading.
///
/// The heading contains the current year and month as well as
/// buttons for changing both.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.Calendar.setShowHeading(value:)`.
///
/// - Parameter showHeading: Determines whether a heading is displayed.
/// - Returns: A copy of this view with the modifier applied.
public func showHeading(_ showHeading: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setShowHeading(value: showHeading()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.Calendar.setShowWeekNumbers(value:)
/// Sets whether week numbers are shown in the calendar.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter showWeekNumbers: Determines whether week numbers are displayed.
/// - Returns: A copy of this view with the modifier applied.
public func showWeekNumbers(_ showWeekNumbers: Bool) -> Self {
appending { w, _ in
w.setShowWeekNumbers(value: showWeekNumbers)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.Calendar.setShowWeekNumbers(value:), GObject.Object.connectNotify(detail:_:), Gtk.Calendar.getShowWeekNumbers()
/// Sets whether week numbers are shown in the calendar.
///
/// 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 showWeekNumbers(_ showWeekNumbers: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, showWeekNumbers, registry: ctx.registry, notifyDetail: "show-week-numbers",
read: { [w] in w.getShowWeekNumbers() },
write: { [w] v in w.setShowWeekNumbers(value: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.Calendar.setShowWeekNumbers(value:)
/// Sets whether week numbers are shown in the calendar.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.Calendar.setShowWeekNumbers(value:)`.
///
/// - Parameter showWeekNumbers: Determines whether week numbers are displayed.
/// - Returns: A copy of this view with the modifier applied.
public func showWeekNumbers(_ showWeekNumbers: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setShowWeekNumbers(value: showWeekNumbers()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.Calendar.setYear(year:)
/// Sets the year for the selected date.
///
/// The new date must be valid. For example, setting the year to 2023 when the
/// date is February 29 will fail.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter year: The selected year.
/// - Returns: A copy of this view with the modifier applied.
public func year(_ year: Int32) -> Self {
appending { w, _ in
w.setYear(year: year)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.Calendar.setYear(year:), GObject.Object.connectNotify(detail:_:), Gtk.Calendar.getYear()
/// Sets the year for the selected date.
///
/// The new date must be valid. For example, setting the year to 2023 when the
/// date is February 29 will fail.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Int32` 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 year(_ year: Portico.Binding<Int32>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, year, registry: ctx.registry, notifyDetail: "year",
read: { [w] in w.getYear() },
write: { [w] v in w.setYear(year: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.Calendar.setYear(year:)
/// Sets the year for the selected date.
///
/// The new date must be valid. For example, setting the year to 2023 when the
/// date is February 29 will fail.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.Calendar.setYear(year:)`.
///
/// - Parameter year: The selected year.
/// - Returns: A copy of this view with the modifier applied.
public func year(_ year: @escaping () -> Int32) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setYear(year: year()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Gtk.Calendar.connectDaySelected(_:)
/// Emitted when the user selects a day.
///
/// - Parameter handler: Invoked when the widget emits the `day-selected` signal.
/// - Returns: A copy of this view with the modifier applied.
public func onDaySelected(_ handler: @escaping () -> Void) -> Self {
appending { w, ctx in
ctx.registry.add(w.connectDaySelected { _ in handler() })
}
}
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Gtk.Calendar.connectNextMonth(_:)
/// Emitted when the user switches to the next month.
///
/// - Parameter handler: Invoked when the widget emits the `next-month` signal.
/// - Returns: A copy of this view with the modifier applied.
public func onNextMonth(_ handler: @escaping () -> Void) -> Self {
appending { w, ctx in
ctx.registry.add(w.connectNextMonth { _ in handler() })
}
}
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Gtk.Calendar.connectNextYear(_:)
/// Emitted when user switches to the next year.
///
/// - Parameter handler: Invoked when the widget emits the `next-year` signal.
/// - Returns: A copy of this view with the modifier applied.
public func onNextYear(_ handler: @escaping () -> Void) -> Self {
appending { w, ctx in
ctx.registry.add(w.connectNextYear { _ in handler() })
}
}
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Gtk.Calendar.connectPrevMonth(_:)
/// Emitted when the user switches to the previous month.
///
/// - Parameter handler: Invoked when the widget emits the `prev-month` signal.
/// - Returns: A copy of this view with the modifier applied.
public func onPrevMonth(_ handler: @escaping () -> Void) -> Self {
appending { w, ctx in
ctx.registry.add(w.connectPrevMonth { _ in handler() })
}
}
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Gtk.Calendar.connectPrevYear(_:)
/// Emitted when user switches to the previous year.
///
/// - Parameter handler: Invoked when the widget emits the `prev-year` signal.
/// - Returns: A copy of this view with the modifier applied.
public func onPrevYear(_ handler: @escaping () -> Void) -> Self {
appending { w, ctx in
ctx.registry.add(w.connectPrevYear { _ in handler() })
}
}
}