gtk.picture

Module for [Picture] class

Types 3

The gtk.picture.Picture widget displays a gdk.paintable.Paintable.

!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 gdk.texture.Texture.newFromFile, then create the gtk.picture.Picture with gtk.picture.Picture.newForPaintable.

Sometimes an application will want to avoid depending on external data files, such as image files. See the documentation of gio.resource.Resource for details. In this case, gtk.picture.Picture.newForResource and gtk.picture.Picture.setResource should be used.

gtk.picture.Picture displays an image at its natural size. See gtk.image.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 gtk.picture.Picture by changing gtk.picture.Picture.contentFit. See gtk.types.ContentFit for details. gtk.picture.Picture.canShrink 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 gtk.widget.Widget.halign and gtk.widget.Widget.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

gtk.picture.Picture has a single CSS node with the name picture.

Accessibility

gtk.picture.Picture uses the gtk.types.AccessibleRole.Img role.

Methods
GType _getGType() static nothrow
GType _gType() @property nothrow
Picture self() nothrowReturns `this`, for use in `with` statements.
PictureGidBuilder builder() static nothrowGet builder for [gtk.picture.Picture] Returns: New builder object
string alternativeText() @property nothrowGet `alternativeText` property. Returns: The alternative textual description for the picture.
void alternativeText(string propval) @property nothrowSet `alternativeText` property. Params: propval = The alternative textual description for the picture.
bool canShrink() @property nothrowGet `canShrink` property. Returns: If the [gtk.picture.Picture] can be made smaller than the natural size of its contents.
void canShrink(bool propval) @property nothrowSet `canShrink` property. Params: propval = If the [gtk.picture.Picture] can be made smaller than the natural size of its contents.
gtk.types.ContentFit contentFit() @property nothrowGet `contentFit` property. Returns: How the content should be resized to fit inside the [gtk.picture.Picture].
void contentFit(gtk.types.ContentFit propval) @property nothrowSet `contentFit` property. Params: propval = How the content should be resized to fit inside the [gtk.picture.Picture].
gio.file.File file() @property nothrowGet `file` property. Returns: The [gio.file.File] that is displayed or null if none.
void file(gio.file.File propval) @property nothrowSet `file` property. Params: propval = The [gio.file.File] that is displayed or null if none.
bool keepAspectRatio() @property nothrowGet `keepAspectRatio` property. Returns: Whether the GtkPicture will render its contents trying to preserve the aspect ratio.
void keepAspectRatio(bool propval) @property nothrowSet `keepAspectRatio` property. Params: propval = Whether the GtkPicture will render its contents trying to preserve the aspect ratio.
gdk.paintable.Paintable paintable() @property nothrowGet `paintable` property. Returns: The [gdk.paintable.Paintable] to be displayed by this [gtk.picture.Picture].
void paintable(gdk.paintable.Paintable propval) @property nothrowSet `paintable` property. Params: propval = The [gdk.paintable.Paintable] to be displayed by this [gtk.picture.Picture].
gtk.picture.Picture newForFile(gio.file.File file = null) static nothrowCreates a new [gtk.picture.Picture] displaying the given file.
gtk.picture.Picture newForFilename(string filename = null) static nothrowCreates a new [gtk.picture.Picture] displaying the file filename.
gtk.picture.Picture newForPaintable(gdk.paintable.Paintable paintable = null) static nothrowCreates a new [gtk.picture.Picture] displaying paintable.
gtk.picture.Picture newForPixbuf(gdkpixbuf.pixbuf.Pixbuf pixbuf = null) static nothrowCreates a new [gtk.picture.Picture] displaying pixbuf.
gtk.picture.Picture newForResource(string resourcePath = null) static nothrowCreates a new [gtk.picture.Picture] displaying the resource at resource_path.
string getAlternativeText() nothrowGets the alternative textual description of the picture.
bool getCanShrink() nothrowReturns whether the [gtk.picture.Picture] respects its contents size. Returns: true if the picture can be made smaller than its contents
gtk.types.ContentFit getContentFit() nothrowReturns the fit mode for the content of the [gtk.picture.Picture].
gio.file.File getFile() nothrowGets the [gio.file.File] currently displayed if self is displaying a file.
bool getKeepAspectRatio() nothrowReturns whether the [gtk.picture.Picture] preserves its contents aspect ratio. Returns: true if the self tries to keep the contents' aspect ratio
gdk.paintable.Paintable getPaintable() nothrowGets the [gdk.paintable.Paintable] being displayed by the [gtk.picture.Picture]. Returns: the displayed paintable
void setAlternativeText(string alternativeText = null) nothrowSets an alternative textual description for the picture contents.
void setCanShrink(bool canShrink) nothrowIf set to true, the self can be made smaller than its contents.
void setContentFit(gtk.types.ContentFit contentFit) nothrowSets how the content should be resized to fit the [gtk.picture.Picture].
void setFile(gio.file.File file = null) nothrowMakes self load and display file.
void setFilename(string filename = null) nothrowMakes self load and display the given filename.
void setKeepAspectRatio(bool keepAspectRatio) nothrowIf set to true, the self will render its contents according to their aspect ratio.
void setPaintable(gdk.paintable.Paintable paintable = null) nothrowMakes self display the given paintable.
void setPixbuf(gdkpixbuf.pixbuf.Pixbuf pixbuf = null) nothrowSets a [gtk.picture.Picture] to show a [gdkpixbuf.pixbuf.Pixbuf].
void setResource(string resourcePath = null) nothrowMakes self load and display the resource at the given resource_path.
Constructors
this(void * ptr, Flag!"Take" take)
this()Creates a new empty [gtk.picture.Picture] widget. Returns: a newly created [gtk.picture.Picture] widget.

Fluent builder implementation template for gtk.picture.Picture

Methods
T alternativeText(string propval) nothrowSet `alternativeText` property. Params: propval = The alternative textual description for the picture. Returns: Builder instance for fluent chaining
T canShrink(bool propval) nothrowSet `canShrink` property. Params: propval = If the [gtk.picture.Picture] can be made smaller than the natural size of its contents. Returns: Builder instance for fluent chaining
T contentFit(gtk.types.ContentFit propval) nothrowSet `contentFit` property. Params: propval = How the content should be resized to fit inside the [gtk.picture.Picture]. Returns: Builder instance for fluent chaining
T file(gio.file.File propval) nothrowSet `file` property. Params: propval = The [gio.file.File] that is displayed or null if none. Returns: Builder instance for fluent chaining
T keepAspectRatio(bool propval) nothrowSet `keepAspectRatio` property. Params: propval = Whether the GtkPicture will render its contents trying to preserve the aspect ratio. Returns: Builder instance for fluent chaining
T paintable(gdk.paintable.Paintable propval) nothrowSet `paintable` property. Params: propval = The [gdk.paintable.Paintable] to be displayed by this [gtk.picture.Picture]. Returns: Builder instance for fluent chaining

Fluent builder for gtk.picture.Picture

Methods
Picture build() nothrowCreate object from builder. Returns: New object