ImageProtocol

public protocol ImageProtocol : MiscProtocol

The GtkImage widget displays an image. Various kinds of object can be displayed as an image; most typically, you would load a GdkPixbuf (“pixel buffer”) from a file, and then display that. There’s a convenience function to do this, gtk_image_new_from_file(), used as follows: (C Language Example):

  GtkWidget *image;
  image = gtk_image_new_from_file ("myfile.png");

If the file isn’t loaded successfully, the image 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 gdk_pixbuf_new_from_file(), then create the GtkImage with gtk_image_new_from_pixbuf().

The image file may contain an animation, if so the GtkImage will display an animation (GdkPixbufAnimation) instead of a static image.

GtkImage is a subclass of GtkMisc, which implies that you can align it (center, left, right) and add padding to it, using GtkMisc methods.

GtkImage is a “no window” widget (has no GdkWindow of its own), so by default does not receive events. If you want to receive events on the image, such as button clicks, place the image inside a GtkEventBox, then connect to the event signals on the event box.

Handling button press events on a GtkImage.

(C Language Example):

  static gboolean
  button_press_callback (GtkWidget      *event_box,
                         GdkEventButton *event,
                         gpointer        data)
  {
    g_print ("Event box clicked at coordinates %f,%f\n",
             event->x, event->y);

    // Returning TRUE means we handled the event, so the signal
    // emission should be stopped (don’t call any further callbacks
    // that may be connected). Return FALSE to continue invoking callbacks.
    return TRUE;
  }

  static GtkWidget*
  create_image (void)
  {
    GtkWidget *image;
    GtkWidget *event_box;

    image = gtk_image_new_from_file ("myfile.png");

    event_box = gtk_event_box_new ();

    gtk_container_add (GTK_CONTAINER (event_box), image);

    g_signal_connect (G_OBJECT (event_box),
                      "button_press_event",
                      G_CALLBACK (button_press_callback),
                      image);

    return image;
  }

When handling events on the event box, keep in mind that coordinates in the image may be different from event box coordinates due to the alignment and padding settings on the image (see GtkMisc). The simplest way to solve this is to set the alignment to 0.0 (left/top), and set the padding to zero. Then the origin of the image will be the same as the origin of the event box.

Sometimes an application will want to avoid depending on external data files, such as image files. GTK+ comes with a program to avoid this, called “gdk-pixbuf-csource”. This library allows you to convert an image into a C variable declaration, which can then be loaded into a GdkPixbuf using gdk_pixbuf_new_from_inline().

CSS nodes

GtkImage has a single CSS node with the name image. The style classes may appear on image CSS nodes: .icon-dropshadow, .lowres-icon.

The ImageProtocol protocol exposes the methods and properties of an underlying GtkImage 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 Image. Alternatively, use ImageRef as a lighweight, unowned reference if you already have an instance you just want to use.

  • ptr

    Untyped pointer to the underlying GtkImage instance.

    Declaration

    Swift

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

    Typed pointer to the underlying GtkImage instance.

    Default Implementation

    Return the stored, untyped pointer as a typed pointer to the GtkImage instance.

    Declaration

    Swift

    var image_ptr: UnsafeMutablePointer<GtkImage>! { get }
  • Required Initialiser for types conforming to ImageProtocol

    Declaration

    Swift

    init(raw: UnsafeMutableRawPointer)

Image Class

  • Bind a ImagePropertyName source property to a given target object.

    Declaration

    Swift

    @discardableResult
    @inlinable
    func bind<Q, T>(property source_property: ImagePropertyName, 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 Image property

    Declaration

    Swift

    @inlinable
    func get(property: ImagePropertyName) -> 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 Image property. Note that this will only have an effect on properties that are writable and not construct-only!

    Declaration

    Swift

    @inlinable
    func set(property: ImagePropertyName, value v: GLibObject.Value)

    Parameters

    property

    the property to get the value for

    Return Value

    the value of the named property

Image Class: ImageProtocol extension (methods and fields)

  • clear() Extension method

    Resets the image to be empty.

    Declaration

    Swift

    @inlinable
    func clear()
  • getAnimation() Extension method

    Gets the GdkPixbufAnimation being displayed by the GtkImage. The storage type of the image must be GTK_IMAGE_EMPTY or GTK_IMAGE_ANIMATION (see gtk_image_get_storage_type()). The caller of this function does not own a reference to the returned animation.

    Declaration

    Swift

    @inlinable
    func getAnimation() -> PixbufAnimationRef!
  • get(gicon:size:) Extension method

    Gets the GIcon and size being displayed by the GtkImage. The storage type of the image must be GTK_IMAGE_EMPTY or GTK_IMAGE_GICON (see gtk_image_get_storage_type()). The caller of this function does not own a reference to the returned GIcon.

    Declaration

    Swift

    @inlinable
    func get(gicon: UnsafeMutablePointer<UnsafeMutablePointer<GIcon>?>! = nil, size: UnsafeMutablePointer<GtkIconSize>! = nil)
  • get(iconName:size:) Extension method

    Gets the icon name and size being displayed by the GtkImage. The storage type of the image must be GTK_IMAGE_EMPTY or GTK_IMAGE_ICON_NAME (see gtk_image_get_storage_type()). The returned string is owned by the GtkImage and should not be freed.

    Declaration

    Swift

    @inlinable
    func get(iconName: UnsafeMutablePointer<UnsafePointer<gchar>?>! = nil, size: UnsafeMutablePointer<GtkIconSize>! = nil)
  • get(iconSet:size:) Extension method

    Gets the icon set and size being displayed by the GtkImage. The storage type of the image must be GTK_IMAGE_EMPTY or GTK_IMAGE_ICON_SET (see gtk_image_get_storage_type()).

    get_icon_set is deprecated: Use gtk_image_get_icon_name() instead.

    Declaration

    Swift

    @available(*, deprecated)
    @inlinable
    func get(iconSet: UnsafeMutablePointer<UnsafeMutablePointer<GtkIconSet>?>! = nil, size: UnsafeMutablePointer<GtkIconSize>! = nil)
  • getPixbuf() Extension method

    Gets the GdkPixbuf being displayed by the GtkImage. The storage type of the image must be GTK_IMAGE_EMPTY or GTK_IMAGE_PIXBUF (see gtk_image_get_storage_type()). The caller of this function does not own a reference to the returned pixbuf.

    Declaration

    Swift

    @inlinable
    func getPixbuf() -> PixbufRef!
  • getPixelSize() Extension method

    Gets the pixel size used for named icons.

    Declaration

    Swift

    @inlinable
    func getPixelSize() -> Int
  • getStock(stockID:size:) Extension method

    Gets the stock icon name and size being displayed by the GtkImage. The storage type of the image must be GTK_IMAGE_EMPTY or GTK_IMAGE_STOCK (see gtk_image_get_storage_type()). The returned string is owned by the GtkImage and should not be freed.

    get_stock is deprecated: Use gtk_image_get_icon_name() instead.

    Declaration

    Swift

    @available(*, deprecated)
    @inlinable
    func getStock(stockID: UnsafeMutablePointer<UnsafeMutablePointer<gchar>?>! = nil, size: UnsafeMutablePointer<GtkIconSize>! = nil)
  • getStorageType() Extension method

    Gets the type of representation being used by the GtkImage to store image data. If the GtkImage has no image data, the return value will be GTK_IMAGE_EMPTY.

    Declaration

    Swift

    @inlinable
    func getStorageType() -> GtkImageType
  • setFrom(animation:) Extension method

    Causes the GtkImage to display the given animation (or display nothing, if you set the animation to nil).

    Declaration

    Swift

    @inlinable
    func setFrom<PixbufAnimationT>(animation: PixbufAnimationT) where PixbufAnimationT : PixbufAnimationProtocol
  • setFromFile(filename:) Extension method

    See gtk_image_new_from_file() for details.

    Declaration

    Swift

    @inlinable
    func setFromFile(filename: UnsafePointer<gchar>? = nil)
  • setFromIcon(icon:size:) Extension method

    See gtk_image_new_from_gicon() for details.

    Declaration

    Swift

    @inlinable
    func setFromIcon<IconT>(icon: IconT, size: GtkIconSize) where IconT : IconProtocol
  • setFrom(iconName:size:) Extension method

    See gtk_image_new_from_icon_name() for details.

    Declaration

    Swift

    @inlinable
    func setFrom(iconName: UnsafePointer<gchar>? = nil, size: GtkIconSize)
  • setFrom(iconSet:size:) Extension method

    See gtk_image_new_from_icon_set() for details.

    set_from_icon_set is deprecated: Use gtk_image_set_from_icon_name() instead.

    Declaration

    Swift

    @available(*, deprecated)
    @inlinable
    func setFrom<IconSetT>(iconSet: IconSetT, size: GtkIconSize) where IconSetT : IconSetProtocol
  • setFrom(pixbuf:) Extension method

    See gtk_image_new_from_pixbuf() for details.

    Declaration

    Swift

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

    See gtk_image_new_from_pixbuf() for details.

    Declaration

    Swift

    @inlinable
    func setFrom<PixbufT>(pixbuf: PixbufT?) where PixbufT : PixbufProtocol
  • setFrom(resourcePath:) Extension method

    See gtk_image_new_from_resource() for details.

    Declaration

    Swift

    @inlinable
    func setFrom(resourcePath: UnsafePointer<gchar>? = nil)
  • setFromStock(stockID:size:) Extension method

    See gtk_image_new_from_stock() for details.

    set_from_stock is deprecated: Use gtk_image_set_from_icon_name() instead.

    Declaration

    Swift

    @available(*, deprecated)
    @inlinable
    func setFromStock(stockID: UnsafePointer<gchar>!, size: GtkIconSize)
  • setFrom(surface:) Extension method

    See gtk_image_new_from_surface() for details.

    Declaration

    Swift

    @inlinable
    func setFrom(surface: Cairo.SurfaceRef? = nil)
  • setFrom(surface:) Extension method

    See gtk_image_new_from_surface() for details.

    Declaration

    Swift

    @inlinable
    func setFrom<SurfaceT>(surface: SurfaceT?) where SurfaceT : SurfaceProtocol
  • set(pixelSize:) Extension method

    Sets the pixel size to use for named icons. If the pixel size is set to a value != -1, it is used instead of the icon size set by gtk_image_set_from_icon_name().

    Declaration

    Swift

    @inlinable
    func set(pixelSize: Int)
  • animation Extension method

    Gets the GdkPixbufAnimation being displayed by the GtkImage. The storage type of the image must be GTK_IMAGE_EMPTY or GTK_IMAGE_ANIMATION (see gtk_image_get_storage_type()). The caller of this function does not own a reference to the returned animation.

    Declaration

    Swift

    @inlinable
    var animation: PixbufAnimationRef! { get }
  • pixbuf Extension method

    Undocumented

    Declaration

    Swift

    @inlinable
    var pixbuf: PixbufRef! { get }
  • pixelSize Extension method

    Gets the pixel size used for named icons.

    Declaration

    Swift

    @inlinable
    var pixelSize: Int { get nonmutating set }
  • storageType Extension method

    Gets the type of representation being used by the GtkImage to store image data. If the GtkImage has no image data, the return value will be GTK_IMAGE_EMPTY.

    Declaration

    Swift

    @inlinable
    var storageType: GtkImageType { get }
  • misc Extension method

    Undocumented

    Declaration

    Swift

    @inlinable
    var misc: GtkMisc { get }