Class: Gtk::CssProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/gtk4/css-provider.rb

Instance Method Summary collapse

Constructor Details

#initializeGtk::CssProvider

Returns a newly created GtkCssProvider.

Instance Method Details

#load(options) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/gtk4/css-provider.rb', line 19

def load(options)
  string = options[:string]
  bytes = options[:bytes]
  data = options[:data]
  file = options[:file]
  path = options[:path]
  resource_path = options[:resource_path]
  if string
    if Version.or_later?(4, 12, 0)
      load_from_string(string)
    else
      load_from_data(string)
    end
  elsif bytes
    if Version.or_later?(4, 12, 0)
      load_from_bytes(bytes)
    else
      load_from_data(bytes)
    end
  elsif data
    if Version.or_later?(4, 12, 0)
      load_from_bytes(data)
    else
      load_from_data(data)
    end
  elsif file
    load_from_file(file)
  elsif path
    load_from_path(path)
  elsif resource_path
    load_from_resource(resource_path)
  else
    message = "Must specify one of " +
              ":string, :bytes, :data, :file, :path or :resource_path"
    raise ArgumentError, "#{message}: #{options.inspect}"
  end
end

#load_from_bytes(data) ⇒ nil

Loads data into css_provider.

This clears any previously loaded information.

Parameters:

  • data (GLib::Bytes)

    GBytes containing the data to load

Returns:

  • (nil)

#load_from_data(data) ⇒ nil

Loads data into css_provider.

This clears any previously loaded information.

Parameters:

  • data (String)

    CSS data to be parsed

  • length (Gtk::gssize)

    the length of data in bytes, or -1 for NUL terminated strings

Returns:

  • (nil)


59
60
61
62
# File 'lib/gtk4/css-provider.rb', line 59

def load_from_data(data)
  data = data.to_s if data.is_a?(GLib::Bytes)
  load_from_data_raw(data, data.bytesize)
end

#load_from_data_rawnil

Loads data into css_provider.

This clears any previously loaded information.

Parameters:

  • data (String)

    CSS data to be parsed

  • length (Gtk::gssize)

    the length of data in bytes, or -1 for NUL terminated strings

Returns:

  • (nil)


# File 'lib/gtk4/css-provider.rb', line 57

#load_from_file(file) ⇒ nil

Loads the data contained in file into css_provider.

This clears any previously loaded information.

Parameters:

  • file (Gio::File)

    GFile pointing to a file to load

Returns:

  • (nil)

#load_from_path(path) ⇒ nil

Loads the data contained in path into css_provider.

This clears any previously loaded information.

Parameters:

  • path (Gtk::filename)

    the path of a filename to load, in the GLib filename encoding

Returns:

  • (nil)

#load_from_resource(resource_path) ⇒ nil

Loads the data contained in the resource at resource_path into the css_provider.

This clears any previously loaded information.

Parameters:

  • resource_path (String)

    a GResource resource path

Returns:

  • (nil)

#load_from_string(string) ⇒ nil

Loads string into css_provider.

This clears any previously loaded information.

Parameters:

  • string (String)

    the CSS to load

Returns:

  • (nil)

#load_named(name, variant) ⇒ nil

Loads a theme from the usual theme paths.

The actual process of finding the theme might change between releases, but it is guaranteed that this function uses the same mechanism to load the theme that GTK uses for loading its own theme.

Parameters:

  • name (String)

    A theme name

  • variant (String)

    variant to load, for example, "dark", or nil for the default

Returns:

  • (nil)

#to_stringString

Converts the provider into a string representation in CSS format.

Using [methodGtk.CssProvider.load_from_string] with the return value from this function on a new provider created with [ctorGtk.CssProvider.new] will basically create a duplicate of this provider.

Returns:

  • (String)

    a new string representing the provider.