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
GtkPicture
instance.Declaration
Swift
var ptr: UnsafeMutableRawPointer! { get }
-
picture_ptr
Default implementationTyped pointer to the underlying
GtkPicture
instance.Default Implementation
Return the stored, untyped pointer as a typed pointer to the
GtkPicture
instance.Declaration
Swift
var picture_ptr: UnsafeMutablePointer<GtkPicture>! { get }
-
Required Initialiser for types conforming to
PictureProtocol
Declaration
Swift
init(raw: UnsafeMutableRawPointer)
-
bind(property:
Extension methodto: _: flags: transformFrom: transformTo: ) Bind a
PicturePropertyName
source 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 : ObjectProtocol
Parameters
source_property
the source property to bind
target
the target object to bind to
target_property
the target property to bind to
flags
the flags to pass to the
Binding
transform_from
ValueTransformer
to use for forward transformationtransform_to
ValueTransformer
to use for backwards transformationReturn Value
binding reference or
nil
in case of an error -
get(property:
Extension method) Get the value of a Picture property
Declaration
Swift
@inlinable func get(property: PicturePropertyName) -> GLibObject.Value
Parameters
property
the 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
property
the 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
nil
if the picture cannot be described textually.Declaration
Swift
@inlinable func getAlternativeText() -> String!
-
getCanShrink()
Extension methodReturns whether the
GtkPicture
respects its contents size.Declaration
Swift
@inlinable func getCanShrink() -> Bool
-
getFile()
Extension methodGets the
GFile
currently displayed ifself
is displaying a file.If
self
is not displaying a file, for example when [methodGtk.Picture.set_paintable
] was used, thennil
is returned.Declaration
Swift
@inlinable func getFile() -> GIO.FileRef!
-
getKeepAspectRatio()
Extension methodReturns whether the
GtkPicture
preserves its contents aspect ratio.Declaration
Swift
@inlinable func getKeepAspectRatio() -> Bool
-
getPaintable()
Extension methodGets the
GdkPaintable
being 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
, theself
can 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
self
load 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
self
load 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
self
load 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
, theself
will 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
false
or 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
GtkPicture
to 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
GtkPicture
to 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
self
load 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)
-
alternativeText
Extension methodGets the alternative textual description of the picture.
The returned string will be
nil
if the picture cannot be described textually.Declaration
Swift
@inlinable var alternativeText: String! { get nonmutating set }
-
canShrink
Extension methodReturns whether the
GtkPicture
respects its contents size.Declaration
Swift
@inlinable var canShrink: Bool { get nonmutating set }
-
file
Extension methodThe
GFile
that is displayed ornil
if none.Declaration
Swift
@inlinable var file: GIO.FileRef! { get nonmutating set }
-
keepAspectRatio
Extension methodReturns whether the
GtkPicture
preserves its contents aspect ratio.Declaration
Swift
@inlinable var keepAspectRatio: Bool { get nonmutating set }
-
paintable
Extension methodThe
GdkPaintable
to be displayed by thisGtkPicture
.Declaration
Swift
@inlinable var paintable: Gdk.PaintableRef! { get nonmutating set }