StyleContext

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

class StyleContext : ObjectWrap {}

Constructors

this
this(void* ptr, Flag!"Take" take)
this
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.

Members

Functions

addClass
void addClass(string className)

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

addProvider
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 affect the style of all widgets, use gtk.style_context.StyleContext.addProviderForScreen.

addRegion
void addRegion(string regionName, gtk.types.RegionFlags flags)

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

cancelAnimations
void cancelAnimations(void* regionId)

Stops all running animations for region_id and all animatable regions underneath.

connectChanged
gulong connectChanged(T callback, Flag!"After" after)

Connect to Changed signal.

getBackgroundColor
void getBackgroundColor(gtk.types.StateFlags state, gdk.rgba.RGBA color)

Gets the background color for a given state.

getBorder
void getBorder(gtk.types.StateFlags state, gtk.border.Border border)

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

getBorderColor
void getBorderColor(gtk.types.StateFlags state, gdk.rgba.RGBA color)

Gets the border color for a given state.

getColor
void getColor(gtk.types.StateFlags state, gdk.rgba.RGBA color)

Gets the foreground color for a given state.

getDirection
gtk.types.TextDirection getDirection()

Returns the widget direction used for rendering.

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

getFrameClock
gdk.frame_clock.FrameClock getFrameClock()

Returns the #GdkFrameClock to which context is attached.

getJunctionSides
gtk.types.JunctionSides getJunctionSides()

Returns the sides where rendered elements connect visually with others.

getMargin
void getMargin(gtk.types.StateFlags state, gtk.border.Border margin)

Gets the margin for a given state as a #GtkBorder. See gtk_style_property_get() and #GTK_STYLE_PROPERTY_MARGIN for details.

getPadding
void getPadding(gtk.types.StateFlags state, gtk.border.Border padding)

Gets the padding for a given state as a #GtkBorder. See gtk.style_context.StyleContext.get and #GTK_STYLE_PROPERTY_PADDING for details.

getParent
gtk.style_context.StyleContext getParent()

Gets the parent context set via gtk.style_context.StyleContext.setParent. See that function for details.

getPath
gtk.widget_path.WidgetPath getPath()

Returns the widget path used for style matching.

getProperty
void getProperty(string property, gtk.types.StateFlags state, gobject.value.Value value)

Gets a style property from context for the given state.

getScale
int getScale()

Returns the scale used for assets.

getScreen
gdk.screen.Screen getScreen()

Returns the #GdkScreen to which context is attached.

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

getState
gtk.types.StateFlags getState()

Returns the state used for style matching.

getStyleProperty
void getStyleProperty(string propertyName, gobject.value.Value value)

Gets the value for a widget style property.

hasClass
bool hasClass(string className)

Returns true if context currently has defined the given class name.

hasRegion
bool hasRegion(string regionName, 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.

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

listClasses
string[] listClasses()

Returns the list of classes currently defined in context.

listRegions
string[] listRegions()

Returns the list of regions currently defined in context.

lookupColor
bool lookupColor(string colorName, gdk.rgba.RGBA color)

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

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

notifyStateChange
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 region_id are animated for state state being set to value state_value.

popAnimatableRegion
void popAnimatableRegion()

Pops an animatable region from context. See gtk.style_context.StyleContext.pushAnimatableRegion.

pushAnimatableRegion
void pushAnimatableRegion(void* regionId)

Pushes 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 for this region if gtk.style_context.StyleContext.notifyStateChange is called for a given state, and the current theme/style defines transition animations for state changes.

removeClass
void removeClass(string className)

Removes class_name from context.

removeProvider
void removeProvider(gtk.style_provider.StyleProvider provider)

Removes provider from the style providers list in context.

removeRegion
void removeRegion(string regionName)

Removes a region from context.

restore
void restore()

Restores context state to a previous stage. See gtk.style_context.StyleContext.save.

save
void save()

Saves the context state, so temporary modifications done through gtk.style_context.StyleContext.addClass, gtk.style_context.StyleContext.removeClass, gtk.style_context.StyleContext.setState, etc. can quickly be reverted in one go through gtk.style_context.StyleContext.restore.

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

self
StyleContext self()

Returns this, for use in with statements.

setBackground
void setBackground(gdk.window.Window window)

Sets the background of window to the background pattern or color specified in context for its current state.

setDirection
void setDirection(gtk.types.TextDirection direction)

Sets the reading direction for rendering purposes.

setFrameClock
void setFrameClock(gdk.frame_clock.FrameClock frameClock)

Attaches context to the given frame clock.

setJunctionSides
void setJunctionSides(gtk.types.JunctionSides sides)

Sets the sides where rendered elements (mostly through gtk.global.renderFrame) will visually connect with other visual elements.

setParent
void setParent(gtk.style_context.StyleContext parent)

Sets the parent style context for context. The parent style context is used to implement inheritance

of properties.

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

setScale
void setScale(int scale)

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

setScreen
void setScreen(gdk.screen.Screen screen)

Attaches context to the given screen.

setState
void setState(gtk.types.StateFlags flags)

Sets the state to be used for style matching.

stateIsRunning
bool stateIsRunning(gtk.types.StateType state, double progress)

Returns true if there is a transition animation running for the current region (see gtk.style_context.StyleContext.pushAnimatableRegion).

toString_
string toString_(gtk.types.StyleContextPrintFlags flags)

Converts the style context into a string representation.

Properties

_gType
GType _gType [@property getter]
direction
gtk.types.TextDirection direction [@property getter]
direction
gtk.types.TextDirection direction [@property setter]
paintClock
gdk.frame_clock.FrameClock paintClock [@property getter]
paintClock
gdk.frame_clock.FrameClock paintClock [@property setter]
parent
gtk.style_context.StyleContext parent [@property getter]

Get parent property.

parent
gtk.style_context.StyleContext parent [@property setter]

Set parent property.

screen
gdk.screen.Screen screen [@property getter]
screen
gdk.screen.Screen screen [@property setter]

Static functions

_getGType
GType _getGType()
addProviderForScreen
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.

builder
StyleContextGidBuilder builder()

Get builder for gtk.style_context.StyleContext

removeProviderForScreen
void removeProviderForScreen(gdk.screen.Screen screen, gtk.style_provider.StyleProvider provider)

Removes provider from the global style providers list in screen.

resetWidgets
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 widget gets a new style, it will both redraw and recompute any cached information about its appearance. As an example, it is used when the color scheme changes in the related #GtkSettings object.

Inherited Members

From ObjectWrap

_setGObject
void _setGObject(void* cObj, Flag!"Take" take)

Set the GObject of a D ObjectWrap wrapper.

_cPtr
void* _cPtr(Flag!"Dup" dup)

Get a pointer to the underlying C object.

_ref
void* _ref(void* gObj)

Calls g_object_ref() on a GObject.

_unref
_unref(void* gObj)

Calls g_object_unref() on a GObject.

_getGType
GType _getGType()

Get the GType of an object.

_gType
GType _gType [@property getter]

GObject GType property.

self
ObjectWrap self()

Convenience method to return this cast to a type. For use in D with statements.

_getDObject
T _getDObject(void* cptr, Flag!"Take" take)

Template to get the D object from a C GObject and cast it to the given D object type.

connectSignalClosure
gulong connectSignalClosure(string signalDetail, DClosure closure, Flag!"After" after)

Connect a D closure to an object signal.

setProperty
void setProperty(string propertyName, T val)

Template for setting a GObject property.

getProperty
T getProperty(string propertyName)

Template for getting a GObject property.

compatControl
size_t compatControl(size_t what, void* data)
bindProperty
gobject.binding.Binding bindProperty(string sourceProperty, gobject.object.ObjectWrap target, string targetProperty, gobject.types.BindingFlags flags)

Creates a binding between source_property on source and target_property on target.

bindPropertyFull
gobject.binding.Binding bindPropertyFull(string sourceProperty, gobject.object.ObjectWrap target, string targetProperty, gobject.types.BindingFlags flags, gobject.closure.Closure transformTo, gobject.closure.Closure transformFrom)

Creates a binding between source_property on source and target_property on target, allowing you to set the transformation functions to be used by the binding.

forceFloating
void forceFloating()

This function is intended for #GObject implementations to re-enforce a floating[floating-ref] object reference. Doing this is seldom required: all #GInitiallyUnowneds are created with a floating reference which usually just needs to be sunken by calling gobject.object.ObjectWrap.refSink.

freezeNotify
void freezeNotify()

Increases the freeze count on object. If the freeze count is non-zero, the emission of "notify" signals on object is stopped. The signals are queued until the freeze count is decreased to zero. Duplicate notifications are squashed so that at most one #GObject::notify signal is emitted for each property modified while the object is frozen.

getData
void* getData(string key)

Gets a named field from the objects table of associations (see gobject.object.ObjectWrap.setData).

getProperty
void getProperty(string propertyName, gobject.value.Value value)

Gets a property of an object.

getQdata
void* getQdata(glib.types.Quark quark)

This function gets back user data pointers stored via gobject.object.ObjectWrap.setQdata.

getv
void getv(string[] names, gobject.value.Value[] values)

Gets n_properties properties for an object. Obtained properties will be set to values. All properties must be valid. Warnings will be emitted and undefined behaviour may result if invalid properties are passed in.

isFloating
bool isFloating()

Checks whether object has a floating[floating-ref] reference.

notify
void notify(string propertyName)

Emits a "notify" signal for the property property_name on object.

notifyByPspec
void notifyByPspec(gobject.param_spec.ParamSpec pspec)

Emits a "notify" signal for the property specified by pspec on object.

refSink
gobject.object.ObjectWrap refSink()

Increase the reference count of object, and possibly remove the floating[floating-ref] reference, if object has a floating reference.

runDispose
void runDispose()

Releases all references to other objects. This can be used to break reference cycles.

setData
void setData(string key, void* data)

Each object carries around a table of associations from strings to pointers. This function lets you set an association.

setProperty
void setProperty(string propertyName, gobject.value.Value value)

Sets a property on an object.

stealData
void* stealData(string key)

Remove a specified datum from the object's data associations, without invoking the association's destroy handler.

stealQdata
void* stealQdata(glib.types.Quark quark)

This function gets back user data pointers stored via gobject.object.ObjectWrap.setQdata and removes the data from object without invoking its destroy() function (if any was set). Usually, calling this function is only required to update user data pointers with a destroy notifier, for example:

thawNotify
void thawNotify()

Reverts the effect of a previous call to gobject.object.ObjectWrap.freezeNotify. The freeze count is decreased on object and when it reaches zero, queued "notify" signals are emitted.

watchClosure
void watchClosure(gobject.closure.Closure closure)

This function essentially limits the life time of the closure to the life time of the object. That is, when the object is finalized, the closure is invalidated by calling gobject.closure.Closure.invalidate on it, in order to prevent invocations of the closure with a finalized (nonexisting) object. Also, gobject.object.ObjectWrap.ref_ and gobject.object.ObjectWrap.unref are added as marshal guards to the closure, to ensure that an extra reference count is held on object during invocation of the closure. Usually, this function will be called on closures that use this object as closure data.

connectNotify
gulong connectNotify(string detail, T callback, Flag!"After" after)

Connect to Notify signal.