Merge pull request 'Add Symbol view' (#73) from marquiskurt/adwaita-swift:main into main

Reviewed-on: aparoksha/adwaita-swift#73
Reviewed-by: david-swift <david-swift@noreply.aproksha.uber.space>
This commit is contained in:
david-swift 2025-10-25 15:37:35 +02:00
commit f86e968028
53 changed files with 296 additions and 52 deletions

View File

@ -2,7 +2,7 @@
// ActionRow.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// AspectFrame.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// Avatar.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// Banner.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// Bin.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// Box.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// Button.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// ButtonContent.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// Carousel.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// CenterBox.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// CheckButton.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// Clamp.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// ComboRow.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// DropDown.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// Entry.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// EntryRow.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// ExpanderRow.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// Fixed.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// FlowBox.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// HeaderBar.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -0,0 +1,182 @@
//
// Image.swift
// Adwaita
//
// Created by auto-generation on 23.10.25.
//
import CAdw
import LevenshteinTransformations
/// Displays an image.
///
/// picture><source srcset="image-dark.png" media="(prefers-color-scheme: dark)"><img alt="An example GtkImage" src="image.png"></picture>
///
/// Various kinds of object can be displayed as an image; most typically,
/// you would load a `GdkTexture` from a file, using the convenience function
/// [ctor@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
/// [ctor@Gdk.Texture.new_from_file], then create the `GtkImage` with
/// [ctor@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, [property@Gtk.Image:resource],
/// [ctor@Gtk.Image.new_from_resource], and [method@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 [class@Gtk.Picture] if you want to show an image
/// at is actual size.
///
/// ## CSS nodes
///
/// `GtkImage` has a single CSS node with the name `image`. The style classes
/// `.normal-icons` or `.large-icons` may appear, depending on the
/// [property@Gtk.Image:icon-size] property.
///
/// ## Accessibility
///
/// `GtkImage` uses the [enum@Gtk.AccessibleRole.img] role.
public struct Image: 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 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
/// [property@Gtk.Image:icon-size] 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)
}
update(storage, data: data, updateProperties: true, type: type)
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 {
var newSelf = self
newSelf.accessibleRole = accessibleRole
return newSelf
}
/// 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 {
var newSelf = self
newSelf.iconName = iconName
return newSelf
}
/// The size in pixels to display icons at.
///
/// If set to a value != -1, this property overrides the
/// [property@Gtk.Image:icon-size] property for images of type
/// `GTK_IMAGE_ICON_NAME`.
public func pixelSize(_ pixelSize: Int?) -> Self {
var newSelf = self
newSelf.pixelSize = pixelSize
return newSelf
}
/// A path to a resource file to display.
public func resource(_ resource: String?) -> Self {
var newSelf = self
newSelf.resource = resource
return newSelf
}
/// The representation being used for image data.
public func storageType(_ storageType: String?) -> Self {
var newSelf = self
newSelf.storageType = storageType
return newSelf
}
/// 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 {
var newSelf = self
newSelf.useFallback = useFallback
return newSelf
}
}

View File

@ -2,7 +2,7 @@
// Label.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// LevelBar.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// LinkButton.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// ListBox.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// Menu.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// NavigationView.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// Overlay.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// OverlaySplitView.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// PasswordEntryRow.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// Picture.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// Popover.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw
@ -13,12 +13,17 @@ import LevenshteinTransformations
/// <picture><source srcset="popover-dark.png" media="(prefers-color-scheme: dark)"><img alt="An example GtkPopover" src="popover.png"></picture>
///
/// It is primarily meant to provide context-dependent information
/// or options. Popovers are attached to a parent widget. By default,
/// they point to the whole widget area, although this behavior can be
/// changed with [method@Gtk.Popover.set_pointing_to].
/// or options. Popovers are attached to a parent widget. The parent widget
/// must support popover children, as [class@Gtk.MenuButton] and
/// [class@Gtk.PopoverMenuBar] do. If you want to make a custom widget that
/// has an attached popover, you need to call [method@Gtk.Popover.present]
/// in your [vfunc@Gtk.Widget.size_allocate] vfunc, in order to update the
/// positioning of the popover.
///
/// The position of a popover relative to the widget it is attached to
/// can also be changed with [method@Gtk.Popover.set_position]
/// can also be changed with [method@Gtk.Popover.set_position]. By default,
/// it points to the whole widget area, but it can be made to point to
/// a specific area using [method@Gtk.Popover.set_pointing_to].
///
/// By default, `GtkPopover` performs a grab, in order to ensure input
/// events get redirected to it while it is shown, and also so the popover

View File

@ -2,7 +2,7 @@
// PreferencesGroup.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// PreferencesPage.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// PreferencesRow.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// ProgressBar.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// ScrolledWindow.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// SearchBar.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// SearchEntry.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// Separator.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// SpinRow.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// Spinner.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw
@ -32,6 +32,10 @@ import LevenshteinTransformations
///
/// `AdwSpinner` has a single node with the name `image` and the style class
/// `.spinner`.
///
/// ## Accessibility
///
/// `AdwSpinner` uses the [enum@Gtk.AccessibleRole.progress-bar] role.
public struct Spinner: AdwaitaWidget {
/// Additional update functions for type extensions.

View File

@ -2,7 +2,7 @@
// SplitButton.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// StatusPage.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// SwitchRow.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// ToastOverlay.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// ToggleButton.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// ToolbarView.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -2,7 +2,7 @@
// WindowTitle.swift
// Adwaita
//
// Created by auto-generation on 19.04.25.
// Created by auto-generation on 23.10.25.
//
import CAdw

View File

@ -0,0 +1,19 @@
//
// 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

@ -34,6 +34,7 @@ enum Page: String, Identifiable, CaseIterable, Codable, CustomStringConvertible
case fixed
case textEditor
case splitView
case symbol
var id: Self {
self
@ -115,6 +116,8 @@ enum Page: String, Identifiable, CaseIterable, Codable, CustomStringConvertible
return "A simple text editor"
case .splitView:
return "A split view whose panes are ajustable in size"
case .symbol:
return "Display a symbolic image"
}
}
@ -166,6 +169,8 @@ enum Page: String, Identifiable, CaseIterable, Codable, CustomStringConvertible
TextEditorDemo()
case .splitView:
SplitViewDemo()
case .symbol:
SymbolDemo()
}
}
// swiftlint:enable cyclomatic_complexity

View File

@ -0,0 +1,28 @@
//
// SymbolDemo.swift
// Adwaita
//
// Created by Marquis Kurt on 23.10.25.
//
// swiftlint:disable missing_docs
import Adwaita
struct SymbolDemo: View {
var view: Body {
HStack {
Symbol(icon: .default(icon: .goNext))
.pixelSize(64)
Symbol(icon: .default(icon: .goPrevious))
.pixelSize(64)
Symbol(icon: .default(icon: .airplaneMode))
.pixelSize(64)
}
.halign(.center)
.hexpand()
}
}
// swiftlint:enable missing_docs

View File

@ -301,6 +301,7 @@ struct GenerationConfiguration {
),
.init(class: "SearchBar"),
.init(class: "Picture", excludeProperties: ["file", "paintable"]),
.init(class: "Image", excludeProperties: ["file", "paintable", "gicon", "icon-size"]),
.init(
class: "AspectFrame",
initializer: "gtk_aspect_frame_new(0.5, 0.5, ratio, 0)",