Compare commits

..

No commits in common. "main" and "AddInitializerImplementation" have entirely different histories.

163 changed files with 4498 additions and 4138 deletions

View File

@ -154,5 +154,5 @@ type_contents_order:
- other_method
excluded:
- Sources/Adwaita/View/Generated/
- Sources/Core/View/Generated/
- .build/

View File

@ -1,4 +1,4 @@
// swift-tools-version: 6.1
// swift-tools-version: 6.0
//
// Package.swift
// Adwaita
@ -8,44 +8,40 @@
import PackageDescription
/// The dependencies.
var dependencies: [Package.Dependency] = [
.package(url: "https://git.aparoksha.dev/aparoksha/meta", branch: "main"),
.package(url: "https://git.aparoksha.dev/aparoksha/meta-sqlite", branch: "main"),
.package(
url: "https://git.aparoksha.dev/aparoksha/levenshtein-transformations",
branch: "main"
),
.package(url: "https://github.com/CoreOffice/XMLCoder", from: "0.17.1")
]
#if os(Linux)
dependencies.append(.package(url: "https://github.com/stephencelis/CSQLite", from: "3.50.4"))
#endif
/// The Adwaita package.
let package = Package(
name: "Adwaita",
platforms: [.macOS(.v13), .iOS(.v13), .tvOS(.v13), .watchOS(.v6), .macCatalyst(.v13)],
platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6), .macCatalyst(.v13)],
products: [
.library(
name: "Adwaita",
targets: ["Adwaita"]
),
.library(
name: "Core",
targets: ["Core"]
),
.library(
name: "CAdw",
targets: ["CAdw"]
)
],
traits: [.trait(name: "exposeGeneratedAppearUpdateFunctions")],
dependencies: dependencies,
dependencies: [
.package(url: "https://git.aparoksha.dev/aparoksha/meta", branch: "main"),
.package(url: "https://git.aparoksha.dev/aparoksha/meta-sqlite", from: "0.1.0"),
.package(
url: "https://git.aparoksha.dev/aparoksha/levenshtein-transformations",
branch: "main"
),
.package(url: "https://github.com/CoreOffice/XMLCoder", from: "0.17.1")
],
targets: [
.systemLibrary(
name: "CAdw",
pkgConfig: "libadwaita-1"
),
.target(
name: "Adwaita",
name: "Core",
dependencies: [
"CAdw",
.product(name: "LevenshteinTransformations", package: "levenshtein-transformations"),
@ -53,6 +49,10 @@ let package = Package(
.product(name: "MetaSQLite", package: "meta-sqlite")
]
),
.target(
name: "Adwaita",
dependencies: ["Core"]
),
.executableTarget(
name: "Generation",
dependencies: [

View File

@ -0,0 +1,17 @@
//
// ActionRow+.swift
// Adwaita
//
// Created by david-swift on 16.10.24.
//
extension ActionRow {
/// Deemphasize the row title and emphasize the subtitle.
/// - Parameter active: Whether the style is currently applied.
/// - Returns: A view.
public func property(_ active: Bool = true) -> AnyView {
style("property", active: active)
}
}

View File

@ -108,13 +108,6 @@ extension AnyView {
style("circular", active: active)
}
/// Make a button or similar widget use round appearance.
/// - Parameter active: Whether the style is currently applied.
/// - Returns: A view.
public func round(_ active: Bool = true) -> AnyView {
style("round", active: active)
}
/// Make a button or similar widget appear as a pill.
/// - Parameter active: Whether the style is currently applied.
/// - Returns: A view.
@ -278,6 +271,13 @@ extension AnyView {
style("frame", active: active)
}
/// Run a function when the view gets an update.
/// - Parameter onUpdate: The function.
/// - Returns: A view.
public func onUpdate(_ onUpdate: @escaping () -> Void) -> AnyView {
inspect { _, _ in onUpdate() }
}
/// Bind to the view's focus.
/// - Parameter focus: Whether the view is focused.
/// - Returns: A view.
@ -336,21 +336,15 @@ extension AnyView {
}
/// Add CSS classes to the app as soon as the view appears.
/// - Parameters:
/// - scheme: The color scheme.
/// - getString: Get the CSS.
/// - Parameter getString: Get the CSS.
/// - Returns: A view.
public func css(scheme: ColorScheme? = nil, getString: @escaping () -> String) -> AnyView {
wrap { storage, updateProperties in
public func css(_ getString: @escaping () -> String) -> AnyView {
inspect { storage, updateProperties in
let cssID = "internal-css"
let providerID = "internal-css-provider"
let previous = storage.fields[cssID] as? String
let string = getString()
if updateProperties, string != previous {
let provider = gtk_css_provider_new()
if let scheme {
gtui_cssprovider_set_prefers_color_scheme(.init(Int(bitPattern: provider)), scheme.gtkValue)
}
gtk_css_provider_load_from_string(
provider,
string
@ -362,32 +356,8 @@ extension AnyView {
.init(GTK_STYLE_PROVIDER_PRIORITY_APPLICATION)
)
g_object_unref(provider)
storage.fields[cssID] = string
if let oldProvider = storage.fields[providerID] as? OpaquePointer {
gtk_style_context_remove_provider_for_display(
display,
oldProvider
)
}
storage.fields[providerID] = provider?.opaque()
}
}
}
/// Whether the view has a width higher or equal to its natural width.
/// - Parameters:
/// - matches: Whether the content view matches the breakpoint.
/// - padding: Increase the natural width by a certain padding.
public func naturalWidth(matches: Binding<Bool>, padding: Int = 0) -> AnyView {
BreakpointBin(condition: .naturalWidth(padding: padding), matches: matches) { self }
}
/// Whether the view has a height higher or equal to its natural height.
/// - Parameters:
/// - matches: Whether the content view matches the breakpoint.
/// - padding: Increase the natural height by a certain padding.
public func naturalHeight(matches: Binding<Bool>, padding: Int = 0) -> AnyView {
BreakpointBin(condition: .naturalHeight(padding: padding), matches: matches) { self }
}
}

View File

@ -5,7 +5,7 @@
// Created by david-swift on 16.10.24.
//
import CAdw
@_exported import Core
import Foundation
extension AnyView {
@ -128,27 +128,12 @@ extension AnyView {
)
}
/// Add a shortcuts dialog to the parent window.
/// - Parameters:
/// - visible: Whether the dialog is presented.
/// - id: The dialog's id.
/// - Returns: The view.
public func shortcutsDialog(
visible: Binding<Bool>,
id: String? = nil
) -> ShortcutsDialog {
.init(
visible: visible,
child: self,
id: id ?? ""
)
}
/// Create an importer file dialog.
/// - Parameters:
/// - open: The signal to open the dialog.
/// - initialFolder: The URL to the folder open when being opened.
/// - extensions: The accepted file extensions.
/// - folders: Whether folders are accepted.
/// - onOpen: Run this when a file for importing has been chosen.
/// - onClose: Run this when the user cancelled the action.
public func fileImporter(
@ -156,37 +141,17 @@ extension AnyView {
initialFolder: URL? = nil,
extensions: [String]? = nil,
onOpen: @escaping (URL) -> Void,
onClose: @escaping () -> Void = { }
onClose: @escaping () -> Void
) -> AnyView {
FileDialog(
type: .importer(folder: false, extensions: extensions),
importer: true,
open: open,
child: self,
result: onOpen,
cancel: onClose,
initialFolder: initialFolder
)
}
/// Create an importer file dialog for folders.
/// - Parameters:
/// - open: The signal to open the dialog.
/// - initialFolder: The URL to the folder open when being opened.
/// - onOpen: Run this when a file for importing has been chosen.
/// - onClose: Run this when the user cancelled the action.
public func folderImporter(
open: Signal,
initialFolder: URL? = nil,
onOpen: @escaping (URL) -> Void,
onClose: @escaping () -> Void = { }
) -> AnyView {
FileDialog(
type: .importer(folder: true, extensions: nil),
open: open,
child: self,
result: onOpen,
cancel: onClose,
initialFolder: initialFolder
initialFolder: initialFolder,
initialName: nil,
extensions: extensions
)
}
@ -202,15 +167,16 @@ extension AnyView {
initialFolder: URL? = nil,
initialName: String? = nil,
onSave: @escaping (URL) -> Void,
onClose: @escaping () -> Void = { }
onClose: @escaping () -> Void
) -> AnyView {
FileDialog(
type: .exporter(initialName: initialName),
importer: false,
open: open,
child: self,
result: onSave,
cancel: onClose,
initialFolder: initialFolder
initialFolder: initialFolder,
initialName: initialName
)
}
@ -244,6 +210,82 @@ extension AnyView {
.maximumSize(maxHeight ?? -1)
}
/// Add padding around a view.
/// - Parameters:
/// - padding: The size of the padding.
/// - edges: The edges which are affected by the padding.
/// - Returns: A view.
public func padding(_ padding: Int = 10, _ edges: Set<Edge> = .all) -> AnyView {
ModifierWrapper(content: self, padding: padding, edges: edges)
}
/// Enable or disable the horizontal expansion.
/// - Parameter enabled: Whether it is enabled or disabled.
/// - Returns: A view.
public func hexpand(_ enabled: Bool = true) -> AnyView {
ModifierWrapper(content: self, hexpand: enabled)
}
/// Enable or disable the vertical expansion.
/// - Parameter enabled: Whether it is enabled or disabled.
/// - Returns: A view.
public func vexpand(_ enabled: Bool = true) -> AnyView {
ModifierWrapper(content: self, vexpand: enabled)
}
/// Set the horizontal alignment.
/// - Parameter align: The alignment.
/// - Returns: A view.
public func halign(_ align: Alignment) -> AnyView {
ModifierWrapper(content: self, halign: align)
}
/// Set the vertical alignment.
/// - Parameter align: The alignment.
/// - Returns: A view.
public func valign(_ align: Alignment) -> AnyView {
ModifierWrapper(content: self, valign: align)
}
/// Set the view's minimal width or height.
/// - Parameters:
/// - minWidth: The minimal width.
/// - minHeight: The minimal height.
/// - Returns: A view.
public func frame(minWidth: Int? = nil, minHeight: Int? = nil) -> AnyView {
ModifierWrapper(content: self, minWidth: minWidth, minHeight: minHeight)
}
/// Add a style class to the view.
/// - Parameters:
/// - style: The style class.
/// - active: Whether the style is currently applied.
/// - Returns: A view.
public func style(_ style: String, active: Bool = true) -> AnyView {
ModifierWrapper(content: self, style: style, styleActive: active)
}
/// Make the view insensitive (useful e.g. in overlays).
/// - Parameter insensitive: Whether the view is insensitive.
/// - Returns: A view.
public func insensitive(_ insensitive: Bool = true) -> AnyView {
ModifierWrapper(content: self, insensitive: insensitive)
}
/// Set the view's visibility.
/// - Parameter visible: Whether the view is visible.
/// - Returns: A view.
public func visible(_ visible: Bool = true) -> AnyView {
ModifierWrapper(content: self, visible: visible)
}
/// Add a tooltip to the widget.
/// - Parameter tooltip: The tooltip text.
/// - Returns: A view.
public func tooltip(_ tooltip: String) -> AnyView {
ModifierWrapper(content: self, tooltip: tooltip)
}
/// Present a toast when the signal gets activated.
/// - Parameters:
/// - title: The title of the toast.
@ -299,11 +341,20 @@ extension AnyView {
BreakpointBin(condition: .minHeight(minHeight), matches: matches) { self }
}
/// Build the UI from scratch once the identifier changes.
/// - Parameter id: The identifier.
public func id(_ id: CustomStringConvertible) -> AnyView {
ViewStack(id: id) { _ in self }
.limitChildren()
/// Whether the view has a width higher or equal to its natural width.
/// - Parameters:
/// - matches: Whether the content view matches the breakpoint.
/// - padding: Increase the natural width by a certain padding.
public func naturalWidth(matches: Binding<Bool>, padding: Int = 0) -> AnyView {
BreakpointBin(condition: .naturalWidth(padding: padding), matches: matches) { self }
}
/// Whether the view has a height higher or equal to its natural height.
/// - Parameters:
/// - matches: Whether the content view matches the breakpoint.
/// - padding: Increase the natural height by a certain padding.
public func naturalHeight(matches: Binding<Bool>, padding: Int = 0) -> AnyView {
BreakpointBin(condition: .naturalHeight(padding: padding), matches: matches) { self }
}
}

View File

@ -0,0 +1,24 @@
//
// List+.swift
// Adwaita
//
// Created by david-swift on 16.10.24.
//
extension List {
/// Add the "navigation-sidebar" style class.
/// - Parameter active: Whether the style is applied.
/// - Returns: A view.
public func sidebarStyle(_ active: Bool = true) -> AnyView {
style("navigation-sidebar", active: active)
}
/// Apply the boxed list style class.
/// - Parameter active: Whether the style is applied.
/// - Returns: A view.
public func boxedList(_ active: Bool = true) -> AnyView {
style("boxed-list", active: active)
}
}

View File

@ -1,23 +0,0 @@
//
// ColorScheme.swift
// Adwaita
//
// Created by david-swift on 01.02.26.
//
import CAdw
/// The system color scheme.
public enum ColorScheme: UInt32 {
/// The dark color scheme.
case dark = 2
/// The light color scheme.
case light = 3
/// The ColorScheme value as GtkInterfaceColorScheme.
var gtkValue: GtkInterfaceColorScheme {
.init(rawValue)
}
}

View File

@ -0,0 +1,17 @@
//
// StatusPage+.swift
// Adwaita
//
// Created by david-swift on 16.10.24.
//
extension StatusPage {
/// Make the status page more compact.
/// - Parameter active: Whether the style is applied.
/// - Returns: A view.
public func compact(_ active: Bool = true) -> AnyView {
style("compact", active: active)
}
}

View File

@ -1,123 +0,0 @@
//
// AnyView+wrapModifier.swift
// Adwaita
//
// Created by david-swift on 02.02.26.
//
import CAdw
extension AnyView {
/// Add padding around a view.
/// - Parameters:
/// - padding: The size of the padding.
/// - edges: The edges which are affected by the padding.
/// - Returns: A view.
public func padding(_ padding: Int = 10, _ edges: Set<Edge> = .all) -> AnyView {
wrapModifier(properties: [padding, edges]) { storage in
if edges.contains(.leading) { gtk_widget_set_margin_start(storage.opaquePointer?.cast(), padding.cInt) }
if edges.contains(.trailing) { gtk_widget_set_margin_end(storage.opaquePointer?.cast(), padding.cInt) }
if edges.contains(.top) { gtk_widget_set_margin_top(storage.opaquePointer?.cast(), padding.cInt) }
if edges.contains(.bottom) { gtk_widget_set_margin_bottom(storage.opaquePointer?.cast(), padding.cInt) }
}
}
/// Add a padding of 10 around a view.
/// - Parameters:
/// - edges: The edges which are affected by the padding.
/// - Returns: A view.
public func padding(_ edges: Set<Edge> = .all) -> AnyView {
padding(10, edges)
}
/// Enable or disable the horizontal expansion.
/// - Parameter enabled: Whether it is enabled or disabled.
/// - Returns: A view.
public func hexpand(_ enabled: Bool = true) -> AnyView {
wrapModifier(properties: [enabled]) { storage in
gtk_widget_set_hexpand(storage.opaquePointer?.cast(), enabled.cBool)
}
}
/// Enable or disable the vertical expansion.
/// - Parameter enabled: Whether it is enabled or disabled.
/// - Returns: A view.
public func vexpand(_ enabled: Bool = true) -> AnyView {
wrapModifier(properties: [enabled]) { storage in
gtk_widget_set_vexpand(storage.opaquePointer?.cast(), enabled.cBool)
}
}
/// Set the horizontal alignment.
/// - Parameter align: The alignment.
/// - Returns: A view.
public func halign(_ align: Alignment) -> AnyView {
wrapModifier(properties: [align]) { storage in
gtk_widget_set_halign(storage.opaquePointer?.cast(), align.cAlign)
}
}
/// Set the vertical alignment.
/// - Parameter align: The alignment.
/// - Returns: A view.
public func valign(_ align: Alignment) -> AnyView {
wrapModifier(properties: [align]) { storage in
gtk_widget_set_valign(storage.opaquePointer?.cast(), align.cAlign)
}
}
/// Set the view's minimal width or height.
/// - Parameters:
/// - minWidth: The minimal width.
/// - minHeight: The minimal height.
/// - Returns: A view.
public func frame(minWidth: Int? = nil, minHeight: Int? = nil) -> AnyView {
wrapModifier(properties: [minWidth, minHeight]) { storage in
gtk_widget_set_size_request(storage.opaquePointer?.cast(), minWidth?.cInt ?? 1, minHeight?.cInt ?? -1)
}
}
/// Add a style class to the view.
/// - Parameters:
/// - style: The style class.
/// - active: Whether the style is currently applied.
/// - Returns: A view.
public func style(_ style: String, active: Bool = true) -> AnyView {
wrapModifier(properties: [style, active]) { storage in
if active {
gtk_widget_add_css_class(storage.opaquePointer?.cast(), style)
} else {
gtk_widget_remove_css_class(storage.opaquePointer?.cast(), style)
}
}
}
/// Make the view insensitive (useful e.g. in overlays).
/// - Parameter insensitive: Whether the view is insensitive.
/// - Returns: A view.
public func insensitive(_ insensitive: Bool = true) -> AnyView {
wrapModifier(properties: [insensitive]) { storage in
gtk_widget_set_sensitive(storage.opaquePointer?.cast(), insensitive ? 0 : 1)
}
}
/// Set the view's visibility.
/// - Parameter visible: Whether the view is visible.
/// - Returns: A view.
public func visible(_ visible: Bool = true) -> AnyView {
wrapModifier(properties: [visible]) { storage in
gtk_widget_set_visible(storage.opaquePointer?.cast(), visible.cBool)
}
}
/// Add a tooltip to the widget.
/// - Parameter tooltip: The tooltip text.
/// - Returns: A view.
public func tooltip(_ tooltip: String) -> AnyView {
wrapModifier(properties: [tooltip]) { storage in
gtk_widget_set_tooltip_markup(storage.opaquePointer?.cast(), tooltip)
}
}
}

View File

@ -1,192 +0,0 @@
//
// ShortcutsDialog.swift
// Adwaita
//
// Created by david-swift on 04.11.25.
//
import CAdw
/// The shortcuts dialog widget.
public struct ShortcutsDialog: AdwaitaWidget {
/// Whether the dialog is visible.
@Binding var visible: Bool
/// An identifier used if multiple dialogs are on one view.
var id: String
/// The shortcuts dialog sections.
var sections: [ShortcutsSection] = []
/// The content.
var child: AnyView
/// The ID for the dialog's storage.
let dialogID = "dialog"
/// The ID for the content's storage.
let contentID = "content"
/// Initialize a dialog wrapper.
/// - Parameters:
/// - visible: Whether the dialog is visible.
/// - child: The wrapped view.
/// - id: A unique identifier for dialogs on the view.
init(
visible: Binding<Bool>,
child: AnyView,
id: String
) {
self._visible = visible
self.child = child
self.id = id
}
/// A shortcuts section.
public struct ShortcutsSection {
/// The section's title.
var title: String?
/// The section's content.
var content: [ShortcutsItem] = []
/// Initialize the shortcuts section.
/// - Parameter title: The section's title.
init(_ title: String?) {
self.title = title
}
/// Get the GTK shortcuts section as well as the section's view storages.
/// - Parameter data: The widget data.
/// - Returns: The shortcuts section pointer and the section's view storages.
func gtkShortcutsSection(data: WidgetData) -> (OpaquePointer?, [ViewStorage]) {
let section = adw_shortcuts_section_new(title)
let items = content.map { $0.gtkShortcutsItem(data: data) }
for item in items {
adw_shortcuts_section_add(section, item.opaquePointer)
}
return (section, items)
}
/// Add a shortcuts item.
/// - Parameters:
/// - title: The item's title.
/// - accelerator: The shortcut acccelerator.
public func shortcutsItem(
_ title: String,
accelerator: String
) -> Self {
var newSelf = self
newSelf.content.append(
.init(
title: title,
accelerator: accelerator
)
)
return newSelf
}
}
/// The shortcuts item.
struct ShortcutsItem {
/// The item's title.
var title: String
/// The item's description.
var accelerator: String
/// Get the GTK preferences group's storage.
/// - Parameter data: The widget data.
/// - Returns: The view storage.
func gtkShortcutsItem(data: WidgetData) -> ViewStorage {
.init(adw_shortcuts_item_new(title, accelerator))
}
}
/// The view storage.
/// - Parameters:
/// - modifiers: Modify views before being updated.
/// - type: The view render data type.
/// - Returns: The view storage.
public func container<Data>(data: WidgetData, type: Data.Type) -> ViewStorage where Data: ViewRenderData {
let child = child.storage(data: data, type: type)
return .init(child.opaquePointer, content: [.mainContent: [child]])
}
/// Update the stored content.
/// - Parameters:
/// - storage: The storage to update.
/// - modifiers: Modify views before being updated
/// - updateProperties: Whether to update the view's properties.
/// - type: The view render data type.
public func update<Data>(
_ storage: ViewStorage,
data: WidgetData,
updateProperties: Bool,
type: Data.Type
) where Data: ViewRenderData {
if let storage = storage.content[.mainContent]?.first {
child.updateStorage(storage, data: data, updateProperties: updateProperties, type: type)
}
guard updateProperties else {
return
}
if visible {
if storage.content[dialogID + id]?.first == nil {
createDialog(storage: storage, data: data, type: type)
adw_dialog_present(
storage.content[dialogID + id]?.first?.opaquePointer?.cast(),
storage.opaquePointer?.cast()
)
}
} else {
if storage.content[dialogID + id]?.first != nil {
let dialog = storage.content[dialogID + id]?.first?.opaquePointer
adw_dialog_close(dialog?.cast())
g_object_unref(dialog?.cast())
for index in sections.indices {
let container = storage.content["shortcuts-\(index)"]?.map { $0.opaquePointer }
container?.forEach { g_object_unref($0?.cast()) }
g_object_unref((storage.fields["shortcuts-\(index)"] as? OpaquePointer)?.cast())
}
}
}
}
/// Create a new instance of the dialog.
/// - Parameters:
/// - storage: The wrapped view's storage.
/// - modifiers: The view modifiers.
/// - type: The view render data type.
func createDialog<Data>(
storage: ViewStorage,
data: WidgetData,
type: Data.Type
) where Data: ViewRenderData {
let pointer = adw_shortcuts_dialog_new()
let dialog = ViewStorage(pointer?.opaque())
storage.content[dialogID + id] = [dialog]
dialog.connectSignal(name: "closed") {
storage.content[dialogID + id] = []
storage.content[contentID + id] = []
if visible {
visible = false
}
}
for (index, section) in sections.map({ $0.gtkShortcutsSection(data: data) }).enumerated() {
storage.content["shortcuts-\(index)"] = section.1
storage.fields["shortcuts-\(index)"] = section.0
adw_shortcuts_dialog_add(pointer?.opaque(), section.0)
}
}
/// Add a shortcuts section.
/// - Parameters:
/// - title: The section's title or `nil`.
/// - content: Modify the shortcuts items.
public func shortcutsSection(
_ title: String? = nil,
content: (ShortcutsSection) -> ShortcutsSection
) -> Self {
modify { $0.sections.append(content(.init(title))) }
}
}

View File

@ -1,168 +0,0 @@
//
// Image.swift
// Adwaita
//
// Created by auto-generation on 04.02.26.
//
import CAdw
import LevenshteinTransformations
/// Displays an image.
///
///
///
/// Various kinds of object can be displayed as an image; most typically,
/// you would load a `GdkTexture` from a file, using the convenience function
/// `Gtk.Image.new_from_file`, for instance:
///
/// ```c
/// GtkWidget *image = gtk_image_new_from_file ("myfile.png");
/// ```
///
/// If the file isnt loaded successfully, the image will contain a
/// broken image icon similar to that used in many web browsers.
///
/// If you want to handle errors in loading the file yourself, for example
/// by displaying an error message, then load the image with an image
/// loading framework such as libglycin, then create the `GtkImage` with
/// `Gtk.Image.new_from_paintable`.
///
/// Sometimes an application will want to avoid depending on external data
/// files, such as image files. See the documentation of `GResource` inside
/// GIO, for details. In this case, ``resource(_:)``,
/// `Gtk.Image.new_from_resource`, and `Gtk.Image.set_from_resource`
/// should be used.
///
/// `GtkImage` displays its image as an icon, with a size that is determined
/// by the application. See `Gtk.Picture` if you want to show an image
/// at is actual size.
///
///
public struct Image: AdwaitaWidget {
#if exposeGeneratedAppearUpdateFunctions
/// Additional update functions for type extensions.
public var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
public var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#else
/// Additional update functions for type extensions.
var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#endif
/// The accessible role of the given `GtkAccessible` implementation.
///
/// The accessible role cannot be changed once set.
var accessibleRole: String?
/// The name of the icon in the icon theme.
///
/// If the icon theme is changed, the image will be updated automatically.
var iconName: String?
/// The size in pixels to display icons at.
///
/// If set to a value != -1, this property overrides the
/// ``iconSize(_:)`` property for images of type
/// `GTK_IMAGE_ICON_NAME`.
var pixelSize: Int?
/// A path to a resource file to display.
var resource: String?
/// The representation being used for image data.
var storageType: String?
/// Whether the icon displayed in the `GtkImage` will use
/// standard icon names fallback.
///
/// The value of this property is only relevant for images of type
/// %GTK_IMAGE_ICON_NAME and %GTK_IMAGE_GICON.
var useFallback: Bool?
/// Initialize `Image`.
public init() {
}
/// The view storage.
/// - Parameters:
/// - modifiers: Modify views before being updated.
/// - type: The view render data type.
/// - Returns: The view storage.
public func container<Data>(data: WidgetData, type: Data.Type) -> ViewStorage where Data: ViewRenderData {
let storage = ViewStorage(gtk_image_new()?.opaque())
for function in appearFunctions {
function(storage, data)
}
return storage
}
/// Update the stored content.
/// - Parameters:
/// - storage: The storage to update.
/// - modifiers: Modify views before being updated
/// - updateProperties: Whether to update the view's properties.
/// - type: The view render data type.
public func update<Data>(_ storage: ViewStorage, data: WidgetData, updateProperties: Bool, type: Data.Type) where Data: ViewRenderData {
storage.modify { widget in
if let iconName, updateProperties, (storage.previousState as? Self)?.iconName != iconName {
gtk_image_set_from_icon_name(widget, iconName)
}
if let pixelSize, updateProperties, (storage.previousState as? Self)?.pixelSize != pixelSize {
gtk_image_set_pixel_size(widget, pixelSize.cInt)
}
}
for function in updateFunctions {
function(storage, data, updateProperties)
}
if updateProperties {
storage.previousState = self
}
}
/// The accessible role of the given `GtkAccessible` implementation.
///
/// The accessible role cannot be changed once set.
public func accessibleRole(_ accessibleRole: String?) -> Self {
modify { $0.accessibleRole = accessibleRole }
}
/// The name of the icon in the icon theme.
///
/// If the icon theme is changed, the image will be updated automatically.
public func iconName(_ iconName: String?) -> Self {
modify { $0.iconName = iconName }
}
/// The size in pixels to display icons at.
///
/// If set to a value != -1, this property overrides the
/// ``iconSize(_:)`` property for images of type
/// `GTK_IMAGE_ICON_NAME`.
public func pixelSize(_ pixelSize: Int?) -> Self {
modify { $0.pixelSize = pixelSize }
}
/// A path to a resource file to display.
public func resource(_ resource: String?) -> Self {
modify { $0.resource = resource }
}
/// The representation being used for image data.
public func storageType(_ storageType: String?) -> Self {
modify { $0.storageType = storageType }
}
/// Whether the icon displayed in the `GtkImage` will use
/// standard icon names fallback.
///
/// The value of this property is only relevant for images of type
/// %GTK_IMAGE_ICON_NAME and %GTK_IMAGE_GICON.
public func useFallback(_ useFallback: Bool? = true) -> Self {
modify { $0.useFallback = useFallback }
}
}

View File

@ -1,331 +0,0 @@
//
// Label.swift
// Adwaita
//
// Created by auto-generation on 04.02.26.
//
import CAdw
import LevenshteinTransformations
/// Displays a small amount of text.
///
/// Most labels are used to label another widget (such as an `Entry`).
///
///
///
///
public struct Label: AdwaitaWidget {
#if exposeGeneratedAppearUpdateFunctions
/// Additional update functions for type extensions.
public var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
public var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#else
/// Additional update functions for type extensions.
var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#endif
/// The accessible role of the given `GtkAccessible` implementation.
///
/// The accessible role cannot be changed once set.
var accessibleRole: String?
/// The contents of the label.
///
/// If the string contains Pango markup (see `Pango.parse_markup`),
/// you will have to set the ``useMarkup(_:)`` property to
/// true in order for the label to display the markup attributes. See also
/// `Gtk.Label.set_markup` for a convenience function that sets both
/// this property and the ``useMarkup(_:)`` property at the
/// same time.
///
/// If the string contains underlines acting as mnemonics, you will have to
/// set the ``useUnderline(_:)`` property to true in order
/// for the label to display them.
var label: String
/// The number of lines to which an ellipsized, wrapping label
/// should display before it gets ellipsized. This both prevents the label
/// from ellipsizing before this many lines are displayed, and limits the
/// height request of the label to this many lines.
///
/// > [!WARNING]
/// > Setting this property has unintuitive and unfortunate consequences
/// for the minimum _width_ of the label. Specifically, if the height
/// of the label is such that it fits a smaller number of lines than
/// the value of this property, the label can not be ellipsized at all,
/// which means it must be wide enough to fit all the text fully.
///
/// This property has no effect if the label is not wrapping or ellipsized.
///
/// Set this property to -1 if you don't want to limit the number of lines.
var lines: Int?
/// The desired maximum width of the label, in characters.
///
/// If this property is set to -1, the width will be calculated automatically.
///
/// See the section on [text layout](class.Label.html
var maxWidthChars: Int?
/// The mnemonic accelerator key for the label.
var mnemonicKeyval: UInt?
/// The widget to be activated when the labels mnemonic key is pressed.
var mnemonicWidget: Body?
/// Whether the label text can be selected with the mouse.
var selectable: Bool?
/// Whether the label is in single line mode.
///
/// In single line mode, the height of the label does not depend on the
/// actual text, it is always set to ascent + descent of the font. This
/// can be an advantage in situations where resizing the label because
/// of text changes would be distracting, e.g. in a statusbar.
var singleLineMode: Bool?
/// True if the text of the label includes Pango markup.
///
/// See `Pango.parse_markup`.
var useMarkup: Bool?
/// True if the text of the label indicates a mnemonic with an `_`
/// before the mnemonic character.
var useUnderline: Bool?
/// The desired width of the label, in characters.
///
/// If this property is set to -1, the width will be calculated automatically.
///
/// See the section on [text layout](class.Label.html
var widthChars: Int?
/// True if the label text will wrap if it gets too wide.
var wrap: Bool?
/// The horizontal alignment of the label text inside its size allocation.
///
/// Compare this to ``halign(_:)``, which determines how the
/// labels size allocation is positioned in the space available for the label.
var xalign: Float?
/// The vertical alignment of the label text inside its size allocation.
///
/// Compare this to ``valign(_:)``, which determines how the
/// labels size allocation is positioned in the space available for the label.
var yalign: Float?
/// Gets emitted to copy the selection to the clipboard.
///
/// The `::copy-clipboard` signal is a [keybinding signal](class.SignalAction.html).
///
/// The default binding for this signal is <kbd>Ctrl</kbd>+<kbd>c</kbd>.
var copyClipboard: (() -> Void)?
/// Initialize `Label`.
public init(label: String) {
self.label = label
}
/// The view storage.
/// - Parameters:
/// - modifiers: Modify views before being updated.
/// - type: The view render data type.
/// - Returns: The view storage.
public func container<Data>(data: WidgetData, type: Data.Type) -> ViewStorage where Data: ViewRenderData {
let storage = ViewStorage(gtk_label_new(label)?.opaque())
for function in appearFunctions {
function(storage, data)
}
if let mnemonicWidgetStorage = mnemonicWidget?.storage(data: data, type: type) {
storage.content["mnemonicWidget"] = [mnemonicWidgetStorage]
gtk_label_set_mnemonic_widget(storage.opaquePointer, mnemonicWidgetStorage.opaquePointer?.cast())
}
return storage
}
/// Update the stored content.
/// - Parameters:
/// - storage: The storage to update.
/// - modifiers: Modify views before being updated
/// - updateProperties: Whether to update the view's properties.
/// - type: The view render data type.
public func update<Data>(_ storage: ViewStorage, data: WidgetData, updateProperties: Bool, type: Data.Type) where Data: ViewRenderData {
if let copyClipboard {
storage.connectSignal(name: "copy-clipboard", argCount: 0) {
copyClipboard()
}
}
storage.modify { widget in
if updateProperties, (storage.previousState as? Self)?.label != label {
gtk_label_set_label(widget, label)
}
if let lines, updateProperties, (storage.previousState as? Self)?.lines != lines {
gtk_label_set_lines(widget, lines.cInt)
}
if let maxWidthChars, updateProperties, (storage.previousState as? Self)?.maxWidthChars != maxWidthChars {
gtk_label_set_max_width_chars(widget, maxWidthChars.cInt)
}
if let widget = storage.content["mnemonicWidget"]?.first {
mnemonicWidget?.updateStorage(widget, data: data, updateProperties: updateProperties, type: type)
}
if let selectable, updateProperties, (storage.previousState as? Self)?.selectable != selectable {
gtk_label_set_selectable(widget, selectable.cBool)
}
if let singleLineMode, updateProperties, (storage.previousState as? Self)?.singleLineMode != singleLineMode {
gtk_label_set_single_line_mode(widget, singleLineMode.cBool)
}
if let useMarkup, updateProperties, (storage.previousState as? Self)?.useMarkup != useMarkup {
gtk_label_set_use_markup(widget, useMarkup.cBool)
}
if let useUnderline, updateProperties, (storage.previousState as? Self)?.useUnderline != useUnderline {
gtk_label_set_use_underline(widget, useUnderline.cBool)
}
if let widthChars, updateProperties, (storage.previousState as? Self)?.widthChars != widthChars {
gtk_label_set_width_chars(widget, widthChars.cInt)
}
if let wrap, updateProperties, (storage.previousState as? Self)?.wrap != wrap {
gtk_label_set_wrap(widget, wrap.cBool)
}
if let xalign, updateProperties, (storage.previousState as? Self)?.xalign != xalign {
gtk_label_set_xalign(widget, xalign)
}
if let yalign, updateProperties, (storage.previousState as? Self)?.yalign != yalign {
gtk_label_set_yalign(widget, yalign)
}
}
for function in updateFunctions {
function(storage, data, updateProperties)
}
if updateProperties {
storage.previousState = self
}
}
/// The accessible role of the given `GtkAccessible` implementation.
///
/// The accessible role cannot be changed once set.
public func accessibleRole(_ accessibleRole: String?) -> Self {
modify { $0.accessibleRole = accessibleRole }
}
/// The contents of the label.
///
/// If the string contains Pango markup (see `Pango.parse_markup`),
/// you will have to set the ``useMarkup(_:)`` property to
/// true in order for the label to display the markup attributes. See also
/// `Gtk.Label.set_markup` for a convenience function that sets both
/// this property and the ``useMarkup(_:)`` property at the
/// same time.
///
/// If the string contains underlines acting as mnemonics, you will have to
/// set the ``useUnderline(_:)`` property to true in order
/// for the label to display them.
public func label(_ label: String) -> Self {
modify { $0.label = label }
}
/// The number of lines to which an ellipsized, wrapping label
/// should display before it gets ellipsized. This both prevents the label
/// from ellipsizing before this many lines are displayed, and limits the
/// height request of the label to this many lines.
///
/// > [!WARNING]
/// > Setting this property has unintuitive and unfortunate consequences
/// for the minimum _width_ of the label. Specifically, if the height
/// of the label is such that it fits a smaller number of lines than
/// the value of this property, the label can not be ellipsized at all,
/// which means it must be wide enough to fit all the text fully.
///
/// This property has no effect if the label is not wrapping or ellipsized.
///
/// Set this property to -1 if you don't want to limit the number of lines.
public func lines(_ lines: Int?) -> Self {
modify { $0.lines = lines }
}
/// The desired maximum width of the label, in characters.
///
/// If this property is set to -1, the width will be calculated automatically.
///
/// See the section on [text layout](class.Label.html
public func maxWidthChars(_ maxWidthChars: Int?) -> Self {
modify { $0.maxWidthChars = maxWidthChars }
}
/// The mnemonic accelerator key for the label.
public func mnemonicKeyval(_ mnemonicKeyval: UInt?) -> Self {
modify { $0.mnemonicKeyval = mnemonicKeyval }
}
/// The widget to be activated when the labels mnemonic key is pressed.
public func mnemonicWidget(@ViewBuilder _ mnemonicWidget: () -> Body) -> Self {
modify { $0.mnemonicWidget = mnemonicWidget() }
}
/// Whether the label text can be selected with the mouse.
public func selectable(_ selectable: Bool? = true) -> Self {
modify { $0.selectable = selectable }
}
/// Whether the label is in single line mode.
///
/// In single line mode, the height of the label does not depend on the
/// actual text, it is always set to ascent + descent of the font. This
/// can be an advantage in situations where resizing the label because
/// of text changes would be distracting, e.g. in a statusbar.
public func singleLineMode(_ singleLineMode: Bool? = true) -> Self {
modify { $0.singleLineMode = singleLineMode }
}
/// True if the text of the label includes Pango markup.
///
/// See `Pango.parse_markup`.
public func useMarkup(_ useMarkup: Bool? = true) -> Self {
modify { $0.useMarkup = useMarkup }
}
/// True if the text of the label indicates a mnemonic with an `_`
/// before the mnemonic character.
public func useUnderline(_ useUnderline: Bool? = true) -> Self {
modify { $0.useUnderline = useUnderline }
}
/// The desired width of the label, in characters.
///
/// If this property is set to -1, the width will be calculated automatically.
///
/// See the section on [text layout](class.Label.html
public func widthChars(_ widthChars: Int?) -> Self {
modify { $0.widthChars = widthChars }
}
/// True if the label text will wrap if it gets too wide.
public func wrap(_ wrap: Bool? = true) -> Self {
modify { $0.wrap = wrap }
}
/// The horizontal alignment of the label text inside its size allocation.
///
/// Compare this to ``halign(_:)``, which determines how the
/// labels size allocation is positioned in the space available for the label.
public func xalign(_ xalign: Float?) -> Self {
modify { $0.xalign = xalign }
}
/// The vertical alignment of the label text inside its size allocation.
///
/// Compare this to ``valign(_:)``, which determines how the
/// labels size allocation is positioned in the space available for the label.
public func yalign(_ yalign: Float?) -> Self {
modify { $0.yalign = yalign }
}
/// Gets emitted to copy the selection to the clipboard.
///
/// The `::copy-clipboard` signal is a [keybinding signal](class.SignalAction.html).
///
/// The default binding for this signal is <kbd>Ctrl</kbd>+<kbd>c</kbd>.
public func copyClipboard(_ copyClipboard: @escaping () -> Void) -> Self {
var newSelf = self
newSelf.copyClipboard = copyClipboard
return newSelf
}
}

View File

@ -1,196 +0,0 @@
//
// ToggleGroup.swift
// Adwaita
//
// Created by auto-generation on 04.02.26.
//
import CAdw
import LevenshteinTransformations
/// A group of exclusive toggles.
///
///
///
/// `AdwToggleGroup` presents a set of exclusive toggles, represented as
/// `Toggle` objects. Each toggle can display an icon, a label, an icon
/// and a label, or a custom child.
///
/// Toggles are indexed by their position, with the first toggle being equivalent
/// to 0, and so on. Use the ``active(_:)`` to get that position.
///
/// Toggles can also have optional names, set via the ``name(_:)``
/// property. The name of the active toggle can be accessed via the
/// ``activeName(_:)`` property.
///
/// `AdwToggle` objects can be retrieved via their index or name, using
/// `ToggleGroup.get_toggle` or `ToggleGroup.get_toggle_by_name`
/// respectively. `AdwToggleGroup` also provides a `Gtk.SelectionModel` of
/// its toggles via the ``toggles(_:)`` property.
///
/// `AdwToggleGroup` is orientable, and the toggles can be displayed horizontally
/// or vertically. This is mostly useful for icon-only toggles.
///
/// Use the ``homogeneous(_:)`` property to make the toggles take
/// the same size, and the ``canShrink(_:)`` to control whether
/// the toggles can ellipsize.
///
/// Example of an `AdwToggleGroup` UI definition:
///
/// ```xml
/// <object class="AdwToggleGroup"><property name="active-name">picture</property><child><object class="AdwToggle"><property name="icon-name">camera-photo-symbolic</property><property name="tooltip" translatable="yes">Picture Mode</property><property name="name">picture</property></object></child><child><object class="AdwToggle"><property name="icon-name">camera-video-symbolic</property><property name="tooltip" translatable="yes">Recording Mode</property><property name="name">recording</property></object></child></object>
/// ```
///
/// See also: `InlineViewSwitcher`.
///
///
public struct ToggleGroup: AdwaitaWidget {
#if exposeGeneratedAppearUpdateFunctions
/// Additional update functions for type extensions.
public var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
public var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#else
/// Additional update functions for type extensions.
var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#endif
/// The index of the active toggle.
///
/// Setting the index to a larger value than the number of toggles in the group
/// unsets the current active toggle.
///
/// If no toggle is active, the property will be set to
/// `Gtk.INVALID_LIST_POSITION`.
var active: Binding<UInt>?
/// The name of the active toggle.
///
/// The name can be set via ``name(_:)``. If the currently active
/// toggle doesn't have a name, the property will be set to `NULL`.
///
/// Set it to `NULL` to unset the current active toggle.
var activeName: Binding<String>?
/// Whether the toggles can be smaller than the natural size of their contents.
///
/// If set to `true`, the toggle labels will ellipsize.
///
/// See ``canShrink(_:)``.
var canShrink: Bool?
/// Whether all toggles take the same size.
var homogeneous: Bool?
/// The number of toggles within the group.
var nToggles: Binding<UInt>?
/// Initialize `ToggleGroup`.
init() {
}
/// The view storage.
/// - Parameters:
/// - modifiers: Modify views before being updated.
/// - type: The view render data type.
/// - Returns: The view storage.
public func container<Data>(data: WidgetData, type: Data.Type) -> ViewStorage where Data: ViewRenderData {
let storage = ViewStorage(adw_toggle_group_new()?.opaque())
for function in appearFunctions {
function(storage, data)
}
return storage
}
/// Update the stored content.
/// - Parameters:
/// - storage: The storage to update.
/// - modifiers: Modify views before being updated
/// - updateProperties: Whether to update the view's properties.
/// - type: The view render data type.
public func update<Data>(_ storage: ViewStorage, data: WidgetData, updateProperties: Bool, type: Data.Type) where Data: ViewRenderData {
storage.modify { widget in
storage.notify(name: "active") {
let newValue = UInt(adw_toggle_group_get_active(storage.opaquePointer))
if let active, newValue != active.wrappedValue {
active.wrappedValue = newValue
}
}
storage.notify(name: "active-name") {
let newValue = String(cString: adw_toggle_group_get_active_name(storage.opaquePointer))
if let activeName, newValue != activeName.wrappedValue {
activeName.wrappedValue = newValue
}
}
storage.notify(name: "n-toggles") {
let newValue = UInt(adw_toggle_group_get_n_toggles(storage.opaquePointer))
if let nToggles, newValue != nToggles.wrappedValue {
nToggles.wrappedValue = newValue
}
}
if let active, updateProperties, (UInt(adw_toggle_group_get_active(storage.opaquePointer))) != active.wrappedValue {
adw_toggle_group_set_active(storage.opaquePointer, active.wrappedValue.cInt)
}
if let activeName, updateProperties, (String(cString: adw_toggle_group_get_active_name(storage.opaquePointer))) != activeName.wrappedValue {
adw_toggle_group_set_active_name(storage.opaquePointer, activeName.wrappedValue)
}
if let canShrink, updateProperties, (storage.previousState as? Self)?.canShrink != canShrink {
adw_toggle_group_set_can_shrink(widget, canShrink.cBool)
}
if let homogeneous, updateProperties, (storage.previousState as? Self)?.homogeneous != homogeneous {
adw_toggle_group_set_homogeneous(widget, homogeneous.cBool)
}
}
for function in updateFunctions {
function(storage, data, updateProperties)
}
if updateProperties {
storage.previousState = self
}
}
/// The index of the active toggle.
///
/// Setting the index to a larger value than the number of toggles in the group
/// unsets the current active toggle.
///
/// If no toggle is active, the property will be set to
/// `Gtk.INVALID_LIST_POSITION`.
public func active(_ active: Binding<UInt>?) -> Self {
modify { $0.active = active }
}
/// The name of the active toggle.
///
/// The name can be set via ``name(_:)``. If the currently active
/// toggle doesn't have a name, the property will be set to `NULL`.
///
/// Set it to `NULL` to unset the current active toggle.
public func activeName(_ activeName: Binding<String>?) -> Self {
modify { $0.activeName = activeName }
}
/// Whether the toggles can be smaller than the natural size of their contents.
///
/// If set to `true`, the toggle labels will ellipsize.
///
/// See ``canShrink(_:)``.
public func canShrink(_ canShrink: Bool? = true) -> Self {
modify { $0.canShrink = canShrink }
}
/// Whether all toggles take the same size.
public func homogeneous(_ homogeneous: Bool? = true) -> Self {
modify { $0.homogeneous = homogeneous }
}
/// The number of toggles within the group.
public func nToggles(_ nToggles: Binding<UInt>?) -> Self {
modify { $0.nToggles = nToggles }
}
}

View File

@ -1,322 +0,0 @@
//
// ToolbarView.swift
// Adwaita
//
// Created by auto-generation on 04.02.26.
//
import CAdw
import LevenshteinTransformations
/// A widget containing a page, as well as top and/or bottom bars.
///
///
///
/// `AdwToolbarView` has a single content widget and one or multiple top and
/// bottom bars, shown at the top and bottom sides respectively.
///
/// Example of an `AdwToolbarView` UI definition:
/// ```xml
/// <object class="AdwToolbarView"><child type="top"><object class="AdwHeaderBar"/></child><property name="content"><object class="AdwPreferencesPage"><!-- ... --></object></property></object>
/// ```
///
/// The following kinds of top and bottom bars are supported:
///
/// - `HeaderBar`
/// - `TabBar`
/// - `ViewSwitcherBar`
/// - `Gtk.ActionBar`
/// - `Gtk.HeaderBar`
/// - `Gtk.PopoverMenuBar`
/// - `Gtk.SearchBar`
/// - Any `Gtk.Box` or a similar widget with the
/// [`.toolbar`](style-classes.html
public struct ToolbarView: AdwaitaWidget {
#if exposeGeneratedAppearUpdateFunctions
/// Additional update functions for type extensions.
public var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
public var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#else
/// Additional update functions for type extensions.
var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#endif
/// The current bottom bar height.
///
/// Bottom bar height does change depending on
/// ``revealBottomBars(_:)``, including during the transition.
///
/// See ``topBarHeight(_:)``.
var bottomBarHeight: Int?
/// Appearance of the bottom bars.
///
/// If set to `ADW_TOOLBAR_FLAT`, bottom bars are flat and scrolling content
/// has a subtle undershoot shadow when touching them, same as the
/// [`.undershoot-bottom`](style-classes.html
var bottomBarStyle: ToolbarStyle?
/// The content widget.
var content: Body?
/// Whether the content widget can extend behind bottom bars.
///
/// This can be used in combination with
/// ``revealBottomBars(_:)`` to show and hide toolbars in
/// fullscreen.
///
/// See ``extendContentToTopEdge(_:)``.
var extendContentToBottomEdge: Bool?
/// Whether the content widget can extend behind top bars.
///
/// This can be used in combination with ``revealTopBars(_:)``
/// to show and hide toolbars in fullscreen.
///
/// See ``extendContentToBottomEdge(_:)``.
var extendContentToTopEdge: Bool?
/// Whether bottom bars are visible.
///
/// The transition will be animated.
///
/// This can be used in combination with
/// ``extendContentToBottomEdge(_:)`` to show and hide
/// toolbars in fullscreen.
///
/// See ``revealTopBars(_:)``.
var revealBottomBars: Bool?
/// Whether top bars are revealed.
///
/// The transition will be animated.
///
/// This can be used in combination with
/// ``extendContentToTopEdge(_:)`` to show and hide toolbars
/// in fullscreen.
///
/// See ``revealBottomBars(_:)``.
var revealTopBars: Bool?
/// The current top bar height.
///
/// Top bar height does change depending ``revealTopBars(_:)``,
/// including during the transition.
///
/// See ``bottomBarHeight(_:)``.
var topBarHeight: Int?
/// Appearance of the top bars.
///
/// If set to `ADW_TOOLBAR_FLAT`, top bars are flat and scrolling content has a
/// subtle undershoot shadow when touching them, same as the
/// [`.undershoot-top`](style-classes.html
var topBarStyle: ToolbarStyle?
/// The body for the widget "bottom".
var bottom: () -> Body = { [] }
/// The body for the widget "top".
var top: () -> Body = { [] }
/// Initialize `ToolbarView`.
public init() {
}
/// The view storage.
/// - Parameters:
/// - modifiers: Modify views before being updated.
/// - type: The view render data type.
/// - Returns: The view storage.
public func container<Data>(data: WidgetData, type: Data.Type) -> ViewStorage where Data: ViewRenderData {
let storage = ViewStorage(adw_toolbar_view_new()?.opaque())
for function in appearFunctions {
function(storage, data)
}
if let contentStorage = content?.storage(data: data, type: type) {
storage.content["content"] = [contentStorage]
adw_toolbar_view_set_content(storage.opaquePointer, contentStorage.opaquePointer?.cast())
}
var bottomStorage: [ViewStorage] = []
for view in bottom() {
bottomStorage.append(view.storage(data: data, type: type))
adw_toolbar_view_add_bottom_bar(storage.opaquePointer, bottomStorage.last?.opaquePointer?.cast())
}
storage.content["bottom"] = bottomStorage
var topStorage: [ViewStorage] = []
for view in top() {
topStorage.append(view.storage(data: data, type: type))
adw_toolbar_view_add_top_bar(storage.opaquePointer, topStorage.last?.opaquePointer?.cast())
}
storage.content["top"] = topStorage
return storage
}
/// Update the stored content.
/// - Parameters:
/// - storage: The storage to update.
/// - modifiers: Modify views before being updated
/// - updateProperties: Whether to update the view's properties.
/// - type: The view render data type.
public func update<Data>(_ storage: ViewStorage, data: WidgetData, updateProperties: Bool, type: Data.Type) where Data: ViewRenderData {
storage.modify { widget in
if let bottomBarStyle, updateProperties, (storage.previousState as? Self)?.bottomBarStyle != bottomBarStyle {
adw_toolbar_view_set_bottom_bar_style(widget, bottomBarStyle.gtkValue)
}
if let widget = storage.content["content"]?.first {
content?.updateStorage(widget, data: data, updateProperties: updateProperties, type: type)
}
if let extendContentToBottomEdge, updateProperties, (storage.previousState as? Self)?.extendContentToBottomEdge != extendContentToBottomEdge {
adw_toolbar_view_set_extend_content_to_bottom_edge(widget, extendContentToBottomEdge.cBool)
}
if let extendContentToTopEdge, updateProperties, (storage.previousState as? Self)?.extendContentToTopEdge != extendContentToTopEdge {
adw_toolbar_view_set_extend_content_to_top_edge(widget, extendContentToTopEdge.cBool)
}
if let revealBottomBars, updateProperties, (storage.previousState as? Self)?.revealBottomBars != revealBottomBars {
adw_toolbar_view_set_reveal_bottom_bars(widget, revealBottomBars.cBool)
}
if let revealTopBars, updateProperties, (storage.previousState as? Self)?.revealTopBars != revealTopBars {
adw_toolbar_view_set_reveal_top_bars(widget, revealTopBars.cBool)
}
if let topBarStyle, updateProperties, (storage.previousState as? Self)?.topBarStyle != topBarStyle {
adw_toolbar_view_set_top_bar_style(widget, topBarStyle.gtkValue)
}
if let bottomStorage = storage.content["bottom"] {
for (index, view) in bottom().enumerated() {
if let storage = bottomStorage[safe: index] {
view.updateStorage(
storage,
data: data,
updateProperties: updateProperties,
type: type
)
}
}
}
if let topStorage = storage.content["top"] {
for (index, view) in top().enumerated() {
if let storage = topStorage[safe: index] {
view.updateStorage(
storage,
data: data,
updateProperties: updateProperties,
type: type
)
}
}
}
}
for function in updateFunctions {
function(storage, data, updateProperties)
}
if updateProperties {
storage.previousState = self
}
}
/// The current bottom bar height.
///
/// Bottom bar height does change depending on
/// ``revealBottomBars(_:)``, including during the transition.
///
/// See ``topBarHeight(_:)``.
public func bottomBarHeight(_ bottomBarHeight: Int?) -> Self {
modify { $0.bottomBarHeight = bottomBarHeight }
}
/// Appearance of the bottom bars.
///
/// If set to `ADW_TOOLBAR_FLAT`, bottom bars are flat and scrolling content
/// has a subtle undershoot shadow when touching them, same as the
/// [`.undershoot-bottom`](style-classes.html
public func bottomBarStyle(_ bottomBarStyle: ToolbarStyle?) -> Self {
modify { $0.bottomBarStyle = bottomBarStyle }
}
/// The content widget.
public func content(@ViewBuilder _ content: () -> Body) -> Self {
modify { $0.content = content() }
}
/// Whether the content widget can extend behind bottom bars.
///
/// This can be used in combination with
/// ``revealBottomBars(_:)`` to show and hide toolbars in
/// fullscreen.
///
/// See ``extendContentToTopEdge(_:)``.
public func extendContentToBottomEdge(_ extendContentToBottomEdge: Bool? = true) -> Self {
modify { $0.extendContentToBottomEdge = extendContentToBottomEdge }
}
/// Whether the content widget can extend behind top bars.
///
/// This can be used in combination with ``revealTopBars(_:)``
/// to show and hide toolbars in fullscreen.
///
/// See ``extendContentToBottomEdge(_:)``.
public func extendContentToTopEdge(_ extendContentToTopEdge: Bool? = true) -> Self {
modify { $0.extendContentToTopEdge = extendContentToTopEdge }
}
/// Whether bottom bars are visible.
///
/// The transition will be animated.
///
/// This can be used in combination with
/// ``extendContentToBottomEdge(_:)`` to show and hide
/// toolbars in fullscreen.
///
/// See ``revealTopBars(_:)``.
public func revealBottomBars(_ revealBottomBars: Bool? = true) -> Self {
modify { $0.revealBottomBars = revealBottomBars }
}
/// Whether top bars are revealed.
///
/// The transition will be animated.
///
/// This can be used in combination with
/// ``extendContentToTopEdge(_:)`` to show and hide toolbars
/// in fullscreen.
///
/// See ``revealBottomBars(_:)``.
public func revealTopBars(_ revealTopBars: Bool? = true) -> Self {
modify { $0.revealTopBars = revealTopBars }
}
/// The current top bar height.
///
/// Top bar height does change depending ``revealTopBars(_:)``,
/// including during the transition.
///
/// See ``bottomBarHeight(_:)``.
public func topBarHeight(_ topBarHeight: Int?) -> Self {
modify { $0.topBarHeight = topBarHeight }
}
/// Appearance of the top bars.
///
/// If set to `ADW_TOOLBAR_FLAT`, top bars are flat and scrolling content has a
/// subtle undershoot shadow when touching them, same as the
/// [`.undershoot-top`](style-classes.html
public func topBarStyle(_ topBarStyle: ToolbarStyle?) -> Self {
modify { $0.topBarStyle = topBarStyle }
}
/// Set the body for "bottom".
/// - Parameter body: The body.
/// - Returns: The widget.
public func bottom(@ViewBuilder _ body: @escaping () -> Body) -> Self {
var newSelf = self
newSelf.bottom = body
return newSelf
}
/// Set the body for "top".
/// - Parameter body: The body.
/// - Returns: The widget.
public func top(@ViewBuilder _ body: @escaping () -> Body) -> Self {
var newSelf = self
newSelf.top = body
return newSelf
}
}

View File

@ -1,131 +0,0 @@
//
// SplitView.swift
// Adwaita
//
// Created by david-swift on 19.09.2025.
//
import CAdw
import Foundation
/// A split view.
struct SplitView: AdwaitaWidget {
/// The start widget.
@ViewProperty(
set: { widget, view in gtk_paned_set_start_child(.init(widget), view.cast()) },
pointer: OpaquePointer.self,
subview: OpaquePointer.self,
context: AdwaitaMainView.self
)
var start
/// The end widget.
@ViewProperty(
set: { widget, view in gtk_paned_set_end_child(.init(widget), view.cast()) },
pointer: OpaquePointer.self,
subview: OpaquePointer.self,
context: AdwaitaMainView.self
)
var end
/// Position of the splitter
@BindingProperty(
observe: { _, binding, storage in
storage.notify(name: "position") {
binding.wrappedValue = Int(gtk_paned_get_position(storage.opaquePointer))
}
},
set: { widget, value, _ in gtk_paned_set_position(widget, Int32(value)) },
pointer: OpaquePointer.self
)
var splitter: Binding<Int> = .constant(0)
/// Whether the split view is vertical.
var vertical: Bool
/// Initialize a split view.
/// - Parameters:
/// - splitter: The position of the splitter.
/// - vertical: Whether to make the splitter vertical.
/// - start: The start widget.
/// - end: The end widget.
init(
splitter: Binding<Int>,
vertical: Bool,
start: Body,
end: Body
) {
self.vertical = vertical
self.splitter = splitter
self.start = start
self.end = end
}
/// Initialize the widget.
func initializeWidget() -> Any {
gtk_paned_new(vertical ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL).opaque() as Any
}
}
/// A horizontal split view.
public struct HSplitView: SimpleView {
/// The splitter.
@Binding var splitter: Int
/// The start widget.
var start: Body
/// The end widget.
var end: Body
/// The view.
public var view: Body {
SplitView(splitter: $splitter, vertical: false, start: start, end: end)
}
/// Initialize a horizontal split view.
/// - Parameters:
/// - splitter: The position of the splitter.
/// - start: The start widget.
/// - end: The end widget.
public init(
splitter: Binding<Int>,
@ViewBuilder start: () -> Body,
@ViewBuilder end: () -> Body
) {
self._splitter = splitter
self.start = start()
self.end = end()
}
}
/// A vertical split view.
public struct VSplitView: SimpleView {
/// The splitter.
@Binding var splitter: Int
/// The start widget.
var start: Body
/// The end widget.
var end: Body
/// The view.
public var view: Body {
SplitView(splitter: $splitter, vertical: true, start: start, end: end)
}
/// Initialize a vertical split view.
/// - Parameters:
/// - splitter: The position of the splitter.
/// - start: The start widget.
/// - end: The end widget.
public init(
splitter: Binding<Int>,
@ViewBuilder start: () -> Body,
@ViewBuilder end: () -> Body
) {
self._splitter = splitter
self.start = start()
self.end = end()
}
}

View File

@ -1,19 +0,0 @@
//
// Symbol.swift
// Adwaita
//
// Created by Marquis Kurt on 23.10.25.
//
/// A view that display a symbolic image.
public typealias Symbol = Image
extension Symbol {
/// Initialize a symbolic image view.
/// - Parameter icon: The icon to display in the view.
public init(icon: Icon) {
self.init()
self.iconName = icon.string
}
}

View File

@ -1,136 +0,0 @@
//
// ToggleGroup+.swift
// Adwaita
//
// Created by david-swift on 03.11.25.
//
import CAdw
import LevenshteinTransformations
extension ToggleGroup {
/// The identifier for the values.
static var values: String { "values" }
/// The identifier for the toggles.
static var toggle: String { "Toggle::" }
/// Initialize a toggle group.
/// - Parameters:
/// - selection: The selected value.
/// - values: The available values.
public init<Element>(
selection: Binding<Element.ID>,
values: [Element]
) where Element: ToggleGroupItem {
self.init(
selection: selection,
values: values,
id: \.id,
label: \.id.description,
icon: \.icon,
showLabel: \.showLabel
)
}
/// Initialize a toggle group.
/// - Parameters:
/// - selection: The selected value.
/// - values: The available values.
/// - id: The path to the identifier.
/// - label: The path to the label.
/// - icon: The path to the icon.
/// - showLabel: The path to the boolean that defines whether to show an element's label.
public init<Element, Identifier>(
selection: Binding<Identifier>,
values: [Element],
id: KeyPath<Element, Identifier>,
label: KeyPath<Element, String>,
icon: KeyPath<Element, Icon?>? = nil,
showLabel: KeyPath<Element, Bool>? = nil
) where Identifier: Equatable {
self.init()
appearFunctions.append { storage, _ in
storage.notify(name: "active-name", id: "init") {
if let name = adw_toggle_group_get_active_name(storage.opaquePointer),
let values = storage.fields[Self.values] as? [Element],
let identifier = values
.map({ $0[keyPath: label] }).first(where: { $0.description == String(cString: name) }),
let value = values.first(where: { $0[keyPath: label] == identifier }) {
selection.wrappedValue = value[keyPath: id]
}
}
}
updateFunctions.append { storage, _, updateProperties in
Self.updateContent(
storage: storage,
selection: selection.wrappedValue,
values: values,
id: id,
label: label,
icon: icon,
showLabel: showLabel,
updateProperties: updateProperties
)
}
}
// swiftlint:disable function_parameter_count
/// Update the combo row's content.
static func updateContent<Element, Identifier>(
storage: ViewStorage,
selection: Identifier,
values: [Element],
id: KeyPath<Element, Identifier>,
label: KeyPath<Element, String>,
icon: KeyPath<Element, Icon?>?,
showLabel: KeyPath<Element, Bool>?,
updateProperties: Bool
) where Identifier: Equatable {
guard updateProperties else {
return
}
let old = storage.fields[Self.values] as? [Element] ?? []
old.transform(
to: values,
id: id,
functions: .init { index in
if let id = old[safe: index]?[keyPath: label],
let toggle = storage.fields[Self.toggle + id] as? OpaquePointer {
adw_toggle_group_remove(storage.opaquePointer, toggle)
}
} insert: { _, element in
let toggle = adw_toggle_new()
adw_toggle_set_name(toggle, element[keyPath: label])
if let showLabel, !element[keyPath: showLabel] {
adw_toggle_set_tooltip(toggle, element[keyPath: label])
} else {
adw_toggle_set_label(toggle, element[keyPath: label])
}
if let icon, let icon = element[keyPath: icon] {
adw_toggle_set_icon_name(toggle, icon.string)
}
storage.fields[Self.toggle + element[keyPath: label]] = toggle
adw_toggle_group_add(storage.opaquePointer, toggle)
}
)
storage.fields[Self.values] = values
if let selection = values.first(where: { $0[keyPath: id] == selection }) {
adw_toggle_group_set_active_name(storage.opaquePointer, selection[keyPath: label])
}
}
// swiftlint:enable function_parameter_count
}
/// An item of a toggle group.
public protocol ToggleGroupItem: Identifiable where Self.ID: CustomStringConvertible {
/// The item's icon.
var icon: Icon? { get }
/// Whether to show the label in the UI (the identifier's string conversion).
///
/// Otherwise, it will be used as the tooltip.
var showLabel: Bool { get }
}

View File

@ -1,133 +0,0 @@
//
// Window+.swift
// Adwaita
//
// Created by david-swift on 30.10.25.
//
extension Window {
/// Add a keyboard shortcut.
/// - Parameters:
/// - shortcut: The keyboard shortcut.
/// - action: The closure to execute when the keyboard shortcut is pressed.
/// - Returns: The window.
public func keyboardShortcut(_ shortcut: String, action: @escaping (AdwaitaWindow) -> Void) -> Self {
var newSelf = self
newSelf.shortcuts[shortcut] = action
return newSelf
}
/// Add the shortcut "<Ctrl>w" which closes the window.
/// - Returns: The window.
public func closeShortcut() -> Self {
keyboardShortcut("w".ctrl()) { $0.close() }
}
/// Add a keyboard shortcut for the whole application.
/// - Parameters:
/// - shortcut: The keyboard shortcut.
/// - action: The closure to execute when the keyboard shortcut is pressed.
/// - Returns: The window.
public func appKeyboardShortcut(_ shortcut: String, action: @escaping (AdwaitaApp) -> Void) -> Self {
var newSelf = self
newSelf.appShortcuts[shortcut] = action
return newSelf
}
/// Add the shortcut "<Ctrl>q" which quits the application.
/// - Returns: The window.
public func quitShortcut() -> Self {
appKeyboardShortcut("q".ctrl()) { $0.quit() }
}
/// Set the window's default size.
/// - Parameters:
/// - width: The window's width.
/// - height: The window's height.
/// - Returns: The window.
public func defaultSize(width: Int? = nil, height: Int? = nil) -> Self {
var newSelf = self
newSelf.defaultWidth = width
newSelf.defaultHeight = height
return newSelf
}
/// Set the window's title.
/// - Parameter title: The title.
/// - Returns: The window.
public func title(_ title: String?) -> Self {
var newSelf = self
newSelf.title = title
return newSelf
}
/// Set whether the window is resizable.
/// - Parameter resizable: The resizability.
/// - Returns: The window.
public func resizable(_ resizable: Bool?) -> Self {
var newSelf = self
newSelf.resizable = resizable
return newSelf
}
/// Set whether the window is deletable.
/// - Parameter resizable: The deletability.
/// - Returns: The window.
public func deletable(_ deletable: Bool?) -> Self {
var newSelf = self
newSelf.deletable = deletable
return newSelf
}
/// Get the window's width and height.
/// - Parameters:
/// - width: The window's actual width.
/// - height: The window's actual height.
/// - Returns: The window.
public func size(width: Binding<Int>? = nil, height: Binding<Int>? = nil) -> Self {
var newSelf = self
newSelf.width = width
newSelf.height = height
return newSelf
}
/// Set the window's minimum width and height.
/// - Parameters:
/// - minWidth: The window's minimum width.
/// - minHeight: The window's minimum height.
public func minSize(width: Int = -1, height: Int = -1) -> Self {
var newSelf = self
newSelf.minWidth = width
newSelf.minHeight = height
return newSelf
}
/// Get and set whether the window is maximized.
/// - Parameter maximized: Whether the window is maximized.
/// - Returns: The window.
public func maximized(_ maximized: Binding<Bool>?) -> Self {
var newSelf = self
newSelf.maximized = maximized
return newSelf
}
/// Whether the window used the development style.
/// - Parameter active: Whether the style is active.
/// - Returns: The window.
public func devel(_ active: Bool? = true) -> Self {
var newSelf = self
newSelf.devel = active
return newSelf
}
/// Run this closure when the window should be closed.
/// - Parameter onClose: The closure.
/// - Returns: The window.
public func onClose(onClose: @escaping () -> CloseConfirmation) -> Self {
var newSelf = self
newSelf.onClose = onClose
return newSelf
}
}

View File

@ -44,26 +44,6 @@ gtui_filedialog_open (uint64_t dialog, uint64_t data, uint64_t window)
gtk_file_dialog_open (dialog, window, NULL, G_CALLBACK (gtui_filedialog_open_finish), (void *)data);
}
static void
gtui_filedialog_open_folder_finish (uint64_t dialog, uint64_t result, uint64_t data)
{
GFile *file = gtk_file_dialog_select_folder_finish (dialog, result, NULL);
if (file != NULL) {
const char *path = g_file_peek_path (file);
g_object_unref (file);
filedialog_on_open_cb (dialog, path, data);
} else {
filedialog_on_open_cb (dialog, NULL, data);
}
}
static void
gtui_filedialog_open_folder (uint64_t dialog, uint64_t data, uint64_t window)
{
swift_retain (data);
gtk_file_dialog_select_folder (dialog, window, NULL, G_CALLBACK (gtui_filedialog_open_folder_finish), (void *)data);
}
static void
gtui_alertdialog_cb (uint64_t dialog, uint64_t result, uint64_t data)
{
@ -85,13 +65,3 @@ gtui_initialize_boolean (gboolean boolean)
g_value_set_boolean(&val, boolean);
return val;
}
static void
gtui_cssprovider_set_prefers_color_scheme (uint64_t provider, GtkInterfaceColorScheme scheme)
{
GValue val = G_VALUE_INIT;
g_value_init(&val, G_TYPE_ENUM);
g_value_set_enum(&val, scheme);
g_object_set_property(provider, "prefers-color-scheme", &val);
g_value_unset(&val);
}

View File

@ -33,7 +33,7 @@ public class AdwaitaApp: AppStorage {
/// - Parameter id: The identifier.
public required init(id: String) {
pointer = adw_application_new(id, G_APPLICATION_DEFAULT_FLAGS)?.cast()
DatabaseInformation.setPath(Self.userDataDir().appendingPathComponent("\(id).sqlite").path)
DatabaseInformation.setPath(Self.userDataDir().appendingPathComponent("data.sqlite").path)
}
/// Copy a string to the clipboard.

View File

@ -21,7 +21,7 @@ public enum WrapMode: GtkWrapMode, RawRepresentable {
/// GTK_WRAP_WORD_CHAR
case wordChar
/// Get the GtkWrapMode.
/// Get the GtkWrapMode.
public var rawValue: GtkWrapMode {
switch self {
case .none:
@ -38,17 +38,17 @@ public enum WrapMode: GtkWrapMode, RawRepresentable {
/// Initialize from the GtkWrapMode.
/// - Parameter rawValue: The GtkWrapMode.
public init?(rawValue: GtkWrapMode) {
switch rawValue {
case GTK_WRAP_NONE:
self = .none
case GTK_WRAP_CHAR:
self = .char
case GTK_WRAP_WORD:
self = .word
case GTK_WRAP_WORD_CHAR:
self = .wordChar
default:
return nil
}
switch rawValue {
case GTK_WRAP_NONE:
self = .none
case GTK_WRAP_CHAR:
self = .char
case GTK_WRAP_WORD:
self = .word
case GTK_WRAP_WORD_CHAR:
self = .wordChar
default:
return nil
}
}
}

View File

@ -11,7 +11,7 @@ import CAdw
public class SignalData {
/// The closure.
public var closure: ([Any?]) -> Any?
public var closure: ([Any?]) -> Void
/// Destroy the class.
public var selfDestruction: (() -> Void)?
@ -19,7 +19,7 @@ public class SignalData {
var handler: @convention(c) (UnsafeMutableRawPointer, UnsafeMutableRawPointer) -> Void {
{ _, data in
let data = unsafeBitCast(data, to: SignalData.self)
_ = data.closure([])
data.closure([])
}
}
@ -31,7 +31,7 @@ public class SignalData {
) -> Void {
{ _, arg1, data in
let data = unsafeBitCast(data, to: SignalData.self)
_ = data.closure([arg1])
data.closure([arg1])
}
}
@ -44,7 +44,7 @@ public class SignalData {
) -> Void {
{ _, arg1, arg2, data in
let data = unsafeBitCast(data, to: SignalData.self)
_ = data.closure([arg1, arg2])
data.closure([arg1, arg2])
}
}
@ -58,70 +58,35 @@ public class SignalData {
) -> Void {
{ _, arg1, arg2, arg3, data in
let data = unsafeBitCast(data, to: SignalData.self)
_ = data.closure([arg1, arg2, arg3])
data.closure([arg1, arg2, arg3])
}
}
/// The closure as a C handler with a return value.
var boolHandler: @convention(c) (UnsafeMutableRawPointer, UnsafeMutableRawPointer) -> Bool {
{ _, data in
let data = unsafeBitCast(data, to: SignalData.self)
return data.closure([]) as? Bool ?? false
}
}
/// Initialize the signal data.
/// - Parameters:
/// - closure: The signal's closure.
/// - destroy: The self destruction.
public convenience init(closure: @escaping () -> Any?, destroy: (() -> Void)? = nil) {
self.init(closure: { _ in closure() }, destroy: destroy)
}
/// Initialize the signal data.
/// - Parameters:
/// - closure: The signal's closure.
/// - destroy: The self destruction.
public convenience init(closure: @escaping () -> Void, destroy: (() -> Void)? = nil) {
self.init(closure: { _ in closure(); return nil }, destroy: destroy)
self.init(closure: { _ in closure() }, destroy: destroy)
}
/// Initialize the signal data.
/// - Parameters:
/// - closure: The signal's closure.
/// - destroy: The self destruction.
public init(closure: @escaping ([Any]) -> Any?, destroy: (() -> Void)? = nil) {
public init(closure: @escaping ([Any]) -> Void, destroy: (() -> Void)? = nil) {
self.closure = closure
self.selfDestruction = destroy
}
/// The return type.
public enum ReturnType {
/// Returns a boolean.
case bool
}
/// Connect the signal data to a signal.
/// - Parameters:
/// - pointer: The pointer to the object which holds the signal.
/// - signal: The signal's name.
/// - argCount: The number of arguments.
/// - return: The return type.
public func connect(
pointer: UnsafeMutableRawPointer?,
signal: String,
argCount: Int = 0,
return: ReturnType? = nil
) {
public func connect(pointer: UnsafeMutableRawPointer?, signal: String, argCount: Int = 0) {
let callback: GCallback
if let `return` {
switch `return` {
case .bool:
callback = unsafeBitCast(boolHandler, to: GCallback.self)
}
} else if argCount >= 3 {
if argCount >= 3 {
callback = unsafeBitCast(fiveParamsHandler, to: GCallback.self)
} else if argCount == 2 {
callback = unsafeBitCast(fourParamsHandler, to: GCallback.self)

View File

@ -48,30 +48,7 @@ extension Storage {
pointer: OpaquePointer? = nil,
handler: @escaping () -> Void
) {
connectSignal(name: name, id: id, argCount: argCount, pointer: pointer) {
handler()
return nil
}
}
/// Connect a handler to a signal.
/// - Parameters:
/// - name: The signal's name.
/// - id: The handlers id to separate form others connecting to the signal.
/// - connectFlags: The GConnectFlags.
/// - argCount: The number of additional arguments (without the first and the last one).
/// - return: The return type.
/// - pointer: A custom pointer instead of the stored one.
/// - handler: The signal's handler.
public func connectSignal(
name: String,
id: String = "",
argCount: Int = 0,
return: SignalData.ReturnType? = nil,
pointer: OpaquePointer? = nil,
handler: @escaping () -> Any?
) {
connectSignal(name: name, id: id, argCount: argCount, return: `return`, pointer: pointer) { _ in
connectSignal(name: name, id: id, argCount: argCount, pointer: pointer) { _ in
handler()
}
}
@ -89,42 +66,13 @@ extension Storage {
argCount: Int = 0,
pointer: OpaquePointer? = nil,
handler: @escaping ([Any]) -> Void
) {
connectSignal(name: name, id: id, argCount: argCount, pointer: pointer) { args in
handler(args)
return nil
}
}
/// Connect a handler to a signal.
/// - Parameters:
/// - name: The signal's name.
/// - id: The handlers id to separate form others connecting to the signal.
/// - argCount: The number of additional arguments (without the first and the last one).
/// - return: The return type.
/// - pointer: A custom pointer instead of the stored one.
/// - handler: The signal's handler.
public func connectSignal(
name: String,
id: String = "",
argCount: Int = 0,
return: SignalData.ReturnType? = nil,
pointer: OpaquePointer? = nil,
handler: @escaping ([Any]) -> Any?
) {
if let data = fields[name + id] as? SignalData {
data.closure = handler
} else {
let data = SignalData(closure: handler) { [self] in fields[name + id] = nil }
fields[name + id] = data
data.connect(
pointer: (
pointer ?? opaquePointer ?? ((self as? SceneStorage)?.pointer as? AdwaitaWindow)?.pointer?.opaque()
)?.cast(),
signal: name,
argCount: argCount,
return: `return`
)
data.connect(pointer: (pointer ?? opaquePointer)?.cast(), signal: name, argCount: argCount)
}
}

View File

@ -45,11 +45,8 @@ extension Button {
/// - window: The application window.
/// - active: Whether the keyboard shortcut is active.
/// - Returns: The button.
public func keyboardShortcut(_ shortcut: String, active: Bool = true) -> AnyView {
inspect { _, data, _ in
guard let window = data.sceneStorage.pointer as? AdwaitaWindow else {
return
}
public func keyboardShortcut(_ shortcut: String, window: AdwaitaWindow, active: Bool = true) -> AnyView {
onUpdate {
if active {
window.app.addKeyboardShortcut(shortcut, id: shortcut, window: window) { self.clicked?() }
} else {
@ -66,15 +63,12 @@ extension Button {
/// - window: The application.
/// - active: Whether the keyboard shortcut is active.
/// - Returns: The button.
public func appKeyboardShortcut(_ shortcut: String, active: Bool = true) -> AnyView {
inspect { _, data, _ in
guard let window = data.sceneStorage.pointer as? AdwaitaWindow else {
return
}
public func keyboardShortcut(_ shortcut: String, app: AdwaitaApp, active: Bool = true) -> AnyView {
onUpdate {
if active {
window.app.addKeyboardShortcut(shortcut, id: shortcut) { self.clicked?() }
app.addKeyboardShortcut(shortcut, id: shortcut) { self.clicked?() }
} else {
window.app.removeKeyboardShortcut(id: shortcut)
app.removeKeyboardShortcut(id: shortcut)
}
}
}

View File

@ -9,7 +9,7 @@ import CAdw
import Foundation
/// The about dialog widget.
struct AboutDialog: AdwaitaWidget {
public struct AboutDialog: AdwaitaWidget {
/// Whether the dialog is visible.
@Binding var visible: Bool
@ -42,7 +42,7 @@ struct AboutDialog: AdwaitaWidget {
/// - icon: The icon.
/// - website: The website's URL.
/// - issues: The link for opening issues.
init(
public init(
visible: Binding<Bool>,
child: AnyView,
appName: String? = nil,
@ -67,8 +67,10 @@ struct AboutDialog: AdwaitaWidget {
/// - modifiers: Modify views before being updated.
/// - type: The view render data type.
/// - Returns: The view storage.
func container<Data>(data: WidgetData, type: Data.Type) -> ViewStorage where Data: ViewRenderData {
child.storage(data: data, type: type)
public func container<Data>(data: WidgetData, type: Data.Type) -> ViewStorage where Data: ViewRenderData {
let storage = child.storage(data: data, type: type)
update(storage, data: data, updateProperties: true, type: type)
return storage
}
/// Update the stored content.
@ -77,7 +79,7 @@ struct AboutDialog: AdwaitaWidget {
/// - modifiers: Modify views before being updated
/// - updateProperties: Whether to update the view's properties.
/// - type: The view render data type.
func update<Data>(
public func update<Data>(
_ storage: ViewStorage,
data: WidgetData,
updateProperties: Bool,

View File

@ -43,7 +43,7 @@ public struct AlertDialog: AdwaitaWidget {
/// - heading: The heading.
/// - body: The body text.
/// - extraChild: The body view.
init(
public init(
visible: Binding<Bool>,
child: AnyView,
id: String,
@ -106,7 +106,9 @@ public struct AlertDialog: AdwaitaWidget {
data: WidgetData,
type: Data.Type
) -> ViewStorage where Data: ViewRenderData {
child.storage(data: data, type: type)
let storage = child.storage(data: data, type: type)
update(storage, data: data, updateProperties: true, type: type)
return storage
}
/// Update the stored content.
@ -215,7 +217,6 @@ public struct AlertDialog: AdwaitaWidget {
storage.content[Self.dialogID + id] = [dialog]
if let extraChild {
let child = extraChild.storage(data: data, type: AdwaitaMainView.self)
extraChild.updateStorage(child, data: data, updateProperties: true, type: AdwaitaMainView.self)
let childPointer = child.pointer as? OpaquePointer
storage.content["extra-child"] = [child]
adw_alert_dialog_set_extra_child(pointer?.cast(), childPointer?.cast())

View File

@ -8,7 +8,7 @@
import CAdw
/// The dialog widget.
struct Dialog: AdwaitaWidget {
public struct Dialog: AdwaitaWidget {
/// Whether the dialog is visible.
@Binding var visible: Bool
@ -39,7 +39,7 @@ struct Dialog: AdwaitaWidget {
/// - title: The title.
/// - width: The width.
/// - height: The height.
init(
public init(
visible: Binding<Bool>,
child: AnyView,
id: String,
@ -62,9 +62,11 @@ struct Dialog: AdwaitaWidget {
/// - modifiers: Modify views before being updated.
/// - type: The view render data type.
/// - Returns: The view storage.
func container<Data>(data: WidgetData, type: Data.Type) -> ViewStorage where Data: ViewRenderData {
public func container<Data>(data: WidgetData, type: Data.Type) -> ViewStorage where Data: ViewRenderData {
let child = child.storage(data: data, type: type)
return .init(child.opaquePointer, content: [.mainContent: [child]])
let storage = ViewStorage(child.opaquePointer, content: [.mainContent: [child]])
update(storage, data: data, updateProperties: true, type: type)
return storage
}
/// Update the stored content.
@ -73,7 +75,7 @@ struct Dialog: AdwaitaWidget {
/// - modifiers: Modify views before being updated
/// - updateProperties: Whether to update the view's properties.
/// - type: The view render data type.
func update<Data>(
public func update<Data>(
_ storage: ViewStorage,
data: WidgetData,
updateProperties: Bool,
@ -130,7 +132,6 @@ struct Dialog: AdwaitaWidget {
let dialog = ViewStorage(pointer?.opaque())
storage.content[dialogID + id] = [dialog]
let contentStorage = content.storage(data: data, type: type)
content.updateStorage(contentStorage, data: data, updateProperties: true, type: type)
adw_dialog_set_child(pointer, contentStorage.opaquePointer?.cast())
storage.content[contentID + id] = [contentStorage]
dialog.connectSignal(name: "closed") {

View File

@ -9,103 +9,67 @@ import CAdw
import Foundation
/// A structure representing a file dialog window.
struct FileDialog: AdwaitaWidget {
public struct FileDialog: AdwaitaWidget {
/// The dialog type.
var type: DialogType
/// Whether the dialog is an importer.
var importer: Bool
/// Whether the dialog should open.
var open: Signal
/// The dialog's child.
var child: AnyView
/// The initial folder.
var initialFolder: URL?
/// The initial file name for the file exporter.
var initialName: String?
/// The accepted extensions for the file importer.
var extensions: [String]?
/// The closure to run when the import or export is successful.
var result: (URL) -> Void
/// The closure to run when the import or export is not successful.
var cancel: () -> Void
// swiftlint:disable function_default_parameter_at_end
/// Initialize the file dialog wrapper.
/// - Parameters:
/// - type: The dialog type.
/// - importer: Whether it is an importer.
/// - open: The signal.
/// - child: The wrapped view.
/// - initialFolder: The initial URL.
/// - initialName: The initial name.
/// - extensions: The file extensions.
/// - result: Run when the import or export succeeds.
/// - cancel: Run when the import or export is not successful.
/// - initialFolder: The initial folder.
init(
type: DialogType,
public init(
importer: Bool = true,
`open`: Signal,
child: AnyView,
result: @escaping (URL) -> Void,
cancel: @escaping () -> Void,
initialFolder: URL? = nil,
initialName: String? = nil,
extensions: [String]? = nil
) {
self.type = type
self.importer = importer
self.open = open
self.child = child
self.result = result
self.cancel = cancel
self.initialFolder = initialFolder
self.initialName = initialName
self.extensions = extensions
}
/// The different types of dialogs and their properties.
enum DialogType {
/// An importer dialog.
case importer(folder: Bool, extensions: [String]?)
/// An exporter dialog.
case exporter(initialName: String?)
/// Whether the dialog is an importer.
var isImporter: Bool {
switch self {
case .importer:
true
default:
false
}
}
/// The supported extensions.
var extensions: [String]? {
switch self {
case let .importer(folder: _, extensions: extensions):
extensions
default:
nil
}
}
/// Whether to import folders.
var folder: Bool {
switch self {
case let .importer(folder: folder, extensions: _):
folder
default:
false
}
}
/// The initial name.
var initialName: String? {
switch self {
case let .exporter(initialName: initialName):
initialName
default:
nil
}
}
}
// swiftlint:enable function_default_parameter_at_end
/// The view storage.
/// - Parameters:
/// - modifiers: Modify views before being updated.
/// - type: The view render data type.
/// - Returns: The view storage.
func container<Data>(data: WidgetData, type: Data.Type) -> ViewStorage where Data: ViewRenderData {
public func container<Data>(data: WidgetData, type: Data.Type) -> ViewStorage where Data: ViewRenderData {
let child = child.storage(data: data, type: type)
return .init(child.opaquePointer, content: [.mainContent: [child]])
let storage = ViewStorage(child.opaquePointer, content: [.mainContent: [child]])
update(storage, data: data, updateProperties: true, type: type)
return storage
}
/// Update the stored content.
@ -114,7 +78,7 @@ struct FileDialog: AdwaitaWidget {
/// - modifiers: Modify views before being updated
/// - updateProperties: Whether to update the view's properties.
/// - type: The view render data type.
func update<Data>(
public func update<Data>(
_ storage: ViewStorage,
data: WidgetData,
updateProperties: Bool,
@ -130,10 +94,10 @@ struct FileDialog: AdwaitaWidget {
var unref: [OpaquePointer?] = []
let pointer = gtk_file_dialog_new()
unref.append(pointer)
if let initialName = self.type.initialName {
if let initialName {
gtk_file_dialog_set_initial_name(pointer, initialName)
}
if let extensions = self.type.extensions {
if let extensions {
let filter = gtk_file_filter_new()
for name in extensions {
gtk_file_filter_add_suffix(filter, name)
@ -161,9 +125,7 @@ struct FileDialog: AdwaitaWidget {
storage.fields["callbacks"] = callbacks
let ptr = UInt64(Int(bitPattern: pointer))
let window = UInt64(Int(bitPattern: gtk_widget_get_root(mainStorage.opaquePointer?.cast())))
if self.type.isImporter && self.type.folder {
gtui_filedialog_open_folder(ptr, unsafeBitCast(callbacks, to: UInt64.self), window)
} else if self.type.isImporter {
if importer {
gtui_filedialog_open(ptr, unsafeBitCast(callbacks, to: UInt64.self), window)
} else {
gtui_filedialog_save(ptr, unsafeBitCast(callbacks, to: UInt64.self), window)

View File

@ -29,7 +29,7 @@ public struct PreferencesDialog: AdwaitaWidget {
/// - visible: Whether the dialog is visible.
/// - child: The wrapped view.
/// - id: An unique identifier for dialogs on the view.
init(
public init(
visible: Binding<Bool>,
child: AnyView,
id: String
@ -53,7 +53,7 @@ public struct PreferencesDialog: AdwaitaWidget {
/// - Parameters:
/// - title: The page title.
/// - icon: The page's icon.
init(_ title: String, icon: Icon) {
public init(_ title: String, icon: Icon) {
self.title = title
self.icon = icon
}
@ -62,18 +62,15 @@ public struct PreferencesDialog: AdwaitaWidget {
/// - Parameter data: The widget data.
/// - Returns: The preferences page pointer and the groups view storages.
func gtkPreferencesPage(data: WidgetData) -> (OpaquePointer?, [ViewStorage]) {
let page = Adwaita.PreferencesPage()
let page = Core.PreferencesPage()
.title(title)
.iconName(icon.string)
let pageStorage = page.storage(data: data.noModifiers, type: AdwaitaMainView.self)
page.update(pageStorage, data: data, updateProperties: true, type: AdwaitaMainView.self)
let groups = content.map { item in
let storage = item.gtkPreferencesGroup(data: data)
item.update(group: storage, data: data, updateProperties: true)
adw_preferences_page_add(pageStorage.opaquePointer?.cast(), storage.opaquePointer?.cast())
return storage
.storage(data: data.noModifiers, type: AdwaitaMainView.self)
let groups = content.map { $0.gtkPreferencesGroup(data: data) }
for group in groups {
adw_preferences_page_add(page.opaquePointer?.cast(), group.opaquePointer?.cast())
}
return (pageStorage.opaquePointer, groups)
return (page.opaquePointer, groups)
}
/// Update the page.
@ -123,7 +120,7 @@ public struct PreferencesDialog: AdwaitaWidget {
/// Get the GTk preferences group.
/// - Parameter data: The widget data.
/// - Returns: The preferences group.
func group(data: WidgetData) -> Adwaita.PreferencesGroup {
func group(data: WidgetData) -> Core.PreferencesGroup {
.init()
.title(title)
.description(description)
@ -156,7 +153,9 @@ public struct PreferencesDialog: AdwaitaWidget {
/// - Returns: The view storage.
public func container<Data>(data: WidgetData, type: Data.Type) -> ViewStorage where Data: ViewRenderData {
let child = child.storage(data: data, type: type)
return .init(child.opaquePointer, content: [.mainContent: [child]])
let storage = ViewStorage(child.opaquePointer, content: [.mainContent: [child]])
update(storage, data: data, updateProperties: true, type: type)
return storage
}
/// Update the stored content.
@ -175,11 +174,9 @@ public struct PreferencesDialog: AdwaitaWidget {
child.updateStorage(storage, data: data, updateProperties: updateProperties, type: type)
}
defer {
if visible {
for (index, page) in pages.enumerated() {
if let preferences = storage.content["preferences-\(index)"] {
page.update(groups: preferences, data: data, updateProperties: updateProperties)
}
for (index, page) in pages.enumerated() {
if let preferences = storage.content["preferences-\(index)"] {
page.update(groups: preferences, data: data, updateProperties: updateProperties)
}
}
}

View File

@ -17,40 +17,27 @@ extension DropDown {
/// Initialize a combo row.
/// - Parameters:
/// - title: The row's title.
/// - selection: The selected value.
/// - values: The available values.
public init<Element>(
selection: Binding<Element.ID>,
values: [Element]
) where Element: Identifiable, Element: CustomStringConvertible {
self.init(selection: selection, values: values, id: \.id, description: \.description)
}
/// Initialize a combo row.
/// - Parameters:
/// - title: The row's title.
/// - selection: The selected value.
/// - values: The available values.
public init<Element, Identifier>(
selection: Binding<Identifier>,
values: [Element],
id: KeyPath<Element, Identifier>,
description: KeyPath<Element, String>
) where Identifier: Equatable {
self.init()
self = self.selected(.init {
.init(values.firstIndex { $0[keyPath: id] == selection.wrappedValue } ?? 0)
.init(values.firstIndex { $0.id == selection.wrappedValue } ?? 0)
} set: { index in
if let id = values[safe: .init(index)]?[keyPath: id] {
if let id = values[safe: .init(index)]?.id {
selection.wrappedValue = id
}
})
appearFunctions.append { storage, _ in
storage.fields[Self.stringList] = gtk_drop_down_get_model(storage.opaquePointer)
Self.updateContent(storage: storage, values: values, id: id, description: description)
Self.updateContent(storage: storage, values: values, element: Element.self)
}
updateFunctions.append { storage, _, _ in
Self.updateContent(storage: storage, values: values, id: id, description: description)
Self.updateContent(storage: storage, values: values, element: Element.self)
}
}
@ -58,23 +45,20 @@ extension DropDown {
/// - Parameters:
/// - storage: The view storage.
/// - values: The elements.
/// - id: The keypath to the id.
/// - description: The keypath to the description.
static func updateContent<Element, Identifier>(
/// - element: The type of the elements.
static func updateContent<Element>(
storage: ViewStorage,
values: [Element],
id: KeyPath<Element, Identifier>,
description: KeyPath<Element, String>
) where Identifier: Equatable {
element: Element.Type
) where Element: Identifiable, Element: CustomStringConvertible {
if let list = storage.fields[Self.stringList] as? OpaquePointer {
let old = storage.fields[Self.values] as? [Element] ?? []
old.transform(
old.identifiableTransform(
to: values,
id: id,
functions: .init { index in
gtk_string_list_remove(list, .init(index))
} insert: { _, element in
gtk_string_list_append(list, element[keyPath: description])
gtk_string_list_append(list, element.description)
}
)
storage.fields[Self.values] = values

View File

@ -17,21 +17,19 @@ extension FlowBox {
/// Initialize `FlowBox`.
/// - Parameters:
/// - elements: The elements.
/// - id: The element identifier keypath.
/// - selection: The identifier of the selected element. Selection disabled if `nil`.
/// - content: The view for an element.
public init(
_ elements: [Element],
id: KeyPath<Element, Identifier>,
selection: Binding<Identifier>? = nil,
selection: Binding<Element.ID>?,
@ViewBuilder content: @escaping (Element) -> Body
) {
self.init(elements, id: id, content: content)
let getID: (ViewStorage, [Element]) -> Identifier? = { storage, elements in
self.init(elements, content: content)
let id: (ViewStorage, [Element]) -> Element.ID? = { storage, elements in
if let child = g_list_nth_data(gtk_flow_box_get_selected_children(storage.opaquePointer), 0) {
let element = gtk_flow_box_child_get_child(child.cast())
return elements[safe: storage.content[.mainContent]?
.firstIndex { $0.opaquePointer?.cast() == element }]?[keyPath: id]
.firstIndex { $0.opaquePointer?.cast() == element }]?.id
}
return nil
}
@ -39,12 +37,12 @@ extension FlowBox {
updateFunctions.append { storage, _, _ in
storage.connectSignal(name: "selected_children_changed", id: Self.selectionField) {
if let elements = storage.fields[Self.elementsField] as? [Element],
let id = getID(storage, elements) {
let id = id(storage, elements) {
selection.wrappedValue = id
}
}
if selection.wrappedValue != getID(storage, elements),
let index = elements.firstIndex(where: { $0[keyPath: id] == selection.wrappedValue })?.cInt {
if selection.wrappedValue != id(storage, elements),
let index = elements.firstIndex(where: { $0.id == selection.wrappedValue })?.cInt {
gtk_flow_box_select_child(
storage.opaquePointer,
gtk_flow_box_get_child_at_index(storage.opaquePointer, index)
@ -59,20 +57,3 @@ extension FlowBox {
}
}
extension FlowBox where Element: Identifiable, Identifier == Element.ID {
/// Initialize `FlowBox`.
/// - Parameters:
/// - elements: The elements.
/// - selection: The identifier of the selected element. Selection disabled if `nil`.
/// - content: The view for an element.
public init(
_ elements: [Element],
selection: Binding<Element.ID>? = nil,
@ViewBuilder content: @escaping (Element) -> Body
) {
self.init(elements, id: \.id, selection: selection, content: content)
}
}

View File

@ -9,7 +9,7 @@ import CAdw
import LevenshteinTransformations
/// A dynamic list but without a list design in the user interface.
public struct ForEach<Element, Identifier>: AdwaitaWidget where Identifier: Equatable {
public struct ForEach<Element>: AdwaitaWidget where Element: Identifiable {
/// The dynamic widget elements.
var elements: [Element]
@ -17,22 +17,12 @@ public struct ForEach<Element, Identifier>: AdwaitaWidget where Identifier: Equa
var content: (Element) -> Body
/// Whether the list is horizontal.
var horizontal: Bool
/// Whether the children should all be the same size.
var homogeneous: Bool?
/// The path to the identifier.
var id: KeyPath<Element, Identifier>
/// Initialize `ForEach`.
public init(
_ elements: [Element],
id: KeyPath<Element, Identifier>,
horizontal: Bool = false,
@ViewBuilder content: @escaping (Element) -> Body
) {
public init(_ elements: [Element], horizontal: Bool = false, @ViewBuilder content: @escaping (Element) -> Body) {
self.elements = elements
self.content = content
self.horizontal = horizontal
self.id = id
}
/// The view storage.
@ -44,9 +34,11 @@ public struct ForEach<Element, Identifier>: AdwaitaWidget where Identifier: Equa
data: WidgetData,
type: Data.Type
) -> ViewStorage where Data: ViewRenderData {
.init(
let storage = ViewStorage(
gtk_box_new(horizontal ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL, 0)?.opaque()
)
update(storage, data: data, updateProperties: true, type: type)
return storage
}
/// Update the stored content.
@ -64,9 +56,8 @@ public struct ForEach<Element, Identifier>: AdwaitaWidget where Identifier: Equa
var contentStorage: [ViewStorage] = storage.content[.mainContent] ?? []
let old = storage.fields["element"] as? [Element] ?? []
let widget: UnsafeMutablePointer<GtkBox>? = storage.opaquePointer?.cast()
old.transform(
old.identifiableTransform(
to: elements,
id: id,
functions: .init { index in
let child = contentStorage[safe: index]?.opaquePointer
gtk_box_remove(widget, child?.cast())
@ -82,16 +73,10 @@ public struct ForEach<Element, Identifier>: AdwaitaWidget where Identifier: Equa
}
)
if updateProperties {
if (storage.previousState as? Self)?.horizontal != horizontal {
gtk_orientable_set_orientation(
widget?.opaque(),
horizontal ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL
)
}
if let homogeneous, (storage.previousState as? Self)?.homogeneous != homogeneous {
gtk_box_set_homogeneous(widget?.cast(), homogeneous.cBool)
}
storage.previousState = self
gtk_orientable_set_orientation(
widget?.opaque(),
horizontal ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL
)
}
storage.fields["element"] = elements
storage.content[.mainContent] = contentStorage
@ -106,23 +91,4 @@ public struct ForEach<Element, Identifier>: AdwaitaWidget where Identifier: Equa
}
}
/// Whether the children should all be the same size.
/// - Parameter homogeneous: Whether the children should all be the same size.
/// - Returns: The for each view.
public func homogeneous(_ homogeneous: Bool? = true) -> Self {
modify { $0.homogeneous = homogeneous }
}
}
extension ForEach where Element: Identifiable, Identifier == Element.ID {
/// Initialize `ForEach`.
public init(_ elements: [Element], horizontal: Bool = false, @ViewBuilder content: @escaping (Element) -> Body) {
self.elements = elements
self.content = content
self.horizontal = horizontal
self.id = \.id
}
}

View File

@ -14,11 +14,4 @@ extension ActionRow {
self = self.title(title)
}
/// Deemphasize the row title and emphasize the subtitle.
/// - Parameter active: Whether the style is currently applied.
/// - Returns: A view.
public func property(_ active: Bool = true) -> AnyView {
style("property", active: active)
}
}

View File

@ -26,26 +26,11 @@ extension ComboRow {
selection: Binding<Element.ID>,
values: [Element]
) where Element: Identifiable, Element: CustomStringConvertible {
self.init(title, selection: selection, values: values, id: \.id, description: \.description)
}
/// Initialize a combo row.
/// - Parameters:
/// - title: The row's title.
/// - selection: The selected value.
/// - values: The available values.
public init<Element, Identifier>(
_ title: String,
selection: Binding<Identifier>,
values: [Element],
id: KeyPath<Element, Identifier>,
description: KeyPath<Element, String>
) where Identifier: Equatable {
self = self.title(title)
self = self.selected(.init {
.init(values.firstIndex { $0[keyPath: id] == selection.wrappedValue } ?? 0)
.init(values.firstIndex { $0.id == selection.wrappedValue } ?? 0)
} set: { index in
if let id = values[safe: .init(index)]?[keyPath: id] {
if let id = values[safe: .init(index)]?.id {
selection.wrappedValue = id
}
})
@ -54,10 +39,34 @@ extension ComboRow {
storage.fields[Self.stringList] = list
adw_combo_row_set_model(storage.opaquePointer?.cast(), list)
g_object_unref(list?.cast())
DropDown.updateContent(storage: storage, values: values, id: id, description: description)
Self.updateContent(storage: storage, values: values, element: Element.self)
}
updateFunctions.append { storage, _, _ in
DropDown.updateContent(storage: storage, values: values, id: id, description: description)
Self.updateContent(storage: storage, values: values, element: Element.self)
}
}
/// Update the combo row's content.
/// - Parameters:
/// - storage: The view storage.
/// - values: The elements.
/// - element: The type of the elements.
static func updateContent<Element>(
storage: ViewStorage,
values: [Element],
element: Element.Type
) where Element: Identifiable, Element: CustomStringConvertible {
if let list = storage.fields[Self.stringList] as? OpaquePointer {
let old = storage.fields[Self.values] as? [Element] ?? []
old.identifiableTransform(
to: values,
functions: .init { index in
gtk_string_list_remove(list, .init(index))
} insert: { _, element in
gtk_string_list_append(list, element.description)
}
)
storage.fields[Self.values] = values
}
}

View File

@ -15,8 +15,11 @@ public struct Form: SimpleView {
/// The view's body.
public var view: Body {
List([Int](content.indices), selection: nil) { index in content[index] }
.style("boxed-list")
ModifierWrapper(
content: List([Int](content.indices), selection: nil) { index in content[index] },
style: "boxed-list",
styleActive: true
)
}
/// Initialize a `Form`.

View File

@ -2,15 +2,15 @@
// ActionRow.swift
// Adwaita
//
// Created by auto-generation on 04.02.26.
// Created by auto-generation on 19.04.25.
//
import CAdw
import LevenshteinTransformations
/// A `Gtk.ListBoxRow` used to present actions.
///
/// A [class@Gtk.ListBoxRow] used to present actions.
///
/// <picture><source srcset="action-row-dark.png" media="(prefers-color-scheme: dark)"><img src="action-row.png" alt="action-row"></picture>
///
/// The `AdwActionRow` widget can have a title, a subtitle and an icon. The row
/// can receive additional widgets at its end, or prefix widgets at its start.
@ -21,35 +21,56 @@ import LevenshteinTransformations
/// will automatically make it activatable, but unsetting it won't change the
/// row's activatability.
///
/// ## AdwActionRow as GtkBuildable
///
/// The `AdwActionRow` implementation of the [iface@Gtk.Buildable] interface
/// supports adding a child at its end by specifying suffix or omitting the
/// type attribute of a <child> element.
///
/// It also supports adding a child as a prefix widget by specifying prefix as
/// the type attribute of a <child> element.
///
/// ## CSS nodes
///
/// `AdwActionRow` has a main CSS node with name `row`.
///
/// It contains the subnode `box.header` for its main horizontal box, and
/// `box.title` for the vertical box containing the title and subtitle labels.
///
/// It contains subnodes `label.title` and `label.subtitle` representing
/// respectively the title label and subtitle label.
///
/// ## Style classes
///
/// `AdwActionRow` can use the [`.property`](style-classes.html#property-rows)
/// style class to emphasize the row subtitle instead of the row title, which is
/// useful for displaying read-only properties.
///
/// <picture><source srcset="property-row-dark.png" media="(prefers-color-scheme: dark)"><img src="property-row.png" alt="property-row"></picture>
///
/// When used together with the `.monospace` style class, only the subtitle
/// becomes monospace, not the title or any extra widgets.
public struct ActionRow: AdwaitaWidget {
#if exposeGeneratedAppearUpdateFunctions
/// Additional update functions for type extensions.
public var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
public var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#else
/// Additional update functions for type extensions.
var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#endif
/// The widget to activate when the row is activated.
///
/// The row can be activated either by clicking on it, calling
/// `ActionRow.activate`, or via mnemonics in the title.
/// See the ``useUnderline(_:)`` property to enable
/// [method@ActionRow.activate], or via mnemonics in the title.
/// See the [property@PreferencesRow:use-underline] property to enable
/// mnemonics.
///
/// The target widget will be activated by emitting the
/// `Gtk.Widget::mnemonic-activate` signal on it.
var activatableWidget: Body?
/// [signal@Gtk.Widget::mnemonic-activate] signal on it.
var activatableWidget: (() -> Body)?
/// The subtitle for this row.
///
/// The subtitle is interpreted as Pango markup unless
/// ``useMarkup(_:)`` is set to `false`.
/// [property@PreferencesRow:use-markup] is set to `FALSE`.
var subtitle: String?
/// The number of lines at the end of which the subtitle label will be
/// ellipsized.
@ -58,12 +79,12 @@ public struct ActionRow: AdwaitaWidget {
var subtitleLines: Int?
/// Whether the user can copy the subtitle from the label.
///
/// See also ``selectable(_:)``.
/// See also [property@Gtk.Label:selectable].
var subtitleSelectable: Bool?
/// The title of the preference represented by this row.
///
/// The title is interpreted as Pango markup unless
/// ``useMarkup(_:)`` is set to `false`.
/// [property@PreferencesRow:use-markup] is set to `FALSE`.
var title: String?
/// The number of lines at the end of which the title label will be ellipsized.
///
@ -71,13 +92,13 @@ public struct ActionRow: AdwaitaWidget {
var titleLines: Int?
/// Whether the user can copy the title from the label.
///
/// See also ``selectable(_:)``.
/// See also [property@Gtk.Label:selectable].
var titleSelectable: Bool?
/// Whether to use Pango markup for the title label.
///
/// Subclasses may also use it for other labels, such as subtitle.
///
/// See also `Pango.parse_markup`.
/// See also [func@Pango.parse_markup].
var useMarkup: Bool?
/// Whether an embedded underline in the title indicates a mnemonic.
var useUnderline: Bool?
@ -102,7 +123,8 @@ public struct ActionRow: AdwaitaWidget {
for function in appearFunctions {
function(storage, data)
}
if let activatableWidgetStorage = activatableWidget?.storage(data: data, type: type) {
update(storage, data: data, updateProperties: true, type: type)
if let activatableWidgetStorage = activatableWidget?().storage(data: data, type: type) {
storage.content["activatableWidget"] = [activatableWidgetStorage]
adw_action_row_set_activatable_widget(storage.opaquePointer?.cast(), activatableWidgetStorage.opaquePointer?.cast())
}
@ -137,7 +159,7 @@ public struct ActionRow: AdwaitaWidget {
storage.modify { widget in
if let widget = storage.content["activatableWidget"]?.first {
activatableWidget?.updateStorage(widget, data: data, updateProperties: updateProperties, type: type)
activatableWidget?().updateStorage(widget, data: data, updateProperties: updateProperties, type: type)
}
if let subtitleLines, updateProperties, (storage.previousState as? Self)?.subtitleLines != subtitleLines {
adw_action_row_set_subtitle_lines(widget?.cast(), subtitleLines.cInt)
@ -202,22 +224,26 @@ public struct ActionRow: AdwaitaWidget {
/// The widget to activate when the row is activated.
///
/// The row can be activated either by clicking on it, calling
/// `ActionRow.activate`, or via mnemonics in the title.
/// See the ``useUnderline(_:)`` property to enable
/// [method@ActionRow.activate], or via mnemonics in the title.
/// See the [property@PreferencesRow:use-underline] property to enable
/// mnemonics.
///
/// The target widget will be activated by emitting the
/// `Gtk.Widget::mnemonic-activate` signal on it.
public func activatableWidget(@ViewBuilder _ activatableWidget: () -> Body) -> Self {
modify { $0.activatableWidget = activatableWidget() }
/// [signal@Gtk.Widget::mnemonic-activate] signal on it.
public func activatableWidget(@ViewBuilder _ activatableWidget: @escaping (() -> Body)) -> Self {
var newSelf = self
newSelf.activatableWidget = activatableWidget
return newSelf
}
/// The subtitle for this row.
///
/// The subtitle is interpreted as Pango markup unless
/// ``useMarkup(_:)`` is set to `false`.
/// [property@PreferencesRow:use-markup] is set to `FALSE`.
public func subtitle(_ subtitle: String?) -> Self {
modify { $0.subtitle = subtitle }
var newSelf = self
newSelf.subtitle = subtitle
return newSelf
}
/// The number of lines at the end of which the subtitle label will be
@ -225,50 +251,64 @@ public struct ActionRow: AdwaitaWidget {
///
/// If the value is 0, the number of lines won't be limited.
public func subtitleLines(_ subtitleLines: Int?) -> Self {
modify { $0.subtitleLines = subtitleLines }
var newSelf = self
newSelf.subtitleLines = subtitleLines
return newSelf
}
/// Whether the user can copy the subtitle from the label.
///
/// See also ``selectable(_:)``.
/// See also [property@Gtk.Label:selectable].
public func subtitleSelectable(_ subtitleSelectable: Bool? = true) -> Self {
modify { $0.subtitleSelectable = subtitleSelectable }
var newSelf = self
newSelf.subtitleSelectable = subtitleSelectable
return newSelf
}
/// The title of the preference represented by this row.
///
/// The title is interpreted as Pango markup unless
/// ``useMarkup(_:)`` is set to `false`.
/// [property@PreferencesRow:use-markup] is set to `FALSE`.
public func title(_ title: String?) -> Self {
modify { $0.title = title }
var newSelf = self
newSelf.title = title
return newSelf
}
/// The number of lines at the end of which the title label will be ellipsized.
///
/// If the value is 0, the number of lines won't be limited.
public func titleLines(_ titleLines: Int?) -> Self {
modify { $0.titleLines = titleLines }
var newSelf = self
newSelf.titleLines = titleLines
return newSelf
}
/// Whether the user can copy the title from the label.
///
/// See also ``selectable(_:)``.
/// See also [property@Gtk.Label:selectable].
public func titleSelectable(_ titleSelectable: Bool? = true) -> Self {
modify { $0.titleSelectable = titleSelectable }
var newSelf = self
newSelf.titleSelectable = titleSelectable
return newSelf
}
/// Whether to use Pango markup for the title label.
///
/// Subclasses may also use it for other labels, such as subtitle.
///
/// See also `Pango.parse_markup`.
/// See also [func@Pango.parse_markup].
public func useMarkup(_ useMarkup: Bool? = true) -> Self {
modify { $0.useMarkup = useMarkup }
var newSelf = self
newSelf.useMarkup = useMarkup
return newSelf
}
/// Whether an embedded underline in the title indicates a mnemonic.
public func useUnderline(_ useUnderline: Bool? = true) -> Self {
modify { $0.useUnderline = useUnderline }
var newSelf = self
newSelf.useUnderline = useUnderline
return newSelf
}
/// This signal is emitted after the row has been activated.

View File

@ -2,7 +2,7 @@
// AspectFrame.swift
// Adwaita
//
// Created by auto-generation on 04.02.26.
// Created by auto-generation on 19.04.25.
//
import CAdw
@ -13,33 +13,34 @@ import LevenshteinTransformations
/// The frame can respect the aspect ratio of the child widget,
/// or use its own aspect ratio.
///
/// # CSS nodes
///
/// `GtkAspectFrame` uses a CSS node with name `aspectframe`.
///
/// # Accessibility
///
/// Until GTK 4.10, `GtkAspectFrame` used the [enum@Gtk.AccessibleRole.group] role.
///
/// Starting from GTK 4.12, `GtkAspectFrame` uses the [enum@Gtk.AccessibleRole.generic] role.
public struct AspectFrame: AdwaitaWidget {
#if exposeGeneratedAppearUpdateFunctions
/// Additional update functions for type extensions.
public var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
public var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#else
/// Additional update functions for type extensions.
var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#endif
/// The accessible role of the given `GtkAccessible` implementation.
///
/// The accessible role cannot be changed once set.
var accessibleRole: String?
/// The child widget.
var child: Body?
var child: (() -> Body)?
/// Whether the `GtkAspectFrame` should use the aspect ratio of its child.
var obeyChild: Bool?
/// The aspect ratio to be used by the `GtkAspectFrame`.
///
/// This property is only used if
/// ``obeyChild(_:)`` is set to `false`.
/// [property@Gtk.AspectFrame:obey-child] is set to %FALSE.
var ratio: Float
/// The horizontal alignment of the child.
var xalign: Float?
@ -61,7 +62,8 @@ public struct AspectFrame: AdwaitaWidget {
for function in appearFunctions {
function(storage, data)
}
if let childStorage = child?.storage(data: data, type: type) {
update(storage, data: data, updateProperties: true, type: type)
if let childStorage = child?().storage(data: data, type: type) {
storage.content["child"] = [childStorage]
gtk_aspect_frame_set_child(storage.opaquePointer, childStorage.opaquePointer?.cast())
}
@ -79,7 +81,7 @@ public struct AspectFrame: AdwaitaWidget {
storage.modify { widget in
if let widget = storage.content["child"]?.first {
child?.updateStorage(widget, data: data, updateProperties: updateProperties, type: type)
child?().updateStorage(widget, data: data, updateProperties: updateProperties, type: type)
}
if let obeyChild, updateProperties, (storage.previousState as? Self)?.obeyChild != obeyChild {
gtk_aspect_frame_set_obey_child(widget, obeyChild.cBool)
@ -109,35 +111,47 @@ public struct AspectFrame: AdwaitaWidget {
///
/// The accessible role cannot be changed once set.
public func accessibleRole(_ accessibleRole: String?) -> Self {
modify { $0.accessibleRole = accessibleRole }
var newSelf = self
newSelf.accessibleRole = accessibleRole
return newSelf
}
/// The child widget.
public func child(@ViewBuilder _ child: () -> Body) -> Self {
modify { $0.child = child() }
public func child(@ViewBuilder _ child: @escaping (() -> Body)) -> Self {
var newSelf = self
newSelf.child = child
return newSelf
}
/// Whether the `GtkAspectFrame` should use the aspect ratio of its child.
public func obeyChild(_ obeyChild: Bool? = true) -> Self {
modify { $0.obeyChild = obeyChild }
var newSelf = self
newSelf.obeyChild = obeyChild
return newSelf
}
/// The aspect ratio to be used by the `GtkAspectFrame`.
///
/// This property is only used if
/// ``obeyChild(_:)`` is set to `false`.
/// [property@Gtk.AspectFrame:obey-child] is set to %FALSE.
public func ratio(_ ratio: Float) -> Self {
modify { $0.ratio = ratio }
var newSelf = self
newSelf.ratio = ratio
return newSelf
}
/// The horizontal alignment of the child.
public func xalign(_ xalign: Float?) -> Self {
modify { $0.xalign = xalign }
var newSelf = self
newSelf.xalign = xalign
return newSelf
}
/// The vertical alignment of the child.
public func yalign(_ yalign: Float?) -> Self {
modify { $0.yalign = yalign }
var newSelf = self
newSelf.yalign = yalign
return newSelf
}
}

View File

@ -2,7 +2,7 @@
// Avatar.swift
// Adwaita
//
// Created by auto-generation on 04.02.26.
// Created by auto-generation on 19.04.25.
//
import CAdw
@ -10,35 +10,34 @@ import LevenshteinTransformations
/// A widget displaying an image, with a generated fallback.
///
///
/// <picture><source srcset="avatar-dark.png" media="(prefers-color-scheme: dark)"><img src="avatar.png" alt="avatar"></picture>
///
/// `AdwAvatar` is a widget that shows a round avatar.
///
/// `AdwAvatar` generates an avatar with the initials of the
/// ``text(_:)`` on top of a colored background.
/// [property@Avatar:text] on top of a colored background.
///
/// The color is picked based on the hash of the ``text(_:)``.
/// The color is picked based on the hash of the [property@Avatar:text].
///
/// If ``showInitials(_:)`` is set to `false`,
/// ``iconName(_:)`` or `avatar-default-symbolic` is shown instead of
/// If [property@Avatar:show-initials] is set to `FALSE`,
/// [property@Avatar:icon-name] or `avatar-default-symbolic` is shown instead of
/// the initials.
///
/// Use ``customImage(_:)`` to set a custom image.
/// Use [property@Avatar:custom-image] to set a custom image.
///
/// ## CSS nodes
///
/// `AdwAvatar` has a single CSS node with name `avatar`.
///
/// ## Accessibility
///
/// `AdwAvatar` uses the `GTK_ACCESSIBLE_ROLE_IMG` role.
public struct Avatar: AdwaitaWidget {
#if exposeGeneratedAppearUpdateFunctions
/// Additional update functions for type extensions.
public var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
public var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#else
/// Additional update functions for type extensions.
var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#endif
/// The name of an icon to use as a fallback.
///
@ -46,14 +45,14 @@ public struct Avatar: AdwaitaWidget {
var iconName: String?
/// Whether initials are used instead of an icon on the fallback avatar.
///
/// See ``iconName(_:)`` for how to change the fallback icon.
/// See [property@Avatar:icon-name] for how to change the fallback icon.
var showInitials: Bool
/// The size of the avatar.
var size: Int
/// Sets the text used to generate the fallback initials and color.
///
/// It's only used to generate the color if ``showInitials(_:)`` is
/// `false`.
/// It's only used to generate the color if [property@Avatar:show-initials] is
/// `FALSE`.
var text: String?
/// Initialize `Avatar`.
@ -72,6 +71,7 @@ public struct Avatar: AdwaitaWidget {
for function in appearFunctions {
function(storage, data)
}
update(storage, data: data, updateProperties: true, type: type)
return storage
}
@ -113,27 +113,35 @@ public struct Avatar: AdwaitaWidget {
///
/// If no name is set, `avatar-default-symbolic` will be used.
public func iconName(_ iconName: String?) -> Self {
modify { $0.iconName = iconName }
var newSelf = self
newSelf.iconName = iconName
return newSelf
}
/// Whether initials are used instead of an icon on the fallback avatar.
///
/// See ``iconName(_:)`` for how to change the fallback icon.
/// See [property@Avatar:icon-name] for how to change the fallback icon.
public func showInitials(_ showInitials: Bool) -> Self {
modify { $0.showInitials = showInitials }
var newSelf = self
newSelf.showInitials = showInitials
return newSelf
}
/// The size of the avatar.
public func size(_ size: Int) -> Self {
modify { $0.size = size }
var newSelf = self
newSelf.size = size
return newSelf
}
/// Sets the text used to generate the fallback initials and color.
///
/// It's only used to generate the color if ``showInitials(_:)`` is
/// `false`.
/// It's only used to generate the color if [property@Avatar:show-initials] is
/// `FALSE`.
public func text(_ text: String?) -> Self {
modify { $0.text = text }
var newSelf = self
newSelf.text = text
return newSelf
}
}

View File

@ -2,7 +2,7 @@
// Banner.swift
// Adwaita
//
// Created by auto-generation on 04.02.26.
// Created by auto-generation on 19.04.25.
//
import CAdw
@ -10,54 +10,49 @@ import LevenshteinTransformations
/// A bar with contextual information.
///
/// <picture><source srcset="banner-dark.png" media="(prefers-color-scheme: dark)"><img src="banner.png" alt="banner"></picture>
///
/// Banners are hidden by default, use [property@Banner:revealed] to show them.
///
/// Banners are hidden by default, use ``revealed(_:)`` to show them.
///
/// Banners have a title, set with ``title(_:)``. Titles can be marked
/// up with Pango markup, use ``useMarkup(_:)`` to enable it.
/// Banners have a title, set with [property@Banner:title]. Titles can be marked
/// up with Pango markup, use [property@Banner:use-markup] to enable it.
///
/// The title will be shown centered or left-aligned depending on available
/// space.
///
/// Banners can optionally have a button with text on it, set through
/// ``buttonLabel(_:)``. The button can be used with a `GAction`,
/// or with the `Banner::button-clicked` signal. The button can have
/// [property@Banner:button-label]. The button can be used with a `GAction`,
/// or with the [signal@Banner::button-clicked] signal. The button can have
/// different styles, a gray style and a suggested style.
///
/// <picture><source srcset="banner-suggested-dark.png" media="(prefers-color-scheme: dark)"><img src="banner-suggested.png" alt="banner with suggested button style"></picture>
///
/// ## CSS nodes
///
///
/// `AdwBanner` has a main CSS node with the name `banner`.
public struct Banner: AdwaitaWidget {
#if exposeGeneratedAppearUpdateFunctions
/// Additional update functions for type extensions.
public var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
public var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#else
/// Additional update functions for type extensions.
var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#endif
/// The label to show on the button.
///
/// If set to `""` or `NULL`, the button won't be shown.
///
/// The button can be used with a `GAction`, or with the
/// `Banner::button-clicked` signal.
/// [signal@Banner::button-clicked] signal.
var buttonLabel: String?
/// Whether the banner is currently revealed.
var revealed: Bool?
/// The title for this banner.
///
/// See also: ``useMarkup(_:)``.
/// See also: [property@Banner:use-markup].
var title: String
/// Whether to use Pango markup for the banner title.
///
/// See also `Pango.parse_markup`.
/// See also [func@Pango.parse_markup].
var useMarkup: Bool?
/// This signal is emitted after the action button has been clicked.
///
@ -79,6 +74,7 @@ public struct Banner: AdwaitaWidget {
for function in appearFunctions {
function(storage, data)
}
update(storage, data: data, updateProperties: true, type: type)
return storage
}
@ -126,28 +122,36 @@ public struct Banner: AdwaitaWidget {
/// If set to `""` or `NULL`, the button won't be shown.
///
/// The button can be used with a `GAction`, or with the
/// `Banner::button-clicked` signal.
/// [signal@Banner::button-clicked] signal.
public func buttonLabel(_ buttonLabel: String?) -> Self {
modify { $0.buttonLabel = buttonLabel }
var newSelf = self
newSelf.buttonLabel = buttonLabel
return newSelf
}
/// Whether the banner is currently revealed.
public func revealed(_ revealed: Bool? = true) -> Self {
modify { $0.revealed = revealed }
var newSelf = self
newSelf.revealed = revealed
return newSelf
}
/// The title for this banner.
///
/// See also: ``useMarkup(_:)``.
/// See also: [property@Banner:use-markup].
public func title(_ title: String) -> Self {
modify { $0.title = title }
var newSelf = self
newSelf.title = title
return newSelf
}
/// Whether to use Pango markup for the banner title.
///
/// See also `Pango.parse_markup`.
/// See also [func@Pango.parse_markup].
public func useMarkup(_ useMarkup: Bool? = true) -> Self {
modify { $0.useMarkup = useMarkup }
var newSelf = self
newSelf.useMarkup = useMarkup
return newSelf
}
/// This signal is emitted after the action button has been clicked.

View File

@ -2,7 +2,7 @@
// Bin.swift
// Adwaita
//
// Created by auto-generation on 04.02.26.
// Created by auto-generation on 19.04.25.
//
import CAdw
@ -10,29 +10,22 @@ import LevenshteinTransformations
/// A widget with one child.
///
/// <picture><source srcset="bin-dark.png" media="(prefers-color-scheme: dark)"><img src="bin.png" alt="bin"></picture>
///
///
/// The `AdwBin` widget has only one child, set with the ``child(_:)``
/// The `AdwBin` widget has only one child, set with the [property@Bin:child]
/// property.
///
/// It is useful for deriving subclasses, since it provides common code needed
/// for handling a single child widget.
public struct Bin: AdwaitaWidget {
#if exposeGeneratedAppearUpdateFunctions
/// Additional update functions for type extensions.
public var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
public var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#else
/// Additional update functions for type extensions.
var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#endif
/// The child widget of the `AdwBin`.
var child: Body?
var child: (() -> Body)?
/// Initialize `Bin`.
public init() {
@ -48,7 +41,8 @@ public struct Bin: AdwaitaWidget {
for function in appearFunctions {
function(storage, data)
}
if let childStorage = child?.storage(data: data, type: type) {
update(storage, data: data, updateProperties: true, type: type)
if let childStorage = child?().storage(data: data, type: type) {
storage.content["child"] = [childStorage]
adw_bin_set_child(storage.opaquePointer?.cast(), childStorage.opaquePointer?.cast())
}
@ -66,7 +60,7 @@ public struct Bin: AdwaitaWidget {
storage.modify { widget in
if let widget = storage.content["child"]?.first {
child?.updateStorage(widget, data: data, updateProperties: updateProperties, type: type)
child?().updateStorage(widget, data: data, updateProperties: updateProperties, type: type)
}
@ -81,8 +75,10 @@ public struct Bin: AdwaitaWidget {
}
/// The child widget of the `AdwBin`.
public func child(@ViewBuilder _ child: () -> Body) -> Self {
modify { $0.child = child() }
public func child(@ViewBuilder _ child: @escaping (() -> Body)) -> Self {
var newSelf = self
newSelf.child = child
return newSelf
}
}

View File

@ -2,7 +2,7 @@
// Box.swift
// Adwaita
//
// Created by auto-generation on 04.02.26.
// Created by auto-generation on 19.04.25.
//
import CAdw
@ -10,43 +10,44 @@ import LevenshteinTransformations
/// Arranges child widgets into a single row or column.
///
///
/// <picture><source srcset="box-dark.png" media="(prefers-color-scheme: dark)"><img alt="An example GtkBox" src="box.png"></picture>
///
/// Whether it is a row or column depends on the value of its
/// ``orientation(_:)`` property. Within the other
/// [property@Gtk.Orientable:orientation] property. Within the other
/// dimension, all children are allocated the same size. The
/// ``halign(_:)`` and ``valign(_:)``
/// [property@Gtk.Widget:halign] and [property@Gtk.Widget:valign]
/// properties can be used on the children to influence their allocation.
///
/// Use repeated calls to `Gtk.Box.append` to pack widgets into a
/// `GtkBox` from start to end. Use `Gtk.Box.remove` to remove widgets
/// from the `GtkBox`. `Gtk.Box.insert_child_after` can be used to add
/// Use repeated calls to [method@Gtk.Box.append] to pack widgets into a
/// `GtkBox` from start to end. Use [method@Gtk.Box.remove] to remove widgets
/// from the `GtkBox`. [method@Gtk.Box.insert_child_after] can be used to add
/// a child at a particular position.
///
/// Use `Gtk.Box.set_homogeneous` to specify whether or not all children
/// Use [method@Gtk.Box.set_homogeneous] to specify whether or not all children
/// of the `GtkBox` are forced to get the same amount of space.
///
/// Use `Gtk.Box.set_spacing` to determine how much space will be minimally
/// Use [method@Gtk.Box.set_spacing] to determine how much space will be minimally
/// placed between all children in the `GtkBox`. Note that spacing is added
/// *between* the children.
///
/// Use `Gtk.Box.reorder_child_after` to move a child to a different
/// Use [method@Gtk.Box.reorder_child_after] to move a child to a different
/// place in the box.
///
/// # CSS nodes
///
/// `GtkBox` uses a single CSS node with name box.
///
/// # Accessibility
///
/// Until GTK 4.10, `GtkBox` used the [enum@Gtk.AccessibleRole.group] role.
///
/// Starting from GTK 4.12, `GtkBox` uses the [enum@Gtk.AccessibleRole.generic] role.
public struct Box: AdwaitaWidget {
#if exposeGeneratedAppearUpdateFunctions
/// Additional update functions for type extensions.
public var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
public var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#else
/// Additional update functions for type extensions.
var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#endif
/// The accessible role of the given `GtkAccessible` implementation.
///
@ -66,7 +67,7 @@ public struct Box: AdwaitaWidget {
var prepend: () -> Body = { [] }
/// Initialize `Box`.
init(spacing: Int) {
public init(spacing: Int) {
self.spacing = spacing
}
@ -80,6 +81,7 @@ public struct Box: AdwaitaWidget {
for function in appearFunctions {
function(storage, data)
}
update(storage, data: data, updateProperties: true, type: type)
var appendStorage: [ViewStorage] = []
for view in append() {
@ -154,24 +156,32 @@ public struct Box: AdwaitaWidget {
///
/// The accessible role cannot be changed once set.
public func accessibleRole(_ accessibleRole: String?) -> Self {
modify { $0.accessibleRole = accessibleRole }
var newSelf = self
newSelf.accessibleRole = accessibleRole
return newSelf
}
/// The position of the child that determines the baseline.
///
/// This is only relevant if the box is in vertical orientation.
public func baselineChild(_ baselineChild: Int?) -> Self {
modify { $0.baselineChild = baselineChild }
var newSelf = self
newSelf.baselineChild = baselineChild
return newSelf
}
/// Whether the children should all be the same size.
public func homogeneous(_ homogeneous: Bool? = true) -> Self {
modify { $0.homogeneous = homogeneous }
var newSelf = self
newSelf.homogeneous = homogeneous
return newSelf
}
/// The amount of space between children.
public func spacing(_ spacing: Int) -> Self {
modify { $0.spacing = spacing }
var newSelf = self
newSelf.spacing = spacing
return newSelf
}
/// Set the body for "append".

View File

@ -2,7 +2,7 @@
// Button.swift
// Adwaita
//
// Created by auto-generation on 04.02.26.
// Created by auto-generation on 19.04.25.
//
import CAdw
@ -10,26 +10,45 @@ import LevenshteinTransformations
/// Calls a callback function when the button is clicked.
///
///
/// <picture><source srcset="button-dark.png" media="(prefers-color-scheme: dark)"><img alt="An example GtkButton" src="button.png"></picture>
///
/// The `GtkButton` widget can hold any valid child widget. That is, it can hold
/// almost any other standard `GtkWidget`. The most commonly used child is the
/// `GtkLabel`.
///
/// # Shortcuts and Gestures
///
/// The following signals have default keybindings:
///
/// - [signal@Gtk.Button::activate]
///
/// # CSS nodes
///
/// `GtkButton` has a single CSS node with name button. The node will get the
/// style classes .image-button or .text-button, if the content is just an
/// image or label, respectively. It may also receive the .flat style class.
/// When activating a button via the keyboard, the button will temporarily
/// gain the .keyboard-activating style class.
///
/// Other style classes that are commonly used with `GtkButton` include
/// .suggested-action and .destructive-action. In special cases, buttons
/// can be made round by adding the .circular style class.
///
/// Button-like widgets like [class@Gtk.ToggleButton], [class@Gtk.MenuButton],
/// [class@Gtk.VolumeButton], [class@Gtk.LockButton], [class@Gtk.ColorButton]
/// or [class@Gtk.FontButton] use style classes such as .toggle, .popup, .scale,
/// .lock, .color on the button node to differentiate themselves from a plain
/// `GtkButton`.
///
/// # Accessibility
///
/// `GtkButton` uses the [enum@Gtk.AccessibleRole.button] role.
public struct Button: AdwaitaWidget {
#if exposeGeneratedAppearUpdateFunctions
/// Additional update functions for type extensions.
public var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
public var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#else
/// Additional update functions for type extensions.
var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#endif
/// The accessible role of the given `GtkAccessible` implementation.
///
@ -46,7 +65,7 @@ public struct Button: AdwaitaWidget {
/// property has no effect.
var canShrink: Bool?
/// The child widget.
var child: Body?
var child: (() -> Body)?
/// Whether the button has a frame.
var hasFrame: Bool?
/// The name of the icon used to automatically populate the button.
@ -59,7 +78,7 @@ public struct Button: AdwaitaWidget {
/// Emitted to animate press then release.
///
/// This is an action signal. Applications should never connect
/// to this signal, but use the `Gtk.Button::clicked` signal.
/// to this signal, but use the [signal@Gtk.Button::clicked] signal.
///
/// The default bindings for this signal are all forms of the
/// <kbd></kbd> and <kbd>Enter</kbd> keys.
@ -68,7 +87,7 @@ public struct Button: AdwaitaWidget {
var clicked: (() -> Void)?
/// Initialize `Button`.
init() {
public init() {
}
/// The view storage.
@ -81,7 +100,8 @@ public struct Button: AdwaitaWidget {
for function in appearFunctions {
function(storage, data)
}
if let childStorage = child?.storage(data: data, type: type) {
update(storage, data: data, updateProperties: true, type: type)
if let childStorage = child?().storage(data: data, type: type) {
storage.content["child"] = [childStorage]
gtk_button_set_child(storage.opaquePointer?.cast(), childStorage.opaquePointer?.cast())
}
@ -115,7 +135,7 @@ public struct Button: AdwaitaWidget {
gtk_button_set_can_shrink(widget?.cast(), canShrink.cBool)
}
if let widget = storage.content["child"]?.first {
child?.updateStorage(widget, data: data, updateProperties: updateProperties, type: type)
child?().updateStorage(widget, data: data, updateProperties: updateProperties, type: type)
}
if let hasFrame, updateProperties, (storage.previousState as? Self)?.hasFrame != hasFrame {
gtk_button_set_has_frame(widget?.cast(), hasFrame.cBool)
@ -145,12 +165,16 @@ public struct Button: AdwaitaWidget {
///
/// The accessible role cannot be changed once set.
public func accessibleRole(_ accessibleRole: String?) -> Self {
modify { $0.accessibleRole = accessibleRole }
var newSelf = self
newSelf.accessibleRole = accessibleRole
return newSelf
}
/// The name of the action with which this widget should be associated.
public func actionName(_ actionName: String?) -> Self {
modify { $0.actionName = actionName }
var newSelf = self
newSelf.actionName = actionName
return newSelf
}
/// Whether the size of the button can be made smaller than the natural
@ -161,39 +185,51 @@ public struct Button: AdwaitaWidget {
/// If the contents of a button are an icon or a custom widget, setting this
/// property has no effect.
public func canShrink(_ canShrink: Bool? = true) -> Self {
modify { $0.canShrink = canShrink }
var newSelf = self
newSelf.canShrink = canShrink
return newSelf
}
/// The child widget.
public func child(@ViewBuilder _ child: () -> Body) -> Self {
modify { $0.child = child() }
public func child(@ViewBuilder _ child: @escaping (() -> Body)) -> Self {
var newSelf = self
newSelf.child = child
return newSelf
}
/// Whether the button has a frame.
public func hasFrame(_ hasFrame: Bool? = true) -> Self {
modify { $0.hasFrame = hasFrame }
var newSelf = self
newSelf.hasFrame = hasFrame
return newSelf
}
/// The name of the icon used to automatically populate the button.
public func iconName(_ iconName: String?) -> Self {
modify { $0.iconName = iconName }
var newSelf = self
newSelf.iconName = iconName
return newSelf
}
/// Text of the label inside the button, if the button contains a label widget.
public func label(_ label: String?) -> Self {
modify { $0.label = label }
var newSelf = self
newSelf.label = label
return newSelf
}
/// If set, an underline in the text indicates that the following character is
/// to be used as mnemonic.
public func useUnderline(_ useUnderline: Bool? = true) -> Self {
modify { $0.useUnderline = useUnderline }
var newSelf = self
newSelf.useUnderline = useUnderline
return newSelf
}
/// Emitted to animate press then release.
///
/// This is an action signal. Applications should never connect
/// to this signal, but use the `Gtk.Button::clicked` signal.
/// to this signal, but use the [signal@Gtk.Button::clicked] signal.
///
/// The default bindings for this signal are all forms of the
/// <kbd></kbd> and <kbd>Enter</kbd> keys.

View File

@ -2,7 +2,7 @@
// ButtonContent.swift
// Adwaita
//
// Created by auto-generation on 04.02.26.
// Created by auto-generation on 19.04.25.
//
import CAdw
@ -10,12 +10,12 @@ import LevenshteinTransformations
/// A helper widget for creating buttons.
///
///
/// <picture><source srcset="button-content-dark.png" media="(prefers-color-scheme: dark)"><img src="button-content.png" alt="button-content"></picture>
///
/// `AdwButtonContent` is a box-like widget with an icon and a label.
///
/// It's intended to be used as a direct child of `Gtk.Button`,
/// `Gtk.MenuButton` or `SplitButton`, when they need to have both an
/// It's intended to be used as a direct child of [class@Gtk.Button],
/// [class@Gtk.MenuButton] or [class@SplitButton], when they need to have both an
/// icon and a label, as follows:
///
/// ```xml
@ -25,26 +25,37 @@ import LevenshteinTransformations
/// `AdwButtonContent` handles style classes and connecting the mnemonic to the
/// button automatically.
///
/// ## CSS nodes
///
/// ```
/// buttoncontent
/// box
/// image
/// label
/// ```
///
/// `AdwButtonContent`'s CSS node is called `buttoncontent`. It contains a `box`
/// subnode that serves as a container for the `image` and `label` nodes.
///
/// When inside a `GtkButton` or `AdwSplitButton`, the button will receive the
/// `.image-text-button` style class. When inside a `GtkMenuButton`, the
/// internal `GtkButton` will receive it instead.
///
/// ## Accessibility
///
/// `AdwButtonContent` uses the `GTK_ACCESSIBLE_ROLE_GROUP` role.
public struct ButtonContent: AdwaitaWidget {
#if exposeGeneratedAppearUpdateFunctions
/// Additional update functions for type extensions.
public var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
public var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#else
/// Additional update functions for type extensions.
var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#endif
/// Whether the button can be smaller than the natural size of its contents.
///
/// If set to `true`, the label will ellipsize.
/// If set to `TRUE`, the label will ellipsize.
///
/// See ``canShrink(_:)``.
/// See [property@Gtk.Button:can-shrink].
var canShrink: Bool?
/// The name of the displayed icon.
///
@ -56,7 +67,7 @@ public struct ButtonContent: AdwaitaWidget {
///
/// The mnemonic can be used to activate the parent button.
///
/// See ``label(_:)``.
/// See [property@ButtonContent:label].
var useUnderline: Bool?
/// Initialize `ButtonContent`.
@ -73,6 +84,7 @@ public struct ButtonContent: AdwaitaWidget {
for function in appearFunctions {
function(storage, data)
}
update(storage, data: data, updateProperties: true, type: type)
return storage
}
@ -112,32 +124,40 @@ public struct ButtonContent: AdwaitaWidget {
/// Whether the button can be smaller than the natural size of its contents.
///
/// If set to `true`, the label will ellipsize.
/// If set to `TRUE`, the label will ellipsize.
///
/// See ``canShrink(_:)``.
/// See [property@Gtk.Button:can-shrink].
public func canShrink(_ canShrink: Bool? = true) -> Self {
modify { $0.canShrink = canShrink }
var newSelf = self
newSelf.canShrink = canShrink
return newSelf
}
/// The name of the displayed icon.
///
/// If empty, the icon is not shown.
public func iconName(_ iconName: String?) -> Self {
modify { $0.iconName = iconName }
var newSelf = self
newSelf.iconName = iconName
return newSelf
}
/// The displayed label.
public func label(_ label: String?) -> Self {
modify { $0.label = label }
var newSelf = self
newSelf.label = label
return newSelf
}
/// Whether an underline in the text indicates a mnemonic.
///
/// The mnemonic can be used to activate the parent button.
///
/// See ``label(_:)``.
/// See [property@ButtonContent:label].
public func useUnderline(_ useUnderline: Bool? = true) -> Self {
modify { $0.useUnderline = useUnderline }
var newSelf = self
newSelf.useUnderline = useUnderline
return newSelf
}
}

View File

@ -2,7 +2,7 @@
// Carousel.swift
// Adwaita
//
// Created by auto-generation on 04.02.26.
// Created by auto-generation on 19.04.25.
//
import CAdw
@ -10,40 +10,35 @@ import LevenshteinTransformations
/// A paginated scrolling widget.
///
///
/// <picture><source srcset="carousel-dark.png" media="(prefers-color-scheme: dark)"><img src="carousel.png" alt="carousel"></picture>
///
/// The `AdwCarousel` widget can be used to display a set of pages with
/// swipe-based navigation between them.
///
/// `CarouselIndicatorDots` and `CarouselIndicatorLines` can be used
/// [class@CarouselIndicatorDots] and [class@CarouselIndicatorLines] can be used
/// to provide page indicators for `AdwCarousel`.
///
/// ## CSS nodes
///
public struct Carousel<Element, Identifier>: AdwaitaWidget where Identifier: Equatable {
/// `AdwCarousel` has a single CSS node with name `carousel`.
public struct Carousel<Element>: AdwaitaWidget where Element: Identifiable {
#if exposeGeneratedAppearUpdateFunctions
/// Additional update functions for type extensions.
public var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
public var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#else
/// Additional update functions for type extensions.
var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#endif
/// Whether to allow swiping for more than one page at a time.
///
/// If the value is `false`, each swipe can only move to the adjacent pages.
/// If the value is `FALSE`, each swipe can only move to the adjacent pages.
var allowLongSwipes: Bool?
/// Sets whether the `AdwCarousel` can be dragged with mouse pointer.
///
/// If the value is `false`, dragging is only available on touch.
/// If the value is `FALSE`, dragging is only available on touch.
var allowMouseDrag: Bool?
/// Whether the widget will respond to scroll wheel events.
///
/// If the value is `false`, wheel events will be ignored.
/// If the value is `FALSE`, wheel events will be ignored.
var allowScrollWheel: Bool?
/// Whether the carousel can be navigated.
///
@ -63,21 +58,18 @@ public struct Carousel<Element, Identifier>: AdwaitaWidget where Identifier: Equ
/// It can be used to implement "infinite scrolling" by amending the pages
/// after every scroll.
///
/// > [!NOTE]
/// > An empty carousel is indicated by `(int)index == -1`.
/// ::: note
/// An empty carousel is indicated by `(int)index == -1`.
var pageChanged: (() -> Void)?
/// The dynamic widget elements.
var elements: [Element]
/// The dynamic widget content.
var content: (Element) -> Body
/// The dynamic widget identifier key path.
var id: KeyPath<Element, Identifier>
/// Initialize `Carousel`.
public init(_ elements: [Element], id: KeyPath<Element, Identifier>, @ViewBuilder content: @escaping (Element) -> Body) {
public init(_ elements: [Element], @ViewBuilder content: @escaping (Element) -> Body) {
self.elements = elements
self.content = content
self.id = id
}
/// The view storage.
@ -90,6 +82,7 @@ public struct Carousel<Element, Identifier>: AdwaitaWidget where Identifier: Equ
for function in appearFunctions {
function(storage, data)
}
update(storage, data: data, updateProperties: true, type: type)
return storage
}
@ -129,9 +122,8 @@ public struct Carousel<Element, Identifier>: AdwaitaWidget where Identifier: Equ
var contentStorage: [ViewStorage] = storage.content[.mainContent] ?? []
let old = storage.fields["element"] as? [Element] ?? []
old.transform(
old.identifiableTransform(
to: elements,
id: id,
functions: .init { index in
adw_carousel_remove(widget, adw_carousel_get_nth_page(widget, UInt(index).cInt))
contentStorage.remove(at: index)
@ -158,23 +150,29 @@ public struct Carousel<Element, Identifier>: AdwaitaWidget where Identifier: Equ
/// Whether to allow swiping for more than one page at a time.
///
/// If the value is `false`, each swipe can only move to the adjacent pages.
/// If the value is `FALSE`, each swipe can only move to the adjacent pages.
public func allowLongSwipes(_ allowLongSwipes: Bool? = true) -> Self {
modify { $0.allowLongSwipes = allowLongSwipes }
var newSelf = self
newSelf.allowLongSwipes = allowLongSwipes
return newSelf
}
/// Sets whether the `AdwCarousel` can be dragged with mouse pointer.
///
/// If the value is `false`, dragging is only available on touch.
/// If the value is `FALSE`, dragging is only available on touch.
public func allowMouseDrag(_ allowMouseDrag: Bool? = true) -> Self {
modify { $0.allowMouseDrag = allowMouseDrag }
var newSelf = self
newSelf.allowMouseDrag = allowMouseDrag
return newSelf
}
/// Whether the widget will respond to scroll wheel events.
///
/// If the value is `false`, wheel events will be ignored.
/// If the value is `FALSE`, wheel events will be ignored.
public func allowScrollWheel(_ allowScrollWheel: Bool? = true) -> Self {
modify { $0.allowScrollWheel = allowScrollWheel }
var newSelf = self
newSelf.allowScrollWheel = allowScrollWheel
return newSelf
}
/// Whether the carousel can be navigated.
@ -182,24 +180,32 @@ public struct Carousel<Element, Identifier>: AdwaitaWidget where Identifier: Equ
/// This can be used to temporarily disable the carousel to only allow
/// navigating it in a certain state.
public func interactive(_ interactive: Bool? = true) -> Self {
modify { $0.interactive = interactive }
var newSelf = self
newSelf.interactive = interactive
return newSelf
}
/// The number of pages in a `AdwCarousel`.
public func nPages(_ nPages: UInt?) -> Self {
modify { $0.nPages = nPages }
var newSelf = self
newSelf.nPages = nPages
return newSelf
}
/// Page reveal duration, in milliseconds.
///
/// Reveal duration is used when animating adding or removing pages.
public func revealDuration(_ revealDuration: UInt?) -> Self {
modify { $0.revealDuration = revealDuration }
var newSelf = self
newSelf.revealDuration = revealDuration
return newSelf
}
/// Spacing between pages in pixels.
public func spacing(_ spacing: UInt?) -> Self {
modify { $0.spacing = spacing }
var newSelf = self
newSelf.spacing = spacing
return newSelf
}
/// This signal is emitted after a page has been changed.
@ -207,8 +213,8 @@ public struct Carousel<Element, Identifier>: AdwaitaWidget where Identifier: Equ
/// It can be used to implement "infinite scrolling" by amending the pages
/// after every scroll.
///
/// > [!NOTE]
/// > An empty carousel is indicated by `(int)index == -1`.
/// ::: note
/// An empty carousel is indicated by `(int)index == -1`.
public func pageChanged(_ pageChanged: @escaping () -> Void) -> Self {
var newSelf = self
newSelf.pageChanged = pageChanged
@ -216,14 +222,3 @@ public struct Carousel<Element, Identifier>: AdwaitaWidget where Identifier: Equ
}
}
extension Carousel where Element: Identifiable, Identifier == Element.ID {
/// Initialize `Carousel`.
public init(_ elements: [Element], @ViewBuilder content: @escaping (Element) -> Body) {
self.elements = elements
self.content = content
self.id = \.id
}
}

View File

@ -2,7 +2,7 @@
// CenterBox.swift
// Adwaita
//
// Created by auto-generation on 04.02.26.
// Created by auto-generation on 19.04.25.
//
import CAdw
@ -11,42 +11,57 @@ import LevenshteinTransformations
/// Arranges three children in a row, keeping the middle child
/// centered as well as possible.
///
/// <picture><source srcset="centerbox-dark.png" media="(prefers-color-scheme: dark)"><img alt="An example GtkCenterBox" src="centerbox.png"></picture>
///
///
/// To add children to `GtkCenterBox`, use `Gtk.CenterBox.set_start_widget`,
/// `Gtk.CenterBox.set_center_widget` and
/// `Gtk.CenterBox.set_end_widget`.
/// To add children to `GtkCenterBox`, use [method@Gtk.CenterBox.set_start_widget],
/// [method@Gtk.CenterBox.set_center_widget] and
/// [method@Gtk.CenterBox.set_end_widget].
///
/// The sizing and positioning of children can be influenced with the
/// align and expand properties of the children.
///
/// # GtkCenterBox as GtkBuildable
///
/// The `GtkCenterBox` implementation of the `GtkBuildable` interface
/// supports placing children in the 3 positions by specifying start, center
/// or end as the type attribute of a `<child>` element.
///
/// # CSS nodes
///
/// `GtkCenterBox` uses a single CSS node with the name box,
///
/// The first child of the `GtkCenterBox` will be allocated depending on the
/// text direction, i.e. in left-to-right layouts it will be allocated on the
/// left and in right-to-left layouts on the right.
///
/// In vertical orientation, the nodes of the children are arranged from top to
/// bottom.
///
/// # Accessibility
///
/// Until GTK 4.10, `GtkCenterBox` used the [enum@Gtk.AccessibleRole.group] role.
///
/// Starting from GTK 4.12, `GtkCenterBox` uses the [enum@Gtk.AccessibleRole.generic]
/// role.
public struct CenterBox: AdwaitaWidget {
#if exposeGeneratedAppearUpdateFunctions
/// Additional update functions for type extensions.
public var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
public var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#else
/// Additional update functions for type extensions.
var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#endif
/// The accessible role of the given `GtkAccessible` implementation.
///
/// The accessible role cannot be changed once set.
var accessibleRole: String?
/// The widget that is placed at the center position.
var centerWidget: Body?
var centerWidget: (() -> Body)?
/// The widget that is placed at the end position.
///
/// In vertical orientation, the end position is at the bottom.
/// In horizontal orientation, the end position is at the trailing
/// edge with respect to the text direction.
var endWidget: Body?
var endWidget: (() -> Body)?
/// Whether to shrink the center widget after other children.
///
/// By default, when there's no space to give all three children their
@ -61,7 +76,7 @@ public struct CenterBox: AdwaitaWidget {
/// In vertical orientation, the start position is at the top.
/// In horizontal orientation, the start position is at the leading
/// edge with respect to the text direction.
var startWidget: Body?
var startWidget: (() -> Body)?
/// Initialize `CenterBox`.
public init() {
@ -77,15 +92,16 @@ public struct CenterBox: AdwaitaWidget {
for function in appearFunctions {
function(storage, data)
}
if let centerWidgetStorage = centerWidget?.storage(data: data, type: type) {
update(storage, data: data, updateProperties: true, type: type)
if let centerWidgetStorage = centerWidget?().storage(data: data, type: type) {
storage.content["centerWidget"] = [centerWidgetStorage]
gtk_center_box_set_center_widget(storage.opaquePointer, centerWidgetStorage.opaquePointer?.cast())
}
if let endWidgetStorage = endWidget?.storage(data: data, type: type) {
if let endWidgetStorage = endWidget?().storage(data: data, type: type) {
storage.content["endWidget"] = [endWidgetStorage]
gtk_center_box_set_end_widget(storage.opaquePointer, endWidgetStorage.opaquePointer?.cast())
}
if let startWidgetStorage = startWidget?.storage(data: data, type: type) {
if let startWidgetStorage = startWidget?().storage(data: data, type: type) {
storage.content["startWidget"] = [startWidgetStorage]
gtk_center_box_set_start_widget(storage.opaquePointer, startWidgetStorage.opaquePointer?.cast())
}
@ -103,16 +119,16 @@ public struct CenterBox: AdwaitaWidget {
storage.modify { widget in
if let widget = storage.content["centerWidget"]?.first {
centerWidget?.updateStorage(widget, data: data, updateProperties: updateProperties, type: type)
centerWidget?().updateStorage(widget, data: data, updateProperties: updateProperties, type: type)
}
if let widget = storage.content["endWidget"]?.first {
endWidget?.updateStorage(widget, data: data, updateProperties: updateProperties, type: type)
endWidget?().updateStorage(widget, data: data, updateProperties: updateProperties, type: type)
}
if let shrinkCenterLast, updateProperties, (storage.previousState as? Self)?.shrinkCenterLast != shrinkCenterLast {
gtk_center_box_set_shrink_center_last(widget, shrinkCenterLast.cBool)
}
if let widget = storage.content["startWidget"]?.first {
startWidget?.updateStorage(widget, data: data, updateProperties: updateProperties, type: type)
startWidget?().updateStorage(widget, data: data, updateProperties: updateProperties, type: type)
}
@ -130,12 +146,16 @@ public struct CenterBox: AdwaitaWidget {
///
/// The accessible role cannot be changed once set.
public func accessibleRole(_ accessibleRole: String?) -> Self {
modify { $0.accessibleRole = accessibleRole }
var newSelf = self
newSelf.accessibleRole = accessibleRole
return newSelf
}
/// The widget that is placed at the center position.
public func centerWidget(@ViewBuilder _ centerWidget: () -> Body) -> Self {
modify { $0.centerWidget = centerWidget() }
public func centerWidget(@ViewBuilder _ centerWidget: @escaping (() -> Body)) -> Self {
var newSelf = self
newSelf.centerWidget = centerWidget
return newSelf
}
/// The widget that is placed at the end position.
@ -143,8 +163,10 @@ public struct CenterBox: AdwaitaWidget {
/// In vertical orientation, the end position is at the bottom.
/// In horizontal orientation, the end position is at the trailing
/// edge with respect to the text direction.
public func endWidget(@ViewBuilder _ endWidget: () -> Body) -> Self {
modify { $0.endWidget = endWidget() }
public func endWidget(@ViewBuilder _ endWidget: @escaping (() -> Body)) -> Self {
var newSelf = self
newSelf.endWidget = endWidget
return newSelf
}
/// Whether to shrink the center widget after other children.
@ -156,7 +178,9 @@ public struct CenterBox: AdwaitaWidget {
/// If false, start and end widgets keep natural width and the
/// center widget starts shrinking instead.
public func shrinkCenterLast(_ shrinkCenterLast: Bool? = true) -> Self {
modify { $0.shrinkCenterLast = shrinkCenterLast }
var newSelf = self
newSelf.shrinkCenterLast = shrinkCenterLast
return newSelf
}
/// The widget that is placed at the start position.
@ -164,8 +188,10 @@ public struct CenterBox: AdwaitaWidget {
/// In vertical orientation, the start position is at the top.
/// In horizontal orientation, the start position is at the leading
/// edge with respect to the text direction.
public func startWidget(@ViewBuilder _ startWidget: () -> Body) -> Self {
modify { $0.startWidget = startWidget() }
public func startWidget(@ViewBuilder _ startWidget: @escaping (() -> Body)) -> Self {
var newSelf = self
newSelf.startWidget = startWidget
return newSelf
}
}

View File

@ -2,7 +2,7 @@
// CheckButton.swift
// Adwaita
//
// Created by auto-generation on 04.02.26.
// Created by auto-generation on 19.04.25.
//
import CAdw
@ -10,29 +10,73 @@ import LevenshteinTransformations
/// Places a label next to an indicator.
///
/// <picture><source srcset="check-button-dark.png" media="(prefers-color-scheme: dark)"><img alt="Example GtkCheckButtons" src="check-button.png"></picture>
///
///
/// A `GtkCheckButton` is created by calling either `Gtk.CheckButton.new`
/// or `Gtk.CheckButton.new_with_label`.
/// A `GtkCheckButton` is created by calling either [ctor@Gtk.CheckButton.new]
/// or [ctor@Gtk.CheckButton.new_with_label].
///
/// The state of a `GtkCheckButton` can be set specifically using
/// `Gtk.CheckButton.set_active`, and retrieved using
/// `Gtk.CheckButton.get_active`.
/// [method@Gtk.CheckButton.set_active], and retrieved using
/// [method@Gtk.CheckButton.get_active].
///
/// # Inconsistent state
///
/// In addition to "on" and "off", check buttons can be an
/// "in between" state that is neither on nor off. This can be used
/// e.g. when the user has selected a range of elements (such as some
/// text or spreadsheet cells) that are affected by a check button,
/// and the current values in that range are inconsistent.
///
/// To set a `GtkCheckButton` to inconsistent state, use
/// [method@Gtk.CheckButton.set_inconsistent].
///
/// # Grouping
///
/// Check buttons can be grouped together, to form mutually exclusive
/// groups - only one of the buttons can be toggled at a time, and toggling
/// another one will switch the currently toggled one off.
///
/// Grouped check buttons use a different indicator, and are commonly referred
/// to as *radio buttons*.
///
/// <picture><source srcset="radio-button-dark.png" media="(prefers-color-scheme: dark)"><img alt="Example GtkRadioButtons" src="radio-button.png"></picture>
///
/// To add a `GtkCheckButton` to a group, use [method@Gtk.CheckButton.set_group].
///
/// When the code must keep track of the state of a group of radio buttons, it
/// is recommended to keep track of such state through a stateful
/// `GAction` with a target for each button. Using the `toggled` signals to keep
/// track of the group changes and state is discouraged.
///
/// # Shortcuts and Gestures
///
/// `GtkCheckButton` supports the following keyboard shortcuts:
///
/// - <kbd></kbd> or <kbd>Enter</kbd> activates the button.
///
/// # CSS nodes
///
/// ```
/// checkbutton[.text-button][.grouped]
/// check
/// [label]
/// ```
///
/// A `GtkCheckButton` has a main node with name checkbutton. If the
/// [property@Gtk.CheckButton:label] or [property@Gtk.CheckButton:child]
/// properties are set, it contains a child widget. The indicator node
/// is named check when no group is set, and radio if the checkbutton
/// is grouped together with other checkbuttons.
///
/// # Accessibility
///
/// `GtkCheckButton` uses the [enum@Gtk.AccessibleRole.checkbox] role.
public struct CheckButton: AdwaitaWidget {
#if exposeGeneratedAppearUpdateFunctions
/// Additional update functions for type extensions.
public var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
public var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#else
/// Additional update functions for type extensions.
var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#endif
/// The accessible role of the given `GtkAccessible` implementation.
///
@ -42,11 +86,11 @@ public struct CheckButton: AdwaitaWidget {
var actionName: String?
/// If the check button is active.
///
/// Setting `active` to `true` will add the `:checked:` state to both
/// Setting `active` to %TRUE will add the `:checked:` state to both
/// the check button and the indicator CSS node.
var active: Binding<Bool>?
/// The child widget.
var child: Body?
var child: (() -> Body)?
/// If the check button is in an in between state.
///
/// The inconsistent state only affects visual appearance,
@ -63,12 +107,12 @@ public struct CheckButton: AdwaitaWidget {
/// emitting it causes the button to animate press then release.
///
/// Applications should never connect to this signal, but use the
/// `Gtk.CheckButton::toggled` signal.
/// [signal@Gtk.CheckButton::toggled] signal.
///
/// The default bindings for this signal are all forms of the
/// <kbd></kbd> and <kbd>Enter</kbd> keys.
var activate: (() -> Void)?
/// Emitted when the buttons's ``active(_:)``
/// Emitted when the buttons's [property@Gtk.CheckButton:active]
/// property changes.
var toggled: (() -> Void)?
@ -86,7 +130,8 @@ public struct CheckButton: AdwaitaWidget {
for function in appearFunctions {
function(storage, data)
}
if let childStorage = child?.storage(data: data, type: type) {
update(storage, data: data, updateProperties: true, type: type)
if let childStorage = child?().storage(data: data, type: type) {
storage.content["child"] = [childStorage]
gtk_check_button_set_child(storage.opaquePointer?.cast(), childStorage.opaquePointer?.cast())
}
@ -126,7 +171,7 @@ if let active, newValue != active.wrappedValue {
gtk_check_button_set_active(storage.opaquePointer?.cast(), active.wrappedValue.cBool)
}
if let widget = storage.content["child"]?.first {
child?.updateStorage(widget, data: data, updateProperties: updateProperties, type: type)
child?().updateStorage(widget, data: data, updateProperties: updateProperties, type: type)
}
if let inconsistent, updateProperties, (storage.previousState as? Self)?.inconsistent != inconsistent {
gtk_check_button_set_inconsistent(widget?.cast(), inconsistent.cBool)
@ -153,25 +198,33 @@ if let active, newValue != active.wrappedValue {
///
/// The accessible role cannot be changed once set.
public func accessibleRole(_ accessibleRole: String?) -> Self {
modify { $0.accessibleRole = accessibleRole }
var newSelf = self
newSelf.accessibleRole = accessibleRole
return newSelf
}
/// The name of the action with which this widget should be associated.
public func actionName(_ actionName: String?) -> Self {
modify { $0.actionName = actionName }
var newSelf = self
newSelf.actionName = actionName
return newSelf
}
/// If the check button is active.
///
/// Setting `active` to `true` will add the `:checked:` state to both
/// Setting `active` to %TRUE will add the `:checked:` state to both
/// the check button and the indicator CSS node.
public func active(_ active: Binding<Bool>?) -> Self {
modify { $0.active = active }
var newSelf = self
newSelf.active = active
return newSelf
}
/// The child widget.
public func child(@ViewBuilder _ child: () -> Body) -> Self {
modify { $0.child = child() }
public func child(@ViewBuilder _ child: @escaping (() -> Body)) -> Self {
var newSelf = self
newSelf.child = child
return newSelf
}
/// If the check button is in an in between state.
@ -179,18 +232,24 @@ if let active, newValue != active.wrappedValue {
/// The inconsistent state only affects visual appearance,
/// not the semantics of the button.
public func inconsistent(_ inconsistent: Bool? = true) -> Self {
modify { $0.inconsistent = inconsistent }
var newSelf = self
newSelf.inconsistent = inconsistent
return newSelf
}
/// Text of the label inside the check button, if it contains a label widget.
public func label(_ label: String?) -> Self {
modify { $0.label = label }
var newSelf = self
newSelf.label = label
return newSelf
}
/// If set, an underline in the text indicates that the following
/// character is to be used as mnemonic.
public func useUnderline(_ useUnderline: Bool? = true) -> Self {
modify { $0.useUnderline = useUnderline }
var newSelf = self
newSelf.useUnderline = useUnderline
return newSelf
}
/// Emitted to when the check button is activated.
@ -199,7 +258,7 @@ if let active, newValue != active.wrappedValue {
/// emitting it causes the button to animate press then release.
///
/// Applications should never connect to this signal, but use the
/// `Gtk.CheckButton::toggled` signal.
/// [signal@Gtk.CheckButton::toggled] signal.
///
/// The default bindings for this signal are all forms of the
/// <kbd></kbd> and <kbd>Enter</kbd> keys.
@ -209,7 +268,7 @@ if let active, newValue != active.wrappedValue {
return newSelf
}
/// Emitted when the buttons's ``active(_:)``
/// Emitted when the buttons's [property@Gtk.CheckButton:active]
/// property changes.
public func toggled(_ toggled: @escaping () -> Void) -> Self {
var newSelf = self

View File

@ -2,7 +2,7 @@
// Clamp.swift
// Adwaita
//
// Created by auto-generation on 04.02.26.
// Created by auto-generation on 19.04.25.
//
import CAdw
@ -10,7 +10,7 @@ import LevenshteinTransformations
/// A widget constraining its child to a given size.
///
///
/// <picture><source srcset="clamp-wide-dark.png" media="(prefers-color-scheme: dark)"><img src="clamp-wide.png" alt="clamp-wide"></picture><picture><source srcset="clamp-narrow-dark.png" media="(prefers-color-scheme: dark)"><img src="clamp-narrow.png" alt="clamp-narrow"></picture>
///
/// The `AdwClamp` widget constrains the size of the widget it contains to a
/// given maximum size. It will constrain the width if it is horizontal, or the
@ -21,27 +21,22 @@ import LevenshteinTransformations
/// allocated the minimum size it can fit in instead.
///
/// `AdwClamp` can scale with the text scale factor, use the
/// ``unit(_:)`` property to enable that behavior.
/// [property@Clamp:unit] property to enable that behavior.
///
/// See also: `ClampLayout`, `ClampScrollable`.
/// See also: [class@ClampLayout], [class@ClampScrollable].
///
/// ## CSS nodes
///
/// `AdwClamp` has a single CSS node with name `clamp`.
public struct Clamp: AdwaitaWidget {
#if exposeGeneratedAppearUpdateFunctions
/// Additional update functions for type extensions.
public var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
public var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#else
/// Additional update functions for type extensions.
var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#endif
/// The child widget of the `AdwClamp`.
var child: Body?
var child: (() -> Body)?
/// The maximum size allocated to the child.
///
/// It is the width if the clamp is horizontal, or the height if it is vertical.
@ -76,7 +71,8 @@ public struct Clamp: AdwaitaWidget {
for function in appearFunctions {
function(storage, data)
}
if let childStorage = child?.storage(data: data, type: type) {
update(storage, data: data, updateProperties: true, type: type)
if let childStorage = child?().storage(data: data, type: type) {
storage.content["child"] = [childStorage]
adw_clamp_set_child(storage.opaquePointer, childStorage.opaquePointer?.cast())
}
@ -94,7 +90,7 @@ public struct Clamp: AdwaitaWidget {
storage.modify { widget in
if let widget = storage.content["child"]?.first {
child?.updateStorage(widget, data: data, updateProperties: updateProperties, type: type)
child?().updateStorage(widget, data: data, updateProperties: updateProperties, type: type)
}
if let maximumSize, updateProperties, (storage.previousState as? Self)?.maximumSize != maximumSize {
adw_clamp_set_maximum_size(widget, maximumSize.cInt)
@ -115,15 +111,19 @@ public struct Clamp: AdwaitaWidget {
}
/// The child widget of the `AdwClamp`.
public func child(@ViewBuilder _ child: () -> Body) -> Self {
modify { $0.child = child() }
public func child(@ViewBuilder _ child: @escaping (() -> Body)) -> Self {
var newSelf = self
newSelf.child = child
return newSelf
}
/// The maximum size allocated to the child.
///
/// It is the width if the clamp is horizontal, or the height if it is vertical.
public func maximumSize(_ maximumSize: Int?) -> Self {
modify { $0.maximumSize = maximumSize }
var newSelf = self
newSelf.maximumSize = maximumSize
return newSelf
}
/// The size above which the child is clamped.
@ -141,7 +141,9 @@ public struct Clamp: AdwaitaWidget {
/// Effectively, tightening the grip on the child before it reaches its maximum
/// size makes transitions to and from the maximum size smoother when resizing.
public func tighteningThreshold(_ tighteningThreshold: Int?) -> Self {
modify { $0.tighteningThreshold = tighteningThreshold }
var newSelf = self
newSelf.tighteningThreshold = tighteningThreshold
return newSelf
}
}

View File

@ -2,15 +2,15 @@
// ComboRow.swift
// Adwaita
//
// Created by auto-generation on 04.02.26.
// Created by auto-generation on 19.04.25.
//
import CAdw
import LevenshteinTransformations
/// A `Gtk.ListBoxRow` used to choose from a list of items.
///
/// A [class@Gtk.ListBoxRow] used to choose from a list of items.
///
/// <picture><source srcset="combo-row-dark.png" media="(prefers-color-scheme: dark)"><img src="combo-row.png" alt="combo-row"></picture>
///
/// The `AdwComboRow` widget allows the user to choose from a list of valid
/// choices. The row displays the selected choice. When activated, the row
@ -21,55 +21,59 @@ import LevenshteinTransformations
/// <object class="AdwComboRow"><property name="title" translatable="yes">Combo Row</property><property name="model"><object class="GtkStringList"><items><item translatable="yes">Foo</item><item translatable="yes">Bar</item><item translatable="yes">Baz</item></items></object></property></object>
/// ```
///
/// The ``selected(_:)`` and ``selectedItem(_:)``
/// The [property@ComboRow:selected] and [property@ComboRow:selected-item]
/// properties can be used to keep track of the selected item and react to their
/// changes.
///
/// `AdwComboRow` mirrors `Gtk.DropDown`, see that widget for details.
/// `AdwComboRow` mirrors [class@Gtk.DropDown], see that widget for details.
///
/// `AdwComboRow` is ``activatable(_:)`` if a model is set.
/// `AdwComboRow` is [property@Gtk.ListBoxRow:activatable] if a model is set.
///
/// ## CSS nodes
///
/// `AdwComboRow` has a main CSS node with name `row` and the `.combo` style
/// class.
///
/// Its popover has the node named `popover` with the `.menu` style class, it
/// contains a [class@Gtk.ScrolledWindow], which in turn contains a
/// [class@Gtk.ListView], both are accessible via their regular nodes.
///
/// ## Accessibility
///
/// `AdwComboRow` uses the `GTK_ACCESSIBLE_ROLE_COMBO_BOX` role.
public struct ComboRow: AdwaitaWidget {
#if exposeGeneratedAppearUpdateFunctions
/// Additional update functions for type extensions.
public var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
public var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#else
/// Additional update functions for type extensions.
var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#endif
/// The widget to activate when the row is activated.
///
/// The row can be activated either by clicking on it, calling
/// `ActionRow.activate`, or via mnemonics in the title.
/// See the ``useUnderline(_:)`` property to enable
/// [method@ActionRow.activate], or via mnemonics in the title.
/// See the [property@PreferencesRow:use-underline] property to enable
/// mnemonics.
///
/// The target widget will be activated by emitting the
/// `Gtk.Widget::mnemonic-activate` signal on it.
var activatableWidget: Body?
/// [signal@Gtk.Widget::mnemonic-activate] signal on it.
var activatableWidget: (() -> Body)?
/// Whether to show a search entry in the popup.
///
/// If set to `true`, a search entry will be shown in the popup that
/// If set to `TRUE`, a search entry will be shown in the popup that
/// allows to search for items in the list.
///
/// Search requires ``expression(_:)`` to be set.
/// Search requires [property@ComboRow:expression] to be set.
var enableSearch: Bool?
/// The position of the selected item.
///
/// If no item is selected, the property has the value
/// `Gtk.INVALID_LIST_POSITION`
/// [const@Gtk.INVALID_LIST_POSITION]
var selected: Binding<UInt>?
/// The subtitle for this row.
///
/// The subtitle is interpreted as Pango markup unless
/// ``useMarkup(_:)`` is set to `false`.
/// [property@PreferencesRow:use-markup] is set to `FALSE`.
var subtitle: String?
/// The number of lines at the end of which the subtitle label will be
/// ellipsized.
@ -78,12 +82,12 @@ public struct ComboRow: AdwaitaWidget {
var subtitleLines: Int?
/// Whether the user can copy the subtitle from the label.
///
/// See also ``selectable(_:)``.
/// See also [property@Gtk.Label:selectable].
var subtitleSelectable: Bool?
/// The title of the preference represented by this row.
///
/// The title is interpreted as Pango markup unless
/// ``useMarkup(_:)`` is set to `false`.
/// [property@PreferencesRow:use-markup] is set to `FALSE`.
var title: String?
/// The number of lines at the end of which the title label will be ellipsized.
///
@ -91,23 +95,23 @@ public struct ComboRow: AdwaitaWidget {
var titleLines: Int?
/// Whether the user can copy the title from the label.
///
/// See also ``selectable(_:)``.
/// See also [property@Gtk.Label:selectable].
var titleSelectable: Bool?
/// Whether to use Pango markup for the title label.
///
/// Subclasses may also use it for other labels, such as subtitle.
///
/// See also `Pango.parse_markup`.
/// See also [func@Pango.parse_markup].
var useMarkup: Bool?
/// Whether to use the current value as the subtitle.
///
/// If you use a custom list item factory, you will need to give the row a
/// name conversion expression with ``expression(_:)``.
/// name conversion expression with [property@ComboRow:expression].
///
/// If set to `true`, you should not access ``subtitle(_:)``.
/// If set to `TRUE`, you should not access [property@ActionRow:subtitle].
///
/// The subtitle is interpreted as Pango markup if
/// ``useMarkup(_:)`` is set to `true`.
/// [property@PreferencesRow:use-markup] is set to `TRUE`.
var useSubtitle: Bool?
/// Whether an embedded underline in the title indicates a mnemonic.
var useUnderline: Bool?
@ -119,7 +123,7 @@ public struct ComboRow: AdwaitaWidget {
var prefix: () -> Body = { [] }
/// Initialize `ComboRow`.
init() {
public init() {
}
/// The view storage.
@ -132,7 +136,8 @@ public struct ComboRow: AdwaitaWidget {
for function in appearFunctions {
function(storage, data)
}
if let activatableWidgetStorage = activatableWidget?.storage(data: data, type: type) {
update(storage, data: data, updateProperties: true, type: type)
if let activatableWidgetStorage = activatableWidget?().storage(data: data, type: type) {
storage.content["activatableWidget"] = [activatableWidgetStorage]
adw_action_row_set_activatable_widget(storage.opaquePointer?.cast(), activatableWidgetStorage.opaquePointer?.cast())
}
@ -173,7 +178,7 @@ if let selected, newValue != selected.wrappedValue {
}
}
if let widget = storage.content["activatableWidget"]?.first {
activatableWidget?.updateStorage(widget, data: data, updateProperties: updateProperties, type: type)
activatableWidget?().updateStorage(widget, data: data, updateProperties: updateProperties, type: type)
}
if let enableSearch, updateProperties, (storage.previousState as? Self)?.enableSearch != enableSearch {
adw_combo_row_set_enable_search(widget?.cast(), enableSearch.cBool)
@ -223,40 +228,48 @@ if let selected, newValue != selected.wrappedValue {
/// The widget to activate when the row is activated.
///
/// The row can be activated either by clicking on it, calling
/// `ActionRow.activate`, or via mnemonics in the title.
/// See the ``useUnderline(_:)`` property to enable
/// [method@ActionRow.activate], or via mnemonics in the title.
/// See the [property@PreferencesRow:use-underline] property to enable
/// mnemonics.
///
/// The target widget will be activated by emitting the
/// `Gtk.Widget::mnemonic-activate` signal on it.
public func activatableWidget(@ViewBuilder _ activatableWidget: () -> Body) -> Self {
modify { $0.activatableWidget = activatableWidget() }
/// [signal@Gtk.Widget::mnemonic-activate] signal on it.
public func activatableWidget(@ViewBuilder _ activatableWidget: @escaping (() -> Body)) -> Self {
var newSelf = self
newSelf.activatableWidget = activatableWidget
return newSelf
}
/// Whether to show a search entry in the popup.
///
/// If set to `true`, a search entry will be shown in the popup that
/// If set to `TRUE`, a search entry will be shown in the popup that
/// allows to search for items in the list.
///
/// Search requires ``expression(_:)`` to be set.
/// Search requires [property@ComboRow:expression] to be set.
public func enableSearch(_ enableSearch: Bool? = true) -> Self {
modify { $0.enableSearch = enableSearch }
var newSelf = self
newSelf.enableSearch = enableSearch
return newSelf
}
/// The position of the selected item.
///
/// If no item is selected, the property has the value
/// `Gtk.INVALID_LIST_POSITION`
/// [const@Gtk.INVALID_LIST_POSITION]
public func selected(_ selected: Binding<UInt>?) -> Self {
modify { $0.selected = selected }
var newSelf = self
newSelf.selected = selected
return newSelf
}
/// The subtitle for this row.
///
/// The subtitle is interpreted as Pango markup unless
/// ``useMarkup(_:)`` is set to `false`.
/// [property@PreferencesRow:use-markup] is set to `FALSE`.
public func subtitle(_ subtitle: String?) -> Self {
modify { $0.subtitle = subtitle }
var newSelf = self
newSelf.subtitle = subtitle
return newSelf
}
/// The number of lines at the end of which the subtitle label will be
@ -264,63 +277,79 @@ if let selected, newValue != selected.wrappedValue {
///
/// If the value is 0, the number of lines won't be limited.
public func subtitleLines(_ subtitleLines: Int?) -> Self {
modify { $0.subtitleLines = subtitleLines }
var newSelf = self
newSelf.subtitleLines = subtitleLines
return newSelf
}
/// Whether the user can copy the subtitle from the label.
///
/// See also ``selectable(_:)``.
/// See also [property@Gtk.Label:selectable].
public func subtitleSelectable(_ subtitleSelectable: Bool? = true) -> Self {
modify { $0.subtitleSelectable = subtitleSelectable }
var newSelf = self
newSelf.subtitleSelectable = subtitleSelectable
return newSelf
}
/// The title of the preference represented by this row.
///
/// The title is interpreted as Pango markup unless
/// ``useMarkup(_:)`` is set to `false`.
/// [property@PreferencesRow:use-markup] is set to `FALSE`.
public func title(_ title: String?) -> Self {
modify { $0.title = title }
var newSelf = self
newSelf.title = title
return newSelf
}
/// The number of lines at the end of which the title label will be ellipsized.
///
/// If the value is 0, the number of lines won't be limited.
public func titleLines(_ titleLines: Int?) -> Self {
modify { $0.titleLines = titleLines }
var newSelf = self
newSelf.titleLines = titleLines
return newSelf
}
/// Whether the user can copy the title from the label.
///
/// See also ``selectable(_:)``.
/// See also [property@Gtk.Label:selectable].
public func titleSelectable(_ titleSelectable: Bool? = true) -> Self {
modify { $0.titleSelectable = titleSelectable }
var newSelf = self
newSelf.titleSelectable = titleSelectable
return newSelf
}
/// Whether to use Pango markup for the title label.
///
/// Subclasses may also use it for other labels, such as subtitle.
///
/// See also `Pango.parse_markup`.
/// See also [func@Pango.parse_markup].
public func useMarkup(_ useMarkup: Bool? = true) -> Self {
modify { $0.useMarkup = useMarkup }
var newSelf = self
newSelf.useMarkup = useMarkup
return newSelf
}
/// Whether to use the current value as the subtitle.
///
/// If you use a custom list item factory, you will need to give the row a
/// name conversion expression with ``expression(_:)``.
/// name conversion expression with [property@ComboRow:expression].
///
/// If set to `true`, you should not access ``subtitle(_:)``.
/// If set to `TRUE`, you should not access [property@ActionRow:subtitle].
///
/// The subtitle is interpreted as Pango markup if
/// ``useMarkup(_:)`` is set to `true`.
/// [property@PreferencesRow:use-markup] is set to `TRUE`.
public func useSubtitle(_ useSubtitle: Bool? = true) -> Self {
modify { $0.useSubtitle = useSubtitle }
var newSelf = self
newSelf.useSubtitle = useSubtitle
return newSelf
}
/// Whether an embedded underline in the title indicates a mnemonic.
public func useUnderline(_ useUnderline: Bool? = true) -> Self {
modify { $0.useUnderline = useUnderline }
var newSelf = self
newSelf.useUnderline = useUnderline
return newSelf
}
/// This signal is emitted after the row has been activated.

View File

@ -2,7 +2,7 @@
// DropDown.swift
// Adwaita
//
// Created by auto-generation on 04.02.26.
// Created by auto-generation on 19.04.25.
//
import CAdw
@ -10,27 +10,27 @@ import LevenshteinTransformations
/// Allows the user to choose an item from a list of options.
///
/// <picture><source srcset="drop-down-dark.png" media="(prefers-color-scheme: dark)"><img alt="An example GtkDropDown" src="drop-down.png"></picture>
///
///
/// The `GtkDropDown` displays the [selected]``selected(_:)``
/// The `GtkDropDown` displays the [selected][property@Gtk.DropDown:selected]
/// choice.
///
/// The options are given to `GtkDropDown` in the form of `GListModel`
/// and how the individual options are represented is determined by
/// a `Gtk.ListItemFactory`. The default factory displays simple strings,
/// a [class@Gtk.ListItemFactory]. The default factory displays simple strings,
/// and adds a checkmark to the selected item in the popup.
///
/// To set your own factory, use `Gtk.DropDown.set_factory`. It is
/// To set your own factory, use [method@Gtk.DropDown.set_factory]. It is
/// possible to use a separate factory for the items in the popup, with
/// `Gtk.DropDown.set_list_factory`.
/// [method@Gtk.DropDown.set_list_factory].
///
/// `GtkDropDown` knows how to obtain strings from the items in a
/// `Gtk.StringList`; for other models, you have to provide an expression
/// to find the strings via `Gtk.DropDown.set_expression`.
/// [class@Gtk.StringList]; for other models, you have to provide an expression
/// to find the strings via [method@Gtk.DropDown.set_expression].
///
/// `GtkDropDown` can optionally allow search in the popup, which is
/// useful if the list of options is long. To enable the search entry,
/// use `Gtk.DropDown.set_enable_search`.
/// use [method@Gtk.DropDown.set_enable_search].
///
/// Here is a UI definition example for `GtkDropDown` with a simple model:
///
@ -39,26 +39,26 @@ import LevenshteinTransformations
/// ```
///
/// If a `GtkDropDown` is created in this manner, or with
/// `Gtk.DropDown.new_from_strings`, for instance, the object returned from
/// `Gtk.DropDown.get_selected_item` will be a `Gtk.StringObject`.
/// [ctor@Gtk.DropDown.new_from_strings], for instance, the object returned from
/// [method@Gtk.DropDown.get_selected_item] will be a [class@Gtk.StringObject].
///
/// To learn more about the list widget framework, see the
/// [overview](section-list-widget.html).
///
/// ## CSS nodes
///
/// `GtkDropDown` has a single CSS node with name dropdown,
/// with the button and popover nodes as children.
///
/// ## Accessibility
///
/// `GtkDropDown` uses the [enum@Gtk.AccessibleRole.combo_box] role.
public struct DropDown: AdwaitaWidget {
#if exposeGeneratedAppearUpdateFunctions
/// Additional update functions for type extensions.
public var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
public var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#else
/// Additional update functions for type extensions.
var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#endif
/// The accessible role of the given `GtkAccessible` implementation.
///
@ -66,7 +66,7 @@ public struct DropDown: AdwaitaWidget {
var accessibleRole: String?
/// Whether to show a search entry in the popup.
///
/// Note that search requires ``expression(_:)``
/// Note that search requires [property@Gtk.DropDown:expression]
/// to be set.
var enableSearch: Bool?
/// The position of the selected item.
@ -83,7 +83,7 @@ public struct DropDown: AdwaitaWidget {
var activate: (() -> Void)?
/// Initialize `DropDown`.
init() {
public init() {
}
/// The view storage.
@ -96,6 +96,7 @@ public struct DropDown: AdwaitaWidget {
for function in appearFunctions {
function(storage, data)
}
update(storage, data: data, updateProperties: true, type: type)
return storage
}
@ -145,15 +146,19 @@ if let selected, newValue != selected.wrappedValue {
///
/// The accessible role cannot be changed once set.
public func accessibleRole(_ accessibleRole: String?) -> Self {
modify { $0.accessibleRole = accessibleRole }
var newSelf = self
newSelf.accessibleRole = accessibleRole
return newSelf
}
/// Whether to show a search entry in the popup.
///
/// Note that search requires ``expression(_:)``
/// Note that search requires [property@Gtk.DropDown:expression]
/// to be set.
public func enableSearch(_ enableSearch: Bool? = true) -> Self {
modify { $0.enableSearch = enableSearch }
var newSelf = self
newSelf.enableSearch = enableSearch
return newSelf
}
/// The position of the selected item.
@ -161,12 +166,16 @@ if let selected, newValue != selected.wrappedValue {
/// If no item is selected, the property has the value
/// %GTK_INVALID_LIST_POSITION.
public func selected(_ selected: Binding<UInt>?) -> Self {
modify { $0.selected = selected }
var newSelf = self
newSelf.selected = selected
return newSelf
}
/// Whether to show an arrow within the GtkDropDown widget.
public func showArrow(_ showArrow: Bool? = true) -> Self {
modify { $0.showArrow = showArrow }
var newSelf = self
newSelf.showArrow = showArrow
return newSelf
}
/// Emitted to when the drop down is activated.

View File

@ -2,7 +2,7 @@
// Entry.swift
// Adwaita
//
// Created by auto-generation on 04.02.26.
// Created by auto-generation on 19.04.25.
//
import CAdw
@ -10,33 +10,33 @@ import LevenshteinTransformations
/// A single-line text entry widget.
///
///
/// <picture><source srcset="entry-dark.png" media="(prefers-color-scheme: dark)"><img alt="An example GtkEntry" src="entry.png"></picture>
///
/// A fairly large set of key bindings are supported by default. If the
/// entered text is longer than the allocation of the widget, the widget
/// will scroll so that the cursor position is visible.
///
/// When using an entry for passwords and other sensitive information, it
/// can be put into password mode using `Gtk.Entry.set_visibility`.
/// can be put into password mode using [method@Gtk.Entry.set_visibility].
/// In this mode, entered text is displayed using a invisible character.
/// By default, GTK picks the best invisible character that is available
/// in the current font, but it can be changed with
/// `Gtk.Entry.set_invisible_char`.
/// [method@Gtk.Entry.set_invisible_char].
///
/// `GtkEntry` has the ability to display progress or activity
/// information behind the text. To make an entry display such information,
/// use `Gtk.Entry.set_progress_fraction` or
/// `Gtk.Entry.set_progress_pulse_step`.
/// use [method@Gtk.Entry.set_progress_fraction] or
/// [method@Gtk.Entry.set_progress_pulse_step].
///
/// Additionally, `GtkEntry` can show icons at either side of the entry.
/// These icons can be activatable by clicking, can be set up as drag source
/// and can have tooltips. To add an icon, use
/// `Gtk.Entry.set_icon_from_gicon` or one of the various other functions
/// [method@Gtk.Entry.set_icon_from_gicon] or one of the various other functions
/// that set an icon from an icon name or a paintable. To trigger an action when
/// the user clicks an icon, connect to the `Gtk.Entry::icon-press` signal.
/// the user clicks an icon, connect to the [signal@Gtk.Entry::icon-press] signal.
/// To allow DND operations from an icon, use
/// `Gtk.Entry.set_icon_drag_source`. To set a tooltip on an icon, use
/// `Gtk.Entry.set_icon_tooltip_text` or the corresponding function
/// [method@Gtk.Entry.set_icon_drag_source]. To set a tooltip on an icon, use
/// [method@Gtk.Entry.set_icon_tooltip_text] or the corresponding function
/// for markup.
///
/// Note that functionality or information that is only available by clicking
@ -45,20 +45,57 @@ import LevenshteinTransformations
/// that any such functionality should also be available by other means, e.g.
/// via the context menu of the entry.
///
/// # CSS nodes
///
/// ```
/// entry[.flat][.warning][.error]
/// text[.readonly]
/// image.left
/// image.right
/// [progress[.pulse]]
/// ```
///
/// `GtkEntry` has a main node with the name entry. Depending on the properties
/// of the entry, the style classes .read-only and .flat may appear. The style
/// classes .warning and .error may also be used with entries.
///
/// When the entry shows icons, it adds subnodes with the name image and the
/// style class .left or .right, depending on where the icon appears.
///
/// When the entry shows progress, it adds a subnode with the name progress.
/// The node has the style class .pulse when the shown progress is pulsing.
///
/// For all the subnodes added to the text node in various situations,
/// see [class@Gtk.Text].
///
/// # GtkEntry as GtkBuildable
///
/// The `GtkEntry` implementation of the `GtkBuildable` interface supports a
/// custom `<attributes>` element, which supports any number of `<attribute>`
/// elements. The `<attribute>` element has attributes named name, value,
/// start and end and allows you to specify `PangoAttribute` values for
/// this label.
///
/// An example of a UI definition fragment specifying Pango attributes:
/// ```xml
/// <object class="GtkEntry"><attributes><attribute name="weight" value="PANGO_WEIGHT_BOLD"/><attribute name="background" value="red" start="5" end="10"/></attributes></object>
/// ```
///
/// The start and end attributes specify the range of characters to which the
/// Pango attribute applies. If start and end are not specified, the attribute
/// is applied to the whole text. Note that specifying ranges does not make much
/// sense with translatable attributes. Use markup embedded in the translatable
/// content instead.
///
/// # Accessibility
///
/// `GtkEntry` uses the [enum@Gtk.AccessibleRole.text_box] role.
public struct Entry: AdwaitaWidget {
#if exposeGeneratedAppearUpdateFunctions
/// Additional update functions for type extensions.
public var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
public var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#else
/// Additional update functions for type extensions.
var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#endif
/// The accessible role of the given `GtkAccessible` implementation.
///
@ -76,15 +113,15 @@ public struct Entry: AdwaitaWidget {
/// If undo/redo should be enabled for the editable.
var enableUndo: Bool?
/// A menu model whose contents will be appended to the context menu.
var extraMenu: Body?
var extraMenu: (() -> Body)?
/// Whether the entry should draw a frame.
var hasFrame: Bool?
/// Which IM (input method) module should be used for this entry.
///
/// See `Gtk.IMContext`.
/// See [class@Gtk.IMContext].
///
/// Setting this to a non-%NULL value overrides the system-wide IM
/// module setting. See the GtkSettings ``gtkImModule(_:)``
/// module setting. See the GtkSettings [property@Gtk.Settings:gtk-im-module]
/// property.
var imModule: String?
/// The character to use when masking entry contents (password mode).
@ -95,32 +132,6 @@ public struct Entry: AdwaitaWidget {
var maxLength: Int?
/// The desired maximum width of the entry, in characters.
var maxWidthChars: Int?
/// Text for an item in the context menu to activate the primary icon action.
///
/// When the primary icon is activatable and this property has been set, a new entry
/// in the context menu of this GtkEntry will appear with this text. Selecting that
/// menu entry will result in the primary icon being activated, exactly in the same way
/// as it would be activated from a mouse click.
///
/// This simplifies adding accessibility support to applications using activatable
/// icons. The activatable icons aren't focusable when navigating the interface with
/// the keyboard This is why Gtk recommends to also add those actions in the context
/// menu. This set of methods greatly simplifies this, by adding a menu item that, when
/// enabled, calls the same callback than clicking on the icon.
var menuEntryIconPrimaryText: String?
/// Text for an item in the context menu to activate the secondary icon action.
///
/// When the primary icon is activatable and this property has been set, a new entry
/// in the context menu of this GtkEntry will appear with this text. Selecting that
/// menu entry will result in the primary icon being activated, exactly in the same way
/// as it would be activated from a mouse click.
///
/// This simplifies adding accessibility support to applications using activatable
/// icons. The activatable icons aren't focusable when navigating the interface with
/// the keyboard This is why Gtk recommends to also add those actions in the context
/// menu. This set of methods greatly simplifies this, by adding a menu item that, when
/// enabled, calls the same callback than clicking on the icon.
var menuEntryIconSecondaryText: String?
/// If text is overwritten when typing in the `GtkEntry`.
var overwriteMode: Bool?
/// The text that will be displayed in the `GtkEntry` when it is empty
@ -128,8 +139,8 @@ public struct Entry: AdwaitaWidget {
var placeholderText: String?
/// Whether the primary icon is activatable.
///
/// GTK emits the `Gtk.Entry::icon-press` and
/// `Gtk.Entry::icon-release` signals only on sensitive,
/// GTK emits the [signal@Gtk.Entry::icon-press] and
/// [signal@Gtk.Entry::icon-release] signals only on sensitive,
/// activatable icons.
///
/// Sensitive, but non-activatable icons can be used for purely
@ -140,7 +151,7 @@ public struct Entry: AdwaitaWidget {
/// Whether the primary icon is sensitive.
///
/// An insensitive icon appears grayed out. GTK does not emit the
/// `Gtk.Entry::icon-press` and `Gtk.Entry::icon-release`
/// [signal@Gtk.Entry::icon-press] and [signal@Gtk.Entry::icon-release]
/// signals and does not allow DND from insensitive icons.
///
/// An icon should be set insensitive if the action that would trigger
@ -148,25 +159,25 @@ public struct Entry: AdwaitaWidget {
var primaryIconSensitive: Bool?
/// The contents of the tooltip on the primary icon, with markup.
///
/// Also see `Gtk.Entry.set_icon_tooltip_markup`.
/// Also see [method@Gtk.Entry.set_icon_tooltip_markup].
var primaryIconTooltipMarkup: String?
/// The contents of the tooltip on the primary icon.
///
/// Also see `Gtk.Entry.set_icon_tooltip_text`.
/// Also see [method@Gtk.Entry.set_icon_tooltip_text].
var primaryIconTooltipText: String?
/// The current fraction of the task that's been completed.
var progressFraction: Double?
/// The fraction of total entry width to move the progress
/// bouncing block for each pulse.
///
/// See `Gtk.Entry.progress_pulse`.
/// See [method@Gtk.Entry.progress_pulse].
var progressPulseStep: Double?
/// Number of pixels of the entry scrolled off the screen to the left.
var scrollOffset: Int?
/// Whether the secondary icon is activatable.
///
/// GTK emits the `Gtk.Entry::icon-press` and
/// `Gtk.Entry::icon-release` signals only on sensitive,
/// GTK emits the [signal@Gtk.Entry::icon-press] and
/// [signal@Gtk.Entry::icon-release] signals only on sensitive,
/// activatable icons.
///
/// Sensitive, but non-activatable icons can be used for purely
@ -177,7 +188,7 @@ public struct Entry: AdwaitaWidget {
/// Whether the secondary icon is sensitive.
///
/// An insensitive icon appears grayed out. GTK does not emit the
/// `Gtk.Entry::icon-press[ and [signal@Gtk.Entry::icon-release`
/// [signal@Gtk.Entry::icon-press[ and [signal@Gtk.Entry::icon-release]
/// signals and does not allow DND from insensitive icons.
///
/// An icon should be set insensitive if the action that would trigger
@ -185,11 +196,11 @@ public struct Entry: AdwaitaWidget {
var secondaryIconSensitive: Bool?
/// The contents of the tooltip on the secondary icon, with markup.
///
/// Also see `Gtk.Entry.set_icon_tooltip_markup`.
/// Also see [method@Gtk.Entry.set_icon_tooltip_markup].
var secondaryIconTooltipMarkup: String?
/// The contents of the tooltip on the secondary icon.
///
/// Also see `Gtk.Entry.set_icon_tooltip_text`.
/// Also see [method@Gtk.Entry.set_icon_tooltip_text].
var secondaryIconTooltipText: String?
/// The position of the opposite end of the selection from the cursor in chars.
var selectionBound: Int?
@ -200,7 +211,7 @@ public struct Entry: AdwaitaWidget {
var text: Binding<String>?
/// The length of the text in the `GtkEntry`.
var textLength: UInt?
/// When `true`, pasted multi-line text is truncated to the first line.
/// When %TRUE, pasted multi-line text is truncated to the first line.
var truncateMultiline: Bool?
/// Whether the entry should show the invisible char instead of the
/// actual text (password mode).
@ -232,7 +243,7 @@ public struct Entry: AdwaitaWidget {
/// range of deleted text, or prevent it from being deleted entirely.
///
/// The @start_pos and @end_pos parameters are interpreted as for
/// `Gtk.Editable.delete_text`.
/// [method@Gtk.Editable.delete_text].
var deleteText: (() -> Void)?
/// This signal is a sign for the cell renderer to update its
/// value from the @cell_editable.
@ -273,7 +284,7 @@ public struct Entry: AdwaitaWidget {
var removeWidget: (() -> Void)?
/// Initialize `Entry`.
init() {
public init() {
}
/// The view storage.
@ -286,8 +297,9 @@ public struct Entry: AdwaitaWidget {
for function in appearFunctions {
function(storage, data)
}
if let extraMenu {
let childStorage = MenuCollection { extraMenu }.getMenu(data: data)
update(storage, data: data, updateProperties: true, type: type)
if let menu = extraMenu?() {
let childStorage = MenuCollection { menu }.getMenu(data: data)
storage.content["extraMenu"] = [childStorage]
gtk_entry_set_extra_menu(storage.opaquePointer?.cast(), childStorage.opaquePointer?.cast())
}
@ -360,7 +372,7 @@ if let text, newValue != text.wrappedValue {
gtk_editable_set_enable_undo(widget, enableUndo.cBool)
}
if let menu = storage.content["extraMenu"]?.first {
MenuCollection { extraMenu ?? [] }
MenuCollection { extraMenu?() ?? [] }
.updateStorage(menu, data: data.noModifiers, updateProperties: updateProperties, type: MenuContext.self)
}
if let hasFrame, updateProperties, (storage.previousState as? Self)?.hasFrame != hasFrame {
@ -415,265 +427,305 @@ if let text, newValue != text.wrappedValue {
///
/// The accessible role cannot be changed once set.
public func accessibleRole(_ accessibleRole: String?) -> Self {
modify { $0.accessibleRole = accessibleRole }
var newSelf = self
newSelf.accessibleRole = accessibleRole
return newSelf
}
/// The current position of the insertion cursor in chars.
public func cursorPosition(_ cursorPosition: Int?) -> Self {
modify { $0.cursorPosition = cursorPosition }
var newSelf = self
newSelf.cursorPosition = cursorPosition
return newSelf
}
/// Whether the entry contents can be edited.
public func editable(_ editable: Bool? = true) -> Self {
modify { $0.editable = editable }
var newSelf = self
newSelf.editable = editable
return newSelf
}
/// Indicates whether editing on the cell has been canceled.
public func editingCanceled(_ editingCanceled: Bool? = true) -> Self {
modify { $0.editingCanceled = editingCanceled }
var newSelf = self
newSelf.editingCanceled = editingCanceled
return newSelf
}
/// Whether to suggest Emoji replacements for :-delimited names
/// like `:heart:`.
public func enableEmojiCompletion(_ enableEmojiCompletion: Bool? = true) -> Self {
modify { $0.enableEmojiCompletion = enableEmojiCompletion }
var newSelf = self
newSelf.enableEmojiCompletion = enableEmojiCompletion
return newSelf
}
/// If undo/redo should be enabled for the editable.
public func enableUndo(_ enableUndo: Bool? = true) -> Self {
modify { $0.enableUndo = enableUndo }
var newSelf = self
newSelf.enableUndo = enableUndo
return newSelf
}
/// A menu model whose contents will be appended to the context menu.
public func extraMenu(@ViewBuilder _ extraMenu: () -> Body) -> Self {
modify { $0.extraMenu = extraMenu() }
public func extraMenu(@ViewBuilder _ extraMenu: @escaping (() -> Body)) -> Self {
var newSelf = self
newSelf.extraMenu = extraMenu
return newSelf
}
/// Whether the entry should draw a frame.
public func hasFrame(_ hasFrame: Bool? = true) -> Self {
modify { $0.hasFrame = hasFrame }
var newSelf = self
newSelf.hasFrame = hasFrame
return newSelf
}
/// Which IM (input method) module should be used for this entry.
///
/// See `Gtk.IMContext`.
/// See [class@Gtk.IMContext].
///
/// Setting this to a non-%NULL value overrides the system-wide IM
/// module setting. See the GtkSettings ``gtkImModule(_:)``
/// module setting. See the GtkSettings [property@Gtk.Settings:gtk-im-module]
/// property.
public func imModule(_ imModule: String?) -> Self {
modify { $0.imModule = imModule }
var newSelf = self
newSelf.imModule = imModule
return newSelf
}
/// The character to use when masking entry contents (password mode).
public func invisibleCharacter(_ invisibleCharacter: UInt?) -> Self {
modify { $0.invisibleCharacter = invisibleCharacter }
var newSelf = self
newSelf.invisibleCharacter = invisibleCharacter
return newSelf
}
/// Whether the invisible char has been set for the `GtkEntry`.
public func invisibleCharacterSet(_ invisibleCharacterSet: Bool? = true) -> Self {
modify { $0.invisibleCharacterSet = invisibleCharacterSet }
var newSelf = self
newSelf.invisibleCharacterSet = invisibleCharacterSet
return newSelf
}
/// Maximum number of characters for this entry.
public func maxLength(_ maxLength: Int?) -> Self {
modify { $0.maxLength = maxLength }
var newSelf = self
newSelf.maxLength = maxLength
return newSelf
}
/// The desired maximum width of the entry, in characters.
public func maxWidthChars(_ maxWidthChars: Int?) -> Self {
modify { $0.maxWidthChars = maxWidthChars }
}
/// Text for an item in the context menu to activate the primary icon action.
///
/// When the primary icon is activatable and this property has been set, a new entry
/// in the context menu of this GtkEntry will appear with this text. Selecting that
/// menu entry will result in the primary icon being activated, exactly in the same way
/// as it would be activated from a mouse click.
///
/// This simplifies adding accessibility support to applications using activatable
/// icons. The activatable icons aren't focusable when navigating the interface with
/// the keyboard This is why Gtk recommends to also add those actions in the context
/// menu. This set of methods greatly simplifies this, by adding a menu item that, when
/// enabled, calls the same callback than clicking on the icon.
public func menuEntryIconPrimaryText(_ menuEntryIconPrimaryText: String?) -> Self {
modify { $0.menuEntryIconPrimaryText = menuEntryIconPrimaryText }
}
/// Text for an item in the context menu to activate the secondary icon action.
///
/// When the primary icon is activatable and this property has been set, a new entry
/// in the context menu of this GtkEntry will appear with this text. Selecting that
/// menu entry will result in the primary icon being activated, exactly in the same way
/// as it would be activated from a mouse click.
///
/// This simplifies adding accessibility support to applications using activatable
/// icons. The activatable icons aren't focusable when navigating the interface with
/// the keyboard This is why Gtk recommends to also add those actions in the context
/// menu. This set of methods greatly simplifies this, by adding a menu item that, when
/// enabled, calls the same callback than clicking on the icon.
public func menuEntryIconSecondaryText(_ menuEntryIconSecondaryText: String?) -> Self {
modify { $0.menuEntryIconSecondaryText = menuEntryIconSecondaryText }
var newSelf = self
newSelf.maxWidthChars = maxWidthChars
return newSelf
}
/// If text is overwritten when typing in the `GtkEntry`.
public func overwriteMode(_ overwriteMode: Bool? = true) -> Self {
modify { $0.overwriteMode = overwriteMode }
var newSelf = self
newSelf.overwriteMode = overwriteMode
return newSelf
}
/// The text that will be displayed in the `GtkEntry` when it is empty
/// and unfocused.
public func placeholderText(_ placeholderText: String?) -> Self {
modify { $0.placeholderText = placeholderText }
var newSelf = self
newSelf.placeholderText = placeholderText
return newSelf
}
/// Whether the primary icon is activatable.
///
/// GTK emits the `Gtk.Entry::icon-press` and
/// `Gtk.Entry::icon-release` signals only on sensitive,
/// GTK emits the [signal@Gtk.Entry::icon-press] and
/// [signal@Gtk.Entry::icon-release] signals only on sensitive,
/// activatable icons.
///
/// Sensitive, but non-activatable icons can be used for purely
/// informational purposes.
public func primaryIconActivatable(_ primaryIconActivatable: Bool? = true) -> Self {
modify { $0.primaryIconActivatable = primaryIconActivatable }
var newSelf = self
newSelf.primaryIconActivatable = primaryIconActivatable
return newSelf
}
/// The icon name to use for the primary icon for the entry.
public func primaryIconName(_ primaryIconName: String?) -> Self {
modify { $0.primaryIconName = primaryIconName }
var newSelf = self
newSelf.primaryIconName = primaryIconName
return newSelf
}
/// Whether the primary icon is sensitive.
///
/// An insensitive icon appears grayed out. GTK does not emit the
/// `Gtk.Entry::icon-press` and `Gtk.Entry::icon-release`
/// [signal@Gtk.Entry::icon-press] and [signal@Gtk.Entry::icon-release]
/// signals and does not allow DND from insensitive icons.
///
/// An icon should be set insensitive if the action that would trigger
/// when clicked is currently not available.
public func primaryIconSensitive(_ primaryIconSensitive: Bool? = true) -> Self {
modify { $0.primaryIconSensitive = primaryIconSensitive }
var newSelf = self
newSelf.primaryIconSensitive = primaryIconSensitive
return newSelf
}
/// The contents of the tooltip on the primary icon, with markup.
///
/// Also see `Gtk.Entry.set_icon_tooltip_markup`.
/// Also see [method@Gtk.Entry.set_icon_tooltip_markup].
public func primaryIconTooltipMarkup(_ primaryIconTooltipMarkup: String?) -> Self {
modify { $0.primaryIconTooltipMarkup = primaryIconTooltipMarkup }
var newSelf = self
newSelf.primaryIconTooltipMarkup = primaryIconTooltipMarkup
return newSelf
}
/// The contents of the tooltip on the primary icon.
///
/// Also see `Gtk.Entry.set_icon_tooltip_text`.
/// Also see [method@Gtk.Entry.set_icon_tooltip_text].
public func primaryIconTooltipText(_ primaryIconTooltipText: String?) -> Self {
modify { $0.primaryIconTooltipText = primaryIconTooltipText }
var newSelf = self
newSelf.primaryIconTooltipText = primaryIconTooltipText
return newSelf
}
/// The current fraction of the task that's been completed.
public func progressFraction(_ progressFraction: Double?) -> Self {
modify { $0.progressFraction = progressFraction }
var newSelf = self
newSelf.progressFraction = progressFraction
return newSelf
}
/// The fraction of total entry width to move the progress
/// bouncing block for each pulse.
///
/// See `Gtk.Entry.progress_pulse`.
/// See [method@Gtk.Entry.progress_pulse].
public func progressPulseStep(_ progressPulseStep: Double?) -> Self {
modify { $0.progressPulseStep = progressPulseStep }
var newSelf = self
newSelf.progressPulseStep = progressPulseStep
return newSelf
}
/// Number of pixels of the entry scrolled off the screen to the left.
public func scrollOffset(_ scrollOffset: Int?) -> Self {
modify { $0.scrollOffset = scrollOffset }
var newSelf = self
newSelf.scrollOffset = scrollOffset
return newSelf
}
/// Whether the secondary icon is activatable.
///
/// GTK emits the `Gtk.Entry::icon-press` and
/// `Gtk.Entry::icon-release` signals only on sensitive,
/// GTK emits the [signal@Gtk.Entry::icon-press] and
/// [signal@Gtk.Entry::icon-release] signals only on sensitive,
/// activatable icons.
///
/// Sensitive, but non-activatable icons can be used for purely
/// informational purposes.
public func secondaryIconActivatable(_ secondaryIconActivatable: Bool? = true) -> Self {
modify { $0.secondaryIconActivatable = secondaryIconActivatable }
var newSelf = self
newSelf.secondaryIconActivatable = secondaryIconActivatable
return newSelf
}
/// The icon name to use for the secondary icon for the entry.
public func secondaryIconName(_ secondaryIconName: String?) -> Self {
modify { $0.secondaryIconName = secondaryIconName }
var newSelf = self
newSelf.secondaryIconName = secondaryIconName
return newSelf
}
/// Whether the secondary icon is sensitive.
///
/// An insensitive icon appears grayed out. GTK does not emit the
/// `Gtk.Entry::icon-press[ and [signal@Gtk.Entry::icon-release`
/// [signal@Gtk.Entry::icon-press[ and [signal@Gtk.Entry::icon-release]
/// signals and does not allow DND from insensitive icons.
///
/// An icon should be set insensitive if the action that would trigger
/// when clicked is currently not available.
public func secondaryIconSensitive(_ secondaryIconSensitive: Bool? = true) -> Self {
modify { $0.secondaryIconSensitive = secondaryIconSensitive }
var newSelf = self
newSelf.secondaryIconSensitive = secondaryIconSensitive
return newSelf
}
/// The contents of the tooltip on the secondary icon, with markup.
///
/// Also see `Gtk.Entry.set_icon_tooltip_markup`.
/// Also see [method@Gtk.Entry.set_icon_tooltip_markup].
public func secondaryIconTooltipMarkup(_ secondaryIconTooltipMarkup: String?) -> Self {
modify { $0.secondaryIconTooltipMarkup = secondaryIconTooltipMarkup }
var newSelf = self
newSelf.secondaryIconTooltipMarkup = secondaryIconTooltipMarkup
return newSelf
}
/// The contents of the tooltip on the secondary icon.
///
/// Also see `Gtk.Entry.set_icon_tooltip_text`.
/// Also see [method@Gtk.Entry.set_icon_tooltip_text].
public func secondaryIconTooltipText(_ secondaryIconTooltipText: String?) -> Self {
modify { $0.secondaryIconTooltipText = secondaryIconTooltipText }
var newSelf = self
newSelf.secondaryIconTooltipText = secondaryIconTooltipText
return newSelf
}
/// The position of the opposite end of the selection from the cursor in chars.
public func selectionBound(_ selectionBound: Int?) -> Self {
modify { $0.selectionBound = selectionBound }
var newSelf = self
newSelf.selectionBound = selectionBound
return newSelf
}
/// Whether the entry will show an Emoji icon in the secondary icon position
/// to open the Emoji chooser.
public func showEmojiIcon(_ showEmojiIcon: Bool? = true) -> Self {
modify { $0.showEmojiIcon = showEmojiIcon }
var newSelf = self
newSelf.showEmojiIcon = showEmojiIcon
return newSelf
}
/// The contents of the entry.
public func text(_ text: Binding<String>?) -> Self {
modify { $0.text = text }
var newSelf = self
newSelf.text = text
return newSelf
}
/// The length of the text in the `GtkEntry`.
public func textLength(_ textLength: UInt?) -> Self {
modify { $0.textLength = textLength }
var newSelf = self
newSelf.textLength = textLength
return newSelf
}
/// When `true`, pasted multi-line text is truncated to the first line.
/// When %TRUE, pasted multi-line text is truncated to the first line.
public func truncateMultiline(_ truncateMultiline: Bool? = true) -> Self {
modify { $0.truncateMultiline = truncateMultiline }
var newSelf = self
newSelf.truncateMultiline = truncateMultiline
return newSelf
}
/// Whether the entry should show the invisible char instead of the
/// actual text (password mode).
public func visibility(_ visibility: Bool? = true) -> Self {
modify { $0.visibility = visibility }
var newSelf = self
newSelf.visibility = visibility
return newSelf
}
/// Number of characters to leave space for in the entry.
public func widthChars(_ widthChars: Int?) -> Self {
modify { $0.widthChars = widthChars }
var newSelf = self
newSelf.widthChars = widthChars
return newSelf
}
/// The horizontal alignment, from 0 (left) to 1 (right).
///
/// Reversed for RTL layouts.
public func xalign(_ xalign: Float?) -> Self {
modify { $0.xalign = xalign }
var newSelf = self
newSelf.xalign = xalign
return newSelf
}
/// Emitted when the entry is activated.
@ -707,7 +759,7 @@ if let text, newValue != text.wrappedValue {
/// range of deleted text, or prevent it from being deleted entirely.
///
/// The @start_pos and @end_pos parameters are interpreted as for
/// `Gtk.Editable.delete_text`.
/// [method@Gtk.Editable.delete_text].
public func deleteText(_ deleteText: @escaping () -> Void) -> Self {
var newSelf = self
newSelf.deleteText = deleteText

View File

@ -2,44 +2,49 @@
// EntryRow.swift
// Adwaita
//
// Created by auto-generation on 04.02.26.
// Created by auto-generation on 19.04.25.
//
import CAdw
import LevenshteinTransformations
/// A `Gtk.ListBoxRow` with an embedded text entry.
///
/// A [class@Gtk.ListBoxRow] with an embedded text entry.
///
/// <picture><source srcset="entry-row-dark.png" media="(prefers-color-scheme: dark)"><img src="entry-row.png" alt="entry-row"></picture>
///
/// `AdwEntryRow` has a title that doubles as placeholder text. It shows an icon
/// indicating that it's editable and can receive additional widgets before or
/// after the editable part.
///
/// If ``showApplyButton(_:)`` is set to `true`, `AdwEntryRow` can
/// If [property@EntryRow:show-apply-button] is set to `TRUE`, `AdwEntryRow` can
/// show an apply button when editing its contents. This can be useful if
/// changing its contents can result in an expensive operation, such as network
/// activity.
///
/// `AdwEntryRow` provides only minimal API and should be used with the
/// `Gtk.Editable` API.
/// [iface@Gtk.Editable] API.
///
/// See also `PasswordEntryRow`.
/// See also [class@PasswordEntryRow].
///
/// ## AdwEntryRow as GtkBuildable
///
/// The `AdwEntryRow` implementation of the [iface@Gtk.Buildable] interface
/// supports adding a child at its end by specifying suffix or omitting the
/// type attribute of a <child> element.
///
/// It also supports adding a child as a prefix widget by specifying prefix as
/// the type attribute of a <child> element.
///
/// ## CSS nodes
///
/// `AdwEntryRow` has a single CSS node with name `row` and the `.entry` style
/// class.
public struct EntryRow: AdwaitaWidget {
#if exposeGeneratedAppearUpdateFunctions
/// Additional update functions for type extensions.
public var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
public var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#else
/// Additional update functions for type extensions.
var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#endif
/// Whether activating the embedded entry can activate the default widget.
var activatesDefault: Bool?
@ -51,9 +56,9 @@ public struct EntryRow: AdwaitaWidget {
var maxLength: Int?
/// Whether to show the apply button.
///
/// When set to `true`, typing text in the entry will reveal an apply button.
/// When set to `TRUE`, typing text in the entry will reveal an apply button.
/// Clicking it or pressing the <kbd>Enter</kbd> key will hide the button and
/// emit the `EntryRow::apply` signal.
/// emit the [signal@EntryRow::apply] signal.
///
/// This is useful if changing the entry contents can trigger an expensive
/// operation, e.g. network activity, to avoid triggering it after typing every
@ -64,23 +69,23 @@ public struct EntryRow: AdwaitaWidget {
/// The title of the preference represented by this row.
///
/// The title is interpreted as Pango markup unless
/// ``useMarkup(_:)`` is set to `false`.
/// [property@PreferencesRow:use-markup] is set to `FALSE`.
var title: String?
/// Whether the user can copy the title from the label.
///
/// See also ``selectable(_:)``.
/// See also [property@Gtk.Label:selectable].
var titleSelectable: Bool?
/// Whether to use Pango markup for the title label.
///
/// Subclasses may also use it for other labels, such as subtitle.
///
/// See also `Pango.parse_markup`.
/// See also [func@Pango.parse_markup].
var useMarkup: Bool?
/// Whether an embedded underline in the title indicates a mnemonic.
var useUnderline: Bool?
/// Emitted when the apply button is pressed.
///
/// See ``showApplyButton(_:)``.
/// See [property@EntryRow:show-apply-button].
var apply: (() -> Void)?
/// Emitted when the embedded entry is activated.
var entryActivated: (() -> Void)?
@ -90,7 +95,7 @@ public struct EntryRow: AdwaitaWidget {
var prefix: () -> Body = { [] }
/// Initialize `EntryRow`.
init() {
public init() {
}
/// The view storage.
@ -103,6 +108,7 @@ public struct EntryRow: AdwaitaWidget {
for function in appearFunctions {
function(storage, data)
}
update(storage, data: data, updateProperties: true, type: type)
var suffixStorage: [ViewStorage] = []
for view in suffix() {
@ -200,71 +206,89 @@ public struct EntryRow: AdwaitaWidget {
/// Whether activating the embedded entry can activate the default widget.
public func activatesDefault(_ activatesDefault: Bool? = true) -> Self {
modify { $0.activatesDefault = activatesDefault }
var newSelf = self
newSelf.activatesDefault = activatesDefault
return newSelf
}
/// Whether to suggest emoji replacements on the entry row.
///
/// Emoji replacement is done with :-delimited names, like `:heart:`.
public func enableEmojiCompletion(_ enableEmojiCompletion: Bool? = true) -> Self {
modify { $0.enableEmojiCompletion = enableEmojiCompletion }
var newSelf = self
newSelf.enableEmojiCompletion = enableEmojiCompletion
return newSelf
}
/// Maximum number of characters for the entry.
public func maxLength(_ maxLength: Int?) -> Self {
modify { $0.maxLength = maxLength }
var newSelf = self
newSelf.maxLength = maxLength
return newSelf
}
/// Whether to show the apply button.
///
/// When set to `true`, typing text in the entry will reveal an apply button.
/// When set to `TRUE`, typing text in the entry will reveal an apply button.
/// Clicking it or pressing the <kbd>Enter</kbd> key will hide the button and
/// emit the `EntryRow::apply` signal.
/// emit the [signal@EntryRow::apply] signal.
///
/// This is useful if changing the entry contents can trigger an expensive
/// operation, e.g. network activity, to avoid triggering it after typing every
/// character.
public func showApplyButton(_ showApplyButton: Bool? = true) -> Self {
modify { $0.showApplyButton = showApplyButton }
var newSelf = self
newSelf.showApplyButton = showApplyButton
return newSelf
}
/// The length of the text in the entry row.
public func textLength(_ textLength: UInt?) -> Self {
modify { $0.textLength = textLength }
var newSelf = self
newSelf.textLength = textLength
return newSelf
}
/// The title of the preference represented by this row.
///
/// The title is interpreted as Pango markup unless
/// ``useMarkup(_:)`` is set to `false`.
/// [property@PreferencesRow:use-markup] is set to `FALSE`.
public func title(_ title: String?) -> Self {
modify { $0.title = title }
var newSelf = self
newSelf.title = title
return newSelf
}
/// Whether the user can copy the title from the label.
///
/// See also ``selectable(_:)``.
/// See also [property@Gtk.Label:selectable].
public func titleSelectable(_ titleSelectable: Bool? = true) -> Self {
modify { $0.titleSelectable = titleSelectable }
var newSelf = self
newSelf.titleSelectable = titleSelectable
return newSelf
}
/// Whether to use Pango markup for the title label.
///
/// Subclasses may also use it for other labels, such as subtitle.
///
/// See also `Pango.parse_markup`.
/// See also [func@Pango.parse_markup].
public func useMarkup(_ useMarkup: Bool? = true) -> Self {
modify { $0.useMarkup = useMarkup }
var newSelf = self
newSelf.useMarkup = useMarkup
return newSelf
}
/// Whether an embedded underline in the title indicates a mnemonic.
public func useUnderline(_ useUnderline: Bool? = true) -> Self {
modify { $0.useUnderline = useUnderline }
var newSelf = self
newSelf.useUnderline = useUnderline
return newSelf
}
/// Emitted when the apply button is pressed.
///
/// See ``showApplyButton(_:)``.
/// See [property@EntryRow:show-apply-button].
public func apply(_ apply: @escaping () -> Void) -> Self {
var newSelf = self
newSelf.apply = apply

View File

@ -2,34 +2,52 @@
// ExpanderRow.swift
// Adwaita
//
// Created by auto-generation on 04.02.26.
// Created by auto-generation on 19.04.25.
//
import CAdw
import LevenshteinTransformations
/// A `Gtk.ListBoxRow` used to reveal widgets.
///
/// A [class@Gtk.ListBoxRow] used to reveal widgets.
///
/// <picture><source srcset="expander-row-dark.png" media="(prefers-color-scheme: dark)"><img src="expander-row.png" alt="expander-row"></picture>
///
/// The `AdwExpanderRow` widget allows the user to reveal or hide widgets below
/// it. It also allows the user to enable the expansion of the row, allowing to
/// disable all that the row contains.
///
/// ## AdwExpanderRow as GtkBuildable
///
/// The `AdwExpanderRow` implementation of the [iface@Gtk.Buildable] interface
/// supports adding a child as an suffix widget by specifying suffix as the
/// type attribute of a <child> element.
///
/// It also supports adding it as a prefix widget by specifying prefix as the
/// type attribute of a <child> element.
///
/// ## CSS nodes
///
/// `AdwExpanderRow` has a main CSS node with name `row` and the `.expander`
/// style class. It has the `.empty` style class when it contains no children.
///
/// It contains the subnodes `row.header` for its main embedded row,
/// `list.nested` for the list it can expand, and `image.expander-row-arrow` for
/// its arrow.
///
/// ## Style classes
///
/// `AdwExpanderRow` can use the [`.`](style-classes.html#property-rows)
/// style class to emphasize the row subtitle instead of the row title, which is
/// useful for displaying read-only properties.
///
/// When used together with the `.monospace` style class, only the subtitle
/// becomes monospace, not the title or any extra widgets.
public struct ExpanderRow: AdwaitaWidget {
#if exposeGeneratedAppearUpdateFunctions
/// Additional update functions for type extensions.
public var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
public var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#else
/// Additional update functions for type extensions.
var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#endif
/// Whether expansion is enabled.
var enableExpansion: Binding<Bool>?
@ -40,7 +58,7 @@ public struct ExpanderRow: AdwaitaWidget {
/// The subtitle for this row.
///
/// The subtitle is interpreted as Pango markup unless
/// ``useMarkup(_:)`` is set to `false`.
/// [property@PreferencesRow:use-markup] is set to `FALSE`.
var subtitle: String?
/// The number of lines at the end of which the subtitle label will be
/// ellipsized.
@ -50,7 +68,7 @@ public struct ExpanderRow: AdwaitaWidget {
/// The title of the preference represented by this row.
///
/// The title is interpreted as Pango markup unless
/// ``useMarkup(_:)`` is set to `false`.
/// [property@PreferencesRow:use-markup] is set to `FALSE`.
var title: String?
/// The number of lines at the end of which the title label will be ellipsized.
///
@ -58,13 +76,13 @@ public struct ExpanderRow: AdwaitaWidget {
var titleLines: Int?
/// Whether the user can copy the title from the label.
///
/// See also ``selectable(_:)``.
/// See also [property@Gtk.Label:selectable].
var titleSelectable: Bool?
/// Whether to use Pango markup for the title label.
///
/// Subclasses may also use it for other labels, such as subtitle.
///
/// See also `Pango.parse_markup`.
/// See also [func@Pango.parse_markup].
var useMarkup: Bool?
/// Whether an embedded underline in the title indicates a mnemonic.
var useUnderline: Bool?
@ -89,6 +107,7 @@ public struct ExpanderRow: AdwaitaWidget {
for function in appearFunctions {
function(storage, data)
}
update(storage, data: data, updateProperties: true, type: type)
var rowsStorage: [ViewStorage] = []
for view in rows() {
@ -212,25 +231,33 @@ if let expanded, newValue != expanded.wrappedValue {
/// Whether expansion is enabled.
public func enableExpansion(_ enableExpansion: Binding<Bool>?) -> Self {
modify { $0.enableExpansion = enableExpansion }
var newSelf = self
newSelf.enableExpansion = enableExpansion
return newSelf
}
/// Whether the row is expanded.
public func expanded(_ expanded: Binding<Bool>?) -> Self {
modify { $0.expanded = expanded }
var newSelf = self
newSelf.expanded = expanded
return newSelf
}
/// Whether the switch enabling the expansion is visible.
public func showEnableSwitch(_ showEnableSwitch: Bool? = true) -> Self {
modify { $0.showEnableSwitch = showEnableSwitch }
var newSelf = self
newSelf.showEnableSwitch = showEnableSwitch
return newSelf
}
/// The subtitle for this row.
///
/// The subtitle is interpreted as Pango markup unless
/// ``useMarkup(_:)`` is set to `false`.
/// [property@PreferencesRow:use-markup] is set to `FALSE`.
public func subtitle(_ subtitle: String?) -> Self {
modify { $0.subtitle = subtitle }
var newSelf = self
newSelf.subtitle = subtitle
return newSelf
}
/// The number of lines at the end of which the subtitle label will be
@ -238,43 +265,55 @@ if let expanded, newValue != expanded.wrappedValue {
///
/// If the value is 0, the number of lines won't be limited.
public func subtitleLines(_ subtitleLines: Int?) -> Self {
modify { $0.subtitleLines = subtitleLines }
var newSelf = self
newSelf.subtitleLines = subtitleLines
return newSelf
}
/// The title of the preference represented by this row.
///
/// The title is interpreted as Pango markup unless
/// ``useMarkup(_:)`` is set to `false`.
/// [property@PreferencesRow:use-markup] is set to `FALSE`.
public func title(_ title: String?) -> Self {
modify { $0.title = title }
var newSelf = self
newSelf.title = title
return newSelf
}
/// The number of lines at the end of which the title label will be ellipsized.
///
/// If the value is 0, the number of lines won't be limited.
public func titleLines(_ titleLines: Int?) -> Self {
modify { $0.titleLines = titleLines }
var newSelf = self
newSelf.titleLines = titleLines
return newSelf
}
/// Whether the user can copy the title from the label.
///
/// See also ``selectable(_:)``.
/// See also [property@Gtk.Label:selectable].
public func titleSelectable(_ titleSelectable: Bool? = true) -> Self {
modify { $0.titleSelectable = titleSelectable }
var newSelf = self
newSelf.titleSelectable = titleSelectable
return newSelf
}
/// Whether to use Pango markup for the title label.
///
/// Subclasses may also use it for other labels, such as subtitle.
///
/// See also `Pango.parse_markup`.
/// See also [func@Pango.parse_markup].
public func useMarkup(_ useMarkup: Bool? = true) -> Self {
modify { $0.useMarkup = useMarkup }
var newSelf = self
newSelf.useMarkup = useMarkup
return newSelf
}
/// Whether an embedded underline in the title indicates a mnemonic.
public func useUnderline(_ useUnderline: Bool? = true) -> Self {
modify { $0.useUnderline = useUnderline }
var newSelf = self
newSelf.useUnderline = useUnderline
return newSelf
}
/// Set the body for "rows".

View File

@ -2,7 +2,7 @@
// Fixed.swift
// Adwaita
//
// Created by auto-generation on 04.02.26.
// Created by auto-generation on 19.04.25.
//
import CAdw
@ -47,17 +47,10 @@ import LevenshteinTransformations
/// widget. But you should be aware of the tradeoffs.
public struct Fixed: AdwaitaWidget {
#if exposeGeneratedAppearUpdateFunctions
/// Additional update functions for type extensions.
public var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
public var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#else
/// Additional update functions for type extensions.
var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#endif
/// The accessible role of the given `GtkAccessible` implementation.
///
@ -78,6 +71,7 @@ public struct Fixed: AdwaitaWidget {
for function in appearFunctions {
function(storage, data)
}
update(storage, data: data, updateProperties: true, type: type)
return storage
}
@ -107,7 +101,9 @@ public struct Fixed: AdwaitaWidget {
///
/// The accessible role cannot be changed once set.
public func accessibleRole(_ accessibleRole: String?) -> Self {
modify { $0.accessibleRole = accessibleRole }
var newSelf = self
newSelf.accessibleRole = accessibleRole
return newSelf
}
}

View File

@ -2,7 +2,7 @@
// FlowBox.swift
// Adwaita
//
// Created by auto-generation on 04.02.26.
// Created by auto-generation on 19.04.25.
//
import CAdw
@ -10,7 +10,7 @@ import LevenshteinTransformations
/// Puts child widgets in a reflowing grid.
///
///
/// <picture><source srcset="flow-box-dark.png" media="(prefers-color-scheme: dark)"><img alt="An example GtkFlowBox" src="flow-box.png"></picture>
///
/// For instance, with the horizontal orientation, the widgets will be
/// arranged from left to right, starting a new row under the previous
@ -30,26 +30,45 @@ import LevenshteinTransformations
/// The children of a `GtkFlowBox` can be dynamically sorted and filtered.
///
/// Although a `GtkFlowBox` must have only `GtkFlowBoxChild` children, you
/// can add any kind of widget to it via `Gtk.FlowBox.insert`, and a
/// can add any kind of widget to it via [method@Gtk.FlowBox.insert], and a
/// `GtkFlowBoxChild` widget will automatically be inserted between the box
/// and the widget.
///
/// Also see `Gtk.ListBox`.
/// Also see [class@Gtk.ListBox].
///
/// # Shortcuts and Gestures
///
public struct FlowBox<Element, Identifier>: AdwaitaWidget where Identifier: Equatable {
/// The following signals have default keybindings:
///
/// - [signal@Gtk.FlowBox::move-cursor]
/// - [signal@Gtk.FlowBox::select-all]
/// - [signal@Gtk.FlowBox::toggle-cursor-child]
/// - [signal@Gtk.FlowBox::unselect-all]
///
/// # CSS nodes
///
/// ```
/// flowbox
/// flowboxchild
/// <child> flowboxchild
/// <child>
/// [rubberband]
/// ```
///
/// `GtkFlowBox` uses a single CSS node with name flowbox. `GtkFlowBoxChild`
/// uses a single CSS node with name flowboxchild. For rubberband selection,
/// a subnode with name rubberband is used.
///
/// # Accessibility
///
/// `GtkFlowBox` uses the [enum@Gtk.AccessibleRole.grid] role, and `GtkFlowBoxChild`
/// uses the [enum@Gtk.AccessibleRole.grid_cell] role.
public struct FlowBox<Element>: AdwaitaWidget where Element: Identifiable {
#if exposeGeneratedAppearUpdateFunctions
/// Additional update functions for type extensions.
public var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
public var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#else
/// Additional update functions for type extensions.
var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#endif
/// Whether to accept unpaired release events.
var acceptUnpairedRelease: Bool?
@ -109,8 +128,8 @@ public struct FlowBox<Element, Identifier>: AdwaitaWidget where Identifier: Equa
var selectAll: (() -> Void)?
/// Emitted when the set of selected children changes.
///
/// Use `Gtk.FlowBox.selected_foreach` or
/// `Gtk.FlowBox.get_selected_children` to obtain the
/// Use [method@Gtk.FlowBox.selected_foreach] or
/// [method@Gtk.FlowBox.get_selected_children] to obtain the
/// selected children.
var selectedChildrenChanged: (() -> Void)?
/// Emitted to toggle the selection of the child that has the focus.
@ -130,14 +149,11 @@ public struct FlowBox<Element, Identifier>: AdwaitaWidget where Identifier: Equa
var elements: [Element]
/// The dynamic widget content.
var content: (Element) -> Body
/// The dynamic widget identifier key path.
var id: KeyPath<Element, Identifier>
/// Initialize `FlowBox`.
init(_ elements: [Element], id: KeyPath<Element, Identifier>, @ViewBuilder content: @escaping (Element) -> Body) {
public init(_ elements: [Element], @ViewBuilder content: @escaping (Element) -> Body) {
self.elements = elements
self.content = content
self.id = id
}
/// The view storage.
@ -150,6 +166,7 @@ public struct FlowBox<Element, Identifier>: AdwaitaWidget where Identifier: Equa
for function in appearFunctions {
function(storage, data)
}
update(storage, data: data, updateProperties: true, type: type)
return storage
}
@ -219,9 +236,8 @@ public struct FlowBox<Element, Identifier>: AdwaitaWidget where Identifier: Equa
var contentStorage: [ViewStorage] = storage.content[.mainContent] ?? []
let old = storage.fields["element"] as? [Element] ?? []
old.transform(
old.identifiableTransform(
to: elements,
id: id,
functions: .init { index in
gtk_flow_box_remove(widget, gtk_flow_box_get_child_at_index(widget, index.cInt)?.cast())
contentStorage.remove(at: index)
@ -248,37 +264,49 @@ public struct FlowBox<Element, Identifier>: AdwaitaWidget where Identifier: Equa
/// Whether to accept unpaired release events.
public func acceptUnpairedRelease(_ acceptUnpairedRelease: Bool? = true) -> Self {
modify { $0.acceptUnpairedRelease = acceptUnpairedRelease }
var newSelf = self
newSelf.acceptUnpairedRelease = acceptUnpairedRelease
return newSelf
}
/// The accessible role of the given `GtkAccessible` implementation.
///
/// The accessible role cannot be changed once set.
public func accessibleRole(_ accessibleRole: String?) -> Self {
modify { $0.accessibleRole = accessibleRole }
var newSelf = self
newSelf.accessibleRole = accessibleRole
return newSelf
}
/// Determines whether children can be activated with a single
/// click, or require a double-click.
public func activateOnSingleClick(_ activateOnSingleClick: Bool? = true) -> Self {
modify { $0.activateOnSingleClick = activateOnSingleClick }
var newSelf = self
newSelf.activateOnSingleClick = activateOnSingleClick
return newSelf
}
/// The amount of horizontal space between two children.
public func columnSpacing(_ columnSpacing: UInt?) -> Self {
modify { $0.columnSpacing = columnSpacing }
var newSelf = self
newSelf.columnSpacing = columnSpacing
return newSelf
}
/// Determines whether all children should be allocated the
/// same size.
public func homogeneous(_ homogeneous: Bool? = true) -> Self {
modify { $0.homogeneous = homogeneous }
var newSelf = self
newSelf.homogeneous = homogeneous
return newSelf
}
/// The maximum amount of children to request space for consecutively
/// in the given orientation.
public func maxChildrenPerLine(_ maxChildrenPerLine: UInt?) -> Self {
modify { $0.maxChildrenPerLine = maxChildrenPerLine }
var newSelf = self
newSelf.maxChildrenPerLine = maxChildrenPerLine
return newSelf
}
/// The minimum number of children to allocate consecutively
@ -288,12 +316,16 @@ public struct FlowBox<Element, Identifier>: AdwaitaWidget where Identifier: Equa
/// that a reasonably small height will be requested
/// for the overall minimum width of the box.
public func minChildrenPerLine(_ minChildrenPerLine: UInt?) -> Self {
modify { $0.minChildrenPerLine = minChildrenPerLine }
var newSelf = self
newSelf.minChildrenPerLine = minChildrenPerLine
return newSelf
}
/// The amount of vertical space between two children.
public func rowSpacing(_ rowSpacing: UInt?) -> Self {
modify { $0.rowSpacing = rowSpacing }
var newSelf = self
newSelf.rowSpacing = rowSpacing
return newSelf
}
/// Emitted when the user activates the @box.
@ -348,8 +380,8 @@ public struct FlowBox<Element, Identifier>: AdwaitaWidget where Identifier: Equa
/// Emitted when the set of selected children changes.
///
/// Use `Gtk.FlowBox.selected_foreach` or
/// `Gtk.FlowBox.get_selected_children` to obtain the
/// Use [method@Gtk.FlowBox.selected_foreach] or
/// [method@Gtk.FlowBox.get_selected_children] to obtain the
/// selected children.
public func selectedChildrenChanged(_ selectedChildrenChanged: @escaping () -> Void) -> Self {
var newSelf = self
@ -381,14 +413,3 @@ public struct FlowBox<Element, Identifier>: AdwaitaWidget where Identifier: Equa
}
}
extension FlowBox where Element: Identifiable, Identifier == Element.ID {
/// Initialize `FlowBox`.
public init(_ elements: [Element], @ViewBuilder content: @escaping (Element) -> Body) {
self.elements = elements
self.content = content
self.id = \.id
}
}

View File

@ -2,7 +2,7 @@
// HeaderBar.swift
// Adwaita
//
// Created by auto-generation on 04.02.26.
// Created by auto-generation on 19.04.25.
//
import CAdw
@ -10,31 +10,106 @@ import LevenshteinTransformations
/// A title bar widget.
///
/// <picture><source srcset="header-bar-dark.png" media="(prefers-color-scheme: dark)"><img src="header-bar.png" alt="header-bar"></picture>
///
///
/// `AdwHeaderBar` is similar to `Gtk.HeaderBar`, but provides additional
/// `AdwHeaderBar` is similar to [class@Gtk.HeaderBar], but provides additional
/// features compared to it. Refer to `GtkHeaderBar` for details. It is typically
/// used as a top bar within `ToolbarView`.
/// used as a top bar within [class@ToolbarView].
///
/// ## Dialog Integration
///
/// When placed inside an [class@Dialog], `AdwHeaderBar` will display the dialog
/// title instead of window title. It will also adjust the decoration layout to
/// ensure it always has a close button and nothing else. Set
/// [property@HeaderBar:show-start-title-buttons] and
/// [property@HeaderBar:show-end-title-buttons] to `FALSE` to remove it if it's
/// unwanted.
///
/// ## Navigation View Integration
///
/// When placed inside an [class@NavigationPage], `AdwHeaderBar` will display the
/// page title instead of window title.
///
/// When used together with [class@NavigationView] or [class@NavigationSplitView],
/// it will also display a back button that can be used to go back to the previous
/// page. The button also has a context menu, allowing to pop multiple pages at
/// once, potentially across multiple navigation views.
///
/// Set [property@HeaderBar:show-back-button] to `FALSE` to disable this behavior
/// in rare scenarios where it's unwanted.
///
/// ## Split View Integration
///
/// When placed inside [class@NavigationSplitView] or [class@OverlaySplitView],
/// `AdwHeaderBar` will automatically hide the title buttons other than at the
/// edges of the window.
///
/// ## Bottom Sheet Integration
///
/// When played inside [class@BottomSheet], `AdwHeaderBar` will not show the title
/// unless [property@BottomSheet:show-drag-handle] is set to `FALSE`, regardless
/// of [property@HeaderBar:show-title]. This only applies to the default title,
/// titles set with [property@HeaderBar:title-widget] will still be shown.
///
/// ## Centering Policy
///
/// [property@HeaderBar:centering-policy] allows to enforce strict centering of
/// the title widget. This can be useful for entries inside [class@Clamp].
///
/// ## Title Buttons
///
/// Unlike `GtkHeaderBar`, `AdwHeaderBar` allows to toggle title button
/// visibility for each side individually, using the
/// [property@HeaderBar:show-start-title-buttons] and
/// [property@HeaderBar:show-end-title-buttons] properties.
///
/// ## CSS nodes
///
/// ```
/// headerbar
/// windowhandle
/// box
/// widget
/// box.start
/// windowcontrols.start
/// widget
/// [button.back]
/// [other children]
/// widget
/// [Title Widget]
/// widget
/// box.end
/// [other children]
/// windowcontrols.end
/// ```
///
/// `AdwHeaderBar`'s CSS node is called `headerbar`. It contains a `windowhandle`
/// subnode, which contains a `box` subnode, which contains three `widget`
/// subnodes at the start, center and end of the header bar. The start and end
/// subnodes contain a `box` subnode with the `.start` and `.end` style classes
/// respectively, and the center node contains a node that represents the title.
///
/// Each of the boxes contains a `windowcontrols` subnode, see
/// [class@Gtk.WindowControls] for details, as well as other children.
///
/// When [property@HeaderBar:show-back-button] is `TRUE`, the start box also
/// contains a node with the name `widget` that contains a node with the name
/// `button` and `.back` style class.
///
/// ## Accessibility
///
/// `AdwHeaderBar` uses the `GTK_ACCESSIBLE_ROLE_GROUP` role.
public struct HeaderBar: AdwaitaWidget {
#if exposeGeneratedAppearUpdateFunctions
/// Additional update functions for type extensions.
public var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
public var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#else
/// Additional update functions for type extensions.
var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#endif
/// The decoration layout for buttons.
///
/// If this property is not set, the
/// ``gtkDecorationLayout(_:)`` setting is used.
/// [property@Gtk.Settings:gtk-decoration-layout] setting is used.
///
/// The format of the string is button names, separated by commas. A colon
/// separates the buttons that should appear at the start from those at the
@ -47,23 +122,23 @@ public struct HeaderBar: AdwaitaWidget {
/// Whether the header bar can show the back button.
///
/// The back button will never be shown unless the header bar is placed inside an
/// `NavigationView`. Usually, there is no reason to set this to `false`.
/// [class@NavigationView]. Usually, there is no reason to set this to `FALSE`.
var showBackButton: Bool?
/// Whether to show title buttons at the end of the header bar.
///
/// See ``showStartTitleButtons(_:)`` for the other side.
/// See [property@HeaderBar:show-start-title-buttons] for the other side.
///
/// Which buttons are actually shown and where is determined by the
/// ``decorationLayout(_:)`` property, and by the state of the
/// [property@HeaderBar:decoration-layout] property, and by the state of the
/// window (e.g. a close button will not be shown if the window can't be
/// closed).
var showEndTitleButtons: Bool?
/// Whether to show title buttons at the start of the header bar.
///
/// See ``showEndTitleButtons(_:)`` for the other side.
/// See [property@HeaderBar:show-end-title-buttons] for the other side.
///
/// Which buttons are actually shown and where is determined by the
/// ``decorationLayout(_:)`` property, and by the state of the
/// [property@HeaderBar:decoration-layout] property, and by the state of the
/// window (e.g. a close button will not be shown if the window can't be
/// closed).
var showStartTitleButtons: Bool?
@ -74,12 +149,12 @@ public struct HeaderBar: AdwaitaWidget {
/// When set to `NULL`, the header bar will display the title of the window it
/// is contained in.
///
/// To use a different title, use `WindowTitle`:
/// To use a different title, use [class@WindowTitle]:
///
/// ```xml
/// <object class="AdwHeaderBar"><property name="title-widget"><object class="AdwWindowTitle"><property name="title" translatable="yes">Title</property></object></property></object>
/// ```
var titleWidget: Body?
var titleWidget: (() -> Body)?
/// The body for the widget "start".
var start: () -> Body = { [] }
/// The body for the widget "end".
@ -99,7 +174,8 @@ public struct HeaderBar: AdwaitaWidget {
for function in appearFunctions {
function(storage, data)
}
if let titleWidgetStorage = titleWidget?.storage(data: data, type: type) {
update(storage, data: data, updateProperties: true, type: type)
if let titleWidgetStorage = titleWidget?().storage(data: data, type: type) {
storage.content["titleWidget"] = [titleWidgetStorage]
adw_header_bar_set_title_widget(storage.opaquePointer, titleWidgetStorage.opaquePointer?.cast())
}
@ -144,7 +220,7 @@ public struct HeaderBar: AdwaitaWidget {
adw_header_bar_set_show_title(widget, showTitle.cBool)
}
if let widget = storage.content["titleWidget"]?.first {
titleWidget?.updateStorage(widget, data: data, updateProperties: updateProperties, type: type)
titleWidget?().updateStorage(widget, data: data, updateProperties: updateProperties, type: type)
}
if let startStorage = storage.content["start"] {
@ -185,7 +261,7 @@ public struct HeaderBar: AdwaitaWidget {
/// The decoration layout for buttons.
///
/// If this property is not set, the
/// ``gtkDecorationLayout(_:)`` setting is used.
/// [property@Gtk.Settings:gtk-decoration-layout] setting is used.
///
/// The format of the string is button names, separated by commas. A colon
/// separates the buttons that should appear at the start from those at the
@ -195,44 +271,54 @@ public struct HeaderBar: AdwaitaWidget {
/// For example, icon:minimize,maximize,close specifies an icon at the start,
/// and minimize, maximize and close buttons at the end.
public func decorationLayout(_ decorationLayout: String?) -> Self {
modify { $0.decorationLayout = decorationLayout }
var newSelf = self
newSelf.decorationLayout = decorationLayout
return newSelf
}
/// Whether the header bar can show the back button.
///
/// The back button will never be shown unless the header bar is placed inside an
/// `NavigationView`. Usually, there is no reason to set this to `false`.
/// [class@NavigationView]. Usually, there is no reason to set this to `FALSE`.
public func showBackButton(_ showBackButton: Bool? = true) -> Self {
modify { $0.showBackButton = showBackButton }
var newSelf = self
newSelf.showBackButton = showBackButton
return newSelf
}
/// Whether to show title buttons at the end of the header bar.
///
/// See ``showStartTitleButtons(_:)`` for the other side.
/// See [property@HeaderBar:show-start-title-buttons] for the other side.
///
/// Which buttons are actually shown and where is determined by the
/// ``decorationLayout(_:)`` property, and by the state of the
/// [property@HeaderBar:decoration-layout] property, and by the state of the
/// window (e.g. a close button will not be shown if the window can't be
/// closed).
public func showEndTitleButtons(_ showEndTitleButtons: Bool? = true) -> Self {
modify { $0.showEndTitleButtons = showEndTitleButtons }
var newSelf = self
newSelf.showEndTitleButtons = showEndTitleButtons
return newSelf
}
/// Whether to show title buttons at the start of the header bar.
///
/// See ``showEndTitleButtons(_:)`` for the other side.
/// See [property@HeaderBar:show-end-title-buttons] for the other side.
///
/// Which buttons are actually shown and where is determined by the
/// ``decorationLayout(_:)`` property, and by the state of the
/// [property@HeaderBar:decoration-layout] property, and by the state of the
/// window (e.g. a close button will not be shown if the window can't be
/// closed).
public func showStartTitleButtons(_ showStartTitleButtons: Bool? = true) -> Self {
modify { $0.showStartTitleButtons = showStartTitleButtons }
var newSelf = self
newSelf.showStartTitleButtons = showStartTitleButtons
return newSelf
}
/// Whether the title widget should be shown.
public func showTitle(_ showTitle: Bool? = true) -> Self {
modify { $0.showTitle = showTitle }
var newSelf = self
newSelf.showTitle = showTitle
return newSelf
}
/// The title widget to display.
@ -240,13 +326,15 @@ public struct HeaderBar: AdwaitaWidget {
/// When set to `NULL`, the header bar will display the title of the window it
/// is contained in.
///
/// To use a different title, use `WindowTitle`:
/// To use a different title, use [class@WindowTitle]:
///
/// ```xml
/// <object class="AdwHeaderBar"><property name="title-widget"><object class="AdwWindowTitle"><property name="title" translatable="yes">Title</property></object></property></object>
/// ```
public func titleWidget(@ViewBuilder _ titleWidget: () -> Body) -> Self {
modify { $0.titleWidget = titleWidget() }
public func titleWidget(@ViewBuilder _ titleWidget: @escaping (() -> Body)) -> Self {
var newSelf = self
newSelf.titleWidget = titleWidget
return newSelf
}
/// Set the body for "start".

View File

@ -0,0 +1,562 @@
//
// Label.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
//
import CAdw
import LevenshteinTransformations
/// Displays a small amount of text.
///
/// Most labels are used to label another widget (such as an [class@Entry]).
///
/// <picture><source srcset="label-dark.png" media="(prefers-color-scheme: dark)"><img alt="An example GtkLabel" src="label.png"></picture>
///
/// ## Shortcuts and Gestures
///
/// `GtkLabel` supports the following keyboard shortcuts, when the cursor is
/// visible:
///
/// - <kbd>Shift</kbd>+<kbd>F10</kbd> or <kbd>Menu</kbd> opens the context menu.
/// - <kbd>Ctrl</kbd>+<kbd>A</kbd> or <kbd>Ctrl</kbd>+<kbd>&sol;</kbd>
/// selects all.
/// - <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>A</kbd> or
/// <kbd>Ctrl</kbd>+<kbd>&bsol;</kbd> unselects all.
///
/// Additionally, the following signals have default keybindings:
///
/// - [signal@Gtk.Label::activate-current-link]
/// - [signal@Gtk.Label::copy-clipboard]
/// - [signal@Gtk.Label::move-cursor]
///
/// ## Actions
///
/// `GtkLabel` defines a set of built-in actions:
///
/// - `clipboard.copy` copies the text to the clipboard.
/// - `clipboard.cut` doesn't do anything, since text in labels can't be deleted.
/// - `clipboard.paste` doesn't do anything, since text in labels can't be
/// edited.
/// - `link.open` opens the link, when activated on a link inside the label.
/// - `link.copy` copies the link to the clipboard, when activated on a link
/// inside the label.
/// - `menu.popup` opens the context menu.
/// - `selection.delete` doesn't do anything, since text in labels can't be
/// deleted.
/// - `selection.select-all` selects all of the text, if the label allows
/// selection.
///
/// ## CSS nodes
///
/// ```
/// label
/// [selection]
/// [link]
///
/// [link]
/// ```
///
/// `GtkLabel` has a single CSS node with the name label. A wide variety
/// of style classes may be applied to labels, such as .title, .subtitle,
/// .dim-label, etc. In the `GtkShortcutsWindow`, labels are used with the
/// .keycap style class.
///
/// If the label has a selection, it gets a subnode with name selection.
///
/// If the label has links, there is one subnode per link. These subnodes
/// carry the link or visited state depending on whether they have been
/// visited. In this case, label node also gets a .link style class.
///
/// ## GtkLabel as GtkBuildable
///
/// The GtkLabel implementation of the GtkBuildable interface supports a
/// custom `<attributes>` element, which supports any number of `<attribute>`
/// elements. The `<attribute>` element has attributes named name, value,
/// start and end and allows you to specify [struct@Pango.Attribute]
/// values for this label.
///
/// An example of a UI definition fragment specifying Pango attributes:
///
/// ```xml
/// <object class="GtkLabel"><attributes><attribute name="weight" value="PANGO_WEIGHT_BOLD"/><attribute name="background" value="red" start="5" end="10"/></attributes></object>
/// ```
///
/// The start and end attributes specify the range of characters to which the
/// Pango attribute applies. If start and end are not specified, the attribute is
/// applied to the whole text. Note that specifying ranges does not make much
/// sense with translatable attributes. Use markup embedded in the translatable
/// content instead.
///
/// ## Accessibility
///
/// `GtkLabel` uses the [enum@Gtk.AccessibleRole.label] role.
///
/// ## Mnemonics
///
/// Labels may contain mnemonics. Mnemonics are underlined characters in the
/// label, used for keyboard navigation. Mnemonics are created by providing a
/// string with an underscore before the mnemonic character, such as `"_File"`,
/// to the functions [ctor@Gtk.Label.new_with_mnemonic] or
/// [method@Gtk.Label.set_text_with_mnemonic].
///
/// Mnemonics automatically activate any activatable widget the label is
/// inside, such as a [class@Gtk.Button]; if the label is not inside the
/// mnemonics target widget, you have to tell the label about the target
/// using [method@Gtk.Label.set_mnemonic_widget].
///
/// Heres a simple example where the label is inside a button:
///
/// ```c
/// // Pressing Alt+H will activate this button
/// GtkWidget *button = gtk_button_new ();
/// GtkWidget *label = gtk_label_new_with_mnemonic ("_Hello");
/// gtk_button_set_child (GTK_BUTTON (button), label);
/// ```
///
/// Theres a convenience function to create buttons with a mnemonic label
/// already inside:
///
/// ```c
/// // Pressing Alt+H will activate this button
/// GtkWidget *button = gtk_button_new_with_mnemonic ("_Hello");
/// ```
///
/// To create a mnemonic for a widget alongside the label, such as a
/// [class@Gtk.Entry], you have to point the label at the entry with
/// [method@Gtk.Label.set_mnemonic_widget]:
///
/// ```c
/// // Pressing Alt+H will focus the entry
/// GtkWidget *entry = gtk_entry_new ();
/// GtkWidget *label = gtk_label_new_with_mnemonic ("_Hello");
/// gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
/// ```
///
/// ## Markup (styled text)
///
/// To make it easy to format text in a label (changing colors, fonts, etc.),
/// label text can be provided in a simple markup format:
///
/// Heres how to create a label with a small font:
/// ```c
/// GtkWidget *label = gtk_label_new (NULL);
/// gtk_label_set_markup (GTK_LABEL (label), "<small>Small text</small>");
/// ```
///
/// (See the Pango manual for complete documentation] of available
/// tags, [func@Pango.parse_markup])
///
/// The markup passed to [method@Gtk.Label.set_markup] must be valid XML; for example,
/// literal `<`, `>` and `&` characters must be escaped as `&lt;`, `&gt;`, and `&amp;`.
/// If you pass text obtained from the user, file, or a network to
/// [method@Gtk.Label.set_markup], youll want to escape it with
/// [func@GLib.markup_escape_text] or [func@GLib.markup_printf_escaped].
///
/// Markup strings are just a convenient way to set the [struct@Pango.AttrList]
/// on a label; [method@Gtk.Label.set_attributes] may be a simpler way to set
/// attributes in some cases. Be careful though; [struct@Pango.AttrList] tends
/// to cause internationalization problems, unless youre applying attributes
/// to the entire string (i.e. unless you set the range of each attribute
/// to [0, `G_MAXINT`)). The reason is that specifying the `start_index` and
/// `end_index` for a [struct@Pango.Attribute] requires knowledge of the exact
/// string being displayed, so translations will cause problems.
///
/// ## Selectable labels
///
/// Labels can be made selectable with [method@Gtk.Label.set_selectable].
/// Selectable labels allow the user to copy the label contents to the
/// clipboard. Only labels that contain useful-to-copy information such
/// as error messages should be made selectable.
///
/// ## Text layout
///
/// A label can contain any number of paragraphs, but will have
/// performance problems if it contains more than a small number.
/// Paragraphs are separated by newlines or other paragraph separators
/// understood by Pango.
///
/// Labels can automatically wrap text if you call [method@Gtk.Label.set_wrap].
///
/// [method@Gtk.Label.set_justify] sets how the lines in a label align
/// with one another. If you want to set how the label as a whole aligns
/// in its available space, see the [property@Gtk.Widget:halign] and
/// [property@Gtk.Widget:valign] properties.
///
/// The [property@Gtk.Label:width-chars] and [property@Gtk.Label:max-width-chars]
/// properties can be used to control the size allocation of ellipsized or
/// wrapped labels. For ellipsizing labels, if either is specified (and less
/// than the actual text size), it is used as the minimum width, and the actual
/// text size is used as the natural width of the label. For wrapping labels,
/// width-chars is used as the minimum width, if specified, and max-width-chars
/// is used as the natural width. Even if max-width-chars specified, wrapping
/// labels will be rewrapped to use all of the available width.
///
/// ## Links
///
/// GTK supports markup for clickable hyperlinks in addition to regular Pango
/// markup. The markup for links is borrowed from HTML, using the `<a>` tag
/// with href, title and class attributes. GTK renders links similar to
/// the way they appear in web browsers, with colored, underlined text. The
/// title attribute is displayed as a tooltip on the link. The class
/// attribute is used as style class on the CSS node for the link.
///
/// An example of inline links looks like this:
///
/// ```c
/// const char *text =
/// "Go to the "
/// "<a href=\"https://www.gtk.org\" title=\"&lt;i&gt;Our&lt;/i&gt; website\">"
/// "GTK website</a> for more...";
/// GtkWidget *label = gtk_label_new (NULL);
/// gtk_label_set_markup (GTK_LABEL (label), text);
/// ```
///
/// It is possible to implement custom handling for links and their tooltips
/// with the [signal@Gtk.Label::activate-link] signal and the
/// [method@Gtk.Label.get_current_uri] function.
public struct Label: AdwaitaWidget {
/// Additional update functions for type extensions.
var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
/// The accessible role of the given `GtkAccessible` implementation.
///
/// The accessible role cannot be changed once set.
var accessibleRole: String?
/// The contents of the label.
///
/// If the string contains Pango markup (see [func@Pango.parse_markup]),
/// you will have to set the [property@Gtk.Label:use-markup] property to
/// true in order for the label to display the markup attributes. See also
/// [method@Gtk.Label.set_markup] for a convenience function that sets both
/// this property and the [property@Gtk.Label:use-markup] property at the
/// same time.
///
/// If the string contains underlines acting as mnemonics, you will have to
/// set the [property@Gtk.Label:use-underline] property to true in order
/// for the label to display them.
var label: String
/// The number of lines to which an ellipsized, wrapping label
/// should display before it gets ellipsized. This both prevents the label
/// from ellipsizing before this many lines are displayed, and limits the
/// height request of the label to this many lines.
///
/// ::: warning
/// Setting this property has unintuitive and unfortunate consequences
/// for the minimum _width_ of the label. Specifically, if the height
/// of the label is such that it fits a smaller number of lines than
/// the value of this property, the label can not be ellipsized at all,
/// which means it must be wide enough to fit all the text fully.
///
/// This property has no effect if the label is not wrapping or ellipsized.
///
/// Set this property to -1 if you don't want to limit the number of lines.
var lines: Int?
/// The desired maximum width of the label, in characters.
///
/// If this property is set to -1, the width will be calculated automatically.
///
/// See the section on [text layout](class.Label.html#text-layout) for details
/// of how [property@Gtk.Label:width-chars] and [property@Gtk.Label:max-width-chars]
/// determine the width of ellipsized and wrapped labels.
var maxWidthChars: Int?
/// The mnemonic accelerator key for the label.
var mnemonicKeyval: UInt?
/// The widget to be activated when the labels mnemonic key is pressed.
var mnemonicWidget: (() -> Body)?
/// Whether the label text can be selected with the mouse.
var selectable: Bool?
/// Whether the label is in single line mode.
///
/// In single line mode, the height of the label does not depend on the
/// actual text, it is always set to ascent + descent of the font. This
/// can be an advantage in situations where resizing the label because
/// of text changes would be distracting, e.g. in a statusbar.
var singleLineMode: Bool?
/// True if the text of the label includes Pango markup.
///
/// See [func@Pango.parse_markup].
var useMarkup: Bool?
/// True if the text of the label indicates a mnemonic with an `_`
/// before the mnemonic character.
var useUnderline: Bool?
/// The desired width of the label, in characters.
///
/// If this property is set to -1, the width will be calculated automatically.
///
/// See the section on [text layout](class.Label.html#text-layout) for details
/// of how [property@Gtk.Label:width-chars] and [property@Gtk.Label:max-width-chars]
/// determine the width of ellipsized and wrapped labels.
var widthChars: Int?
/// True if the label text will wrap if it gets too wide.
var wrap: Bool?
/// The horizontal alignment of the label text inside its size allocation.
///
/// Compare this to [property@Gtk.Widget:halign], which determines how the
/// labels size allocation is positioned in the space available for the label.
var xalign: Float?
/// The vertical alignment of the label text inside its size allocation.
///
/// Compare this to [property@Gtk.Widget:valign], which determines how the
/// labels size allocation is positioned in the space available for the label.
var yalign: Float?
/// Gets emitted to copy the selection to the clipboard.
///
/// The `::copy-clipboard` signal is a [keybinding signal](class.SignalAction.html).
///
/// The default binding for this signal is <kbd>Ctrl</kbd>+<kbd>c</kbd>.
var copyClipboard: (() -> Void)?
/// Initialize `Label`.
public init(label: String) {
self.label = label
}
/// The view storage.
/// - Parameters:
/// - modifiers: Modify views before being updated.
/// - type: The view render data type.
/// - Returns: The view storage.
public func container<Data>(data: WidgetData, type: Data.Type) -> ViewStorage where Data: ViewRenderData {
let storage = ViewStorage(gtk_label_new(label)?.opaque())
for function in appearFunctions {
function(storage, data)
}
update(storage, data: data, updateProperties: true, type: type)
if let mnemonicWidgetStorage = mnemonicWidget?().storage(data: data, type: type) {
storage.content["mnemonicWidget"] = [mnemonicWidgetStorage]
gtk_label_set_mnemonic_widget(storage.opaquePointer, mnemonicWidgetStorage.opaquePointer?.cast())
}
return storage
}
/// Update the stored content.
/// - Parameters:
/// - storage: The storage to update.
/// - modifiers: Modify views before being updated
/// - updateProperties: Whether to update the view's properties.
/// - type: The view render data type.
public func update<Data>(_ storage: ViewStorage, data: WidgetData, updateProperties: Bool, type: Data.Type) where Data: ViewRenderData {
if let copyClipboard {
storage.connectSignal(name: "copy-clipboard", argCount: 0) {
copyClipboard()
}
}
storage.modify { widget in
if updateProperties, (storage.previousState as? Self)?.label != label {
gtk_label_set_label(widget, label)
}
if let lines, updateProperties, (storage.previousState as? Self)?.lines != lines {
gtk_label_set_lines(widget, lines.cInt)
}
if let maxWidthChars, updateProperties, (storage.previousState as? Self)?.maxWidthChars != maxWidthChars {
gtk_label_set_max_width_chars(widget, maxWidthChars.cInt)
}
if let widget = storage.content["mnemonicWidget"]?.first {
mnemonicWidget?().updateStorage(widget, data: data, updateProperties: updateProperties, type: type)
}
if let selectable, updateProperties, (storage.previousState as? Self)?.selectable != selectable {
gtk_label_set_selectable(widget, selectable.cBool)
}
if let singleLineMode, updateProperties, (storage.previousState as? Self)?.singleLineMode != singleLineMode {
gtk_label_set_single_line_mode(widget, singleLineMode.cBool)
}
if let useMarkup, updateProperties, (storage.previousState as? Self)?.useMarkup != useMarkup {
gtk_label_set_use_markup(widget, useMarkup.cBool)
}
if let useUnderline, updateProperties, (storage.previousState as? Self)?.useUnderline != useUnderline {
gtk_label_set_use_underline(widget, useUnderline.cBool)
}
if let widthChars, updateProperties, (storage.previousState as? Self)?.widthChars != widthChars {
gtk_label_set_width_chars(widget, widthChars.cInt)
}
if let wrap, updateProperties, (storage.previousState as? Self)?.wrap != wrap {
gtk_label_set_wrap(widget, wrap.cBool)
}
if let xalign, updateProperties, (storage.previousState as? Self)?.xalign != xalign {
gtk_label_set_xalign(widget, xalign)
}
if let yalign, updateProperties, (storage.previousState as? Self)?.yalign != yalign {
gtk_label_set_yalign(widget, yalign)
}
}
for function in updateFunctions {
function(storage, data, updateProperties)
}
if updateProperties {
storage.previousState = self
}
}
/// The accessible role of the given `GtkAccessible` implementation.
///
/// The accessible role cannot be changed once set.
public func accessibleRole(_ accessibleRole: String?) -> Self {
var newSelf = self
newSelf.accessibleRole = accessibleRole
return newSelf
}
/// The contents of the label.
///
/// If the string contains Pango markup (see [func@Pango.parse_markup]),
/// you will have to set the [property@Gtk.Label:use-markup] property to
/// true in order for the label to display the markup attributes. See also
/// [method@Gtk.Label.set_markup] for a convenience function that sets both
/// this property and the [property@Gtk.Label:use-markup] property at the
/// same time.
///
/// If the string contains underlines acting as mnemonics, you will have to
/// set the [property@Gtk.Label:use-underline] property to true in order
/// for the label to display them.
public func label(_ label: String) -> Self {
var newSelf = self
newSelf.label = label
return newSelf
}
/// The number of lines to which an ellipsized, wrapping label
/// should display before it gets ellipsized. This both prevents the label
/// from ellipsizing before this many lines are displayed, and limits the
/// height request of the label to this many lines.
///
/// ::: warning
/// Setting this property has unintuitive and unfortunate consequences
/// for the minimum _width_ of the label. Specifically, if the height
/// of the label is such that it fits a smaller number of lines than
/// the value of this property, the label can not be ellipsized at all,
/// which means it must be wide enough to fit all the text fully.
///
/// This property has no effect if the label is not wrapping or ellipsized.
///
/// Set this property to -1 if you don't want to limit the number of lines.
public func lines(_ lines: Int?) -> Self {
var newSelf = self
newSelf.lines = lines
return newSelf
}
/// The desired maximum width of the label, in characters.
///
/// If this property is set to -1, the width will be calculated automatically.
///
/// See the section on [text layout](class.Label.html#text-layout) for details
/// of how [property@Gtk.Label:width-chars] and [property@Gtk.Label:max-width-chars]
/// determine the width of ellipsized and wrapped labels.
public func maxWidthChars(_ maxWidthChars: Int?) -> Self {
var newSelf = self
newSelf.maxWidthChars = maxWidthChars
return newSelf
}
/// The mnemonic accelerator key for the label.
public func mnemonicKeyval(_ mnemonicKeyval: UInt?) -> Self {
var newSelf = self
newSelf.mnemonicKeyval = mnemonicKeyval
return newSelf
}
/// The widget to be activated when the labels mnemonic key is pressed.
public func mnemonicWidget(@ViewBuilder _ mnemonicWidget: @escaping (() -> Body)) -> Self {
var newSelf = self
newSelf.mnemonicWidget = mnemonicWidget
return newSelf
}
/// Whether the label text can be selected with the mouse.
public func selectable(_ selectable: Bool? = true) -> Self {
var newSelf = self
newSelf.selectable = selectable
return newSelf
}
/// Whether the label is in single line mode.
///
/// In single line mode, the height of the label does not depend on the
/// actual text, it is always set to ascent + descent of the font. This
/// can be an advantage in situations where resizing the label because
/// of text changes would be distracting, e.g. in a statusbar.
public func singleLineMode(_ singleLineMode: Bool? = true) -> Self {
var newSelf = self
newSelf.singleLineMode = singleLineMode
return newSelf
}
/// True if the text of the label includes Pango markup.
///
/// See [func@Pango.parse_markup].
public func useMarkup(_ useMarkup: Bool? = true) -> Self {
var newSelf = self
newSelf.useMarkup = useMarkup
return newSelf
}
/// True if the text of the label indicates a mnemonic with an `_`
/// before the mnemonic character.
public func useUnderline(_ useUnderline: Bool? = true) -> Self {
var newSelf = self
newSelf.useUnderline = useUnderline
return newSelf
}
/// The desired width of the label, in characters.
///
/// If this property is set to -1, the width will be calculated automatically.
///
/// See the section on [text layout](class.Label.html#text-layout) for details
/// of how [property@Gtk.Label:width-chars] and [property@Gtk.Label:max-width-chars]
/// determine the width of ellipsized and wrapped labels.
public func widthChars(_ widthChars: Int?) -> Self {
var newSelf = self
newSelf.widthChars = widthChars
return newSelf
}
/// True if the label text will wrap if it gets too wide.
public func wrap(_ wrap: Bool? = true) -> Self {
var newSelf = self
newSelf.wrap = wrap
return newSelf
}
/// The horizontal alignment of the label text inside its size allocation.
///
/// Compare this to [property@Gtk.Widget:halign], which determines how the
/// labels size allocation is positioned in the space available for the label.
public func xalign(_ xalign: Float?) -> Self {
var newSelf = self
newSelf.xalign = xalign
return newSelf
}
/// The vertical alignment of the label text inside its size allocation.
///
/// Compare this to [property@Gtk.Widget:valign], which determines how the
/// labels size allocation is positioned in the space available for the label.
public func yalign(_ yalign: Float?) -> Self {
var newSelf = self
newSelf.yalign = yalign
return newSelf
}
/// Gets emitted to copy the selection to the clipboard.
///
/// The `::copy-clipboard` signal is a [keybinding signal](class.SignalAction.html).
///
/// The default binding for this signal is <kbd>Ctrl</kbd>+<kbd>c</kbd>.
public func copyClipboard(_ copyClipboard: @escaping () -> Void) -> Self {
var newSelf = self
newSelf.copyClipboard = copyClipboard
return newSelf
}
}

View File

@ -2,7 +2,7 @@
// LevelBar.swift
// Adwaita
//
// Created by auto-generation on 04.02.26.
// Created by auto-generation on 19.04.25.
//
import CAdw
@ -13,10 +13,10 @@ import LevenshteinTransformations
/// 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 `Gtk.LevelBar.set_value` to set the current value, and
/// `Gtk.LevelBar.add_offset_value` to set the value offsets at which
/// 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
@ -26,20 +26,91 @@ import LevenshteinTransformations
/// 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.
public struct LevelBar: AdwaitaWidget {
#if exposeGeneratedAppearUpdateFunctions
/// Additional update functions for type extensions.
public var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
public var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#else
/// Additional update functions for type extensions.
var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#endif
/// The accessible role of the given `GtkAccessible` implementation.
///
@ -58,7 +129,7 @@ public struct LevelBar: AdwaitaWidget {
var value: Double?
/// Emitted when an offset specified on the bar changes value.
///
/// This typically is the result of a `Gtk.LevelBar.add_offset_value`
/// This typically is the result of a [method@Gtk.LevelBar.add_offset_value]
/// call.
///
/// The signal supports detailed connections; you can connect to the
@ -80,6 +151,7 @@ public struct LevelBar: AdwaitaWidget {
for function in appearFunctions {
function(storage, data)
}
update(storage, data: data, updateProperties: true, type: type)
return storage
}
@ -126,7 +198,9 @@ public struct LevelBar: AdwaitaWidget {
///
/// The accessible role cannot be changed once set.
public func accessibleRole(_ accessibleRole: String?) -> Self {
modify { $0.accessibleRole = accessibleRole }
var newSelf = self
newSelf.accessibleRole = accessibleRole
return newSelf
}
/// Whether the `GtkLeveBar` is inverted.
@ -134,27 +208,35 @@ public struct LevelBar: AdwaitaWidget {
/// Level bars normally grow from top to bottom or left to right.
/// Inverted level bars grow in the opposite direction.
public func inverted(_ inverted: Bool? = true) -> Self {
modify { $0.inverted = inverted }
var newSelf = self
newSelf.inverted = inverted
return newSelf
}
/// Determines the maximum value of the interval that can be displayed by the bar.
public func maxValue(_ maxValue: Double?) -> Self {
modify { $0.maxValue = maxValue }
var newSelf = self
newSelf.maxValue = maxValue
return newSelf
}
/// Determines the minimum value of the interval that can be displayed by the bar.
public func minValue(_ minValue: Double?) -> Self {
modify { $0.minValue = minValue }
var newSelf = self
newSelf.minValue = minValue
return newSelf
}
/// Determines the currently filled value of the level bar.
public func value(_ value: Double?) -> Self {
modify { $0.value = value }
var newSelf = self
newSelf.value = value
return newSelf
}
/// Emitted when an offset specified on the bar changes value.
///
/// This typically is the result of a `Gtk.LevelBar.add_offset_value`
/// This typically is the result of a [method@Gtk.LevelBar.add_offset_value]
/// call.
///
/// The signal supports detailed connections; you can connect to the

View File

@ -2,7 +2,7 @@
// LinkButton.swift
// Adwaita
//
// Created by auto-generation on 04.02.26.
// Created by auto-generation on 19.04.25.
//
import CAdw
@ -10,36 +10,49 @@ import LevenshteinTransformations
/// A button with a hyperlink.
///
///
/// <picture><source srcset="link-button-dark.png" media="(prefers-color-scheme: dark)"><img alt="An example GtkLinkButton" src="link-button.png"></picture>
///
/// It is useful to show quick links to resources.
///
/// A link button is created by calling either `Gtk.LinkButton.new` or
/// `Gtk.LinkButton.new_with_label`. If using the former, the URI you
/// A link button is created by calling either [ctor@Gtk.LinkButton.new] or
/// [ctor@Gtk.LinkButton.new_with_label]. If using the former, the URI you
/// pass to the constructor is used as a label for the widget.
///
/// The URI bound to a `GtkLinkButton` can be set specifically using
/// `Gtk.LinkButton.set_uri`.
/// [method@Gtk.LinkButton.set_uri].
///
/// By default, `GtkLinkButton` calls `Gtk.FileLauncher.launch` when the button
/// By default, `GtkLinkButton` calls [method@Gtk.FileLauncher.launch] when the button
/// is clicked. This behaviour can be overridden by connecting to the
/// `Gtk.LinkButton::activate-link` signal and returning `true` from
/// [signal@Gtk.LinkButton::activate-link] signal and returning %TRUE from
/// the signal handler.
///
/// # Shortcuts and Gestures
///
/// `GtkLinkButton` supports the following keyboard shortcuts:
///
/// - <kbd>Shift</kbd>+<kbd>F10</kbd> or <kbd>Menu</kbd> opens the context menu.
///
/// # Actions
///
/// `GtkLinkButton` defines a set of built-in actions:
///
/// - `clipboard.copy` copies the url to the clipboard.
/// - `menu.popup` opens the context menu.
///
/// # CSS nodes
///
/// `GtkLinkButton` has a single CSS node with name button. To differentiate
/// it from a plain `GtkButton`, it gets the .link style class.
///
/// # Accessibility
///
/// `GtkLinkButton` uses the [enum@Gtk.AccessibleRole.link] role.
public struct LinkButton: AdwaitaWidget {
#if exposeGeneratedAppearUpdateFunctions
/// Additional update functions for type extensions.
public var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
public var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#else
/// Additional update functions for type extensions.
var updateFunctions: [(ViewStorage, WidgetData, Bool) -> Void] = []
/// Additional appear functions for type extensions.
var appearFunctions: [(ViewStorage, WidgetData) -> Void] = []
#endif
/// The accessible role of the given `GtkAccessible` implementation.
///
@ -56,7 +69,7 @@ public struct LinkButton: AdwaitaWidget {
/// property has no effect.
var canShrink: Bool?
/// The child widget.
var child: Body?
var child: (() -> Body)?
/// Whether the button has a frame.
var hasFrame: Bool?
/// The name of the icon used to automatically populate the button.
@ -75,7 +88,7 @@ public struct LinkButton: AdwaitaWidget {
/// Emitted to animate press then release.
///
/// This is an action signal. Applications should never connect
/// to this signal, but use the `Gtk.Button::clicked` signal.
/// to this signal, but use the [signal@Gtk.Button::clicked] signal.
///
/// The default bindings for this signal are all forms of the
/// <kbd></kbd> and <kbd>Enter</kbd> keys.
@ -98,7 +111,8 @@ public struct LinkButton: AdwaitaWidget {
for function in appearFunctions {
function(storage, data)
}
if let childStorage = child?.storage(data: data, type: type) {
update(storage, data: data, updateProperties: true, type: type)
if let childStorage = child?().storage(data: data, type: type) {
storage.content["child"] = [childStorage]
gtk_button_set_child(storage.opaquePointer?.cast(), childStorage.opaquePointer?.cast())
}
@ -132,7 +146,7 @@ public struct LinkButton: AdwaitaWidget {
gtk_button_set_can_shrink(widget?.cast(), canShrink.cBool)
}
if let widget = storage.content["child"]?.first {
child?.updateStorage(widget, data: data, updateProperties: updateProperties, type: type)
child?().updateStorage(widget, data: data, updateProperties: updateProperties, type: type)
}
if let hasFrame, updateProperties, (storage.previousState as? Self)?.hasFrame != hasFrame {
gtk_button_set_has_frame(widget?.cast(), hasFrame.cBool)
@ -168,12 +182,16 @@ public struct LinkButton: AdwaitaWidget {
///
/// The accessible role cannot be changed once set.
public func accessibleRole(_ accessibleRole: String?) -> Self {
modify { $0.accessibleRole = accessibleRole }
var newSelf = self
newSelf.accessibleRole = accessibleRole
return newSelf
}
/// The name of the action with which this widget should be associated.
public func actionName(_ actionName: String?) -> Self {
modify { $0.actionName = actionName }
var newSelf = self
newSelf.actionName = actionName
return newSelf
}
/// Whether the size of the button can be made smaller than the natural
@ -184,51 +202,67 @@ public struct LinkButton: AdwaitaWidget {
/// If the contents of a button are an icon or a custom widget, setting this
/// property has no effect.
public func canShrink(_ canShrink: Bool? = true) -> Self {
modify { $0.canShrink = canShrink }
var newSelf = self
newSelf.canShrink = canShrink
return newSelf
}
/// The child widget.
public func child(@ViewBuilder _ child: () -> Body) -> Self {
modify { $0.child = child() }
public func child(@ViewBuilder _ child: @escaping (() -> Body)) -> Self {
var newSelf = self
newSelf.child = child
return newSelf
}
/// Whether the button has a frame.
public func hasFrame(_ hasFrame: Bool? = true) -> Self {
modify { $0.hasFrame = hasFrame }
var newSelf = self
newSelf.hasFrame = hasFrame
return newSelf
}
/// The name of the icon used to automatically populate the button.
public func iconName(_ iconName: String?) -> Self {
modify { $0.iconName = iconName }
var newSelf = self
newSelf.iconName = iconName
return newSelf
}
/// Text of the label inside the button, if the button contains a label widget.
public func label(_ label: String?) -> Self {
modify { $0.label = label }
var newSelf = self
newSelf.label = label
return newSelf
}
/// The URI bound to this button.
public func uri(_ uri: String) -> Self {
modify { $0.uri = uri }
var newSelf = self
newSelf.uri = uri
return newSelf
}
/// If set, an underline in the text indicates that the following character is
/// to be used as mnemonic.
public func useUnderline(_ useUnderline: Bool? = true) -> Self {
modify { $0.useUnderline = useUnderline }
var newSelf = self
newSelf.useUnderline = useUnderline
return newSelf
}
/// The 'visited' state of this button.
///
/// A visited link is drawn in a different color.
public func visited(_ visited: Bool? = true) -> Self {
modify { $0.visited = visited }
var newSelf = self
newSelf.visited = visited
return newSelf
}
/// Emitted to animate press then release.
///
/// This is an action signal. Applications should never connect
/// to this signal, but use the `Gtk.Button::clicked` signal.
/// to this signal, but use the [signal@Gtk.Button::clicked] signal.
///
/// The default bindings for this signal are all forms of the
/// <kbd></kbd> and <kbd>Enter</kbd> keys.

Some files were not shown because too many files have changed in this diff Show More