Class: Gtk::Image

Inherits:
Object
  • Object
show all
Extended by:
GLib::Deprecatable
Defined in:
lib/gtk4/image.rb,
lib/gtk4/deprecated.rb

Instance Method Summary collapse

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)

Examples:

Create an empty image.

image = Gtk::Image.new

Create an image from a file.

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

Create an image from icon name.

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

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

file.

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)

Create an image from a GdkPixbuf::Pixbuf.

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

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)

Parameters:

  • Hash (Symbol => String, Gio::Icon, GdkPixbuf::Pixbuf)


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# 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

Instance Method Details

#initialize_rawObject



19
# File 'lib/gtk4/image.rb', line 19

alias_method :initialize_raw, :initialize