CssProviderProtocol

public protocol CssProviderProtocol : ObjectProtocol, StyleProviderProtocol

GtkCssProvider is an object implementing the GtkStyleProvider 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 [methodGtk.CssProvider.load_from_file] or [methodGtk.CssProvider.load_from_resource] and adding the provider with [methodGtk.StyleContext.add_provider] or [funcGtk.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 [propertyGtk.Settings:gtk-theme-name] setting), VARIANT is the variant to load (see the [propertyGtk.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 [signalGtk.CssProvider::parsing-error] signal.

The CssProviderProtocol protocol exposes the methods and properties of an underlying GtkCssProvider instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, see CssProvider. Alternatively, use CssProviderRef as a lighweight, unowned reference if you already have an instance you just want to use.

  • ptr

    Untyped pointer to the underlying GtkCssProvider instance.

    Declaration

    Swift

    var ptr: UnsafeMutableRawPointer! { get }
  • css_provider_ptr Default implementation

    Typed pointer to the underlying GtkCssProvider instance.

    Default Implementation

    Return the stored, untyped pointer as a typed pointer to the GtkCssProvider instance.

    Declaration

    Swift

    var css_provider_ptr: UnsafeMutablePointer<GtkCssProvider>! { get }
  • Required Initialiser for types conforming to CssProviderProtocol

    Declaration

    Swift

    init(raw: UnsafeMutableRawPointer)
  • styleProvider Extension method

    Return the CSS provider as a style provider

    Declaration

    Swift

    @inlinable
    var styleProvider: StyleProviderRef { get }
  • load(from:) Extension method

    Loads the data provided in the given string into the CSS Provider

    Throws

    an ErrorType if there is an issue with the CSS

    Declaration

    Swift

    @inlinable
    func load(from data: String)

    Parameters

    data

    the CSS data represented as a String

CssProvider signals

  • Connect a Swift signal handler to the given, typed CssProviderSignalName signal

    Declaration

    Swift

    @discardableResult
    @inlinable
    func connect(signal s: CssProviderSignalName, flags f: ConnectFlags = ConnectFlags(0), handler h: @escaping SignalHandler) -> Int

    Parameters

    signal

    The signal to connect

    flags

    The connection flags to use

    data

    A pointer to user data to provide to the callback

    destroyData

    A GClosureNotify C function to destroy the data pointed to by userData

    handler

    The Swift signal handler (function or callback) to invoke on the given signal

    Return Value

    The signal handler ID (always greater than 0 for successful connections)

  • Connect a C signal handler to the given, typed CssProviderSignalName signal

    Declaration

    Swift

    @discardableResult
    @inlinable
    func connect(signal s: CssProviderSignalName, flags f: ConnectFlags = ConnectFlags(0), data userData: gpointer!, destroyData destructor: GClosureNotify? = nil, signalHandler h: @escaping GCallback) -> Int

    Parameters

    signal

    The signal to connect

    flags

    The connection flags to use

    data

    A pointer to user data to provide to the callback

    destroyData

    A GClosureNotify C function to destroy the data pointed to by userData

    signalHandler

    The C function to be called on the given signal

    Return Value

    The signal handler ID (always greater than 0 for successful connections)

  • 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.

    Note

    This represents the underlying parsing-error signal

    Declaration

    Swift

    @discardableResult
    @inlinable
    func onParsingError(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: CssProviderRef, _ section: CssSectionRef, _ error: GLib.ErrorRef) -> Void) -> Int

    Parameters

    flags

    Flags

    unownedSelf

    Reference to instance of self

    section

    section the error happened in

    error

    The parsing error

    handler

    The signal handler to call Run the given callback whenever the parsingError signal is emitted

  • parsingErrorSignal Extension method

    Typed parsing-error signal for using the connect(signal:) methods

    Declaration

    Swift

    static var parsingErrorSignal: CssProviderSignalName { get }

CssProvider Class: CssProviderProtocol extension (methods and fields)

  • load(from:length:) Extension method

    Loads data into css_provider.

    This clears any previously loaded information.

    Declaration

    Swift

    @inlinable
    func load(from data: UnsafePointer<CChar>!, length: gssize)
  • load(from:) Extension method

    Loads the data contained in file into css_provider.

    This clears any previously loaded information.

    Declaration

    Swift

    @inlinable
    func load<FileT>(from file: FileT) where FileT : FileProtocol
  • load(from:) Extension method

    Loads the data contained in path into css_provider.

    This clears any previously loaded information.

    Declaration

    Swift

    @inlinable
    func load(from path: UnsafePointer<CChar>!)
  • Loads the data contained in the resource at resource_path into the css_provider.

    This clears any previously loaded information.

    Declaration

    Swift

    @inlinable
    func loadFromResource(resourcePath: UnsafePointer<CChar>!)
  • loadNamed(name:variant:) Extension method

    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.

    Declaration

    Swift

    @inlinable
    func loadNamed(name: UnsafePointer<CChar>!, variant: UnsafePointer<CChar>? = nil)
  • toString() Extension method

    Converts the provider into a string representation in CSS format.

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

    Declaration

    Swift

    @inlinable
    func toString() -> String!
  • parentInstance Extension method

    Undocumented

    Declaration

    Swift

    @inlinable
    var parentInstance: GObject { get }