Warning: StyleContext is deprecated since 4.10.
`GtkStyleContext` stores styling information affecting a widget.
Note:
The relevant API has been moved to [class@Gtk.Widget] where applicable; otherwise, there is no replacement for querying the style
machinery. Stylable UI elements should use widgets.
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 [method@Gtk.StyleContext.add_provider], or to the display through [
func@Gtk.StyleContext.add_provider_for_display]. The resulting style is a combination of all providers’ information in priority order.
For GTK widgets, any `GtkStyleContext` returned by [method@Gtk.Widget.get_style_context] will already have a `GdkDisplay` 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 `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-4.0/gtk.css` will still take precedence over your changes, as it uses the
gtk_style_provider_priority_user priority.
- public void add_class (string class_name)
Adds a style class to this, so later uses
of the style context will make use of this new class for styling.
- public void add_provider (StyleProvider provider, uint priority)
Adds a style provider to this, to be used
in style construction.
- public virtual void changed ()
- public Border get_border ()
Gets the border for a given state as a `GtkBorder`.
- public RGBA get_color ()
Gets the foreground color for a given state.
- public unowned Display get_display ()
Returns the `GdkDisplay` to which this is
attached.
- public Border get_margin ()
Gets the margin for a given state as a `GtkBorder`.
- public Border get_padding ()
Gets the padding for a given state as a `GtkBorder`.
- public int get_scale ()
Returns the scale used for assets.
- public StateFlags get_state ()
Returns the state used for style matching.
- public bool has_class (string class_name)
Returns true if
this currently has defined the given class name.
- public bool lookup_color (string color_name, out RGBA color)
Looks up and resolves a color name in the this
color map.
- public void remove_class (string class_name)
Removes class_name
from this.
- public void remove_provider (StyleProvider provider)
Removes provider
from the style providers list in
this.
- public void render_activity (Context cr, double x, double y, double width, double height)
Renders an activity indicator (such as in `GtkSpinner`).
- public void render_arrow (Context cr, double angle, double x, double y, double size)
Renders an arrow pointing to angle
.
- public void render_background (Context cr, double x, double y, double width, double height)
Renders the background of an element.
- public void render_check (Context cr, double x, double y, double width, double height)
Renders a checkmark (as in a `GtkCheckButton`).
- public void render_expander (Context cr, double x, double y, double width, double height)
Renders an expander (as used in `GtkTreeView` and `GtkExpander`) in the area
defined by x
, y
, width
, height
.
- public void render_focus (Context cr, double x, double y, double width, double height)
Renders a focus indicator on the rectangle determined by x
,
y
, width
, height
.
- public void render_frame (Context cr, double x, double y, double width, double height)
Renders a frame around the rectangle defined by x
, y
, width
, height
.
- public void render_handle (Context cr, double x, double y, double width, double height)
Renders a handle (as in `GtkPaned` and `GtkWindow`’s resize grip), in the
rectangle determined by x
, y
, width
, height
.
- public void render_icon (Context cr, Texture texture, double x, double y)
Renders the icon in texture
at the specified x
and
y
coordinates.
- public void render_layout (Context cr, double x, double y, Layout layout)
Renders layout
on the coordinates x
, y
- public void render_line (Context cr, double x0, double y0, double x1, double y1)
Renders a line from (x0, y0) to (x1, y1).
- public void render_option (Context cr, double x, double y, double width, double height)
Renders an option mark (as in a radio button), the
gtk_state_flag_checked state will determine whether the option is on or off, and
gtk_state_flag_inconsistent whether it should be marked as undefined.
- public void restore ()
Restores this state to a previous stage.
- public void save ()
Saves the this state.
- public void set_display (Display display)
Attaches this to the given display.
- public void set_scale (int scale)
Sets the scale to use when getting image assets for the style.
- public void set_state (StateFlags flags)
Sets the state to be used for style matching.
- public string to_string (StyleContextPrintFlags flags)
Converts the style context into a string representation.