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 _gType() @property
StyleContext self()Returns `this`, for use in `with` statements.
StyleContextGidBuilder builder()Get builder for [gtk.style_context.StyleContext] Returns: New builder object
void direction(gtk.types.TextDirection propval) @property
void paintClock(gdk.frame_clock.FrameClock propval) @property
gtk.style_context.StyleContext parent() @propertyGet `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) @propertySet `parent` property. Params: propval = Sets or gets the style context’s parent. See [gtk.style_context.StyleContext.setParent] for details.
void screen(gdk.screen.Screen propval) @property
void addProviderForScreen(gdk.screen.Screen screen, gtk.style_provider.StyleProvider provider, uint priority)Adds 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)Removes provider from the global style providers list in screen.
void resetWidgets(gdk.screen.Screen screen)This 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)Adds a style class to context, so posterior calls to [gtk.stylecontext.StyleContext.get] or any of the gtkrender_*() functions will make use of this new class for styling.
void addProvider(gtk.style_provider.StyleProvider provider, uint priority)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 a...
void addRegion(string regionName, gtk.types.RegionFlags flags)Adds a region to context, so posterior calls to [gtk.stylecontext.StyleContext.get] or any of the gtkrender_*() functions will make use of this new region for styling.
void cancelAnimations(void * regionId = null)Stops all running animations for region_id and all animatable regions underneath.
void getBackgroundColor(gtk.types.StateFlags state, out gdk.rgba.RGBA color)Gets the background color for a given state.
void getBorder(gtk.types.StateFlags state, out gtk.border.Border border)Gets the border for a given state as a #GtkBorder.
void getBorderColor(gtk.types.StateFlags state, out gdk.rgba.RGBA color)Gets the border color for a given state.
void getColor(gtk.types.StateFlags state, out gdk.rgba.RGBA color)Gets the foreground color for a given state.
gtk.types.TextDirection getDirection()Returns the widget direction used for rendering. Returns: the widget direction
pango.font_description.FontDescription getFont(gtk.types.StateFlags state)Returns 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()Returns 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()Returns the sides where rendered elements connect visually with others. Returns: the junction sides
void getMargin(gtk.types.StateFlags state, out gtk.border.Border margin)Gets the margin for a given state as a #GtkBorder. See gtkstylepropertyget() and #GTKSTYLEPROPERTYMARGIN for details.
void getPadding(gtk.types.StateFlags state, out gtk.border.Border padding)Gets the padding for a given state as a #GtkBorder. See [gtk.stylecontext.StyleContext.get] and #GTKSTYLEPROPERTYPADDING for details.
gtk.style_context.StyleContext getParent()Gets 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()Returns the widget path used for style matching. Returns: A #GtkWidgetPath
void getProperty(string property, gtk.types.StateFlags state, out gobject.value.Value value)Gets a style property from context for the given state.
int getScale()Returns the scale used for assets. Returns: the scale
gdk.screen.Screen getScreen()Returns the #GdkScreen to which context is attached. Returns: a #GdkScreen.
gtk.css_section.CssSection getSection(string property)Queries 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()Returns the state used for style matching.
void getStyleProperty(string propertyName, gobject.value.Value value)Gets the value for a widget style property.
bool hasClass(string className)Returns true if context currently has defined the given class name.
bool hasRegion(string regionName, out gtk.types.RegionFlags flagsReturn)Returns true if context has the region defined. If flags_return is not null, it is set to the flags affecting the region.
void invalidate()Invalidates 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()Returns 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()Returns 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)Looks up and resolves a color name in the context color map.
gtk.icon_set.IconSet lookupIconSet(string stockId)Looks 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)Notifies a state change on context, so if the current style makes use of transition animations, one will be started so all rendered elements under regionid are animated for state state being set to...
void popAnimatableRegion()Pops an animatable region from context. See [gtk.style_context.StyleContext.pushAnimatableRegion].
void pushAnimatableRegion(void * regionId = null)Pushes an animatable region, so all further gtkrender*() calls between this call and the following [gtk.stylecontext.StyleContext.popAnimatableRegion] will potentially show transition animations fo...
void removeClass(string className)Removes class_name from context.
void removeProvider(gtk.style_provider.StyleProvider provider)Removes provider from the style providers list in context.
void removeRegion(string regionName)Removes a region from context.
void restore()Restores context state to a previous stage. See [gtk.style_context.StyleContext.save].
void save()Saves the context state, so temporary modifications done through [gtk.stylecontext.StyleContext.addClass], [gtk.stylecontext.StyleContext.removeClass], [gtk.stylecontext.StyleContext.setState], etc...
void scrollAnimations(gdk.window.Window window, int dx, int dy)This 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)Sets the background of window to the background pattern or color specified in context for its current state.
void setDirection(gtk.types.TextDirection direction)Sets the reading direction for rendering purposes.
void setFrameClock(gdk.frame_clock.FrameClock frameClock)Attaches context to the given frame clock.
void setJunctionSides(gtk.types.JunctionSides sides)Sets 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)Sets 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)Sets the #GtkWidgetPath used for style matching. As a consequence, the style will be regenerated to match the new given path.
void setScale(int scale)Sets the scale to use when getting image assets for the style.
void setScreen(gdk.screen.Screen screen)Attaches context to the given screen.
void setState(gtk.types.StateFlags flags)Sets the state to be used for style matching.
bool stateIsRunning(gtk.types.StateType state, out double progress)Returns true if there is a transition animation running for the current region (see [gtk.style_context.StyleContext.pushAnimatableRegion]).
string toString_(gtk.types.StyleContextPrintFlags flags)Converts 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)Connect 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.
Methods
T parent(gtk.style_context.StyleContext propval)Set `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

Fluent builder for [gtk.style_context.StyleContext]