Class: Gtk::Image
- Extended by:
- GLib::Deprecatable
- Defined in:
- lib/gtk4/image.rb,
lib/gtk4/deprecated.rb
Overview
The GtkImage widget displays an image.

Various kinds of object can be displayed as an image; most typically,
you would load a GdkTexture from a file, using the convenience function
[ctorGtk.Image.new_from_file], for instance:
GtkWidget *image = gtk_image_new_from_file ("myfile.png");
If the file isn’t loaded successfully, the image 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
[ctorGdk.Texture.new_from_file], then create the GtkImage with
[ctorGtk.Image.new_from_paintable].
Sometimes an application will want to avoid depending on external data
files, such as image files. See the documentation of GResource inside
GIO, for details. In this case, [propertyGtk.Image:resource],
[ctorGtk.Image.new_from_resource], and [methodGtk.Image.set_from_resource]
should be used.
GtkImage displays its image as an icon, with a size that is determined
by the application. See [classGtk.Picture] if you want to show an image
at is actual size.
CSS nodes
GtkImage has a single CSS node with the name image. The style classes
.normal-icons or .large-icons may appear, depending on the
[propertyGtk.Image:icon-size] property.
Accessibility
GtkImage uses the GTK_ACCESSIBLE_ROLE_IMG role.
Instance Method Summary collapse
-
#clear ⇒ nil
Resets the image to be empty.
-
#file ⇒ String
A path to the file to display.
-
#file=(file) ⇒ String
A path to the file to display.
-
#from_file=(filename) ⇒ nil
Sets a
GtkImageto show a file. -
#from_gicon=(icon) ⇒ nil
Sets a
GtkImageto show aGIcon. -
#from_icon_name=(icon_name) ⇒ nil
Sets a
GtkImageto show a named icon. -
#from_paintable=(paintable) ⇒ nil
Sets a
GtkImageto show aGdkPaintable. -
#from_pixbuf=(pixbuf) ⇒ nil
Sets a
GtkImageto show aGdkPixbuf. -
#from_resource=(resource_path) ⇒ nil
Sets a
GtkImageto show a resource. -
#gicon ⇒ Gio::Icon
The
GIcondisplayed in the GtkImage. -
#gicon=(gicon) ⇒ Gio::Icon
The
GIcondisplayed in the GtkImage. -
#icon_name ⇒ String
The name of the icon in the icon theme.
-
#icon_name=(icon_name) ⇒ String
The name of the icon in the icon theme.
-
#icon_size ⇒ Gtk::IconSize
The symbolic size to display icons at.
-
#icon_size=(icon_size) ⇒ Gtk::IconSize
The symbolic size to display icons at.
-
#initialize(options = {}) ⇒ Image
constructor
Creates a Gtk::Image.
-
#initialize_raw ⇒ Gtk::Widget
Creates a new
GtkImagedisplaying the resource file resource_path. -
#paintable ⇒ Gdk::Paintable
The
GdkPaintableto display. -
#paintable=(paintable) ⇒ Gdk::Paintable
The
GdkPaintableto display. -
#pixel_size ⇒ Integer
The size in pixels to display icons at.
-
#pixel_size=(pixel_size) ⇒ Integer
The size in pixels to display icons at.
-
#resource ⇒ String
A path to a resource file to display.
-
#resource=(resource) ⇒ String
A path to a resource file to display.
-
#storage_type ⇒ Gtk::ImageType
The representation being used for image data.
-
#storage_type=(storage_type) ⇒ Gtk::ImageType
The representation being used for image data.
-
#use_fallback=(use_fallback) ⇒ Boolean
Whether the icon displayed in the
GtkImagewill use standard icon names fallback. -
#use_fallback? ⇒ Boolean
Whether the icon displayed in the
GtkImagewill use standard icon names fallback.
Methods inherited from Widget
#accessible_role, #accessible_role=, #action_set_enabled, #activate, #activate_action, #activate_action_variant, #activate_default, #activate_signal, #activate_signal=, #activate_signal_from_name=, #add_binding, #add_binding_action, #add_binding_signal, #add_controller, #add_css_class, #add_mnemonic_label, #add_shortcut, #add_tick_callback, #allocate, #allocated_baseline, #allocated_height, #allocated_width, #baseline, #bind_template_callback_full, #bind_template_child, #bind_template_child_full, #can_focus, #can_focus=, #can_focus?, #can_target, #can_target=, #can_target?, #child_focus, #child_visible, #child_visible=, #children, #clipboard, #compute_bounds, #compute_expand, #compute_point, #compute_transform, #contains, #create_pango_context, #create_pango_layout, #css_classes, #css_classes=, #css_name, #css_name=, #cursor, #cursor=, #cursor_from_name=, default_direction, default_direction=, #direction, #direction=, #display, #dispose_template, #drag_check_threshold, #error_bell, #first_child, #focus_child, #focus_child=, #focus_on_click, #focus_on_click=, #focus_on_click?, #focusable, #focusable=, #focusable?, #font_map, #font_map=, #font_options, #font_options=, #frame_clock, #get_allocation, #get_ancestor, #get_color, #get_preferred_size, #get_size, #get_size_request, #get_template_child, #grab_focus, #halign, #halign=, #has_css_class, #has_default, #has_default=, #has_default?, #has_focus, #has_focus=, #has_focus?, #has_tooltip, #has_tooltip=, #has_tooltip?, #has_visible_focus, have_template?, #height, #height_request, #height_request=, #hexpand, #hexpand=, #hexpand?, #hexpand_set, #hexpand_set=, #hexpand_set?, #hide, #in_destruction, #init_template, #insert_action_group, #insert_action_group_raw, #insert_after, #insert_before, #install_action, #install_property_action, #is_ancestor, #is_drawable, #is_focus, #is_sensitive, #is_visible, #keynav_failed, #last_child, #layout_manager, #layout_manager=, #layout_manager_type, #layout_manager_type=, #list_mnemonic_labels, #map, #mapped, #margin_bottom, #margin_bottom=, #margin_end, #margin_end=, #margin_start, #margin_start=, #margin_top, #margin_top=, #measure, #mnemonic_activate, #name, #name=, #native, #next_sibling, #observe_children, #observe_controllers, #opacity, #opacity=, #overflow, #overflow=, #pango_context, #parent, #parent=, #pick, #prev_sibling, #primary_clipboard, #query_action, #queue_allocate, #queue_draw, #queue_resize, #realize, #realized, #receives_default, #receives_default=, #receives_default?, #remove_controller, #remove_css_class, #remove_mnemonic_label, #remove_tick_callback, #request_mode, #root, #root=, #scale_factor, #scale_factor=, #sensitive, #sensitive=, #sensitive?, #set_size_request, #set_size_request_raw, #set_state_flags, #set_template, #set_template_raw, #settings, #should_layout, #show, #size_allocate, #snapshot_child, #state_flags, #style_context, #style_context_raw, #template=, template_children, #template_from_resource=, #template_scope=, #tooltip_markup, #tooltip_markup=, #tooltip_text, #tooltip_text=, #translate_coordinates, #translate_coordinates_raw, #trigger_tooltip_query, #unmap, #unparent, #unrealize, #unset_state_flags, #valign, #valign=, #vexpand, #vexpand=, #vexpand?, #vexpand_set, #vexpand_set=, #vexpand_set?, #visible, #visible=, #visible?, #width, #width_request, #width_request=
Constructor Details
#initialize(options = {}) ⇒ Image
Creates a Gtk::Image. The source of the image depends on the options given.
icon = Gio::Icon.new_for_string 'path/to/the/image.png' image = Gtk::Image.new(icon: icon)
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/gtk4/image.rb', line 58 def initialize(={}) icon_name = [:icon_name] || nil icon = [:icon] || [:gicon] || nil file = [:file] || nil pixbuf = [:pixbuf] || nil resource = [:resource] || nil paintable = [:paintable] || nil if icon_name initialize_new_from_icon_name(icon_name) elsif icon initialize_new_from_gicon(icon) elsif file initialize_new_from_file(file) elsif pixbuf initialize_new_from_pixbuf(pixbuf) elsif resource initialize_new_from_resource(resource) elsif paintable initialize_new_from_paintable(paintable) else initialize_raw end end |
Instance Method Details
#clear ⇒ nil
Resets the image to be empty.
#file ⇒ String
A path to the file to display.
#file=(file) ⇒ String
A path to the file to display.
#from_file=(filename) ⇒ nil
Sets a GtkImage to show a file.
See [ctorGtk.Image.new_from_file] for details.
#from_gicon=(icon) ⇒ nil
Sets a GtkImage to show a GIcon.
See [ctorGtk.Image.new_from_gicon] for details.
#from_icon_name=(icon_name) ⇒ nil
Sets a GtkImage to show a named icon.
See [ctorGtk.Image.new_from_icon_name] for details.
#from_paintable=(paintable) ⇒ nil
Sets a GtkImage to show a GdkPaintable.
See [ctorGtk.Image.new_from_paintable] for details.
#from_pixbuf=(pixbuf) ⇒ nil
Sets a GtkImage to show a GdkPixbuf.
See [ctorGtk.Image.new_from_pixbuf] for details.
Note: This is a helper for [methodGtk.Image.set_from_paintable], and you can't get back the exact pixbuf once this is called, only a paintable.
#from_resource=(resource_path) ⇒ nil
Sets a GtkImage to show a resource.
See [ctorGtk.Image.new_from_resource] for details.
#gicon ⇒ Gio::Icon
The GIcon displayed in the GtkImage.
For themed icons, If the icon theme is changed, the image will be updated automatically.
#gicon=(gicon) ⇒ Gio::Icon
The GIcon displayed in the GtkImage.
For themed icons, If the icon theme is changed, the image will be updated automatically.
#icon_name ⇒ String
The name of the icon in the icon theme.
If the icon theme is changed, the image will be updated automatically.
#icon_name=(icon_name) ⇒ String
The name of the icon in the icon theme.
If the icon theme is changed, the image will be updated automatically.
#icon_size ⇒ Gtk::IconSize
The symbolic size to display icons at.
#icon_size=(icon_size) ⇒ Gtk::IconSize
The symbolic size to display icons at.
#initialize_raw ⇒ Gtk::Widget
Creates a new GtkImage displaying the resource file resource_path.
If the file isn’t found or can’t be loaded, the resulting GtkImage will
display a “broken image” icon. This function never returns nil,
it always returns a valid GtkImage widget.
If you need to detect failures to load the file, use
[ctorGdkPixbuf.Pixbuf.new_from_file] to load the file yourself,
then create the GtkImage from the pixbuf.
The storage type (see [methodGtk.Image.get_storage_type]) of the returned image is not defined, it will be whatever is appropriate for displaying the file.
|
|
# File 'lib/gtk4/image.rb', line 19
|
#paintable ⇒ Gdk::Paintable
The GdkPaintable to display.
#paintable=(paintable) ⇒ Gdk::Paintable
The GdkPaintable to display.
#pixel_size ⇒ Integer
The size in pixels to display icons at.
If set to a value != -1, this property overrides the
[propertyGtk.Image:icon-size] property for images of type
GTK_IMAGE_ICON_NAME.
#pixel_size=(pixel_size) ⇒ Integer
The size in pixels to display icons at.
If set to a value != -1, this property overrides the
[propertyGtk.Image:icon-size] property for images of type
GTK_IMAGE_ICON_NAME.
#resource ⇒ String
A path to a resource file to display.
#resource=(resource) ⇒ String
A path to a resource file to display.
#storage_type ⇒ Gtk::ImageType
The representation being used for image data.
#storage_type=(storage_type) ⇒ Gtk::ImageType
The representation being used for image data.
#use_fallback=(use_fallback) ⇒ Boolean
Whether the icon displayed in the GtkImage will use
standard icon names fallback.
The value of this property is only relevant for images of type %GTK_IMAGE_ICON_NAME and %GTK_IMAGE_GICON.
#use_fallback? ⇒ Boolean
Whether the icon displayed in the GtkImage will use
standard icon names fallback.
The value of this property is only relevant for images of type %GTK_IMAGE_ICON_NAME and %GTK_IMAGE_GICON.