Add support for GtkPicture
This commit is contained in:
parent
7748668f4b
commit
b7aabb0966
1
.gitignore
vendored
1
.gitignore
vendored
@ -10,3 +10,4 @@ DerivedData/
|
|||||||
/Package.resolved
|
/Package.resolved
|
||||||
.Ulysses-Group.plist
|
.Ulysses-Group.plist
|
||||||
/.docc-build
|
/.docc-build
|
||||||
|
/io.github.AparokshaUI.Generation.json
|
||||||
52
.vscode/launch.json
vendored
Normal file
52
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
{
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "lldb",
|
||||||
|
"request": "launch",
|
||||||
|
"sourceLanguages": [
|
||||||
|
"swift"
|
||||||
|
],
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder:adwaita-swift}",
|
||||||
|
"name": "Debug Generation",
|
||||||
|
"program": "${workspaceFolder:adwaita-swift}/.build/debug/Generation",
|
||||||
|
"preLaunchTask": "swift: Build Debug Generation"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "lldb",
|
||||||
|
"request": "launch",
|
||||||
|
"sourceLanguages": [
|
||||||
|
"swift"
|
||||||
|
],
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder:adwaita-swift}",
|
||||||
|
"name": "Release Generation",
|
||||||
|
"program": "${workspaceFolder:adwaita-swift}/.build/release/Generation",
|
||||||
|
"preLaunchTask": "swift: Build Release Generation"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "lldb",
|
||||||
|
"request": "launch",
|
||||||
|
"sourceLanguages": [
|
||||||
|
"swift"
|
||||||
|
],
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder:adwaita-swift}",
|
||||||
|
"name": "Debug Demo",
|
||||||
|
"program": "${workspaceFolder:adwaita-swift}/.build/debug/Demo",
|
||||||
|
"preLaunchTask": "swift: Build Debug Demo"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "lldb",
|
||||||
|
"request": "launch",
|
||||||
|
"sourceLanguages": [
|
||||||
|
"swift"
|
||||||
|
],
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder:adwaita-swift}",
|
||||||
|
"name": "Release Demo",
|
||||||
|
"program": "${workspaceFolder:adwaita-swift}/.build/release/Demo",
|
||||||
|
"preLaunchTask": "swift: Build Release Demo"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -2,7 +2,7 @@
|
|||||||
// ActionRow.swift
|
// ActionRow.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// Avatar.swift
|
// Avatar.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// Banner.swift
|
// Banner.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// Bin.swift
|
// Bin.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// Box.swift
|
// Box.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// Button.swift
|
// Button.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// ButtonContent.swift
|
// ButtonContent.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// Carousel.swift
|
// Carousel.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// CenterBox.swift
|
// CenterBox.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// CheckButton.swift
|
// CheckButton.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// Clamp.swift
|
// Clamp.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// ComboRow.swift
|
// ComboRow.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// EntryRow.swift
|
// EntryRow.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// ExpanderRow.swift
|
// ExpanderRow.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// FlowBox.swift
|
// FlowBox.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// HeaderBar.swift
|
// HeaderBar.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// Label.swift
|
// Label.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// LevelBar.swift
|
// LevelBar.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// LinkButton.swift
|
// LinkButton.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// ListBox.swift
|
// ListBox.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// Menu.swift
|
// Menu.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// NavigationView.swift
|
// NavigationView.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// Overlay.swift
|
// Overlay.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// OverlaySplitView.swift
|
// OverlaySplitView.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// PasswordEntryRow.swift
|
// PasswordEntryRow.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
157
Sources/Adwaita/View/Generated/Picture.swift
Normal file
157
Sources/Adwaita/View/Generated/Picture.swift
Normal file
@ -0,0 +1,157 @@
|
|||||||
|
//
|
||||||
|
// Picture.swift
|
||||||
|
// Adwaita
|
||||||
|
//
|
||||||
|
// Created by auto-generation on 21.04.24.
|
||||||
|
//
|
||||||
|
|
||||||
|
import CAdw
|
||||||
|
import LevenshteinTransformations
|
||||||
|
|
||||||
|
/// The `GtkPicture` widget displays a `GdkPaintable`.
|
||||||
|
///
|
||||||
|
/// 
|
||||||
|
///
|
||||||
|
/// Many convenience functions are provided to make pictures simple to use.
|
||||||
|
/// For example, if you want to load an image from a file, and then display
|
||||||
|
/// it, there’s a convenience function to do this:
|
||||||
|
///
|
||||||
|
/// ```c
|
||||||
|
/// GtkWidget *widget = gtk_picture_new_for_filename ("myfile.png");
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// If the file isn’t loaded successfully, the picture 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 `GtkPicture` with
|
||||||
|
/// [ctor@Gtk.Picture.new_for_paintable].
|
||||||
|
///
|
||||||
|
/// Sometimes an application will want to avoid depending on external data
|
||||||
|
/// files, such as image files. See the documentation of `GResource` for details.
|
||||||
|
/// In this case, [ctor@Gtk.Picture.new_for_resource] and
|
||||||
|
/// [method@Gtk.Picture.set_resource] should be used.
|
||||||
|
///
|
||||||
|
/// `GtkPicture` displays an image at its natural size. See [class@Gtk.Image]
|
||||||
|
/// if you want to display a fixed-size image, such as an icon.
|
||||||
|
///
|
||||||
|
/// ## Sizing the paintable
|
||||||
|
///
|
||||||
|
/// You can influence how the paintable is displayed inside the `GtkPicture`
|
||||||
|
/// by changing [property@Gtk.Picture:content-fit]. See [enum@Gtk.ContentFit]
|
||||||
|
/// for details. [property@Gtk.Picture:can-shrink] can be unset to make sure
|
||||||
|
/// that paintables are never made smaller than their ideal size - but
|
||||||
|
/// be careful if you do not know the size of the paintable in use (like
|
||||||
|
/// when displaying user-loaded images). This can easily cause the picture to
|
||||||
|
/// grow larger than the screen. And [property@Gtk.Widget:halign] and
|
||||||
|
/// [property@Gtk.Widget:valign] can be used to make sure the paintable doesn't
|
||||||
|
/// fill all available space but is instead displayed at its original size.
|
||||||
|
///
|
||||||
|
/// ## CSS nodes
|
||||||
|
///
|
||||||
|
/// `GtkPicture` has a single CSS node with the name `picture`.
|
||||||
|
///
|
||||||
|
/// ## Accessibility
|
||||||
|
///
|
||||||
|
/// `GtkPicture` uses the `GTK_ACCESSIBLE_ROLE_IMG` role.
|
||||||
|
public struct Picture: Widget {
|
||||||
|
|
||||||
|
/// Additional update functions for type extensions.
|
||||||
|
var updateFunctions: [(ViewStorage, [(View) -> View], Bool) -> Void] = []
|
||||||
|
/// Additional appear functions for type extensions.
|
||||||
|
var appearFunctions: [(ViewStorage, [(View) -> View]) -> Void] = []
|
||||||
|
|
||||||
|
/// The accessible role of the given `GtkAccessible` implementation.
|
||||||
|
///
|
||||||
|
/// The accessible role cannot be changed once set.
|
||||||
|
var accessibleRole: String?
|
||||||
|
/// The alternative textual description for the picture.
|
||||||
|
var alternativeText: String?
|
||||||
|
/// If the `GtkPicture` can be made smaller than the natural size of its contents.
|
||||||
|
var canShrink: Bool?
|
||||||
|
/// Whether the GtkPicture will render its contents trying to preserve the aspect
|
||||||
|
/// ratio.
|
||||||
|
var keepAspectRatio: Bool?
|
||||||
|
/// The application.
|
||||||
|
var app: GTUIApp?
|
||||||
|
/// The window.
|
||||||
|
var window: GTUIApplicationWindow?
|
||||||
|
|
||||||
|
/// Initialize `Picture`.
|
||||||
|
public init() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the widget's view storage.
|
||||||
|
/// - Parameter modifiers: The view modifiers.
|
||||||
|
/// - Returns: The view storage.
|
||||||
|
public func container(modifiers: [(View) -> View]) -> ViewStorage {
|
||||||
|
let storage = ViewStorage(gtk_picture_new()?.opaque())
|
||||||
|
update(storage, modifiers: modifiers, updateProperties: true)
|
||||||
|
|
||||||
|
for function in appearFunctions {
|
||||||
|
function(storage, modifiers)
|
||||||
|
}
|
||||||
|
return storage
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Update the widget's view storage.
|
||||||
|
/// - Parameters:
|
||||||
|
/// - storage: The view storage.
|
||||||
|
/// - modifiers: The view modifiers.
|
||||||
|
/// - updateProperties: Whether to update the view's properties.
|
||||||
|
public func update(_ storage: ViewStorage, modifiers: [(View) -> View], updateProperties: Bool) {
|
||||||
|
storage.modify { widget in
|
||||||
|
|
||||||
|
if let alternativeText, updateProperties {
|
||||||
|
gtk_picture_set_alternative_text(widget, alternativeText)
|
||||||
|
}
|
||||||
|
if let canShrink, updateProperties {
|
||||||
|
gtk_picture_set_can_shrink(widget, canShrink.cBool)
|
||||||
|
}
|
||||||
|
if let keepAspectRatio, updateProperties {
|
||||||
|
gtk_picture_set_keep_aspect_ratio(widget, keepAspectRatio.cBool)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
for function in updateFunctions {
|
||||||
|
function(storage, modifiers, updateProperties)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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 alternative textual description for the picture.
|
||||||
|
public func alternativeText(_ alternativeText: String?) -> Self {
|
||||||
|
var newSelf = self
|
||||||
|
newSelf.alternativeText = alternativeText
|
||||||
|
|
||||||
|
return newSelf
|
||||||
|
}
|
||||||
|
|
||||||
|
/// If the `GtkPicture` can be made smaller than the natural size of its contents.
|
||||||
|
public func canShrink(_ canShrink: Bool? = true) -> Self {
|
||||||
|
var newSelf = self
|
||||||
|
newSelf.canShrink = canShrink
|
||||||
|
|
||||||
|
return newSelf
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether the GtkPicture will render its contents trying to preserve the aspect
|
||||||
|
/// ratio.
|
||||||
|
public func keepAspectRatio(_ keepAspectRatio: Bool? = true) -> Self {
|
||||||
|
var newSelf = self
|
||||||
|
newSelf.keepAspectRatio = keepAspectRatio
|
||||||
|
|
||||||
|
return newSelf
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -2,7 +2,7 @@
|
|||||||
// Popover.swift
|
// Popover.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// PreferencesGroup.swift
|
// PreferencesGroup.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// PreferencesPage.swift
|
// PreferencesPage.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// PreferencesRow.swift
|
// PreferencesRow.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// ProgressBar.swift
|
// ProgressBar.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// ScrolledWindow.swift
|
// ScrolledWindow.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// SearchBar.swift
|
// SearchBar.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// SearchEntry.swift
|
// SearchEntry.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// SpinRow.swift
|
// SpinRow.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// Spinner.swift
|
// Spinner.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// SplitButton.swift
|
// SplitButton.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// StatusPage.swift
|
// StatusPage.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// SwitchRow.swift
|
// SwitchRow.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// ToastOverlay.swift
|
// ToastOverlay.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// ToggleButton.swift
|
// ToggleButton.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// ToolbarView.swift
|
// ToolbarView.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
@ -34,8 +34,8 @@ import LevenshteinTransformations
|
|||||||
///
|
///
|
||||||
/// By default, top and bottom bars are flat and scrolling content has a subtle
|
/// By default, top and bottom bars are flat and scrolling content has a subtle
|
||||||
/// undershoot shadow, same as when using the
|
/// undershoot shadow, same as when using the
|
||||||
/// [`.undershoot-top`](style-classes.html#undershot-indicators) and
|
/// [`.undershoot-top`](style-classes.html#undershoot-indicators) and
|
||||||
/// [`.undershoot-bottom`](style-classes.html#undershot-indicators) style
|
/// [`.undershoot-bottom`](style-classes.html#undershoot-indicators) style
|
||||||
/// classes. This works well in most cases, e.g. with [class@StatusPage] or
|
/// classes. This works well in most cases, e.g. with [class@StatusPage] or
|
||||||
/// [class@PreferencesPage], where the background at the top and bottom parts of
|
/// [class@PreferencesPage], where the background at the top and bottom parts of
|
||||||
/// the page is uniform. Additionally, windows with sidebars should always use
|
/// the page is uniform. Additionally, windows with sidebars should always use
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// WindowTitle.swift
|
// WindowTitle.swift
|
||||||
// Adwaita
|
// Adwaita
|
||||||
//
|
//
|
||||||
// Created by auto-generation on 20.03.24.
|
// Created by auto-generation on 21.04.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import CAdw
|
import CAdw
|
||||||
|
|||||||
31
Sources/Adwaita/View/Picture+.swift
Normal file
31
Sources/Adwaita/View/Picture+.swift
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
//
|
||||||
|
// Picture+.swift
|
||||||
|
// Adwaita
|
||||||
|
//
|
||||||
|
// Created by david-swift on 21.04.24.
|
||||||
|
//
|
||||||
|
|
||||||
|
import CAdw
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
extension Picture {
|
||||||
|
|
||||||
|
/// Load the picture from Foundation's `Data`.
|
||||||
|
/// - Parameter data: The data.
|
||||||
|
/// - Returns: The view.
|
||||||
|
public func data(_ data: Data?) -> View {
|
||||||
|
inspect { storage in
|
||||||
|
let pointer = storage.pointer
|
||||||
|
guard let data else {
|
||||||
|
gtk_picture_set_paintable(pointer, gdk_paintable_new_empty(0, 0))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let bytes = data.withUnsafeBytes { ptr in
|
||||||
|
g_bytes_new(ptr.baseAddress, .init(data.count))
|
||||||
|
}
|
||||||
|
let texture = gdk_texture_new_from_bytes(bytes, nil)
|
||||||
|
gtk_picture_set_paintable(pointer, texture)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -259,7 +259,8 @@ struct GenerationConfiguration {
|
|||||||
bindings: [.init(property: "text")],
|
bindings: [.init(property: "text")],
|
||||||
excludeProperties: ["input-hints", "input-purpose"]
|
excludeProperties: ["input-hints", "input-purpose"]
|
||||||
),
|
),
|
||||||
.init(class: "SearchBar")
|
.init(class: "SearchBar"),
|
||||||
|
.init(class: "Picture", excludeProperties: ["content-fit", "file", "paintable"])
|
||||||
]
|
]
|
||||||
|
|
||||||
/// The unshortening map.
|
/// The unshortening map.
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
// swiftlint:disable missing_docs implicitly_unwrapped_optional no_magic_numbers
|
// swiftlint:disable missing_docs implicitly_unwrapped_optional no_magic_numbers
|
||||||
|
|
||||||
import Adwaita
|
import Adwaita
|
||||||
|
import Foundation
|
||||||
|
|
||||||
@main
|
@main
|
||||||
struct Demo: App {
|
struct Demo: App {
|
||||||
@ -15,11 +16,14 @@ struct Demo: App {
|
|||||||
let id = "io.github.AparokshaUI.Demo"
|
let id = "io.github.AparokshaUI.Demo"
|
||||||
var app: GTUIApp!
|
var app: GTUIApp!
|
||||||
|
|
||||||
|
@State private var pictureURL: URL?
|
||||||
|
|
||||||
var scene: Scene {
|
var scene: Scene {
|
||||||
Window(id: "main") { window in
|
Window(id: "main") { window in
|
||||||
DemoContent(window: window, app: app)
|
DemoContent(window: window, app: app, pictureURL: pictureURL)
|
||||||
}
|
}
|
||||||
HelperWindows()
|
HelperWindows()
|
||||||
|
FileDialog(importer: "picture", extensions: ["jpg", "jpeg", "png", "svg"]) { pictureURL = $0 } onClose: { }
|
||||||
}
|
}
|
||||||
|
|
||||||
struct HelperWindows: WindowSceneGroup {
|
struct HelperWindows: WindowSceneGroup {
|
||||||
@ -75,6 +79,7 @@ struct Demo: App {
|
|||||||
@State private var about = false
|
@State private var about = false
|
||||||
var window: GTUIApplicationWindow
|
var window: GTUIApplicationWindow
|
||||||
var app: GTUIApp!
|
var app: GTUIApp!
|
||||||
|
var pictureURL: URL?
|
||||||
|
|
||||||
var view: Body {
|
var view: Body {
|
||||||
OverlaySplitView(visible: $sidebarVisible) {
|
OverlaySplitView(visible: $sidebarVisible) {
|
||||||
@ -99,7 +104,7 @@ struct Demo: App {
|
|||||||
selection.label,
|
selection.label,
|
||||||
icon: selection.icon,
|
icon: selection.icon,
|
||||||
description: selection.description
|
description: selection.description
|
||||||
) { selection.view(app: app, window: window, toast: toast) }
|
) { selection.view(app: app, window: window, toast: toast, pictureURL: pictureURL) }
|
||||||
.topToolbar {
|
.topToolbar {
|
||||||
HeaderBar {
|
HeaderBar {
|
||||||
Toggle(icon: .default(icon: .sidebarShow), isOn: $sidebarVisible)
|
Toggle(icon: .default(icon: .sidebarShow), isOn: $sidebarVisible)
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
// swiftlint:disable missing_docs implicitly_unwrapped_optional
|
// swiftlint:disable missing_docs implicitly_unwrapped_optional
|
||||||
|
|
||||||
import Adwaita
|
import Adwaita
|
||||||
|
import Foundation
|
||||||
|
|
||||||
enum Page: String, Identifiable, CaseIterable, Codable {
|
enum Page: String, Identifiable, CaseIterable, Codable {
|
||||||
|
|
||||||
@ -27,6 +28,7 @@ enum Page: String, Identifiable, CaseIterable, Codable {
|
|||||||
case popover
|
case popover
|
||||||
case flowBox
|
case flowBox
|
||||||
case navigationView
|
case navigationView
|
||||||
|
case picture
|
||||||
|
|
||||||
var id: Self {
|
var id: Self {
|
||||||
self
|
self
|
||||||
@ -90,12 +92,14 @@ enum Page: String, Identifiable, CaseIterable, Codable {
|
|||||||
return "Display views in a reflowing grid"
|
return "Display views in a reflowing grid"
|
||||||
case .navigationView:
|
case .navigationView:
|
||||||
return "A page-based navigation container"
|
return "A page-based navigation container"
|
||||||
|
case .picture:
|
||||||
|
return "Display an image"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// swiftlint:disable cyclomatic_complexity
|
// swiftlint:disable cyclomatic_complexity
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
func view(app: GTUIApp!, window: GTUIApplicationWindow, toast: Signal) -> Body {
|
func view(app: GTUIApp!, window: GTUIApplicationWindow, toast: Signal, pictureURL: URL?) -> Body {
|
||||||
switch self {
|
switch self {
|
||||||
case .welcome:
|
case .welcome:
|
||||||
[]
|
[]
|
||||||
@ -129,6 +133,8 @@ enum Page: String, Identifiable, CaseIterable, Codable {
|
|||||||
FlowBoxDemo()
|
FlowBoxDemo()
|
||||||
case .navigationView:
|
case .navigationView:
|
||||||
NavigationViewDemo(app: app)
|
NavigationViewDemo(app: app)
|
||||||
|
case .picture:
|
||||||
|
PictureDemo(url: pictureURL, app: app, window: window)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// swiftlint:enable cyclomatic_complexity
|
// swiftlint:enable cyclomatic_complexity
|
||||||
|
|||||||
41
Tests/PictureDemo.swift
Normal file
41
Tests/PictureDemo.swift
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
//
|
||||||
|
// PictureDemo.swift
|
||||||
|
// Adwaita
|
||||||
|
//
|
||||||
|
// Created by david-swift on 21.04.24.
|
||||||
|
//
|
||||||
|
|
||||||
|
// swiftlint:disable missing_docs
|
||||||
|
|
||||||
|
import Adwaita
|
||||||
|
import CAdw
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
struct PictureDemo: View {
|
||||||
|
|
||||||
|
var url: URL?
|
||||||
|
var app: GTUIApp
|
||||||
|
var window: GTUIWindow
|
||||||
|
|
||||||
|
var data: Data {
|
||||||
|
guard let url, let data = try? Data(contentsOf: url) else {
|
||||||
|
return .init()
|
||||||
|
}
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
var view: Body {
|
||||||
|
Picture()
|
||||||
|
.data(data)
|
||||||
|
Button("Import") {
|
||||||
|
app.addWindow("picture", parent: window)
|
||||||
|
}
|
||||||
|
.halign(.center)
|
||||||
|
.style("pill")
|
||||||
|
.style("suggested-action")
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// swiftlint:enable missing_docs
|
||||||
Loading…
x
Reference in New Issue
Block a user