class Gtk::Image

Public Class Methods

new(options={}) click to toggle source

Creates a Gtk::Image. The source of the image depends on the options given.

@param Hash{Symbol => String, Gio::Icon, GdkPixbuf::Pixbuf}

@example Create an empty image.

image = Gtk::Image.new

@example Create an image from a file.

image = Gtk::Image.new(file: 'path/to/the/image.png')

@example Create an image from icon name.

image = Gtk::Image.new(icon_name: 'gtk-open')

@example Create an image from a Gio::Icon, that itself is loaded from a

       file.
icon = Gio::Icon.new_for_string 'path/to/the/image.png'
image = Gtk::Image.new(icon: icon)

@example Create an image from from a Gio::Icon that is an Gio::ThemedIcon.

icon = Gio::ThemedIcon.new 'gtk-open'
image = Gtk::Image.new(icon: icon)

@example Create an image from a GdkPixbuf::Pixbuf.

pixbuf = GdkPixbuf::Pixbuf.new(:file => 'path/to/the/image.png')
image = Gtk::Image.new(pixbuf: pixbuf)

@example Create an image from a file in a resource file

resource = Gio::Resource.load(a_resource_file)
Gio::Resources.register(resource)
resource_path = "/path/to/image.png"
image = Gtk::Image.new(resource: resource_path)
# File lib/gtk4/image.rb, line 52
def initialize(options={})
  icon_name = options[:icon_name] || nil
  icon      = options[:icon] || options[:gicon] || nil
  file      = options[:file] || nil
  pixbuf    = options[:pixbuf] || nil
  resource  = options[:resource] || 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)
  else
    initialize_raw
  end
end
Also aliased as: initialize_raw

Public Instance Methods

initialize_raw(options={})
Alias for: new