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

Contents

- Exported types
- Methods
  - addClass
  - addProvider
  - addProviderForDisplay
  - getBorder
  - getColor
  - getDisplay
  - getMargin
  - getPadding
  - getScale
  - getState
  - hasClass
  - lookupColor
  - removeClass
  - removeProvider
  - removeProviderForDisplay
  - restore
  - save
  - setDisplay
  - setScale
  - setState
  - toString
- Properties
  - display

Description

`GtkStyleContext` stores styling information affecting a widget.

In order to construct the final style information, `GtkStyleContext` queries information from all attached `GtkStyleProviders`. Style providers can be either attached explicitly to the context through `styleContextAddProvider`, or to the display through `styleContextAddProviderForDisplay`. The resulting style is a combination of all providers’ information in priority order.

For GTK widgets, any `GtkStyleContext` returned by `widgetGetStyleContext` will already have a `GdkDisplay` and RTL/LTR information set. The style context will also be updated automatically if any of these settings change on the widget.

## Style Classes

Widgets can add style classes to their context, which can be used to associate different styles by class. The documentation for individual widgets lists which style classes it uses itself, and which style classes may be added by applications to affect their appearance.

# Custom styling in UI libraries and applications

If you are developing a library with custom widgets that render differently than standard components, you may need to add a `GtkStyleProvider` yourself with the `STYLE_PROVIDER_PRIORITY_FALLBACK` priority, either a `GtkCssProvider` or a custom object implementing the `GtkStyleProvider` interface. This way themes may still attempt to style your UI elements in a different way if needed so.

If you are using custom styling on an applications, you probably want then to make your style information prevail to the theme’s, so you must use a `GtkStyleProvider` with the `STYLE_PROVIDER_PRIORITY_APPLICATION` priority, keep in mind that the user settings in `XDG_CONFIG_HOME/gtk-4.0/gtk.css` will still take precedence over your changes, as it uses the `STYLE_PROVIDER_PRIORITY_USER` priority.

Synopsis

- newtype StyleContext = StyleContext (ManagedPtr StyleContext)
- class (GObject o, IsDescendantOf StyleContext o) => IsStyleContext o
- toStyleContext :: (MonadIO m, IsStyleContext o) => o -> m StyleContext
- styleContextAddClass :: (HasCallStack, MonadIO m, IsStyleContext a) => a -> Text -> m ()
- styleContextAddProvider :: (HasCallStack, MonadIO m, IsStyleContext a, IsStyleProvider b) => a -> b -> Word32 -> m ()
- styleContextAddProviderForDisplay :: (HasCallStack, MonadIO m, IsDisplay a, IsStyleProvider b) => a -> b -> Word32 -> m ()
- styleContextGetBorder :: (HasCallStack, MonadIO m, IsStyleContext a) => a -> m Border
- styleContextGetColor :: (HasCallStack, MonadIO m, IsStyleContext a) => a -> m RGBA
- styleContextGetDisplay :: (HasCallStack, MonadIO m, IsStyleContext a) => a -> m Display
- styleContextGetMargin :: (HasCallStack, MonadIO m, IsStyleContext a) => a -> m Border
- styleContextGetPadding :: (HasCallStack, MonadIO m, IsStyleContext a) => a -> m Border
- styleContextGetScale :: (HasCallStack, MonadIO m, IsStyleContext a) => a -> m Int32
- styleContextGetState :: (HasCallStack, MonadIO m, IsStyleContext a) => a -> m [StateFlags]
- styleContextHasClass :: (HasCallStack, MonadIO m, IsStyleContext a) => a -> Text -> m Bool
- styleContextLookupColor :: (HasCallStack, MonadIO m, IsStyleContext a) => a -> Text -> m (Bool, RGBA)
- styleContextRemoveClass :: (HasCallStack, MonadIO m, IsStyleContext a) => a -> Text -> m ()
- styleContextRemoveProvider :: (HasCallStack, MonadIO m, IsStyleContext a, IsStyleProvider b) => a -> b -> m ()
- styleContextRemoveProviderForDisplay :: (HasCallStack, MonadIO m, IsDisplay a, IsStyleProvider b) => a -> b -> m ()
- styleContextRestore :: (HasCallStack, MonadIO m, IsStyleContext a) => a -> m ()
- styleContextSave :: (HasCallStack, MonadIO m, IsStyleContext a) => a -> m ()
- styleContextSetDisplay :: (HasCallStack, MonadIO m, IsStyleContext a, IsDisplay b) => a -> b -> m ()
- styleContextSetScale :: (HasCallStack, MonadIO m, IsStyleContext a) => a -> Int32 -> m ()
- styleContextSetState :: (HasCallStack, MonadIO m, IsStyleContext a) => a -> [StateFlags] -> m ()
- styleContextToString :: (HasCallStack, MonadIO m, IsStyleContext a) => a -> [StyleContextPrintFlags] -> m Text
- constructStyleContextDisplay :: (IsStyleContext o, MonadIO m, IsDisplay a) => a -> m (GValueConstruct o)
- getStyleContextDisplay :: (MonadIO m, IsStyleContext o) => o -> m Display
- setStyleContextDisplay :: (MonadIO m, IsStyleContext o, IsDisplay a) => o -> a -> m ()

# Exported types

newtype StyleContext Source #

Memory-managed wrapper type.

Constructors

StyleContext (ManagedPtr StyleContext) |

#### Instances

Instances details

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

class (GObject o, IsDescendantOf StyleContext o) => IsStyleContext o Source #

Type class for types which can be safely cast to `StyleContext`, for instance with `toStyleContext`.

#### Instances

Instances details

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

toStyleContext :: (MonadIO m, IsStyleContext o) => o -> m StyleContext Source #

Cast to `StyleContext`, 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

addClass, addProvider, bindProperty, bindPropertyFull, forceFloating, freezeNotify, getv, hasClass, isFloating, lookupColor, notify, notifyByPspec, ref, refSink, removeClass, removeProvider, restore, runDispose, save, stealData, stealQdata, thawNotify, toString, unref, watchClosure.

#### Getters

getBorder, getColor, getData, getDisplay, getMargin, getPadding, getProperty, getQdata, getScale, getState.

#### Setters

setData, setDataFull, setDisplay, setProperty, setScale, setState.

## addClass

styleContextAddClass Source #

Arguments

:: (HasCallStack, MonadIO m, IsStyleContext a) |
=> a | `context`: a `GtkStyleContext`
-> Text | `className`: class name to use in styling
-> m () |

Deprecated: (Since version 4.10)Use `widgetAddCssClass` instead

Adds a style class to `context`, so later uses of the style context will make use of this new class for styling.

In the CSS file format, a `GtkEntry` defining a “search” class, would be matched by:

### css code

    entry.search { ... }

While any widget defining a “search” class would be matched by:

### css code

    .search { ... }

## addProvider

styleContextAddProvider Source #

Arguments

:: (HasCallStack, MonadIO m, IsStyleContext a, IsStyleProvider b) |
=> a | `context`: a `GtkStyleContext`
-> b | `provider`: a `GtkStyleProvider`
-> Word32 | `priority`: the priority of the style provider. The lower it is, the earlier it will be used in the style construction. Typically this will be in the range between `STYLE_PROVIDER_PRIORITY_FALLBACK` and `STYLE_PROVIDER_PRIORITY_USER`
-> m () |

Deprecated: (Since version 4.10)Use style classes instead

Adds a style provider to `context`, to be used in style construction.

Note that a style provider added by this function only affects the style of the widget to which `context` belongs. If you want to affect the style of all widgets, use `styleContextAddProviderForDisplay`.

Note: If both priorities are the same, a `GtkStyleProvider` added through this function takes precedence over another added through `styleContextAddProviderForDisplay`.

## addProviderForDisplay

styleContextAddProviderForDisplay Source #

Arguments

:: (HasCallStack, MonadIO m, IsDisplay a, IsStyleProvider b) |
=> a | `display`: a `GdkDisplay`
-> b | `provider`: a `GtkStyleProvider`
-> Word32 | `priority`: the priority of the style provider. The lower it is, the earlier it will be used in the style construction. Typically this will be in the range between `STYLE_PROVIDER_PRIORITY_FALLBACK` and `STYLE_PROVIDER_PRIORITY_USER`
-> m () |

Adds a global style provider to `display`, which will be used in style construction for all `GtkStyleContexts` under `display`.

GTK uses this to make styling information from `GtkSettings` available.

Note: If both priorities are the same, A `GtkStyleProvider` added through `styleContextAddProvider` takes precedence over another added through this function.

## getBorder

styleContextGetBorder Source #

Arguments

:: (HasCallStack, MonadIO m, IsStyleContext a) |
=> a | `context`: a `GtkStyleContext`
-> m Border |

Deprecated: (Since version 4.10)This api will be removed in GTK 5

Gets the border for a given state as a `GtkBorder`.

## getColor

styleContextGetColor Source #

Arguments

:: (HasCallStack, MonadIO m, IsStyleContext a) |
=> a | `context`: a `GtkStyleContext`
-> m RGBA |

Deprecated: (Since version 4.10)Use `widgetGetColor` instead

Gets the foreground color for a given state.

## getDisplay

styleContextGetDisplay Source #

Arguments

:: (HasCallStack, MonadIO m, IsStyleContext a) |
=> a | `context`: a `GtkStyleContext`
-> m Display | Returns: a `GdkDisplay`.

Deprecated: (Since version 4.10)Use `widgetGetDisplay` instead

Returns the `GdkDisplay` to which `context` is attached.

## getMargin

styleContextGetMargin Source #

Arguments

:: (HasCallStack, MonadIO m, IsStyleContext a) |
=> a | `context`: a `GtkStyleContext`
-> m Border |

Deprecated: (Since version 4.10)This api will be removed in GTK 5

Gets the margin for a given state as a `GtkBorder`.

## getPadding

styleContextGetPadding Source #

Arguments

:: (HasCallStack, MonadIO m, IsStyleContext a) |
=> a | `context`: a `GtkStyleContext`
-> m Border |

Deprecated: (Since version 4.10)This api will be removed in GTK 5

Gets the padding for a given state as a `GtkBorder`.

## getScale

styleContextGetScale Source #

Arguments

:: (HasCallStack, MonadIO m, IsStyleContext a) |
=> a | `context`: a `GtkStyleContext`
-> m Int32 | Returns: the scale

Deprecated: (Since version 4.10)Use `widgetGetScaleFactor` instead

Returns the scale used for assets.

## getState

styleContextGetState Source #

Arguments

:: (HasCallStack, MonadIO m, IsStyleContext a) |
=> a | `context`: a `GtkStyleContext`
-> m [StateFlags] | Returns: the state flags

Deprecated: (Since version 4.10)Use `widgetGetStateFlags` instead

Returns the state used for style matching.

This method should only be used to retrieve the `GtkStateFlags` to pass to `GtkStyleContext` methods, like `styleContextGetPadding`. If you need to retrieve the current state of a `GtkWidget`, use `widgetGetStateFlags`.

## hasClass

styleContextHasClass Source #

Arguments

:: (HasCallStack, MonadIO m, IsStyleContext a) |
=> a | `context`: a `GtkStyleContext`
-> Text | `className`: a class name
-> m Bool | Returns: `True` if `context` has `className` defined

Deprecated: (Since version 4.10)Use `widgetHasCssClass` instead

Returns `True` if `context` currently has defined the given class name.

## lookupColor

styleContextLookupColor Source #

Arguments

:: (HasCallStack, MonadIO m, IsStyleContext a) |
=> a | `context`: a `GtkStyleContext`
-> Text | `colorName`: color name to lookup
-> m (Bool, RGBA) | Returns: `True` if `colorName` was found and resolved, `False` otherwise

Deprecated: (Since version 4.10)This api will be removed in GTK 5

Looks up and resolves a color name in the `context` color map.

## removeClass

styleContextRemoveClass Source #

Arguments

:: (HasCallStack, MonadIO m, IsStyleContext a) |
=> a | `context`: a `GtkStyleContext`
-> Text | `className`: class name to remove
-> m () |

Deprecated: (Since version 4.10)Use `widgetRemoveCssClass` instead

Removes `className` from `context`.

## removeProvider

styleContextRemoveProvider Source #

Arguments

:: (HasCallStack, MonadIO m, IsStyleContext a, IsStyleProvider b) |
=> a | `context`: a `GtkStyleContext`
-> b | `provider`: a `GtkStyleProvider`
-> m () |

Deprecated: (Since version 4.10)

Removes `provider` from the style providers list in `context`.

## removeProviderForDisplay

styleContextRemoveProviderForDisplay Source #

Arguments

:: (HasCallStack, MonadIO m, IsDisplay a, IsStyleProvider b) |
=> a | `display`: a `GdkDisplay`
-> b | `provider`: a `GtkStyleProvider`
-> m () |

Removes `provider` from the global style providers list in `display`.

## restore

styleContextRestore Source #

Arguments

:: (HasCallStack, MonadIO m, IsStyleContext a) |
=> a | `context`: a `GtkStyleContext`
-> m () |

Deprecated: (Since version 4.10)This API will be removed in GTK 5

Restores `context` state to a previous stage.

See `styleContextSave`.

## save

styleContextSave Source #

Arguments

:: (HasCallStack, MonadIO m, IsStyleContext a) |
=> a | `context`: a `GtkStyleContext`
-> m () |

Deprecated: (Since version 4.10)This API will be removed in GTK 5

Saves the `context` state.

This allows temporary modifications done through `styleContextAddClass`, `styleContextRemoveClass`, `styleContextSetState` to be quickly reverted in one go through `styleContextRestore`.

The matching call to `styleContextRestore` must be done before GTK returns to the main loop.

## setDisplay

styleContextSetDisplay Source #

Arguments

:: (HasCallStack, MonadIO m, IsStyleContext a, IsDisplay b) |
=> a | `context`: a `GtkStyleContext`
-> b | `display`: a `GdkDisplay`
-> m () |

Deprecated: (Since version 4.10)You should not use this api

Attaches `context` to the given display.

The display is used to add style information from “global” style providers, such as the display's `GtkSettings` instance.

If you are using a `GtkStyleContext` returned from `widgetGetStyleContext`, you do not need to call this yourself.

## setScale

styleContextSetScale Source #

Arguments

:: (HasCallStack, MonadIO m, IsStyleContext a) |
=> a | `context`: a `GtkStyleContext`
-> Int32 | `scale`: scale
-> m () |

Deprecated: (Since version 4.10)You should not use this api

Sets the scale to use when getting image assets for the style.

## setState

styleContextSetState Source #

Arguments

:: (HasCallStack, MonadIO m, IsStyleContext a) |
=> a | `context`: a `GtkStyleContext`
-> [StateFlags] | `flags`: state to represent
-> m () |

Deprecated: (Since version 4.10)You should not use this api

Sets the state to be used for style matching.

## toString

styleContextToString Source #

Arguments

:: (HasCallStack, MonadIO m, IsStyleContext a) |
=> a | `context`: a `GtkStyleContext`
-> [StyleContextPrintFlags] | `flags`: Flags that determine what to print
-> m Text | Returns: a newly allocated string representing `context`

Deprecated: (Since version 4.10)This api will be removed in GTK 5

Converts the style context into a string representation.

The string representation always includes information about the name, state, id, visibility and style classes of the CSS node that is backing `context`. Depending on the flags, more information may be included.

This function is intended for testing and debugging of the CSS implementation in GTK. There are no guarantees about the format of the returned string, it may change.

# Properties

## display

The display of the style context.

constructStyleContextDisplay :: (IsStyleContext o, MonadIO m, IsDisplay a) => a -> m (GValueConstruct o) Source #

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

getStyleContextDisplay :: (MonadIO m, IsStyleContext o) => o -> m Display Source #

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

    get styleContext #display

setStyleContextDisplay :: (MonadIO m, IsStyleContext o, IsDisplay a) => o -> a -> m () Source #

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

    set styleContext [ #display := value ]