Class

GtkStyleContext

Description [src]

class Gtk.StyleContext : GObject.Object {
  parent_object: GObject,
  priv: GtkStyleContextPrivate*
}

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_add_provider(), or to the screen through gtk_style_context_add_provider_for_screen(). The resulting style is a combination of all providers’ information in priority order.

For GTK+ widgets, any GtkStyleContext returned by gtk_widget_get_style_context() 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_set_path() and possibly gtk_style_context_set_screen(). 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_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_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_STYLE_PROVIDER_PRIORITY_USER priority.

Hierarchy

hierarchy this GtkStyleContext ancestor_0 GObject ancestor_0--this

Ancestors

Constructors

gtk_style_context_new

Creates a standalone GtkStyleContext, this style context won’t be attached to any widget, so you may want to call gtk_style_context_set_path() yourself.

Functions

gtk_style_context_add_provider_for_screen

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

Available since: 3.0

gtk_style_context_remove_provider_for_screen

Removes provider from the global style providers list in screen.

Available since: 3.0

gtk_style_context_reset_widgets

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.

Available since: 3.0

Instance methods

gtk_style_context_add_class

Adds a style class to context, so posterior calls to gtk_style_context_get() or any of the gtk_render_*() functions will make use of this new class for styling.

Available since: 3.0

gtk_style_context_add_provider

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_add_provider_for_screen().

Available since: 3.0

gtk_style_context_add_region

Adds a region to context, so posterior calls to gtk_style_context_get() or any of the gtk_render_*() functions will make use of this new region for styling.

Available since: 3.0

gtk_style_context_cancel_animations

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

Available since: 3.0

Deprecated since: 3.6

gtk_style_context_get

Retrieves several style property values from context for a given state.

Available since: 3.0

gtk_style_context_get_background_color

Gets the background color for a given state.

Available since: 3.0

Deprecated since: 3.16

gtk_style_context_get_border

Gets the border for a given state as a GtkBorder.

Available since: 3.0

gtk_style_context_get_border_color

Gets the border color for a given state.

Available since: 3.0

Deprecated since: 3.16

gtk_style_context_get_color

Gets the foreground color for a given state.

Available since: 3.0

gtk_style_context_get_direction

Returns the widget direction used for rendering.

Available since: 3.0

Deprecated since: 3.8

gtk_style_context_get_font

Returns the font description for a given state. The returned object is const and will remain valid until the GtkStyleContext::changed signal happens.

Available since: 3.0

Deprecated since: 3.8

gtk_style_context_get_frame_clock

Returns the GdkFrameClock to which context is attached.

Available since: 3.8

gtk_style_context_get_junction_sides

Returns the sides where rendered elements connect visually with others.

Available since: 3.0

gtk_style_context_get_margin

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

Available since: 3.0

gtk_style_context_get_padding

Gets the padding for a given state as a GtkBorder. See gtk_style_context_get() and #GTK_STYLE_PROPERTY_PADDING for details.

Available since: 3.0

gtk_style_context_get_parent

Gets the parent context set via gtk_style_context_set_parent(). See that function for details.

Available since: 3.4

gtk_style_context_get_path

Returns the widget path used for style matching.

Available since: 3.0

gtk_style_context_get_property

Gets a style property from context for the given state.

Available since: 3.0

gtk_style_context_get_scale

Returns the scale used for assets.

Available since: 3.10

gtk_style_context_get_screen

Returns the GdkScreen to which context is attached.

gtk_style_context_get_section

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_get_state().

gtk_style_context_get_state

Returns the state used for style matching.

Available since: 3.0

gtk_style_context_get_style

Retrieves several widget style properties from context according to the current style.

Available since: 3.0

gtk_style_context_get_style_property

Gets the value for a widget style property.

gtk_style_context_get_style_valist

Retrieves several widget style properties from context according to the current style.

Available since: 3.0

gtk_style_context_get_valist

Retrieves several style property values from context for a given state.

Available since: 3.0

gtk_style_context_has_class

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

Available since: 3.0

gtk_style_context_has_region

Returns TRUE if context has the region defined. If flags_return is not NULL, it is set to the flags affecting the region.

Available since: 3.0

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

Available since: 3.0

Deprecated since: 3.12

gtk_style_context_list_classes

Returns the list of classes currently defined in context.

Available since: 3.0

gtk_style_context_list_regions

Returns the list of regions currently defined in context.

Available since: 3.0

gtk_style_context_lookup_color

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

gtk_style_context_lookup_icon_set

Looks up stock_id in the icon factories associated to context and the default icon factory, returning an icon set if found, otherwise NULL.

Deprecated since: 3.10

gtk_style_context_notify_state_change

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.

Available since: 3.0

Deprecated since: 3.6

gtk_style_context_pop_animatable_region

Pops an animatable region from context. See gtk_style_context_push_animatable_region().

Available since: 3.0

Deprecated since: 3.6

gtk_style_context_push_animatable_region

Pushes an animatable region, so all further gtk_render_*() calls between this call and the following gtk_style_context_pop_animatable_region() will potentially show transition animations for this region if gtk_style_context_notify_state_change() is called for a given state, and the current theme/style defines transition animations for state changes.

Available since: 3.0

Deprecated since: 3.6

gtk_style_context_remove_class

Removes class_name from context.

Available since: 3.0

gtk_style_context_remove_provider

Removes provider from the style providers list in context.

Available since: 3.0

gtk_style_context_remove_region

Removes a region from context.

Available since: 3.0

gtk_style_context_restore

Restores context state to a previous stage. See gtk_style_context_save().

Available since: 3.0

gtk_style_context_save

Saves the context state, so temporary modifications done through gtk_style_context_add_class(), gtk_style_context_remove_class(), gtk_style_context_set_state(), etc. can quickly be reverted in one go through gtk_style_context_restore().

Available since: 3.0

gtk_style_context_scroll_animations

This function is analogous to gdk_window_scroll(), and should be called together with it so the invalidation areas for any ongoing animation are scrolled together with it.

Available since: 3.0

Deprecated since: 3.6

gtk_style_context_set_background

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

Available since: 3.0

Deprecated since: 3.18

gtk_style_context_set_direction

Sets the reading direction for rendering purposes.

Available since: 3.0

Deprecated since: 3.8

gtk_style_context_set_frame_clock

Attaches context to the given frame clock.

Available since: 3.8

gtk_style_context_set_junction_sides

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

Available since: 3.0

gtk_style_context_set_parent

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

Available since: 3.4

gtk_style_context_set_path

Sets the GtkWidgetPath used for style matching. As a consequence, the style will be regenerated to match the new given path.

Available since: 3.0

gtk_style_context_set_scale

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

Available since: 3.10

gtk_style_context_set_screen

Attaches context to the given screen.

Available since: 3.0

gtk_style_context_set_state

Sets the state to be used for style matching.

Available since: 3.0

gtk_style_context_state_is_running

Returns TRUE if there is a transition animation running for the current region (see gtk_style_context_push_animatable_region()).

Available since: 3.0

Deprecated since: 3.6

gtk_style_context_to_string

Converts the style context into a string representation.

Available since: 3.20

Methods inherited from GObject (42)

Properties

Gtk.StyleContext:direction
No description available.
Gtk.StyleContext:paint-clock
No description available.
Gtk.StyleContext:parent

Sets or gets the style context’s parent. See gtk_style_context_set_parent() for details.

Available since: 3.4

Gtk.StyleContext:screen
No description available.

Signals

Gtk.StyleContext::changed

The ::changed signal is emitted when there is a change in the GtkStyleContext.

Available since: 3.0

Signals inherited from GObject (1)

Class structure

struct GtkStyleContextClass {
  GObjectClass parent_class;
  void (* changed) (
    GtkStyleContext* context
  );
  void (* _gtk_reserved1) (
void
  );
  void (* _gtk_reserved2) (
void
  );
  void (* _gtk_reserved3) (
void
  );
  void (* _gtk_reserved4) (
void
  );
  
}
Class members
parent_class
GObjectClass
  No description available.
changed
void (* changed) (
    GtkStyleContext* context
  )
  No description available.
_gtk_reserved1
void (* _gtk_reserved1) (
void
  )
  No description available.
_gtk_reserved2
void (* _gtk_reserved2) (
void
  )
  No description available.
_gtk_reserved3
void (* _gtk_reserved3) (
void
  )
  No description available.
_gtk_reserved4
void (* _gtk_reserved4) (
void
  )
  No description available.

Virtual methods

Gtk.StyleContextClass.changed
No description available.