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
GtkCssProvider
instance.Declaration
Swift
var ptr: UnsafeMutableRawPointer! { get }
-
css_provider_ptr
Default implementationTyped 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 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
anErrorType
if there is an issue with the CSSDeclaration
Swift
@inlinable func load(from data: String)
Parameters
data
the CSS data represented as a String
-
connect(signal:
Extension methodflags: handler: ) Connect a Swift signal handler to the given, typed
CssProviderSignalName
signalDeclaration
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 byuserData
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(signal:
Extension methodflags: data: destroyData: signalHandler: ) Connect a C signal handler to the given, typed
CssProviderSignalName
signalDeclaration
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 byuserData
signalHandler
The 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
,line
andposition
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 underlyingparsing-error
signalDeclaration
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 methodTyped
parsing-error
signal for using theconnect(signal:)
methodsDeclaration
Swift
static var parsingErrorSignal: CssProviderSignalName { get }
-
load(from:
Extension methodlength: ) Loads
data
intocss_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
intocss_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
intocss_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_path
into 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
provider
into 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!
-
parentInstance
Extension methodUndocumented
Declaration
Swift
@inlinable var parentInstance: GObject { get }