class Gtk::CssProvider

Overview

Gtk::CssProvider is an object implementing the Gtk::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 Gtk::CssProvider#load_from_file or Gtk::CssProvider#load_from_resource and adding the provider with Gtk::StyleContext#add_provider or Gtk::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 [property@Gtk.Settings:gtk-theme-name] setting), VARIANT is the variant to load (see the [property@Gtk.Settings:gtk-application-prefer-dark-theme] 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 [signal@Gtk.CssProvider::parsing-error] signal.

Included Modules

Defined in:

lib/gi-crystal/src/auto/gtk-4.0/css_provider.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from module Gtk::StyleProvider

gtk_private_changed_signal gtk_private_changed_signal, to_unsafe to_unsafe

Class methods inherited from module Gtk::StyleProvider

g_type : UInt64 g_type

Instance methods inherited from class GObject::Object

bind_property(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags) : GObject::Binding bind_property, bind_property_full(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags, transform_to : GObject::Closure, transform_from : GObject::Closure) : GObject::Binding bind_property_full, data(key : String) : Pointer(Void)? data, finalize finalize, freeze_notify : Nil freeze_notify, getv(names : Enumerable(String), values : Enumerable(_)) : Nil getv, notify(property_name : String) : Nil notify, notify_by_pspec(pspec : GObject::ParamSpec) : Nil notify_by_pspec, notify_signal notify_signal, property(property_name : String, value : _) : Nil property, qdata(quark : UInt32) : Pointer(Void)? qdata, ref_count : UInt32 ref_count, run_dispose : Nil run_dispose, set_data(key : String, data : Pointer(Void)?) : Nil set_data, set_property(property_name : String, value : _) : Nil set_property, steal_data(key : String) : Pointer(Void)? steal_data, steal_qdata(quark : UInt32) : Pointer(Void)? steal_qdata, thaw_notify : Nil thaw_notify, to_unsafe : Pointer(Void) to_unsafe, watch_closure(closure : GObject::Closure) : Nil watch_closure

Constructor methods inherited from class GObject::Object

cast(obj : GObject::Object) : self cast, cast?(obj : GObject::Object) : self? cast?, new(pointer : Pointer(Void), transfer : GICrystal::Transfer)
new
new
, newv(object_type : UInt64, parameters : Enumerable(GObject::Parameter)) : self newv

Class methods inherited from class GObject::Object

compat_control(what : UInt64, data : Pointer(Void)?) : UInt64 compat_control, g_type : UInt64 g_type, interface_find_property(g_iface : GObject::TypeInterface, property_name : String) : GObject::ParamSpec interface_find_property, interface_list_properties(g_iface : GObject::TypeInterface) : Enumerable(GObject::ParamSpec) interface_list_properties

Constructor Detail

def self.new : self #

Returns a newly created Gtk::CssProvider.


Class Method Detail

def self.g_type : UInt64 #

Returns the type id (GType) registered in GLib type system.


Instance Method Detail

def load_from_data(data : Enumerable(UInt8)) : Nil #

Loads @data into @css_provider.

This clears any previously loaded information.


def load_from_data(*data : UInt8) #

def load_from_file(file : Gio::File) : Nil #

Loads the data contained in @file into @css_provider.

This clears any previously loaded information.


def load_from_path(path : String) : Nil #

Loads the data contained in @path into @css_provider.

This clears any previously loaded information.


def load_from_resource(resource_path : String) : Nil #

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

This clears any previously loaded information.


def load_named(name : String, variant : String?) : 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.


def parsing_error_signal #

def to_string : String #

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

Using Gtk::CssProvider#load_from_data with the return value from this function on a new provider created with Gtk::CssProvider.new will basically create a duplicate of this @provider.