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.
-
Untyped pointer to the underlying
GtkCssProviderinstance.Declaration
Swift
var ptr: UnsafeMutableRawPointer! { get } -
css_provider_ptrDefault implementationTyped pointer to the underlying
GtkCssProviderinstance.Default Implementation
Return the stored, untyped pointer as a typed pointer to the
GtkCssProviderinstance.Declaration
Swift
var css_provider_ptr: UnsafeMutablePointer<GtkCssProvider>! { get } -
Required Initialiser for types conforming to
CssProviderProtocolDeclaration
Swift
init(raw: UnsafeMutableRawPointer) -
styleProviderExtension methodReturn 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
anErrorTypeif there is an issue with the CSSDeclaration
Swift
@inlinable func load(from data: String)Parameters
datathe CSS data represented as a String
-
connect(signal:Extension methodflags: handler: ) Connect a Swift signal handler to the given, typed
CssProviderSignalNamesignalDeclaration
Swift
@discardableResult @inlinable func connect(signal s: CssProviderSignalName, flags f: ConnectFlags = ConnectFlags(0), handler h: @escaping SignalHandler) -> IntParameters
signalThe signal to connect
flagsThe connection flags to use
dataA pointer to user data to provide to the callback
destroyDataA
GClosureNotifyC function to destroy the data pointed to byuserDatahandlerThe 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(signal:Extension methodflags: data: destroyData: signalHandler: ) Connect a C signal handler to the given, typed
CssProviderSignalNamesignalDeclaration
Swift
@discardableResult @inlinable func connect(signal s: CssProviderSignalName, flags f: ConnectFlags = ConnectFlags(0), data userData: gpointer!, destroyData destructor: GClosureNotify? = nil, signalHandler h: @escaping GCallback) -> IntParameters
signalThe signal to connect
flagsThe connection flags to use
dataA pointer to user data to provide to the callback
destroyDataA
GClosureNotifyC function to destroy the data pointed to byuserDatasignalHandlerThe C function to be called on the given signal
Return Value
The signal handler ID (always greater than 0 for successful connections)
-
onParsingError(flags:Extension methodhandler: ) Signals that a parsing error occurred.
The
path,lineandpositiondescribe 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 underlyingparsing-errorsignalDeclaration
Swift
@discardableResult @inlinable func onParsingError(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: CssProviderRef, _ section: CssSectionRef, _ error: GLib.ErrorRef) -> Void) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
sectionsection the error happened in
errorThe parsing error
handlerThe signal handler to call Run the given callback whenever the
parsingErrorsignal is emitted -
parsingErrorSignalExtension methodTyped
parsing-errorsignal for using theconnect(signal:)methodsDeclaration
Swift
static var parsingErrorSignal: CssProviderSignalName { get }
-
load(from:Extension methodlength: ) Loads
dataintocss_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
fileintocss_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
pathintocss_provider.This clears any previously loaded information.
Declaration
Swift
@inlinable func load(from path: UnsafePointer<CChar>!) -
loadFromResource(resourcePath:Extension method) Loads the data contained in the resource at
resource_pathinto thecss_provider.This clears any previously loaded information.
Declaration
Swift
@inlinable func loadFromResource(resourcePath: UnsafePointer<CChar>!) -
loadNamed(name:Extension methodvariant: ) 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 methodConverts the
providerinto a string representation in CSS format.Using [method
Gtk.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 thisprovider.Declaration
Swift
@inlinable func toString() -> String! -
parentInstanceExtension methodUndocumented
Declaration
Swift
@inlinable var parentInstance: GObject { get }
View on GitHub
Install in Dash
CssProviderProtocol Protocol Reference