ImageRef
public struct ImageRef : ImageProtocol, GWeakCapturing
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 ImageRef type acts as a lightweight Swift reference to an underlying GtkImage instance.
It exposes methods that can operate on this data type through ImageProtocol conformance.
Use ImageRef only as an unowned reference to an existing GtkImage instance.
-
Untyped pointer to the underlying `GtkImage` instance.For type-safe access, use the generated, typed pointer
image_ptrproperty instead.Declaration
Swift
public let ptr: UnsafeMutableRawPointer!
-
Designated initialiser from the underlying
Cdata typeDeclaration
Swift
@inlinable init(_ p: UnsafeMutablePointer<GtkImage>) -
Designated initialiser from a constant pointer to the underlying
Cdata typeDeclaration
Swift
@inlinable init(_ p: UnsafePointer<GtkImage>) -
Conditional initialiser from an optional pointer to the underlying
Cdata typeDeclaration
Swift
@inlinable init!(_ maybePointer: UnsafeMutablePointer<GtkImage>?) -
Conditional initialiser from an optional, non-mutable pointer to the underlying
Cdata typeDeclaration
Swift
@inlinable init!(_ maybePointer: UnsafePointer<GtkImage>?) -
Conditional initialiser from an optional
gpointerDeclaration
Swift
@inlinable init!(gpointer g: gpointer?) -
Conditional initialiser from an optional, non-mutable
gconstpointerDeclaration
Swift
@inlinable init!(gconstpointer g: gconstpointer?) -
Reference intialiser for a related type that implements
ImageProtocolDeclaration
Swift
@inlinable init<T>(_ other: T) where T : ImageProtocol -
This factory is syntactic sugar for setting weak pointers wrapped in
GWeak<T>Declaration
Swift
@inlinable static func unowned<T>(_ other: T) -> ImageRef where T : ImageProtocol -
Unsafe typed initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
ImageProtocol.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
ImageProtocol.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
ImageProtocol.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
ImageProtocol.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
ImageProtocol.Declaration
Swift
@inlinable init(opaquePointer: OpaquePointer) -
Creates a new empty
GtkImagewidget.Declaration
Swift
@inlinable init() -
Creates a
GtkImagedisplaying the given animation. TheGtkImagedoes not assume a reference to the animation; you still need to unref it if you own references.GtkImagewill add its own reference rather than adopting yours.Note that the animation frames are shown using a timeout with
G_PRIORITY_DEFAULT. When using animations to indicate busyness, keep in mind that the animation will only be shown if the main loop is not busy with something that has a higher priority.Declaration
Swift
@inlinable init<PixbufAnimationT>(animation: PixbufAnimationT) where PixbufAnimationT : PixbufAnimationProtocol -
Creates a new
GtkImagedisplaying the filefilename. If the file isn’t found or can’t be loaded, the resultingGtkImagewill display a “broken image” icon. This function never returnsnil, it always returns a validGtkImagewidget.If the file contains an animation, the image will contain an animation.
If you need to detect failures to load the file, use
gdk_pixbuf_new_from_file()to load the file yourself, then create theGtkImagefrom the pixbuf. (Or for animations, usegdk_pixbuf_animation_new_from_file()).The storage type (
gtk_image_get_storage_type()) of the returned image is not defined, it will be whatever is appropriate for displaying the file.Declaration
Swift
@inlinable init(file filename: UnsafePointer<gchar>!) -
Creates a
GtkImagedisplaying an icon from the current icon theme. If the icon name isn’t known, a “broken image” icon will be displayed instead. If the current icon theme is changed, the icon will be updated appropriately.Declaration
Swift
@inlinable init<IconT>(gicon icon: IconT, size: GtkIconSize) where IconT : IconProtocol -
Creates a
GtkImagedisplaying an icon from the current icon theme. If the icon name isn’t known, a “broken image” icon will be displayed instead. If the current icon theme is changed, the icon will be updated appropriately.Declaration
Swift
@inlinable init(iconName: UnsafePointer<gchar>? = nil, size: GtkIconSize) -
Creates a
GtkImagedisplaying an icon set. Sample stock sizes areGTK_ICON_SIZE_MENU,GTK_ICON_SIZE_SMALL_TOOLBAR. Instead of using this function, usually it’s better to create aGtkIconFactory, put your icon sets in the icon factory, add the icon factory to the list of default factories withgtk_icon_factory_add_default(), and then usegtk_image_new_from_stock(). This will allow themes to override the icon you ship with your application.The
GtkImagedoes not assume a reference to the icon set; you still need to unref it if you own references.GtkImagewill add its own reference rather than adopting yours.new_from_icon_set is deprecated: Use gtk_image_new_from_icon_name() instead.
Declaration
Swift
@available(*, deprecated) @inlinable init<IconSetT>(iconSet: IconSetT, size: GtkIconSize) where IconSetT : IconSetProtocol -
Creates a new
GtkImagedisplayingpixbuf. TheGtkImagedoes not assume a reference to the pixbuf; you still need to unref it if you own references.GtkImagewill add its own reference rather than adopting yours.Note that this function just creates an
GtkImagefrom the pixbuf. TheGtkImagecreated will not react to state changes. Should you want that, you should usegtk_image_new_from_icon_name().Declaration
Swift
@inlinable init<PixbufT>(pixbuf: PixbufT?) where PixbufT : PixbufProtocol -
Creates a new
GtkImagedisplaying the resource fileresource_path. If the file isn’t found or can’t be loaded, the resultingGtkImagewill display a “broken image” icon. This function never returnsnil, it always returns a validGtkImagewidget.If the file contains an animation, the image will contain an animation.
If you need to detect failures to load the file, use
gdk_pixbuf_new_from_file()to load the file yourself, then create theGtkImagefrom the pixbuf. (Or for animations, usegdk_pixbuf_animation_new_from_file()).The storage type (
gtk_image_get_storage_type()) of the returned image is not defined, it will be whatever is appropriate for displaying the file.Declaration
Swift
@inlinable init(resource resourcePath: UnsafePointer<gchar>!) -
Creates a
GtkImagedisplaying a stock icon. Sample stock icon names areGTK_STOCK_OPEN,GTK_STOCK_QUIT. Sample stock sizes areGTK_ICON_SIZE_MENU,GTK_ICON_SIZE_SMALL_TOOLBAR. If the stock icon name isn’t known, the image will be empty. You can register your own stock icon names, seegtk_icon_factory_add_default()andgtk_icon_factory_add().new_from_stock is deprecated: Use gtk_image_new_from_icon_name() instead.
Declaration
Swift
@available(*, deprecated) @inlinable init(stock stockID: UnsafePointer<gchar>!, size: GtkIconSize) -
Creates a new
GtkImagedisplayingsurface. TheGtkImagedoes not assume a reference to the surface; you still need to unref it if you own references.GtkImagewill add its own reference rather than adopting yours.Declaration
Swift
@inlinable init<SurfaceT>(surface: SurfaceT?) where SurfaceT : SurfaceProtocol -
Creates a
GtkImagedisplaying the given animation. TheGtkImagedoes not assume a reference to the animation; you still need to unref it if you own references.GtkImagewill add its own reference rather than adopting yours.Note that the animation frames are shown using a timeout with
G_PRIORITY_DEFAULT. When using animations to indicate busyness, keep in mind that the animation will only be shown if the main loop is not busy with something that has a higher priority.Declaration
Swift
@inlinable static func newFrom<PixbufAnimationT>(animation: PixbufAnimationT) -> WidgetRef! where PixbufAnimationT : PixbufAnimationProtocol -
Creates a new
GtkImagedisplaying the filefilename. If the file isn’t found or can’t be loaded, the resultingGtkImagewill display a “broken image” icon. This function never returnsnil, it always returns a validGtkImagewidget.If the file contains an animation, the image will contain an animation.
If you need to detect failures to load the file, use
gdk_pixbuf_new_from_file()to load the file yourself, then create theGtkImagefrom the pixbuf. (Or for animations, usegdk_pixbuf_animation_new_from_file()).The storage type (
gtk_image_get_storage_type()) of the returned image is not defined, it will be whatever is appropriate for displaying the file.Declaration
Swift
@inlinable static func newFrom(file filename: UnsafePointer<gchar>!) -> WidgetRef! -
Creates a
GtkImagedisplaying an icon from the current icon theme. If the icon name isn’t known, a “broken image” icon will be displayed instead. If the current icon theme is changed, the icon will be updated appropriately.Declaration
Swift
@inlinable static func newFromG<IconT>(gicon icon: IconT, size: GtkIconSize) -> WidgetRef! where IconT : IconProtocol -
Creates a
GtkImagedisplaying an icon from the current icon theme. If the icon name isn’t known, a “broken image” icon will be displayed instead. If the current icon theme is changed, the icon will be updated appropriately.Declaration
Swift
@inlinable static func newFrom(iconName: UnsafePointer<gchar>? = nil, size: GtkIconSize) -> WidgetRef! -
Creates a
GtkImagedisplaying an icon set. Sample stock sizes areGTK_ICON_SIZE_MENU,GTK_ICON_SIZE_SMALL_TOOLBAR. Instead of using this function, usually it’s better to create aGtkIconFactory, put your icon sets in the icon factory, add the icon factory to the list of default factories withgtk_icon_factory_add_default(), and then usegtk_image_new_from_stock(). This will allow themes to override the icon you ship with your application.The
GtkImagedoes not assume a reference to the icon set; you still need to unref it if you own references.GtkImagewill add its own reference rather than adopting yours.new_from_icon_set is deprecated: Use gtk_image_new_from_icon_name() instead.
Declaration
Swift
@available(*, deprecated) @inlinable static func newFrom<IconSetT>(iconSet: IconSetT, size: GtkIconSize) -> WidgetRef! where IconSetT : IconSetProtocol -
Creates a new
GtkImagedisplayingpixbuf. TheGtkImagedoes not assume a reference to the pixbuf; you still need to unref it if you own references.GtkImagewill add its own reference rather than adopting yours.Note that this function just creates an
GtkImagefrom the pixbuf. TheGtkImagecreated will not react to state changes. Should you want that, you should usegtk_image_new_from_icon_name().Declaration
Swift
@inlinable static func newFrom<PixbufT>(pixbuf: PixbufT?) -> WidgetRef! where PixbufT : PixbufProtocol -
Creates a new
GtkImagedisplaying the resource fileresource_path. If the file isn’t found or can’t be loaded, the resultingGtkImagewill display a “broken image” icon. This function never returnsnil, it always returns a validGtkImagewidget.If the file contains an animation, the image will contain an animation.
If you need to detect failures to load the file, use
gdk_pixbuf_new_from_file()to load the file yourself, then create theGtkImagefrom the pixbuf. (Or for animations, usegdk_pixbuf_animation_new_from_file()).The storage type (
gtk_image_get_storage_type()) of the returned image is not defined, it will be whatever is appropriate for displaying the file.Declaration
Swift
@inlinable static func newFrom(resource resourcePath: UnsafePointer<gchar>!) -> WidgetRef! -
Creates a
GtkImagedisplaying a stock icon. Sample stock icon names areGTK_STOCK_OPEN,GTK_STOCK_QUIT. Sample stock sizes areGTK_ICON_SIZE_MENU,GTK_ICON_SIZE_SMALL_TOOLBAR. If the stock icon name isn’t known, the image will be empty. You can register your own stock icon names, seegtk_icon_factory_add_default()andgtk_icon_factory_add().new_from_stock is deprecated: Use gtk_image_new_from_icon_name() instead.
Declaration
Swift
@available(*, deprecated) @inlinable static func newFrom(stock stockID: UnsafePointer<gchar>!, size: GtkIconSize) -> WidgetRef! -
Creates a new
GtkImagedisplayingsurface. TheGtkImagedoes not assume a reference to the surface; you still need to unref it if you own references.GtkImagewill add its own reference rather than adopting yours.Declaration
Swift
@inlinable static func newFrom<SurfaceT>(surface: SurfaceT?) -> WidgetRef! where SurfaceT : SurfaceProtocol
View on GitHub
Install in Dash
ImageRef Structure Reference