PictureRef

public struct PictureRef : PictureProtocol, GWeakCapturing

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 PictureRef type acts as a lightweight Swift reference to an underlying GtkPicture instance. It exposes methods that can operate on this data type through PictureProtocol conformance. Use PictureRef only as an unowned reference to an existing GtkPicture instance.

  • ptr
    Untyped pointer to the underlying `GtkPicture` instance.
    

    For type-safe access, use the generated, typed pointer picture_ptr property instead.

    Declaration

    Swift

    public let ptr: UnsafeMutableRawPointer!

Picture Class

  • Designated initialiser from the underlying C data type

    Declaration

    Swift

    @inlinable
    init(_ p: UnsafeMutablePointer<GtkPicture>)
  • Designated initialiser from a constant pointer to the underlying C data type

    Declaration

    Swift

    @inlinable
    init(_ p: UnsafePointer<GtkPicture>)
  • Conditional initialiser from an optional pointer to the underlying C data type

    Declaration

    Swift

    @inlinable
    init!(_ maybePointer: UnsafeMutablePointer<GtkPicture>?)
  • Conditional initialiser from an optional, non-mutable pointer to the underlying C data type

    Declaration

    Swift

    @inlinable
    init!(_ maybePointer: UnsafePointer<GtkPicture>?)
  • Conditional initialiser from an optional gpointer

    Declaration

    Swift

    @inlinable
    init!(gpointer g: gpointer?)
  • Conditional initialiser from an optional, non-mutable gconstpointer

    Declaration

    Swift

    @inlinable
    init!(gconstpointer g: gconstpointer?)
  • Reference intialiser for a related type that implements PictureProtocol

    Declaration

    Swift

    @inlinable
    init<T>(_ other: T) where T : PictureProtocol
  • This factory is syntactic sugar for setting weak pointers wrapped in GWeak<T>

    Declaration

    Swift

    @inlinable
    static func unowned<T>(_ other: T) -> PictureRef where T : PictureProtocol
  • Unsafe typed initialiser. Do not use unless you know the underlying data type the pointer points to conforms to PictureProtocol.

    Declaration

    Swift

    @inlinable
    init<T>(cPointer: UnsafeMutablePointer<T>)
  • Unsafe typed initialiser. Do not use unless you know the underlying data type the pointer points to conforms to PictureProtocol.

    Declaration

    Swift

    @inlinable
    init<T>(constPointer: UnsafePointer<T>)
  • Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to PictureProtocol.

    Declaration

    Swift

    @inlinable
    init(mutating raw: UnsafeRawPointer)
  • Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to PictureProtocol.

    Declaration

    Swift

    @inlinable
    init(raw: UnsafeMutableRawPointer)
  • Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to PictureProtocol.

    Declaration

    Swift

    @inlinable
    init(opaquePointer: OpaquePointer)
  • Creates a new empty GtkPicture widget.

    Declaration

    Swift

    @inlinable
    init()
  • Creates a new GtkPicture displaying the given file.

    If the file isn’t found or can’t be loaded, the resulting GtkPicture is empty.

    If you need to detect failures to load the file, use [ctorGdk.Texture.new_from_file] to load the file yourself, then create the GtkPicture from the texture.

    Declaration

    Swift

    @inlinable
    init<FileT>(file: FileT?) where FileT : FileProtocol
  • Creates a new GtkPicture displaying the file filename.

    This is a utility function that calls [ctorGtk.Picture.new_for_file]. See that function for details.

    Declaration

    Swift

    @inlinable
    init(filename: UnsafePointer<CChar>? = nil)
  • Creates a new GtkPicture displaying paintable.

    The GtkPicture will track changes to the paintable and update its size and contents in response to it.

    Declaration

    Swift

    @inlinable
    init<PaintableT>(paintable: PaintableT?) where PaintableT : PaintableProtocol
  • Creates a new GtkPicture displaying pixbuf.

    This is a utility function that calls [ctorGtk.Picture.new_for_paintable], See that function for details.

    The pixbuf must not be modified after passing it to this function.

    Declaration

    Swift

    @inlinable
    init<PixbufT>(pixbuf: PixbufT?) where PixbufT : PixbufProtocol
  • Creates a new GtkPicture displaying the resource at resource_path.

    This is a utility function that calls [ctorGtk.Picture.new_for_file]. See that function for details.

    Declaration

    Swift

    @inlinable
    init(resource resourcePath: UnsafePointer<CChar>? = nil)
  • Creates a new GtkPicture displaying the given file.

    If the file isn’t found or can’t be loaded, the resulting GtkPicture is empty.

    If you need to detect failures to load the file, use [ctorGdk.Texture.new_from_file] to load the file yourself, then create the GtkPicture from the texture.

    Declaration

    Swift

    @inlinable
    static func newFor<FileT>(file: FileT?) -> WidgetRef! where FileT : FileProtocol
  • Creates a new GtkPicture displaying the file filename.

    This is a utility function that calls [ctorGtk.Picture.new_for_file]. See that function for details.

    Declaration

    Swift

    @inlinable
    static func newFor(filename: UnsafePointer<CChar>? = nil) -> WidgetRef!
  • Creates a new GtkPicture displaying paintable.

    The GtkPicture will track changes to the paintable and update its size and contents in response to it.

    Declaration

    Swift

    @inlinable
    static func newFor<PaintableT>(paintable: PaintableT?) -> WidgetRef! where PaintableT : PaintableProtocol
  • Creates a new GtkPicture displaying pixbuf.

    This is a utility function that calls [ctorGtk.Picture.new_for_paintable], See that function for details.

    The pixbuf must not be modified after passing it to this function.

    Declaration

    Swift

    @inlinable
    static func newFor<PixbufT>(pixbuf: PixbufT?) -> WidgetRef! where PixbufT : PixbufProtocol
  • Creates a new GtkPicture displaying the resource at resource_path.

    This is a utility function that calls [ctorGtk.Picture.new_for_file]. See that function for details.

    Declaration

    Swift

    @inlinable
    static func newFor(resource resourcePath: UnsafePointer<CChar>? = nil) -> WidgetRef!