gtk.style_context

Module for [StyleContext] class

Types 3

#GtkStyleContext is an object that stores styling information affecting a widget defined by #GtkWidgetPath.

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 gtk.style_context.StyleContext.addProvider, or to the screen through gtk.style_context.StyleContext.addProviderForScreen. The resulting style is a combination of all providers’ information in priority order.

For GTK+ widgets, any #GtkStyleContext returned by gtk.widget.Widget.getStyleContext will already have a #GtkWidgetPath, a #GdkScreen and RTL/LTR information set. The style context will also be updated automatically if any of these settings change on the widget.

If you are using the theming layer standalone, you will need to set a widget path and a screen yourself to the created style context through gtk.style_context.StyleContext.setPath and possibly gtk.style_context.StyleContext.setScreen. See the “Foreign drawing“ example in gtk3-demo.

Style Classes # {#gtkstylecontext-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.

GTK+ defines macros for a number of style classes.

Style Regions

Widgets can also add regions with flags to their context. This feature is deprecated and will be removed in a future GTK+ update. Please use style classes instead.

GTK+ defines macros for a number of style regions.

Custom styling in UI libraries and applications

If you are developing a library with custom #GtkWidgets that render differently than standard components, you may need to add a #GtkStyleProvider yourself with the gtk.types.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 gtk.types.STYLE_PROVIDER_PRIORITY_APPLICATION priority, keep in mind that the user settings in XDG_CONFIG_HOME/gtk-3.0/gtk.css will still take precedence over your changes, as it uses the gtk.types.STYLE_PROVIDER_PRIORITY_USER priority.

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
void direction(gtk.types.TextDirection propval) @property nothrow
void paintClock(gdk.frame_clock.FrameClock propval) @property nothrow
gtk.style_context.StyleContext parent() @property nothrowGet `parent` property. Returns: Sets or gets the style context’s parent. See [gtk.style_context.StyleContext.setParent] for details.
void parent(gtk.style_context.StyleContext propval) @property nothrowSet `parent` property. Params: propval = Sets or gets the style context’s parent. See [gtk.style_context.StyleContext.setParent] for details.
gdk.screen.Screen screen() @property nothrow
void screen(gdk.screen.Screen propval) @property nothrow
void addProviderForScreen(gdk.screen.Screen screen, gtk.style_provider.StyleProvider provider, uint priority) static nothrowAdds a global style provider to screen, which will be used in style construction for all #GtkStyleContexts under screen.
void removeProviderForScreen(gdk.screen.Screen screen, gtk.style_provider.StyleProvider provider) static nothrowRemoves provider from the global style providers list in screen.
void resetWidgets(gdk.screen.Screen screen) static nothrowThis function recomputes the styles for all widgets under a particular #GdkScreen. This is useful when some global parameter has changed that affects the appearance of all widgets, because when a w...
void addClass(string className) nothrowAdds a style class to context, so posterior calls to [gtk.style_context.StyleContext.get] or any of the gtk_render_*() functions 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. Note that a style provider added by this function only affects the style of the widget to which context belongs. If you want to a...
void addRegion(string regionName, gtk.types.RegionFlags flags) nothrowAdds a region to context, so posterior calls to [gtk.style_context.StyleContext.get] or any of the gtk_render_*() functions will make use of this new region for styling.
void cancelAnimations(void * regionId = null) nothrowStops all running animations for region_id and all animatable regions underneath.
void getBackgroundColor(gtk.types.StateFlags state, out gdk.rgba.RGBA color) nothrowGets the background color for a given state.
void getBorder(gtk.types.StateFlags state, out gtk.border.Border border) nothrowGets the border for a given state as a #GtkBorder.
void getBorderColor(gtk.types.StateFlags state, out gdk.rgba.RGBA color) nothrowGets the border color for a given state.
void getColor(gtk.types.StateFlags state, out gdk.rgba.RGBA color) nothrowGets the foreground color for a given state.
gtk.types.TextDirection getDirection() nothrowReturns the widget direction used for rendering. Returns: the widget direction
pango.font_description.FontDescription getFont(gtk.types.StateFlags state) nothrowReturns the font description for a given state. The returned object is const and will remain valid until the #GtkStyleContext::changed signal happens.
gdk.frame_clock.FrameClock getFrameClock() nothrowReturns the #GdkFrameClock to which context is attached. Returns: a #GdkFrameClock, or null if context does not have an attached frame clock.
gtk.types.JunctionSides getJunctionSides() nothrowReturns the sides where rendered elements connect visually with others. Returns: the junction sides
void getMargin(gtk.types.StateFlags state, out gtk.border.Border margin) nothrowGets the margin for a given state as a #GtkBorder. See gtk_style_property_get() and #GTK_STYLE_PROPERTY_MARGIN for details.
void getPadding(gtk.types.StateFlags state, out gtk.border.Border padding) nothrowGets the padding for a given state as a #GtkBorder. See [gtk.style_context.StyleContext.get] and #GTK_STYLE_PROPERTY_PADDING for details.
gtk.style_context.StyleContext getParent() nothrowGets the parent context set via [gtk.style_context.StyleContext.setParent]. See that function for details. Returns: the parent context or null
gtk.widget_path.WidgetPath getPath() nothrowReturns the widget path used for style matching. Returns: A #GtkWidgetPath
void getProperty(string property, gtk.types.StateFlags state, out gobject.value.Value value) nothrowGets a style property from context for the given state.
int getScale() nothrowReturns the scale used for assets. Returns: the scale
gdk.screen.Screen getScreen() nothrowReturns the #GdkScreen to which context is attached. Returns: a #GdkScreen.
gtk.css_section.CssSection getSection(string property) nothrowQueries the location in the CSS where property was defined for the current context. Note that the state to be queried is taken from [gtk.style_context.StyleContext.getState].
gtk.types.StateFlags getState() nothrowReturns the state used for style matching.
void getStyleProperty(string propertyName, gobject.value.Value value) nothrowGets the value for a widget style property.
bool hasClass(string className) nothrowReturns true if context currently has defined the given class name.
bool hasRegion(string regionName, out gtk.types.RegionFlags flagsReturn) nothrowReturns true if context has the region defined. If flags_return is not null, it is set to the flags affecting the region.
void invalidate() nothrowInvalidates context style information, so it will be reconstructed again. It is useful if you modify the context and need the new information immediately.
string[] listClasses() nothrowReturns the list of classes currently defined in context. Returns: a #GList of strings with the currently defined classes. The contents of the list are owned by GTK+, but you must free the list its...
string[] listRegions() nothrowReturns the list of regions currently defined in context. Returns: a #GList of strings with the currently defined regions. The contents of the list are owned by GTK+, but you must free the list its...
bool lookupColor(string colorName, out gdk.rgba.RGBA color) nothrowLooks up and resolves a color name in the context color map.
gtk.icon_set.IconSet lookupIconSet(string stockId) nothrowLooks up stock_id in the icon factories associated to context and the default icon factory, returning an icon set if found, otherwise null.
void notifyStateChange(gdk.window.Window window, void * regionId, gtk.types.StateType state, bool stateValue) nothrowNotifies a state change on context, so if the current style makes use of transition animations, one will be started so all rendered elements under region_id are animated for state state being set t...
void popAnimatableRegion() nothrowPops an animatable region from context. See [gtk.style_context.StyleContext.pushAnimatableRegion].
void pushAnimatableRegion(void * regionId = null) nothrowPushes an animatable region, so all further gtk_render_*() calls between this call and the following [gtk.style_context.StyleContext.popAnimatableRegion] will potentially show transition animations...
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 removeRegion(string regionName) nothrowRemoves a region from context.
void restore() nothrowRestores context state to a previous stage. See [gtk.style_context.StyleContext.save].
void save() nothrowSaves the context state, so temporary modifications done through [gtk.style_context.StyleContext.addClass], [gtk.style_context.StyleContext.removeClass], [gtk.style_context.StyleContext.setState], ...
void scrollAnimations(gdk.window.Window window, int dx, int dy) nothrowThis function is analogous to [gdk.window.Window.scroll], and should be called together with it so the invalidation areas for any ongoing animation are scrolled together with it.
void setBackground(gdk.window.Window window) nothrowSets the background of window to the background pattern or color specified in context for its current state.
void setDirection(gtk.types.TextDirection direction) nothrowSets the reading direction for rendering purposes.
void setFrameClock(gdk.frame_clock.FrameClock frameClock) nothrowAttaches context to the given frame clock.
void setJunctionSides(gtk.types.JunctionSides sides) nothrowSets the sides where rendered elements (mostly through [gtk.global.renderFrame]) will visually connect with other visual elements.
void setParent(gtk.style_context.StyleContext parent = null) nothrowSets the parent style context for context. The parent style context is used to implement [inheritance](http://www.w3.org/TR/css3-cascade/#inheritance) of properties.
void setPath(gtk.widget_path.WidgetPath path) nothrowSets the #GtkWidgetPath used for style matching. As a consequence, the style will be regenerated to match the new given path.
void setScale(int scale) nothrowSets the scale to use when getting image assets for the style.
void setScreen(gdk.screen.Screen screen) nothrowAttaches context to the given screen.
void setState(gtk.types.StateFlags flags) nothrowSets the state to be used for style matching.
bool stateIsRunning(gtk.types.StateType state, out double progress) nothrowReturns true if there is a transition animation running for the current region (see [gtk.style_context.StyleContext.pushAnimatableRegion]).
string toString_(gtk.types.StyleContextPrintFlags flags) nothrowConverts the style context into a string representation.
gulong connectChanged(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.style_context.StyleContext))) && Parameters!T.length < 2) nothrowConnect to `Changed` signal.
Constructors
this(void * ptr, Flag!"Take" take)
this()Creates a standalone #GtkStyleContext, this style context won’t be attached to any widget, so you may want to call [gtk.style_context.StyleContext.setPath] yourself.

Fluent builder implementation template for gtk.style_context.StyleContext

Methods
T parent(gtk.style_context.StyleContext propval) nothrowSet `parent` property. Params: propval = Sets or gets the style context’s parent. See [gtk.style_context.StyleContext.setParent] for details. Returns: Builder instance for fluent chaining
T screen(gdk.screen.Screen propval) nothrow
Methods
StyleContext build() nothrowCreate object from builder. Returns: New object