gtk.style_context

Module for [StyleContext] class

Types 3

gtk.style_context.StyleContext stores styling information affecting a widget.

In order to construct the final style information, gtk.style_context.StyleContext queries information from all attached GtkStyleProviders. Style providers can be either attached explicitly to the context through gtk.style_context.StyleContext.addProvider, or to the display through gtk.style_context.StyleContext.addProviderForDisplay. The resulting style is a combination of all providers’ information in priority order.

For GTK widgets, any gtk.style_context.StyleContext returned by gtk.widget.Widget.getStyleContext will already have a gdk.display.Display 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 gtk.style_provider.StyleProvider yourself with the gtk.types.STYLE_PROVIDER_PRIORITY_FALLBACK priority, either a gtk.css_provider.CssProvider or a custom object implementing the gtk.style_provider.StyleProvider 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 gtk.style_provider.StyleProvider with the gtk.types.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 gtk.types.STYLE_PROVIDER_PRIORITY_USER priority.

Deprecated

The relevant API has been moved to gtk.widget.Widget

where applicable; otherwise, there is no replacement for querying the style machinery. Stylable UI elements should use widgets.

Methods
GType _getGType() static nothrow
GType _gType() @property nothrow
StyleContext self() nothrowReturns `this`, for use in `with` statements.
StyleContextGidBuilder builder() static nothrowGet builder for [gtk.style_context.StyleContext] Returns: New builder object
gdk.display.Display display() @property nothrow
void display(gdk.display.Display propval) @property nothrow
void addProviderForDisplay(gdk.display.Display display, gtk.style_provider.StyleProvider provider, uint priority) static nothrowAdds a global style provider to display, which will be used in style construction for all `GtkStyleContexts` under display.
void removeProviderForDisplay(gdk.display.Display display, gtk.style_provider.StyleProvider provider) static nothrowRemoves provider from the global style providers list in display.
void addClass(string className) nothrowAdds a style class to context, so later uses of the style context will make use of this new class for styling.
void addProvider(gtk.style_provider.StyleProvider provider, uint priority) nothrowAdds a style provider to context, to be used in style construction.
void getBorder(out gtk.border.Border border) nothrowGets the border for a given state as a [gtk.border.Border].
void getColor(out gdk.rgba.RGBA color) nothrowGets the foreground color for a given state.
gdk.display.Display getDisplay() nothrowReturns the [gdk.display.Display] to which context is attached. Returns: a [gdk.display.Display].
void getMargin(out gtk.border.Border margin) nothrowGets the margin for a given state as a [gtk.border.Border].
void getPadding(out gtk.border.Border padding) nothrowGets the padding for a given state as a [gtk.border.Border].
int getScale() nothrowReturns the scale used for assets. Returns: the scale
gtk.types.StateFlags getState() nothrowReturns the state used for style matching.
bool hasClass(string className) nothrowReturns true if context currently has defined the given class name.
bool lookupColor(string colorName, out gdk.rgba.RGBA color) nothrowLooks up and resolves a color name in the context color map.
void removeClass(string className) nothrowRemoves class_name from context.
void removeProvider(gtk.style_provider.StyleProvider provider) nothrowRemoves provider from the style providers list in context.
void restore() nothrowRestores context state to a previous stage.
void save() nothrowSaves the context state.
void setDisplay(gdk.display.Display display) nothrowAttaches context to the given display.
void setScale(int scale) nothrowSets the scale to use when getting image assets for the style.
void setState(gtk.types.StateFlags flags) nothrowSets the state to be used for style matching.
string toString_(gtk.types.StyleContextPrintFlags flags) nothrowConverts the style context into a string representation.
Constructors
this(void * ptr, Flag!"Take" take)

Fluent builder implementation template for gtk.style_context.StyleContext

Methods
T display(gdk.display.Display propval) nothrow
Methods
StyleContext build() nothrowCreate object from builder. Returns: New object