PictureProtocol
public protocol PictureProtocol : WidgetProtocol
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:
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
[ctorGdk.Texture.new_from_file], then create the GtkPicture with
[ctorGtk.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, [ctorGtk.Picture.new_for_resource] and
[methodGtk.Picture.set_resource] should be used.
GtkPicture displays an image at its natural size. See [classGtk.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 turning off [propertyGtk.Picture:keep-aspect-ratio] you can allow the
paintable to get stretched. [propertyGtk.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 [propertyGtkWidget:halign] and
[propertyGtkWidget: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.
The PictureProtocol protocol exposes the methods and properties of an underlying GtkPicture instance.
The default implementation of these can be found in the protocol extension below.
For a concrete class that implements these methods and properties, see Picture.
Alternatively, use PictureRef as a lighweight, unowned reference if you already have an instance you just want to use.
-
Untyped pointer to the underlying
GtkPictureinstance.Declaration
Swift
var ptr: UnsafeMutableRawPointer! { get } -
picture_ptrDefault implementationTyped pointer to the underlying
GtkPictureinstance.Default Implementation
Return the stored, untyped pointer as a typed pointer to the
GtkPictureinstance.Declaration
Swift
var picture_ptr: UnsafeMutablePointer<GtkPicture>! { get } -
Required Initialiser for types conforming to
PictureProtocolDeclaration
Swift
init(raw: UnsafeMutableRawPointer)
-
bind(property:Extension methodto: _: flags: transformFrom: transformTo: ) Bind a
PicturePropertyNamesource property to a given target object.Declaration
Swift
@discardableResult @inlinable func bind<Q, T>(property source_property: PicturePropertyName, to target: T, _ target_property: Q, flags f: BindingFlags = .default, transformFrom transform_from: @escaping GLibObject.ValueTransformer = { $0.transform(destValue: $1) }, transformTo transform_to: @escaping GLibObject.ValueTransformer = { $0.transform(destValue: $1) }) -> BindingRef! where Q : PropertyNameProtocol, T : ObjectProtocolParameters
source_propertythe source property to bind
targetthe target object to bind to
target_propertythe target property to bind to
flagsthe flags to pass to the
Bindingtransform_fromValueTransformerto use for forward transformationtransform_toValueTransformerto use for backwards transformationReturn Value
binding reference or
nilin case of an error -
get(property:Extension method) Get the value of a Picture property
Declaration
Swift
@inlinable func get(property: PicturePropertyName) -> GLibObject.ValueParameters
propertythe property to get the value for
Return Value
the value of the named property
-
set(property:Extension methodvalue: ) Set the value of a Picture property. Note that this will only have an effect on properties that are writable and not construct-only!
Declaration
Swift
@inlinable func set(property: PicturePropertyName, value v: GLibObject.Value)Parameters
propertythe property to get the value for
Return Value
the value of the named property
-
getAlternativeText()Extension methodGets the alternative textual description of the picture.
The returned string will be
nilif the picture cannot be described textually.Declaration
Swift
@inlinable func getAlternativeText() -> String! -
getCanShrink()Extension methodReturns whether the
GtkPicturerespects its contents size.Declaration
Swift
@inlinable func getCanShrink() -> Bool -
getFile()Extension methodGets the
GFilecurrently displayed ifselfis displaying a file.If
selfis not displaying a file, for example when [methodGtk.Picture.set_paintable] was used, thennilis returned.Declaration
Swift
@inlinable func getFile() -> GIO.FileRef! -
getKeepAspectRatio()Extension methodReturns whether the
GtkPicturepreserves its contents aspect ratio.Declaration
Swift
@inlinable func getKeepAspectRatio() -> Bool -
getPaintable()Extension methodGets the
GdkPaintablebeing displayed by theGtkPicture.Declaration
Swift
@inlinable func getPaintable() -> Gdk.PaintableRef! -
set(alternativeText:Extension method) Sets an alternative textual description for the picture contents.
It is equivalent to the “alt” attribute for images on websites.
This text will be made available to accessibility tools.
If the picture cannot be described textually, set this property to
nil.Declaration
Swift
@inlinable func set(alternativeText: UnsafePointer<CChar>? = nil) -
set(canShrink:Extension method) If set to
true, theselfcan be made smaller than its contents.The contents will then be scaled down when rendering.
If you want to still force a minimum size manually, consider using [method
Gtk.Widget.set_size_request].Also of note is that a similar function for growing does not exist because the grow behavior can be controlled via [method
Gtk.Widget.set_halign] and [methodGtk.Widget.set_valign].Declaration
Swift
@inlinable func set(canShrink: Bool) -
set(file:Extension method) Makes
selfload and displayfile.See [ctor
Gtk.Picture.new_for_file] for details.Declaration
Swift
@inlinable func set(file: GIO.FileRef? = nil) -
set(file:Extension method) Makes
selfload and displayfile.See [ctor
Gtk.Picture.new_for_file] for details.Declaration
Swift
@inlinable func set<FileT>(file: FileT?) where FileT : FileProtocol -
set(filename:Extension method) Makes
selfload and display the givenfilename.This is a utility function that calls [method
Gtk.Picture.set_file].Declaration
Swift
@inlinable func set(filename: UnsafePointer<CChar>? = nil) -
set(keepAspectRatio:Extension method) If set to
true, theselfwill render its contents according to their aspect ratio.That means that empty space may show up at the top/bottom or left/right of
self.If set to
falseor if the contents provide no aspect ratio, the contents will be stretched over the picture’s whole area.Declaration
Swift
@inlinable func set(keepAspectRatio: Bool) -
set(paintable:Extension method) -
set(paintable:Extension method) -
set(pixbuf:Extension method) Sets a
GtkPictureto show aGdkPixbuf.See [ctor
Gtk.Picture.new_for_pixbuf] for details.This is a utility function that calls [method
Gtk.Picture.set_paintable].Declaration
Swift
@inlinable func set(pixbuf: PixbufRef? = nil) -
set(pixbuf:Extension method) Sets a
GtkPictureto show aGdkPixbuf.See [ctor
Gtk.Picture.new_for_pixbuf] for details.This is a utility function that calls [method
Gtk.Picture.set_paintable].Declaration
Swift
@inlinable func set<PixbufT>(pixbuf: PixbufT?) where PixbufT : PixbufProtocol -
setResource(resourcePath:Extension method) Makes
selfload and display the resource at the givenresource_path.This is a utility function that calls [method
Gtk.Picture.set_file].Declaration
Swift
@inlinable func setResource(resourcePath: UnsafePointer<CChar>? = nil) -
alternativeTextExtension methodGets the alternative textual description of the picture.
The returned string will be
nilif the picture cannot be described textually.Declaration
Swift
@inlinable var alternativeText: String! { get nonmutating set } -
canShrinkExtension methodReturns whether the
GtkPicturerespects its contents size.Declaration
Swift
@inlinable var canShrink: Bool { get nonmutating set } -
fileExtension methodThe
GFilethat is displayed ornilif none.Declaration
Swift
@inlinable var file: GIO.FileRef! { get nonmutating set } -
keepAspectRatioExtension methodReturns whether the
GtkPicturepreserves its contents aspect ratio.Declaration
Swift
@inlinable var keepAspectRatio: Bool { get nonmutating set } -
paintableExtension methodThe
GdkPaintableto be displayed by thisGtkPicture.Declaration
Swift
@inlinable var paintable: Gdk.PaintableRef! { get nonmutating set }
View on GitHub
Install in Dash
PictureProtocol Protocol Reference