Struct gtk4::Picture[][src]

pub struct Picture(_);
Expand description

The Picture widget displays a gdk::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:

⚠️ The following code is in c ⚠️

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::from_file()][crate::gdk::`Texture::from_file()`], then create the [`Picture`][crate::Picture] with [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, for_resource() and set_resource() should be used.

Picture displays an image at its natural size. See 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 Picture. By turning off property::Picture::keep-aspect-ratio you can allow the paintable to get stretched. property::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 property::GtkWidget::halign and property::GtkWidget::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

Picture has a single CSS node with the name picture.

Accessibility

Picture uses the GTK_ACCESSIBLE_ROLE_IMG role.

Implements

WidgetExt, glib::ObjectExt, AccessibleExt, BuildableExt, ConstraintTargetExt, WidgetExtManual, AccessibleExtManual

Implementations

Creates a new empty Picture widget.

Returns

a newly created Picture widget.

Creates a new Picture displaying the given file.

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

If you need to detect failures to load the file, use gdk::Texture::from_file()`` to load the file yourself, then create the Picture from the texture.

file

a GFile

Returns

a new Picture

Creates a new Picture displaying the file filename.

This is a utility function that calls for_file(). See that function for details.

filename

a filename

Returns

a new Picture

Creates a new Picture displaying paintable.

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

paintable

a gdk::Paintable

Returns

a new Picture

Creates a new Picture displaying pixbuf.

This is a utility function that calls for_paintable(), See that function for details.

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

pixbuf

a gdk_pixbuf::Pixbuf

Returns

a new Picture

Creates a new Picture displaying the resource at resource_path.

This is a utility function that calls for_file(). See that function for details.

resource_path

resource path to play back

Returns

a new Picture

Creates a new builder-pattern struct instance to construct Picture objects.

This method returns an instance of PictureBuilder which can be used to create Picture objects.

Gets the alternative textual description of the picture.

The returned string will be None if the picture cannot be described textually.

Returns

the alternative textual description of self.

Returns whether the Picture respects its contents size.

Returns

true if the picture can be made smaller than its contents

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

If self is not displaying a file, for example when set_paintable() was used, then None is returned.

Returns

The GFile displayed by self.

Returns whether the Picture preserves its contents aspect ratio.

Returns

true if the self tries to keep the contents’ aspect ratio

Gets the gdk::Paintable being displayed by the Picture.

Returns

the displayed paintable

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 None.

alternative_text

a textual description of the contents

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 WidgetExt::set_size_request().

Also of note is that a similar function for growing does not exist because the grow behavior can be controlled via WidgetExt::set_halign() and WidgetExt::set_valign().

can_shrink

if self can be made smaller than its contents

Makes self load and display file.

See for_file() for details.

file

a GFile

Makes self load and display the given filename.

This is a utility function that calls set_file().

filename

the filename to play

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.

keep_aspect_ratio

whether to keep aspect ratio

Makes self display the given paintable.

If paintable is None, nothing will be displayed.

See for_paintable() for details.

paintable

a gdk::Paintable

Sets a Picture to show a gdk_pixbuf::Pixbuf.

See for_pixbuf() for details.

This is a utility function that calls set_paintable().

pixbuf

a gdk_pixbuf::Pixbuf

Makes self load and display the resource at the given resource_path.

This is a utility function that calls set_file().

resource_path

the resource to set

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Returns the type identifier of Self.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Upcasts an object to a superclass or interface T. Read more

Upcasts an object to a reference of its superclass or interface T. Read more

Tries to downcast to a subclass or interface implementor T. Read more

Tries to downcast to a reference of its subclass or interface implementor T. Read more

Tries to cast to an object of type T. This handles upcasting, downcasting and casting between interface and interface implementors. All checks are performed at runtime, while downcast and upcast will do many checks at compile-time already. Read more

Tries to cast to reference to an object of type T. This handles upcasting, downcasting and casting between interface and interface implementors. All checks are performed at runtime, while downcast and upcast will do many checks at compile-time already. Read more

Casts to T unconditionally. Read more

Casts to &T unconditionally. Read more

Performs the conversion.

Performs the conversion.

Returns true if the object is an instance of (can be cast to) T.

Safety Read more

Safety Read more

Safety Read more

Safety Read more

Safety Read more

Safety Read more

Same as connect but takes a SignalId instead of a signal name.

Same as connect_local but takes a SignalId instead of a signal name.

Same as connect_unsafe but takes a SignalId instead of a signal name.

Emit signal by signal id.

Same as emit but takes Value for the arguments.

Emit signal by its name.

Same as emit_by_name but takes Value for the arguments.

Emit signal with details by signal id.

Same as emit_with_details but takes Value for the arguments.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Returns a SendValue clone of self.

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.