About all my projects
Gnome::Gtk4::CssProvider

Gnome::Gtk4::CssProvider

Description

Gnome::Gtk4::CssProvider is an object implementing the Gnome::Gtk4::R-StyleProvider interface for CSS.

It is able to parse CSS-like input in order to style widgets.

An application can make GTK parse a specific CSS style sheet by calling .load-from-file() or .load-from-resource() and adding the provider with .add-provider() in class Gnome::Gtk4::StyleContext or .StyleContext.add-provider-for-display().

In addition, certain files will be read when GTK is initialized. First, the file `$XDG_CONFIG_HOME/gtk-4.0/gtk.css` is loaded if it exists. Then, GTK loads the first existing file among XDG_DATA_HOME/themes/THEME/gtk-VERSION/gtk-VARIANT.css`, `$HOME/.themes/THEME/gtk-VERSION/gtk-VARIANT.css`, `$XDG_DATA_DIRS/themes/THEME/gtk-VERSION/gtk-VARIANT.css` and DATADIR/share/themes/THEME/gtk-VERSION/gtk-VARIANT.css`, where THEME is the name of the current theme (see the gtk-theme-name defined in Gnome::Gtk4::Settings setting), VARIANT is the variant to load (see the gtk-application-prefer-dark-theme defined in Gnome::Gtk4::Settings setting), DATADIR is the prefix configured when GTK was compiled (unless overridden by the GTK_DATA_PREFIX environment variable), and VERSION is the GTK version number. If no file is found for the current version, GTK tries older versions all the way back to 4.0.

To track errors while loading CSS, connect to the parsing-error signal.

Class initialization

new

:native-object

Create an object using a native object from elsewhere. See also Gnome::N::TopLevelSupportClass.

multi method new ( N-Object :$native-object! )

new-cssprovider

Returns a newly created Gnome::Gtk4::CssProvider.

method new-cssprovider ( --> Gnome::Gtk4::CssProvider \)

Methods

load-from-bytes

Loads $data into $css-provider.

This clears any previously loaded information.

method load-from-bytes ( N-Object $data )
  • $data; Gnome::Glib::N-Bytes containing the data to load

load-from-data

Note: The native version of this routine is deprecated in gtk4-lib() since version 4.12

Loads $data into $css-provider.

This clears any previously loaded information.

method load-from-data ( Str $data, Int() $length )
  • $data; CSS data to be parsed.

  • $length; the length of $data in bytes, or -1 for NUL terminated strings.

load-from-file

Loads the data contained in $file into $css-provider.

This clears any previously loaded information.

method load-from-file ( N-Object() $file )
  • $file; Gnome::Gio::R-File pointing to a file to load.

load-from-path

Loads the data contained in $path into $css-provider.

This clears any previously loaded information.

method load-from-path ( Str $path )
  • $path; the path of a filename to load, in the GLib filename encoding.

load-from-resource

Loads the data contained in the resource at $resource-path into the $css-provider.

This clears any previously loaded information.

method load-from-resource ( Str $resource-path )
  • $resource-path; a Gnome::Gio::N-Resource resource path.

load-from-string

Loads $string into $css-provider.

This clears any previously loaded information.

method load-from-string ( Str $string )
  • $string; the CSS to load.

load-named

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.

method load-named ( Str $name, Str $variant )
  • $name; A theme name.

  • $variant; variant to load, for example, "dark", or undefined for the default.

to-string

Converts the $provider into a string representation in CSS format.

Using .load-from-string() with the return value from this function on a new provider created with .newcssprovider() will basically create a duplicate of this $provider.

method to-string (--> Str )

Return value; a new string representing the $provider..

Signals

parsing-error

Signals that a parsing error occurred.

The $path, $line and $position describe the actual location of the error as accurately as possible.

Parsing errors are never fatal, so the parsing will resume after the error. Errors may however cause parts of the given data or even all of it to not be parsed at all. So it is a useful idea to check that the parsing succeeds by connecting to this signal.

Note that this signal may be emitted at any time as the css provider may opt to defer parsing parts or all of the input to a later time than when a loading function was called.

method handler (
  N-Object $section,
   $error,
  Int :$_handle_id,
  N-GObject :$_native-object,
  Gnome::Gtk4::CssProvider :$_widget,
  *C<user>-options
)
  • $section; section the error happened in.

  • $error; The parsing error.

  • $_handle_id; The registered event handler id.

  • $_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gtk4::CssProvider object.

  • $_widget; The object which registered the signal. User code may have left the object going out of scope.

  • user-options; A list of named arguments provided at the .register-signal() method from Gnome::GObject::Object.