Class: Gtk::IconTheme

Inherits:
Object
  • Object
show all
Defined in:
(unknown)

Instance Method Summary collapse

Instance Method Details

#add_resource_path(path) ⇒ nil

Adds a resource path that will be looked at when looking for icons, similar to search paths.

This function should be used to make application-specific icons available as part of the icon theme.

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`. Icons that are directly placed in the resource path instead of a subdirectory are also considered as ultimate fallback.

Parameters:

  • path (String)

    a resource path

Returns:

  • (nil)

#append_search_path(path) ⇒ nil

Appends a directory to the search path. See gtk_icon_theme_set_search_path().

Parameters:

  • path (Gtk::filename)

    directory name to append to the icon path

Returns:

  • (nil)

#choose_icon(icon_names, size, flags) ⇒ Gtk::IconInfo

Looks up a named icon and returns a Gtk::IconInfo containing information such as the filename of the icon. The icon can then be rendered into a pixbuf using gtk_icon_info_load_icon(). (gtk_icon_theme_load_icon() combines these two steps if all you need is the pixbuf.)

If icon_names contains more than one name, this function tries them all in the given order before falling back to inherited icon themes. containing information about the icon, or nil if the icon wasn’t found.

Parameters:

  • icon_names (Array<String>)

    nil-terminated array of icon names to lookup

  • size (Integer)

    desired icon size

  • flags (Gtk::IconLookupFlags)

    flags modifying the behavior of the icon lookup

Returns:

#choose_icon_for_scale(icon_names, size, scale, flags) ⇒ Gtk::IconInfo

Looks up a named icon for a particular window scale and returns a Gtk::IconInfo containing information such as the filename of the icon. The icon can then be rendered into a pixbuf using gtk_icon_info_load_icon(). (gtk_icon_theme_load_icon() combines these two steps if all you need is the pixbuf.)

If icon_names contains more than one name, this function tries them all in the given order before falling back to inherited icon themes.

Parameters:

  • icon_names (Array<String>)

    nil-terminated array of icon names to lookup

  • size (Integer)

    desired icon size

  • scale (Integer)

    desired scale

  • flags (Gtk::IconLookupFlags)

    flags modifying the behavior of the icon lookup

Returns:

  • (Gtk::IconInfo)

    a Gtk::IconInfo object containing information about the icon, or nil if the icon wasn’t found.

#custom_theme=(theme_name) ⇒ nil

Sets the name of the icon theme that the Gtk::IconTheme object uses overriding system configuration. This function cannot be called on the icon theme objects returned from gtk_icon_theme_get_default() and gtk_icon_theme_get_for_screen().

Parameters:

  • theme_name (String)

    name of icon theme to use instead of configured theme, or nil to unset a previously set custom theme

Returns:

  • (nil)

#example_icon_nameString

Gets the name of an icon that is representative of the current theme (for instance, to use when presenting a list of themes to the user.)

Returns:

  • (String)

    the name of an example icon or nil. Free with g_free().

#get_icon_sizes(icon_name) ⇒ Array<Integer>

Returns an array of integers describing the sizes at which the icon is available without scaling. A size of -1 means that the icon is available in a scalable format. The array is zero-terminated. allocated array describing the sizes at which the icon is available. The array should be freed with g_free() when it is no longer needed.

Parameters:

  • icon_name (String)

    the name of an icon

Returns:

  • (Array<Integer>)

    An newly

#get_search_path(path, n_elements) ⇒ nil

Gets the current search path. See gtk_icon_theme_set_search_path().

Parameters:

  • path (Array<Gtk::filename>)

    location to store a list of icon theme path directories or nil. The stored value should be freed with g_strfreev().

  • n_elements (Integer)

    location to store number of elements in path, or nil

Returns:

  • (nil)

#has_icon(icon_name) ⇒ TrueClass

Checks whether an icon theme includes an icon for a particular name.

Parameters:

  • icon_name (String)

    the name of an icon

Returns:

  • (TrueClass)

    true if icon_theme includes an icon for icon_name.

#list_contextsGLib::List

Gets the list of contexts available within the current hierarchy of icon themes. See gtk_icon_theme_list_icons() for details about contexts.

Returns:

  • (GLib::List)

    a #GList list holding the names of all the contexts in the theme. You must first free each element in the list with g_free(), then free the list itself with g_list_free().

#list_icons(context) ⇒ GLib::List

Lists the icons in the current icon theme. Only a subset of the icons can be listed by providing a context string. The set of values for the context string is system dependent, but will typically include such values as “Applications” and “MimeTypes”. Contexts are explained in the [Icon Theme Specification](www.freedesktop.org/wiki/Specifications/icon-theme-spec). The standard contexts are listed in the [Icon Naming Specification](www.freedesktop.org/wiki/Specifications/icon-naming-spec). Also see gtk_icon_theme_list_contexts().

Parameters:

  • context (String)

    a string identifying a particular type of icon, or nil to list all icons.

Returns:

  • (GLib::List)

    a #GList list holding the names of all the icons in the theme. You must first free each element in the list with g_free(), then free the list itself with g_list_free().

#load_icon(icon_name, size, flags) ⇒ GdkPixbuf::Pixbuf

Looks up an icon in an icon theme, scales it to the given size and renders it into a pixbuf. This is a convenience function; if more details about the icon are needed, use gtk_icon_theme_lookup_icon() followed by gtk_icon_info_load_icon().

Note that you probably want to listen for icon theme changes and update the icon. This is usually done by connecting to the GtkWidget::style-set signal. If for some reason you do not want to update the icon when the icon theme changes, you should consider using gdk_pixbuf_copy() to make a private copy of the pixbuf returned by this function. Otherwise GTK+ may need to keep the old icon theme loaded, which would be a waste of memory.

Parameters:

  • icon_name (String)

    the name of the icon to lookup

  • size (Integer)

    the desired icon size. The resulting icon may not be exactly this size; see gtk_icon_info_load_icon().

  • flags (Gtk::IconLookupFlags)

    flags modifying the behavior of the icon lookup

Returns:

  • (GdkPixbuf::Pixbuf)

    the rendered icon; this may be a newly created icon or a new reference to an internal icon, so you must not modify the icon. Use g_object_unref() to release your reference to the icon. nil if the icon isn’t found.

#load_icon_for_scale(icon_name, size, scale, flags) ⇒ GdkPixbuf::Pixbuf

Looks up an icon in an icon theme for a particular window scale, scales it to the given size and renders it into a pixbuf. This is a convenience function; if more details about the icon are needed, use gtk_icon_theme_lookup_icon() followed by gtk_icon_info_load_icon().

Note that you probably want to listen for icon theme changes and update the icon. This is usually done by connecting to the GtkWidget::style-set signal. If for some reason you do not want to update the icon when the icon theme changes, you should consider using gdk_pixbuf_copy() to make a private copy of the pixbuf returned by this function. Otherwise GTK+ may need to keep the old icon theme loaded, which would be a waste of memory.

Parameters:

  • icon_name (String)

    the name of the icon to lookup

  • size (Integer)

    the desired icon size. The resulting icon may not be exactly this size; see gtk_icon_info_load_icon().

  • scale (Integer)

    desired scale

  • flags (Gtk::IconLookupFlags)

    flags modifying the behavior of the icon lookup

Returns:

  • (GdkPixbuf::Pixbuf)

    the rendered icon; this may be a newly created icon or a new reference to an internal icon, so you must not modify the icon. Use g_object_unref() to release your reference to the icon. nil if the icon isn’t found.

#load_surface(icon_name, size, scale, for_window, flags) ⇒ cairo::Surface

Looks up an icon in an icon theme for a particular window scale, scales it to the given size and renders it into a cairo surface. This is a convenience function; if more details about the icon are needed, use gtk_icon_theme_lookup_icon() followed by gtk_icon_info_load_surface().

Note that you probably want to listen for icon theme changes and update the icon. This is usually done by connecting to the GtkWidget::style-set signal.

Parameters:

  • icon_name (String)

    the name of the icon to lookup

  • size (Integer)

    the desired icon size. The resulting icon may not be exactly this size; see gtk_icon_info_load_icon().

  • scale (Integer)

    desired scale

  • for_window (Gdk::Window)

    Gdk::Window to optimize drawing for, or nil

  • flags (Gtk::IconLookupFlags)

    flags modifying the behavior of the icon lookup

Returns:

  • (cairo::Surface)

    the rendered icon; this may be a newly created icon or a new reference to an internal icon, so you must not modify the icon. Use cairo_surface_destroy() to release your reference to the icon. nil if the icon isn’t found.

#lookup_by_gicon(icon, size, flags) ⇒ Gtk::IconInfo

Looks up an icon and returns a Gtk::IconInfo containing information such as the filename of the icon. The icon can then be rendered into a pixbuf using gtk_icon_info_load_icon().

When rendering on displays with high pixel densities you should not use a size multiplied by the scaling factor returned by functions like gdk_window_get_scale_factor(). Instead, you should use gtk_icon_theme_lookup_by_gicon_for_scale(), as the assets loaded for a given scaling factor may be different.

Parameters:

  • icon (Gio::Icon)

    the #GIcon to look up

  • size (Integer)

    desired icon size

  • flags (Gtk::IconLookupFlags)

    flags modifying the behavior of the icon lookup

Returns:

  • (Gtk::IconInfo)

    a Gtk::IconInfo containing information about the icon, or nil if the icon wasn’t found. Unref with g_object_unref()

#lookup_by_gicon_for_scale(icon, size, scale, flags) ⇒ Gtk::IconInfo

Looks up an icon and returns a Gtk::IconInfo containing information such as the filename of the icon. The icon can then be rendered into a pixbuf using gtk_icon_info_load_icon().

Parameters:

  • icon (Gio::Icon)

    the #GIcon to look up

  • size (Integer)

    desired icon size

  • scale (Integer)

    the desired scale

  • flags (Gtk::IconLookupFlags)

    flags modifying the behavior of the icon lookup

Returns:

  • (Gtk::IconInfo)

    a Gtk::IconInfo containing information about the icon, or nil if the icon wasn’t found. Unref with g_object_unref()

#lookup_icon(icon_name, size, flags) ⇒ Gtk::IconInfo

Looks up a named icon and returns a Gtk::IconInfo containing information such as the filename of the icon. The icon can then be rendered into a pixbuf using gtk_icon_info_load_icon(). (gtk_icon_theme_load_icon() combines these two steps if all you need is the pixbuf.)

When rendering on displays with high pixel densities you should not use a size multiplied by the scaling factor returned by functions like gdk_window_get_scale_factor(). Instead, you should use gtk_icon_theme_lookup_icon_for_scale(), as the assets loaded for a given scaling factor may be different.

Parameters:

  • icon_name (String)

    the name of the icon to lookup

  • size (Integer)

    desired icon size

  • flags (Gtk::IconLookupFlags)

    flags modifying the behavior of the icon lookup

Returns:

  • (Gtk::IconInfo)

    a Gtk::IconInfo object containing information about the icon, or nil if the icon wasn’t found.

#lookup_icon_for_scale(icon_name, size, scale, flags) ⇒ Gtk::IconInfo

Looks up a named icon for a particular window scale and returns a Gtk::IconInfo containing information such as the filename of the icon. The icon can then be rendered into a pixbuf using gtk_icon_info_load_icon(). (gtk_icon_theme_load_icon() combines these two steps if all you need is the pixbuf.)

Parameters:

  • icon_name (String)

    the name of the icon to lookup

  • size (Integer)

    desired icon size

  • scale (Integer)

    the desired scale

  • flags (Gtk::IconLookupFlags)

    flags modifying the behavior of the icon lookup

Returns:

  • (Gtk::IconInfo)

    a Gtk::IconInfo object containing information about the icon, or nil if the icon wasn’t found.

#newGtk::IconTheme

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 gtk_icon_theme_get_default() or gtk_icon_theme_get_for_screen() rather than creating a new icon theme object for scratch.

Returns:

#prepend_search_path(path) ⇒ nil

Prepends a directory to the search path. See gtk_icon_theme_set_search_path().

Parameters:

  • path (Gtk::filename)

    directory name to prepend to the icon path

Returns:

  • (nil)

#rescan_if_neededTrueClass

Checks to see if the icon theme has changed; if it has, any currently cached information is discarded and will be reloaded next time icon_theme is accessed.

Returns:

  • (TrueClass)

    true if the icon theme has changed and needed to be reloaded.

#screen=(screen) ⇒ nil

Sets the screen for an icon theme; the screen is used to track the user’s currently configured icon theme, which might be different for different screens.

Parameters:

Returns:

  • (nil)

#set_search_path(path, n_elements) ⇒ nil

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

Parameters:

  • path (Array<Gtk::filename>)

    array of directories that are searched for icon themes

  • n_elements (Integer)

    number of elements in path.

Returns:

  • (nil)