PictureProtocol

public protocol PictureProtocol : WidgetProtocol

The GtkPicture widget displays a GdkPaintable.

An example GtkPicture

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.

  • ptr

    Untyped pointer to the underlying GtkPicture instance.

    Declaration

    Swift

    var ptr: UnsafeMutableRawPointer! { get }
  • picture_ptr Default implementation

    Typed 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)

Picture Class

  • 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 transformation

    transform_to

    ValueTransformer to use for backwards transformation

    Return 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:value:) Extension method

    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

Picture Class: PictureProtocol extension (methods and fields)

  • getAlternativeText() Extension method

    Gets 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 method

    Returns whether the GtkPicture respects its contents size.

    Declaration

    Swift

    @inlinable
    func getCanShrink() -> Bool
  • getFile() Extension method

    Gets the GFile currently displayed if self is displaying a file.

    If self is not displaying a file, for example when [methodGtk.Picture.set_paintable] was used, then nil is returned.

    Declaration

    Swift

    @inlinable
    func getFile() -> GIO.FileRef!
  • getKeepAspectRatio() Extension method

    Returns whether the GtkPicture preserves its contents aspect ratio.

    Declaration

    Swift

    @inlinable
    func getKeepAspectRatio() -> Bool
  • getPaintable() Extension method

    Gets the GdkPaintable being displayed by the GtkPicture.

    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, the self 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 [methodGtk.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 [methodGtk.Widget.set_halign] and [methodGtk.Widget.set_valign].

    Declaration

    Swift

    @inlinable
    func set(canShrink: Bool)
  • set(file:) Extension method

    Makes self load and display file.

    See [ctorGtk.Picture.new_for_file] for details.

    Declaration

    Swift

    @inlinable
    func set(file: GIO.FileRef? = nil)
  • set(file:) Extension method

    Makes self load and display file.

    See [ctorGtk.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 given filename.

    This is a utility function that calls [methodGtk.Picture.set_file].

    Declaration

    Swift

    @inlinable
    func set(filename: UnsafePointer<CChar>? = nil)
  • set(keepAspectRatio:) Extension method

    If set to true, the self 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

    Makes self display the given paintable.

    If paintable is nil, nothing will be displayed.

    See [ctorGtk.Picture.new_for_paintable] for details.

    Declaration

    Swift

    @inlinable
    func set(paintable: Gdk.PaintableRef? = nil)
  • set(paintable:) Extension method

    Makes self display the given paintable.

    If paintable is nil, nothing will be displayed.

    See [ctorGtk.Picture.new_for_paintable] for details.

    Declaration

    Swift

    @inlinable
    func set<PaintableT>(paintable: PaintableT?) where PaintableT : PaintableProtocol
  • set(pixbuf:) Extension method

    Sets a GtkPicture to show a GdkPixbuf.

    See [ctorGtk.Picture.new_for_pixbuf] for details.

    This is a utility function that calls [methodGtk.Picture.set_paintable].

    Declaration

    Swift

    @inlinable
    func set(pixbuf: PixbufRef? = nil)
  • set(pixbuf:) Extension method

    Sets a GtkPicture to show a GdkPixbuf.

    See [ctorGtk.Picture.new_for_pixbuf] for details.

    This is a utility function that calls [methodGtk.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 given resource_path.

    This is a utility function that calls [methodGtk.Picture.set_file].

    Declaration

    Swift

    @inlinable
    func setResource(resourcePath: UnsafePointer<CChar>? = nil)
  • alternativeText Extension method

    Gets 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 method

    Returns whether the GtkPicture respects its contents size.

    Declaration

    Swift

    @inlinable
    var canShrink: Bool { get nonmutating set }
  • file Extension method

    The GFile that is displayed or nil if none.

    Declaration

    Swift

    @inlinable
    var file: GIO.FileRef! { get nonmutating set }
  • keepAspectRatio Extension method

    Returns whether the GtkPicture preserves its contents aspect ratio.

    Declaration

    Swift

    @inlinable
    var keepAspectRatio: Bool { get nonmutating set }
  • paintable Extension method

    The GdkPaintable to be displayed by this GtkPicture.

    Declaration

    Swift

    @inlinable
    var paintable: Gdk.PaintableRef! { get nonmutating set }