#[repr(transparent)]pub struct Picture { /* private fields */ }
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()
, then create the 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 changing property::Picture::content-fit
. See ContentFit
for details. 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§
source§impl Picture
impl Picture
sourcepub fn for_file(file: &impl IsA<File>) -> Picture
pub fn for_file(file: &impl IsA<File>) -> Picture
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
sourcepub fn for_filename(filename: impl AsRef<Path>) -> Picture
pub fn for_filename(filename: impl AsRef<Path>) -> 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
sourcepub fn for_paintable(paintable: &impl IsA<Paintable>) -> Picture
pub fn for_paintable(paintable: &impl IsA<Paintable>) -> Picture
sourcepub fn for_pixbuf(pixbuf: &Pixbuf) -> Picture
pub fn for_pixbuf(pixbuf: &Pixbuf) -> 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
sourcepub fn for_resource(resource_path: &str) -> Picture
pub fn for_resource(resource_path: &str) -> 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
sourcepub fn builder() -> PictureBuilder
pub fn builder() -> PictureBuilder
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.
sourcepub fn alternative_text(&self) -> Option<GString>
pub fn alternative_text(&self) -> Option<GString>
sourcepub fn can_shrink(&self) -> bool
pub fn can_shrink(&self) -> bool
sourcepub fn content_fit(&self) -> ContentFit
Available on crate feature v4_8
only.
pub fn content_fit(&self) -> ContentFit
v4_8
only.Returns the fit mode for the content of the Picture
.
See ContentFit
for details.
Returns
the content fit mode
sourcepub fn file(&self) -> Option<File>
pub fn file(&self) -> Option<File>
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.
sourcepub fn is_keep_aspect_ratio(&self) -> bool
pub fn is_keep_aspect_ratio(&self) -> bool
Returns whether the Picture
preserves its contents aspect ratio.
Deprecated since 4.8
Use content_fit()
instead. This will
now return FALSE
only if property::Picture::content-fit
is
GTK_CONTENT_FIT_FILL
. Returns TRUE
otherwise.
Returns
true
if the self tries to keep the contents’ aspect ratio
sourcepub fn set_alternative_text(&self, alternative_text: Option<&str>)
pub fn set_alternative_text(&self, alternative_text: Option<&str>)
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
sourcepub fn set_can_shrink(&self, can_shrink: bool)
pub fn set_can_shrink(&self, can_shrink: bool)
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
sourcepub fn set_content_fit(&self, content_fit: ContentFit)
Available on crate feature v4_8
only.
pub fn set_content_fit(&self, content_fit: ContentFit)
v4_8
only.Sets how the content should be resized to fit the Picture
.
See ContentFit
for details.
content_fit
the content fit mode
sourcepub fn set_filename(&self, filename: Option<impl AsRef<Path>>)
pub fn set_filename(&self, filename: Option<impl AsRef<Path>>)
Makes @self load and display the given @filename.
This is a utility function that calls set_file()
.
filename
the filename to play
sourcepub fn set_keep_aspect_ratio(&self, keep_aspect_ratio: bool)
pub fn set_keep_aspect_ratio(&self, keep_aspect_ratio: bool)
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.
Deprecated since 4.8
Use set_content_fit()
instead. If still
used, this method will always set the property::Picture::content-fit
property to GTK_CONTENT_FIT_CONTAIN
if @keep_aspect_ratio is true,
otherwise it will set it to GTK_CONTENT_FIT_FILL
.
keep_aspect_ratio
whether to keep aspect ratio
sourcepub fn set_paintable(&self, paintable: Option<&impl IsA<Paintable>>)
pub fn set_paintable(&self, paintable: Option<&impl IsA<Paintable>>)
Makes @self display the given @paintable.
If @paintable is None
, nothing will be displayed.
See for_paintable()
for details.
paintable
sourcepub fn set_pixbuf(&self, pixbuf: Option<&Pixbuf>)
pub fn set_pixbuf(&self, pixbuf: Option<&Pixbuf>)
Sets a Picture
to show a gdk_pixbuf::Pixbuf
.
See for_pixbuf()
for details.
This is a utility function that calls set_paintable()
.
pixbuf
sourcepub fn set_resource(&self, resource_path: Option<&str>)
pub fn set_resource(&self, resource_path: Option<&str>)
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_can_shrink_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_content_fit_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
v4_8
only.pub fn connect_file_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_keep_aspect_ratio_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_paintable_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
Trait Implementations§
source§impl Ord for Picture
impl Ord for Picture
source§impl<OT: ObjectType> PartialEq<OT> for Picture
impl<OT: ObjectType> PartialEq<OT> for Picture
source§impl<OT: ObjectType> PartialOrd<OT> for Picture
impl<OT: ObjectType> PartialOrd<OT> for Picture
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl StaticType for Picture
impl StaticType for Picture
source§fn static_type() -> Type
fn static_type() -> Type
Self
.impl Eq for Picture
impl IsA<Accessible> for Picture
impl IsA<Buildable> for Picture
impl IsA<ConstraintTarget> for Picture
impl IsA<Widget> for Picture
Auto Trait Implementations§
impl RefUnwindSafe for Picture
impl !Send for Picture
impl !Sync for Picture
impl Unpin for Picture
impl UnwindSafe for Picture
Blanket Implementations§
source§impl<O> AccessibleExtManual for Owhere
O: IsA<Accessible>,
impl<O> AccessibleExtManual for Owhere
O: IsA<Accessible>,
source§fn update_property(&self, properties: &[Property<'_>])
fn update_property(&self, properties: &[Property<'_>])
source§fn update_relation(&self, relations: &[Relation<'_>])
fn update_relation(&self, relations: &[Relation<'_>])
source§fn update_state(&self, states: &[State])
fn update_state(&self, states: &[State])
source§impl<T> Cast for Twhere
T: ObjectType,
impl<T> Cast for Twhere
T: ObjectType,
source§fn upcast<T>(self) -> Twhere
T: ObjectType,
Self: IsA<T>,
fn upcast<T>(self) -> Twhere
T: ObjectType,
Self: IsA<T>,
T
. Read moresource§fn upcast_ref<T>(&self) -> &Twhere
T: ObjectType,
Self: IsA<T>,
fn upcast_ref<T>(&self) -> &Twhere
T: ObjectType,
Self: IsA<T>,
T
. Read moresource§fn downcast<T>(self) -> Result<T, Self>where
T: ObjectType,
Self: CanDowncast<T>,
fn downcast<T>(self) -> Result<T, Self>where
T: ObjectType,
Self: CanDowncast<T>,
T
. Read moresource§fn downcast_ref<T>(&self) -> Option<&T>where
T: ObjectType,
Self: CanDowncast<T>,
fn downcast_ref<T>(&self) -> Option<&T>where
T: ObjectType,
Self: CanDowncast<T>,
T
. Read moresource§fn dynamic_cast<T>(self) -> Result<T, Self>where
T: ObjectType,
fn dynamic_cast<T>(self) -> Result<T, Self>where
T: ObjectType,
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 moresource§fn dynamic_cast_ref<T>(&self) -> Option<&T>where
T: ObjectType,
fn dynamic_cast_ref<T>(&self) -> Option<&T>where
T: ObjectType,
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 moresource§unsafe fn unsafe_cast<T>(self) -> Twhere
T: ObjectType,
unsafe fn unsafe_cast<T>(self) -> Twhere
T: ObjectType,
T
unconditionally. Read moresource§unsafe fn unsafe_cast_ref<T>(&self) -> &Twhere
T: ObjectType,
unsafe fn unsafe_cast_ref<T>(&self) -> &Twhere
T: ObjectType,
&T
unconditionally. Read moresource§impl<U> IsSubclassableExt for Uwhere
U: IsClass + ParentClassIs,
impl<U> IsSubclassableExt for Uwhere
U: IsClass + ParentClassIs,
fn parent_class_init<T>(class: &mut Class<U>)where
T: ObjectSubclass,
<U as ParentClassIs>::Parent: IsSubclassable<T>,
fn parent_instance_init<T>(instance: &mut InitializingObject<T>)where
T: ObjectSubclass,
<U as ParentClassIs>::Parent: IsSubclassable<T>,
source§impl<T> ObjectExt for Twhere
T: ObjectType,
impl<T> ObjectExt for Twhere
T: ObjectType,
source§fn is<U>(&self) -> boolwhere
U: StaticType,
fn is<U>(&self) -> boolwhere
U: StaticType,
true
if the object is an instance of (can be cast to) T
.source§fn object_class(&self) -> &Class<Object>
fn object_class(&self) -> &Class<Object>
ObjectClass
of the object. Read moresource§fn class_of<U>(&self) -> Option<&Class<U>>where
U: IsClass,
fn class_of<U>(&self) -> Option<&Class<U>>where
U: IsClass,
T
. Read moresource§fn interface<U>(&self) -> Option<InterfaceRef<'_, U>>where
U: IsInterface,
fn interface<U>(&self) -> Option<InterfaceRef<'_, U>>where
U: IsInterface,
T
of the object. Read moresource§fn set_property<V>(&self, property_name: &str, value: V)where
V: ToValue,
fn set_property<V>(&self, property_name: &str, value: V)where
V: ToValue,
source§fn set_property_from_value(&self, property_name: &str, value: &Value)
fn set_property_from_value(&self, property_name: &str, value: &Value)
source§fn set_properties(&self, property_values: &[(&str, &dyn ToValue)])
fn set_properties(&self, property_values: &[(&str, &dyn ToValue)])
source§fn set_properties_from_value(&self, property_values: &[(&str, Value)])
fn set_properties_from_value(&self, property_values: &[(&str, Value)])
source§fn property<V>(&self, property_name: &str) -> Vwhere
V: 'static + for<'b> FromValue<'b>,
fn property<V>(&self, property_name: &str) -> Vwhere
V: 'static + for<'b> FromValue<'b>,
property_name
of the object and cast it to the type V. Read moresource§fn property_value(&self, property_name: &str) -> Value
fn property_value(&self, property_name: &str) -> Value
property_name
of the object. Read moresource§fn property_type(&self, property_name: &str) -> Option<Type>
fn property_type(&self, property_name: &str) -> Option<Type>
property_name
of this object. Read moresource§fn find_property(&self, property_name: &str) -> Option<ParamSpec>
fn find_property(&self, property_name: &str) -> Option<ParamSpec>
ParamSpec
of the property property_name
of this object.source§fn list_properties(&self) -> PtrSlice<ParamSpec>
fn list_properties(&self) -> PtrSlice<ParamSpec>
ParamSpec
of the properties of this object.source§fn freeze_notify(&self) -> PropertyNotificationFreezeGuard
fn freeze_notify(&self) -> PropertyNotificationFreezeGuard
source§unsafe fn set_qdata<QD>(&self, key: Quark, value: QD)where
QD: 'static,
unsafe fn set_qdata<QD>(&self, key: Quark, value: QD)where
QD: 'static,
key
. Read moresource§unsafe fn qdata<QD>(&self, key: Quark) -> Option<NonNull<QD>>where
QD: 'static,
unsafe fn qdata<QD>(&self, key: Quark) -> Option<NonNull<QD>>where
QD: 'static,
key
. Read moresource§unsafe fn steal_qdata<QD>(&self, key: Quark) -> Option<QD>where
QD: 'static,
unsafe fn steal_qdata<QD>(&self, key: Quark) -> Option<QD>where
QD: 'static,
key
. Read moresource§unsafe fn set_data<QD>(&self, key: &str, value: QD)where
QD: 'static,
unsafe fn set_data<QD>(&self, key: &str, value: QD)where
QD: 'static,
key
. Read moresource§unsafe fn data<QD>(&self, key: &str) -> Option<NonNull<QD>>where
QD: 'static,
unsafe fn data<QD>(&self, key: &str) -> Option<NonNull<QD>>where
QD: 'static,
key
. Read moresource§unsafe fn steal_data<QD>(&self, key: &str) -> Option<QD>where
QD: 'static,
unsafe fn steal_data<QD>(&self, key: &str) -> Option<QD>where
QD: 'static,
key
. Read moresource§fn block_signal(&self, handler_id: &SignalHandlerId)
fn block_signal(&self, handler_id: &SignalHandlerId)
source§fn unblock_signal(&self, handler_id: &SignalHandlerId)
fn unblock_signal(&self, handler_id: &SignalHandlerId)
source§fn stop_signal_emission(&self, signal_id: SignalId, detail: Option<Quark>)
fn stop_signal_emission(&self, signal_id: SignalId, detail: Option<Quark>)
source§fn stop_signal_emission_by_name(&self, signal_name: &str)
fn stop_signal_emission_by_name(&self, signal_name: &str)
source§fn connect<F>(
&self,
signal_name: &str,
after: bool,
callback: F
) -> SignalHandlerIdwhere
F: 'static + Fn(&[Value]) -> Option<Value> + Send + Sync,
fn connect<F>(
&self,
signal_name: &str,
after: bool,
callback: F
) -> SignalHandlerIdwhere
F: 'static + Fn(&[Value]) -> Option<Value> + Send + Sync,
signal_name
on this object. Read moresource§fn connect_id<F>(
&self,
signal_id: SignalId,
details: Option<Quark>,
after: bool,
callback: F
) -> SignalHandlerIdwhere
F: 'static + Fn(&[Value]) -> Option<Value> + Send + Sync,
fn connect_id<F>(
&self,
signal_id: SignalId,
details: Option<Quark>,
after: bool,
callback: F
) -> SignalHandlerIdwhere
F: 'static + Fn(&[Value]) -> Option<Value> + Send + Sync,
signal_id
on this object. Read moresource§fn connect_local<F>(
&self,
signal_name: &str,
after: bool,
callback: F
) -> SignalHandlerIdwhere
F: 'static + Fn(&[Value]) -> Option<Value>,
fn connect_local<F>(
&self,
signal_name: &str,
after: bool,
callback: F
) -> SignalHandlerIdwhere
F: 'static + Fn(&[Value]) -> Option<Value>,
signal_name
on this object. Read moresource§fn connect_local_id<F>(
&self,
signal_id: SignalId,
details: Option<Quark>,
after: bool,
callback: F
) -> SignalHandlerIdwhere
F: 'static + Fn(&[Value]) -> Option<Value>,
fn connect_local_id<F>(
&self,
signal_id: SignalId,
details: Option<Quark>,
after: bool,
callback: F
) -> SignalHandlerIdwhere
F: 'static + Fn(&[Value]) -> Option<Value>,
signal_id
on this object. Read moresource§unsafe fn connect_unsafe<F>(
&self,
signal_name: &str,
after: bool,
callback: F
) -> SignalHandlerIdwhere
F: Fn(&[Value]) -> Option<Value>,
unsafe fn connect_unsafe<F>(
&self,
signal_name: &str,
after: bool,
callback: F
) -> SignalHandlerIdwhere
F: Fn(&[Value]) -> Option<Value>,
signal_name
on this object. Read moresource§unsafe fn connect_unsafe_id<F>(
&self,
signal_id: SignalId,
details: Option<Quark>,
after: bool,
callback: F
) -> SignalHandlerIdwhere
F: Fn(&[Value]) -> Option<Value>,
unsafe fn connect_unsafe_id<F>(
&self,
signal_id: SignalId,
details: Option<Quark>,
after: bool,
callback: F
) -> SignalHandlerIdwhere
F: Fn(&[Value]) -> Option<Value>,
signal_id
on this object. Read moresource§fn connect_closure(
&self,
signal_name: &str,
after: bool,
closure: RustClosure
) -> SignalHandlerId
fn connect_closure(
&self,
signal_name: &str,
after: bool,
closure: RustClosure
) -> SignalHandlerId
signal_name
on this object. Read moresource§fn connect_closure_id(
&self,
signal_id: SignalId,
details: Option<Quark>,
after: bool,
closure: RustClosure
) -> SignalHandlerId
fn connect_closure_id(
&self,
signal_id: SignalId,
details: Option<Quark>,
after: bool,
closure: RustClosure
) -> SignalHandlerId
signal_id
on this object. Read moresource§fn watch_closure(&self, closure: &impl AsRef<Closure>)
fn watch_closure(&self, closure: &impl AsRef<Closure>)
closure
to the lifetime of the object. When
the object’s reference count drops to zero, the closure will be
invalidated. An invalidated closure will ignore any calls to
invoke_with_values
, or
invoke
when using Rust closures.source§fn emit<R>(&self, signal_id: SignalId, args: &[&dyn ToValue]) -> Rwhere
R: TryFromClosureReturnValue,
fn emit<R>(&self, signal_id: SignalId, args: &[&dyn ToValue]) -> Rwhere
R: TryFromClosureReturnValue,
source§fn emit_with_values(&self, signal_id: SignalId, args: &[Value]) -> Option<Value>
fn emit_with_values(&self, signal_id: SignalId, args: &[Value]) -> Option<Value>
Self::emit
but takes Value
for the arguments.source§fn emit_by_name<R>(&self, signal_name: &str, args: &[&dyn ToValue]) -> Rwhere
R: TryFromClosureReturnValue,
fn emit_by_name<R>(&self, signal_name: &str, args: &[&dyn ToValue]) -> Rwhere
R: TryFromClosureReturnValue,
source§fn emit_by_name_with_values(
&self,
signal_name: &str,
args: &[Value]
) -> Option<Value>
fn emit_by_name_with_values(
&self,
signal_name: &str,
args: &[Value]
) -> Option<Value>
source§fn emit_by_name_with_details<R>(
&self,
signal_name: &str,
details: Quark,
args: &[&dyn ToValue]
) -> Rwhere
R: TryFromClosureReturnValue,
fn emit_by_name_with_details<R>(
&self,
signal_name: &str,
details: Quark,
args: &[&dyn ToValue]
) -> Rwhere
R: TryFromClosureReturnValue,
source§fn emit_by_name_with_details_and_values(
&self,
signal_name: &str,
details: Quark,
args: &[Value]
) -> Option<Value>
fn emit_by_name_with_details_and_values(
&self,
signal_name: &str,
details: Quark,
args: &[Value]
) -> Option<Value>
source§fn emit_with_details<R>(
&self,
signal_id: SignalId,
details: Quark,
args: &[&dyn ToValue]
) -> Rwhere
R: TryFromClosureReturnValue,
fn emit_with_details<R>(
&self,
signal_id: SignalId,
details: Quark,
args: &[&dyn ToValue]
) -> Rwhere
R: TryFromClosureReturnValue,
source§fn emit_with_details_and_values(
&self,
signal_id: SignalId,
details: Quark,
args: &[Value]
) -> Option<Value>
fn emit_with_details_and_values(
&self,
signal_id: SignalId,
details: Quark,
args: &[Value]
) -> Option<Value>
source§fn disconnect(&self, handler_id: SignalHandlerId)
fn disconnect(&self, handler_id: SignalHandlerId)
source§fn connect_notify<F>(&self, name: Option<&str>, f: F) -> SignalHandlerIdwhere
F: 'static + Fn(&T, &ParamSpec) + Send + Sync,
fn connect_notify<F>(&self, name: Option<&str>, f: F) -> SignalHandlerIdwhere
F: 'static + Fn(&T, &ParamSpec) + Send + Sync,
notify
signal of the object. Read moresource§fn connect_notify_local<F>(&self, name: Option<&str>, f: F) -> SignalHandlerIdwhere
F: 'static + Fn(&T, &ParamSpec),
fn connect_notify_local<F>(&self, name: Option<&str>, f: F) -> SignalHandlerIdwhere
F: 'static + Fn(&T, &ParamSpec),
notify
signal of the object. Read moresource§unsafe fn connect_notify_unsafe<F>(
&self,
name: Option<&str>,
f: F
) -> SignalHandlerIdwhere
F: Fn(&T, &ParamSpec),
unsafe fn connect_notify_unsafe<F>(
&self,
name: Option<&str>,
f: F
) -> SignalHandlerIdwhere
F: Fn(&T, &ParamSpec),
notify
signal of the object. Read more