Struct gtk4::Picture [−][src]
pub struct Picture(_);
Expand description
The Picture
widget displays a gdk::Paintable
.
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 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 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
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 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
.
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 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
Sets a Picture
to show a gdk_pixbuf::Pixbuf
.
See for_pixbuf()
for details.
This is a utility function that calls set_paintable()
.
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
pub fn connect_alternative_text_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_keep_aspect_ratio_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
Trait Implementations
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
Returns the type identifier of Self
.
Auto Trait Implementations
impl RefUnwindSafe for Picture
impl UnwindSafe for Picture
Blanket Implementations
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
Returns true
if the object is an instance of (can be cast to) T
.
pub fn set_property<'a, N, V>(
&self,
property_name: N,
value: V
) -> Result<(), BoolError> where
N: Into<&'a str>,
V: ToValue,
pub fn set_property_from_value<'a, N>(
&self,
property_name: N,
value: &Value
) -> Result<(), BoolError> where
N: Into<&'a str>,
pub fn set_properties_from_value(
&self,
property_values: &[(&str, Value)]
) -> Result<(), BoolError>
pub fn has_property<'a, N>(&self, property_name: N, type_: Option<Type>) -> bool where
N: Into<&'a str>,
pub fn find_property<'a, N>(&self, property_name: N) -> Option<ParamSpec> where
N: Into<&'a str>,
Safety Read more
Safety Read more
Safety Read more
Safety Read more
pub fn connect<'a, N, F>(
&self,
signal_name: N,
after: bool,
callback: F
) -> Result<SignalHandlerId, BoolError> where
N: Into<&'a str>,
F: 'static + Fn(&[Value]) -> Option<Value> + Send + Sync,
Same as connect
but takes a SignalId
instead of a signal name.
pub fn connect_local<'a, N, F>(
&self,
signal_name: N,
after: bool,
callback: F
) -> Result<SignalHandlerId, BoolError> where
N: Into<&'a str>,
F: 'static + Fn(&[Value]) -> Option<Value>,
Same as connect_local
but takes a SignalId
instead of a signal name.
pub unsafe fn connect_unsafe<'a, N, F>(
&self,
signal_name: N,
after: bool,
callback: F
) -> Result<SignalHandlerId, BoolError> where
N: Into<&'a str>,
F: Fn(&[Value]) -> Option<Value>,
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.
pub fn connect_notify<F>(&self, name: Option<&str>, f: F) -> SignalHandlerId where
F: 'static + Fn(&T, &ParamSpec) + Send + Sync,
pub fn connect_notify_local<F>(
&self,
name: Option<&str>,
f: F
) -> SignalHandlerId where
F: 'static + Fn(&T, &ParamSpec),
pub unsafe fn connect_notify_unsafe<F>(
&self,
name: Option<&str>,
f: F
) -> SignalHandlerId where
F: Fn(&T, &ParamSpec),
pub fn bind_property<'a, O, N, M>(
&'a self,
source_property: N,
target: &'a O,
target_property: M
) -> BindingBuilder<'a> where
O: ObjectType,
N: Into<&'a str>,
M: Into<&'a str>,
Returns a SendValue
clone of self
.