Add support for picture's content fit modifier

This commit is contained in:
david-swift 2024-07-19 10:26:59 +02:00
parent 9bcf802b54
commit 46d4fc1173
47 changed files with 100 additions and 48 deletions

View File

@ -0,0 +1,31 @@
//
// ContentFit.swift
// Adwaita
//
// Created by david-swift on 19.07.24.
//
import CAdw
/// Control how a content should be made to fit inside an allocation.
public enum ContentFit: UInt32 {
/// Make the content fill the entire allocation,
/// without taking its aspect ratio in consideration.
case fill
/// Scale the content to fit the allocation,
/// while taking its aspect ratio in consideration.
case contain
/// Cover the entire allocation,
/// while taking the content aspect ratio in consideration.
case cover
/// The content is scaled down to fit the allocation, if needed,
/// otherwise its original size is used.
case scaleDown
/// The ContentFit value as a GtkContentFit value.
var gtkValue: GtkContentFit {
.init(rawValue)
}
}

View File

@ -2,7 +2,7 @@
// ActionRow.swift // ActionRow.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 22.05.24. // Created by auto-generation on 19.07.24.
// //
import CAdw import CAdw
@ -39,6 +39,11 @@ import LevenshteinTransformations
/// ///
/// It contains subnodes `label.title` and `label.subtitle` representing /// It contains subnodes `label.title` and `label.subtitle` representing
/// respectively the title label and subtitle label. /// respectively the title label and subtitle label.
///
/// `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.
public struct ActionRow: Widget { public struct ActionRow: Widget {
/// Additional update functions for type extensions. /// Additional update functions for type extensions.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,7 +2,7 @@
// HeaderBar.swift // HeaderBar.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 22.05.24. // Created by auto-generation on 19.07.24.
// //
import CAdw import CAdw
@ -40,7 +40,7 @@ import LevenshteinTransformations
/// ///
/// ## Split View Integration /// ## Split View Integration
/// ///
/// When placed inside `AdwNavigationSplitView` or `AdwOverlaySplitView`, /// When placed inside [class@NavigationSplitView] or [class@OverlaySplitView],
/// `AdwHeaderBar` will automatically hide the title buttons other than at the /// `AdwHeaderBar` will automatically hide the title buttons other than at the
/// edges of the window. /// edges of the window.
/// ///

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,7 +2,7 @@
// Picture.swift // Picture.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 22.05.24. // Created by auto-generation on 19.07.24.
// //
import CAdw import CAdw
@ -69,6 +69,8 @@ public struct Picture: Widget {
var alternativeText: String? var alternativeText: String?
/// If the `GtkPicture` can be made smaller than the natural size of its contents. /// If the `GtkPicture` can be made smaller than the natural size of its contents.
var canShrink: Bool? var canShrink: Bool?
/// How the content should be resized to fit inside the `GtkPicture`.
var contentFit: ContentFit?
/// Whether the GtkPicture will render its contents trying to preserve the aspect /// Whether the GtkPicture will render its contents trying to preserve the aspect
/// ratio. /// ratio.
var keepAspectRatio: Bool? var keepAspectRatio: Bool?
@ -108,6 +110,9 @@ public struct Picture: Widget {
if let canShrink, updateProperties { if let canShrink, updateProperties {
gtk_picture_set_can_shrink(widget, canShrink.cBool) gtk_picture_set_can_shrink(widget, canShrink.cBool)
} }
if let contentFit, updateProperties {
gtk_picture_set_content_fit(widget, contentFit.gtkValue)
}
if let keepAspectRatio, updateProperties { if let keepAspectRatio, updateProperties {
gtk_picture_set_keep_aspect_ratio(widget, keepAspectRatio.cBool) gtk_picture_set_keep_aspect_ratio(widget, keepAspectRatio.cBool)
} }
@ -145,6 +150,14 @@ public struct Picture: Widget {
return newSelf return newSelf
} }
/// How the content should be resized to fit inside the `GtkPicture`.
public func contentFit(_ contentFit: ContentFit?) -> Self {
var newSelf = self
newSelf.contentFit = contentFit
return newSelf
}
/// Whether the GtkPicture will render its contents trying to preserve the aspect /// Whether the GtkPicture will render its contents trying to preserve the aspect
/// ratio. /// ratio.
public func keepAspectRatio(_ keepAspectRatio: Bool? = true) -> Self { public func keepAspectRatio(_ keepAspectRatio: Bool? = true) -> Self {

View File

@ -2,7 +2,7 @@
// Popover.swift // Popover.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 22.05.24. // Created by auto-generation on 19.07.24.
// //
import CAdw import CAdw

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,7 +2,7 @@
// Spinner.swift // Spinner.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 22.05.24. // Created by auto-generation on 19.07.24.
// //
import CAdw import CAdw

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -24,6 +24,8 @@ struct GIRType: Decodable {
func generate(configuration: GenerationConfiguration) throws -> String { func generate(configuration: GenerationConfiguration) throws -> String {
if let cType { if let cType {
return cType.convertCType(configuration: configuration) return cType.convertCType(configuration: configuration)
} else if let name, let type = configuration.cTypeReplacements[name] {
return type
} }
return "String" return "String"
} }

View File

@ -261,7 +261,7 @@ struct GenerationConfiguration {
excludeProperties: ["input-hints", "input-purpose"] excludeProperties: ["input-hints", "input-purpose"]
), ),
.init(class: "SearchBar"), .init(class: "SearchBar"),
.init(class: "Picture", excludeProperties: ["content-fit", "file", "paintable"]) .init(class: "Picture", excludeProperties: ["file", "paintable"])
] ]
/// The unshortening map. /// The unshortening map.
@ -284,14 +284,16 @@ struct GenerationConfiguration {
"GIcon*": "OpaquePointer", "GIcon*": "OpaquePointer",
"GdkPixbuf*": "OpaquePointer", "GdkPixbuf*": "OpaquePointer",
"GdkPaintable*": "OpaquePointer", "GdkPaintable*": "OpaquePointer",
"NavigationPage": "NavigationPage" "NavigationPage": "NavigationPage",
"ContentFit": "ContentFit"
] ]
/// Modifications for converting a Swift into a C type. /// Modifications for converting a Swift into a C type.
var cTypeProperties = [ var cTypeProperties = [
"Bool": "cBool", "Bool": "cBool",
"Int": "cInt", "Int": "cInt",
"UInt": "cInt" "UInt": "cInt",
"ContentFit": "gtkValue"
] ]
/// Default values for modifiers with a certain type. /// Default values for modifiers with a certain type.

View File

@ -8,7 +8,6 @@
// swiftlint:disable missing_docs // swiftlint:disable missing_docs
import Adwaita import Adwaita
import CAdw
import Foundation import Foundation
struct PictureDemo: View { struct PictureDemo: View {