Struct gtk4::IconTheme [−][src]
pub struct IconTheme(_);
Expand description
IconTheme
provides a facility for loading themed icons.
The main reason for using a name rather than simply providing a filename
is to allow different icons to be used depending on what “icon theme” is
selected by the user. The operation of icon themes on Linux and Unix
follows the Icon Theme Specification
There is a fallback icon theme, named hicolor
, where applications
should install their icons, but additional icon themes can be installed
as operating system vendors and users choose.
In many cases, named themes are used indirectly, via Image
rather than directly, but looking up icons directly is also simple. The
IconTheme
object acts as a database of all the icons in the current
theme. You can create new IconTheme
objects, but it’s much more
efficient to use the standard icon theme of the Widget
so that the
icon information is shared with other people looking up icons.
⚠️ The following code is in c ⚠️
GtkIconTheme *icon_theme;
GtkIconPaintable *icon;
GdkPaintable *paintable;
icon_theme = gtk_icon_theme_get_for_display (gtk_widget_get_display (my_widget));
icon = gtk_icon_theme_lookup_icon (icon_theme,
"my-icon-name", // icon name
48, // icon size
1, // scale
0, // flags);
paintable = GDK_PAINTABLE (icon);
// Use the paintable
g_object_unref (icon);
Implements
Implementations
Creates a new icon theme object.
Icon theme objects are used to lookup up an icon by name
in a particular icon theme. Usually, you’ll want to use
for_display()
rather than creating
a new icon theme object for scratch.
Returns
the newly created IconTheme
object.
Creates a new builder-pattern struct instance to construct IconTheme
objects.
This method returns an instance of IconThemeBuilder
which can be used to create IconTheme
objects.
Adds a resource path that will be looked at when looking for icons, similar to search paths.
See set_resource_path()
.
This function should be used to make application-specific icons available as part of the icon theme.
path
a resource path
Appends a directory to the search path.
See set_search_path()
.
path
directory name to append to the icon path
Lists the names of icons in the current icon theme.
Returns
a string array
holding the names of all the icons in the theme. You must
free the array using g_strfreev()
.
Gets the current icon theme name.
Returns (transfer full): the current icon theme name,
This is supported on crate feature v4_2
only.
v4_2
only.pub fn lookup_by_gicon<P: IsA<Icon>>(
&self,
icon: &P,
size: i32,
scale: i32,
direction: TextDirection,
flags: IconLookupFlags
) -> Option<IconPaintable>
pub fn lookup_by_gicon<P: IsA<Icon>>(
&self,
icon: &P,
size: i32,
scale: i32,
direction: TextDirection,
flags: IconLookupFlags
) -> Option<IconPaintable>
Looks up a icon for a desired size and window scale.
The icon can then be rendered by using it as a gdk::Paintable
,
or you can get information such as the filename and size.
icon
the GIcon
to look up
size
desired icon size
scale
the desired scale
direction
text direction the icon will be displayed in
flags
flags modifying the behavior of the icon lookup
Returns
a IconPaintable
containing
information about the icon. Unref with g_object_unref()
pub fn lookup_icon(
&self,
icon_name: &str,
fallbacks: &[&str],
size: i32,
scale: i32,
direction: TextDirection,
flags: IconLookupFlags
) -> Option<IconPaintable>
pub fn lookup_icon(
&self,
icon_name: &str,
fallbacks: &[&str],
size: i32,
scale: i32,
direction: TextDirection,
flags: IconLookupFlags
) -> Option<IconPaintable>
Looks up a named icon for a desired size and window scale,
returning a IconPaintable
.
The icon can then be rendered by using it as a gdk::Paintable
,
or you can get information such as the filename and size.
If the available icon_name
is not available and fallbacks
are
provided, they will be tried in order.
If no matching icon is found, then a paintable that renders the
“missing icon” icon is returned. If you need to do something else
for missing icons you need to use has_icon()
.
Note that you probably want to listen for icon theme changes and
update the icon. This is usually done by overriding the
GtkWidgetClass.css-changed()
function.
icon_name
the name of the icon to lookup
size
desired icon size.
scale
the window scale this will be displayed on
direction
text direction the icon will be displayed in
flags
flags modifying the behavior of the icon lookup
Returns
a IconPaintable
object
containing the icon.
Sets the resource paths that will be looked at when looking for icons, similar to search paths.
The resources are considered as part of the hicolor icon theme
and must be located in subdirectories that are defined in the
hicolor icon theme, such as path`/16x16/actions/run.png` or
path/scalable/actions/run.svg
.
Icons that are directly placed in the resource path instead of a subdirectory are also considered as ultimate fallback, but they are treated like unthemed icons.
path
NULL-terminated array of resource paths that are searched for icons
Sets the search path for the icon theme object.
When looking for an icon theme, GTK will search for a subdirectory
of one or more of the directories in path
with the same name
as the icon theme containing an index.theme file. (Themes from
multiple of the path elements are combined to allow themes to be
extended by adding icons in the user’s home directory.)
In addition if an icon found isn’t found either in the current
icon theme or the default icon theme, and an image file with
the right name is found directly in one of the elements of
path
, then that image will be used for the icon name.
(This is legacy feature, and new icons should be put
into the fallback icon theme, which is called hicolor,
rather than directly on the icon path.)
path
NULL-terminated array of directories that are searched for icon themes
Sets the name of the icon theme that the IconTheme
object uses
overriding system configuration.
This function cannot be called on the icon theme objects returned
from for_display()
.
theme_name
name of icon theme to use instead of
configured theme, or None
to unset a previously set custom theme
The display that this icon theme object is attached to.
Gets the icon theme object associated with display
.
If this function has not previously been called for the given
display, a new icon theme object will be created and associated
with the display. Icon theme objects are fairly expensive to create,
so using this function is usually a better choice than calling
new()
and setting the display yourself; by using
this function a single icon theme object will be shared between users.
display
Returns
A unique IconTheme
associated with
the given display. This icon theme is associated with the display
and can be used as long as the display is open. Do not ref or unref it.
Emitted when the icon theme changes.
This can happen becuase current icon theme is switched or because GTK detects that a change has occurred in the contents of the current icon theme.
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 IconTheme
impl UnwindSafe for IconTheme
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
.