gi-gtk4-4.0.12: Gtk 4.x bindings

Copyright | Will Thompson and Iñaki García Etxebarria
License | LGPL-2.1
Maintainer | Iñaki García Etxebarria
Safe Haskell | None
Language | Haskell2010

GI.Gtk.Objects.CssProvider

Contents

- Exported types
- Methods
  - loadFromBytes
  - loadFromData
  - loadFromFile
  - loadFromPath
  - loadFromResource
  - loadFromString
  - loadNamed
  - new
  - toString
- Properties
  - prefersColorScheme
  - prefersContrast
  - prefersReducedMotion
- Signals
  - parsingError

Description

A style provider 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 `cssProviderLoadFromFile` or `cssProviderLoadFromResource` and adding the provider with `styleContextAddProvider` or `styleContextAddProviderForDisplay`.

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 Settings:gtkThemeName setting), `VARIANT` is the variant to load (see the Settings:gtkApplicationPreferDarkTheme 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 CssProvider::parsingError signal.

Synopsis

- newtype CssProvider = CssProvider (ManagedPtr CssProvider)
- class (GObject o, IsDescendantOf CssProvider o) => IsCssProvider o
- toCssProvider :: (MonadIO m, IsCssProvider o) => o -> m CssProvider
- cssProviderLoadFromBytes :: (HasCallStack, MonadIO m, IsCssProvider a) => a -> Bytes -> m ()
- cssProviderLoadFromData :: (HasCallStack, MonadIO m, IsCssProvider a) => a -> Text -> Int64 -> m ()
- cssProviderLoadFromFile :: (HasCallStack, MonadIO m, IsCssProvider a, IsFile b) => a -> b -> m ()
- cssProviderLoadFromPath :: (HasCallStack, MonadIO m, IsCssProvider a) => a -> [Char] -> m ()
- cssProviderLoadFromResource :: (HasCallStack, MonadIO m, IsCssProvider a) => a -> Text -> m ()
- cssProviderLoadFromString :: (HasCallStack, MonadIO m, IsCssProvider a) => a -> Text -> m ()
- cssProviderLoadNamed :: (HasCallStack, MonadIO m, IsCssProvider a) => a -> Text -> Maybe Text -> m ()
- cssProviderNew :: (HasCallStack, MonadIO m) => m CssProvider
- cssProviderToString :: (HasCallStack, MonadIO m, IsCssProvider a) => a -> m Text
- constructCssProviderPrefersColorScheme :: (IsCssProvider o, MonadIO m) => InterfaceColorScheme -> m (GValueConstruct o)
- getCssProviderPrefersColorScheme :: (MonadIO m, IsCssProvider o) => o -> m InterfaceColorScheme
- setCssProviderPrefersColorScheme :: (MonadIO m, IsCssProvider o) => o -> InterfaceColorScheme -> m ()
- constructCssProviderPrefersContrast :: (IsCssProvider o, MonadIO m) => InterfaceContrast -> m (GValueConstruct o)
- getCssProviderPrefersContrast :: (MonadIO m, IsCssProvider o) => o -> m InterfaceContrast
- setCssProviderPrefersContrast :: (MonadIO m, IsCssProvider o) => o -> InterfaceContrast -> m ()
- constructCssProviderPrefersReducedMotion :: (IsCssProvider o, MonadIO m) => ReducedMotion -> m (GValueConstruct o)
- getCssProviderPrefersReducedMotion :: (MonadIO m, IsCssProvider o) => o -> m ReducedMotion
- setCssProviderPrefersReducedMotion :: (MonadIO m, IsCssProvider o) => o -> ReducedMotion -> m ()
- type CssProviderParsingErrorCallback = CssSection -> GError -> IO ()
- afterCssProviderParsingError :: (IsCssProvider a, MonadIO m) => a -> ((?self :: a) => CssProviderParsingErrorCallback) -> m SignalHandlerId
- onCssProviderParsingError :: (IsCssProvider a, MonadIO m) => a -> ((?self :: a) => CssProviderParsingErrorCallback) -> m SignalHandlerId

# Exported types

newtype CssProvider Source #

Memory-managed wrapper type.

Constructors

CssProvider (ManagedPtr CssProvider) |

#### Instances

Instances details

Eq CssProvider Source # |
Instance details Defined in GI.Gtk.Objects.CssProvider Methods (==) :: CssProvider -> CssProvider -> Bool Source # (/=) :: CssProvider -> CssProvider -> Bool Source #
GObject CssProvider Source # |
Instance details Defined in GI.Gtk.Objects.CssProvider
ManagedPtrNewtype CssProvider Source # |
Instance details Defined in GI.Gtk.Objects.CssProvider Methods toManagedPtr :: CssProvider -> ManagedPtr CssProvider Source #
TypedObject CssProvider Source # |
Instance details Defined in GI.Gtk.Objects.CssProvider Methods glibType :: IO GType Source #
HasParentTypes CssProvider Source # |
Instance details Defined in GI.Gtk.Objects.CssProvider
IsGValue (Maybe CssProvider) Source # | Convert `CssProvider` to and from `GValue`. See `toGValue` and `fromGValue`.
Instance details Defined in GI.Gtk.Objects.CssProvider Methods gvalueGType_ :: IO GType Source # gvalueSet_ :: Ptr GValue -> Maybe CssProvider -> IO () Source # gvalueGet_ :: Ptr GValue -> IO (Maybe CssProvider) Source #
type ParentTypes CssProvider Source # |
Instance details Defined in GI.Gtk.Objects.CssProvider type ParentTypes CssProvider = '[Object, StyleProvider]

class (GObject o, IsDescendantOf CssProvider o) => IsCssProvider o Source #

Type class for types which can be safely cast to `CssProvider`, for instance with `toCssProvider`.

#### Instances

Instances details

(GObject o, IsDescendantOf CssProvider o) => IsCssProvider o Source # |
Instance details Defined in GI.Gtk.Objects.CssProvider

toCssProvider :: (MonadIO m, IsCssProvider o) => o -> m CssProvider Source #

Cast to `CssProvider`, for types for which this is known to be safe. For general casts, use `castTo`.

# Methods

### Click to display all available methods, including inherited ones

Expand

#### Methods

bindProperty, bindPropertyFull, forceFloating, freezeNotify, getv, isFloating, loadFromBytes, loadFromData, loadFromFile, loadFromPath, loadFromResource, loadFromString, loadNamed, notify, notifyByPspec, ref, refSink, runDispose, stealData, stealQdata, thawNotify, toString, unref, watchClosure.

#### Getters

getData, getProperty, getQdata.

#### Setters

setData, setDataFull, setProperty.

## loadFromBytes

cssProviderLoadFromBytes Source #

Arguments

:: (HasCallStack, MonadIO m, IsCssProvider a) |
=> a | `cssProvider`: a `GtkCssProvider`
-> Bytes | `data`: `GBytes` containing the data to load
-> m () |

Loads `data` into `cssProvider`.

This clears any previously loaded information.

Since: 4.12

## loadFromData

cssProviderLoadFromData Source #

Arguments

:: (HasCallStack, MonadIO m, IsCssProvider a) |
=> a | `cssProvider`: a `GtkCssProvider`
-> Text | `data`: CSS data to be parsed
-> Int64 | `length`: the length of `data` in bytes, or -1 for NUL terminated strings
-> m () |

Deprecated: (Since version 4.12)Use `cssProviderLoadFromString`or `cssProviderLoadFromBytes` instead

Loads `data` into `cssProvider`.

This clears any previously loaded information.

## loadFromFile

cssProviderLoadFromFile Source #

Arguments

:: (HasCallStack, MonadIO m, IsCssProvider a, IsFile b) |
=> a | `cssProvider`: a `GtkCssProvider`
-> b | `file`: `GFile` pointing to a file to load
-> m () |

Loads the data contained in `file` into `cssProvider`.

This clears any previously loaded information.

## loadFromPath

cssProviderLoadFromPath Source #

Arguments

:: (HasCallStack, MonadIO m, IsCssProvider a) |
=> a | `cssProvider`: a `GtkCssProvider`
-> [Char] | `path`: the path of a filename to load, in the GLib filename encoding
-> m () |

Loads the data contained in `path` into `cssProvider`.

This clears any previously loaded information.

## loadFromResource

cssProviderLoadFromResource Source #

Arguments

:: (HasCallStack, MonadIO m, IsCssProvider a) |
=> a | `cssProvider`: a `GtkCssProvider`
-> Text | `resourcePath`: a `GResource` resource path
-> m () |

Loads the data contained in the resource at `resourcePath` into the `cssProvider`.

This clears any previously loaded information.

## loadFromString

cssProviderLoadFromString Source #

Arguments

:: (HasCallStack, MonadIO m, IsCssProvider a) |
=> a | `cssProvider`: a `GtkCssProvider`
-> Text | `string`: the CSS to load
-> m () |

Loads `string` into `cssProvider`.

This clears any previously loaded information.

Since: 4.12

## loadNamed

cssProviderLoadNamed Source #

Arguments

:: (HasCallStack, MonadIO m, IsCssProvider a) |
=> a | `provider`: a `GtkCssProvider`
-> Text | `name`: A theme name
-> Maybe Text | `variant`: variant to load, for example, "dark", or `Nothing` for the default
-> m () |

Deprecated: (Since version 4.20)Using any of the other theme loaders, combine with media queries.

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.

## new

cssProviderNew Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> m CssProvider | Returns: A new `GtkCssProvider`

Returns a newly created `GtkCssProvider`.

## toString

cssProviderToString Source #

Arguments

:: (HasCallStack, MonadIO m, IsCssProvider a) |
=> a | `provider`: the provider to write to a string
-> m Text | Returns: a new string representing the `provider`.

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

Using `cssProviderLoadFromString` with the return value from this function on a new provider created with `cssProviderNew` will basically create a duplicate of this `provider`.

# Properties

## prefersColorScheme

Define the color scheme used for rendering the user interface.

The UI can be set to either `InterfaceColorSchemeLight`, or `InterfaceColorSchemeDark` mode. Other values will be interpreted the same as `InterfaceColorSchemeLight`.

This setting is be available for media queries in CSS:

### css code

    @media (prefers-color-scheme: dark) {
      // some dark mode styling
    }

Changing this setting will reload the style sheet.

Since: 4.20

constructCssProviderPrefersColorScheme :: (IsCssProvider o, MonadIO m) => InterfaceColorScheme -> m (GValueConstruct o) Source #

Construct a `GValueConstruct` with valid value for the “`prefers-color-scheme`” property. This is rarely needed directly, but it is used by `new`.

getCssProviderPrefersColorScheme :: (MonadIO m, IsCssProvider o) => o -> m InterfaceColorScheme Source #

Get the value of the “`prefers-color-scheme`” property. When overloading is enabled, this is equivalent to

    get cssProvider #prefersColorScheme

setCssProviderPrefersColorScheme :: (MonadIO m, IsCssProvider o) => o -> InterfaceColorScheme -> m () Source #

Set the value of the “`prefers-color-scheme`” property. When overloading is enabled, this is equivalent to

    set cssProvider [ #prefersColorScheme := value ]

## prefersContrast

Define the contrast mode to use for the user interface.

When set to `InterfaceContrastMore` or `InterfaceContrastLess`, the UI is rendered in high or low contrast.

When set to `InterfaceContrastNoPreference` (the default), the user interface will be rendered in default mode.

This setting is be available for media queries in CSS:

### css code

    @media (prefers-contrast: more) {
      // some style with high contrast
    }

Changing this setting will reload the style sheet.

Since: 4.20

constructCssProviderPrefersContrast :: (IsCssProvider o, MonadIO m) => InterfaceContrast -> m (GValueConstruct o) Source #

Construct a `GValueConstruct` with valid value for the “`prefers-contrast`” property. This is rarely needed directly, but it is used by `new`.

getCssProviderPrefersContrast :: (MonadIO m, IsCssProvider o) => o -> m InterfaceContrast Source #

Get the value of the “`prefers-contrast`” property. When overloading is enabled, this is equivalent to

    get cssProvider #prefersContrast

setCssProviderPrefersContrast :: (MonadIO m, IsCssProvider o) => o -> InterfaceContrast -> m () Source #

Set the value of the “`prefers-contrast`” property. When overloading is enabled, this is equivalent to

    set cssProvider [ #prefersContrast := value ]

## prefersReducedMotion

Define the type of reduced motion to use for the user interface.

When set to `ReducedMotionReduce` the UI is rendered in with reduced motion animations.

When set to `ReducedMotionNoPreference` (the default), the user interface will be rendered in default mode.

This setting is be available for media queries in CSS:

### css code

    @media (prefers-reduced-motion: reduce) {
      // some style with reduced motion
    }

Changing this setting will reload the style sheet.

Since: 4.22

constructCssProviderPrefersReducedMotion :: (IsCssProvider o, MonadIO m) => ReducedMotion -> m (GValueConstruct o) Source #

Construct a `GValueConstruct` with valid value for the “`prefers-reduced-motion`” property. This is rarely needed directly, but it is used by `new`.

getCssProviderPrefersReducedMotion :: (MonadIO m, IsCssProvider o) => o -> m ReducedMotion Source #

Get the value of the “`prefers-reduced-motion`” property. When overloading is enabled, this is equivalent to

    get cssProvider #prefersReducedMotion

setCssProviderPrefersReducedMotion :: (MonadIO m, IsCssProvider o) => o -> ReducedMotion -> m () Source #

Set the value of the “`prefers-reduced-motion`” property. When overloading is enabled, this is equivalent to

    set cssProvider [ #prefersReducedMotion := value ]

# Signals

## parsingError

type CssProviderParsingErrorCallback Source #

Arguments

= CssSection | `section`: section the error happened in
-> GError | `error`: The parsing error
-> IO () |

Signals that a parsing error occurred.

The expected error values are in the [error`gtk`.CssParserError] and `CssParserWarning` enumerations.

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.

Errors in the `CssParserWarning` enumeration should not be treated as fatal errors.

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.

afterCssProviderParsingError :: (IsCssProvider a, MonadIO m) => a -> ((?self :: a) => CssProviderParsingErrorCallback) -> m SignalHandlerId Source #

Connect a signal handler for the parsingError signal, to be run after the default handler. When overloading is enabled, this is equivalent to

    after cssProvider #parsingError callback

By default the object invoking the signal is not passed to the callback. If you need to access it, you can use the implit `?self` parameter. Note that this requires activating the `ImplicitParams` GHC extension.

onCssProviderParsingError :: (IsCssProvider a, MonadIO m) => a -> ((?self :: a) => CssProviderParsingErrorCallback) -> m SignalHandlerId Source #

Connect a signal handler for the parsingError signal, to be run before the default handler. When overloading is enabled, this is equivalent to

    on cssProvider #parsingError callback