StyleContext is an object that stores styling information affecting a widget defined by
WidgetPath.
In order to construct the final style information, StyleContext queries information from all attached
StyleProviders. Style providers can be either attached explicitly to the
context through add_provider, or to the screen through
add_provider_for_screen. The resulting style is a
combination of all providers’ information in priority order.
For GTK+ widgets, any StyleContext returned by
get_style_context will already have a WidgetPath, a
Screen 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
set_path and possibly
set_screen. See the “Foreign drawing“ example in gtk3-demo.
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.
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 Widgets that render differently than standard
components, you may need to add a StyleProvider yourself with the
gtk_style_provider_priority_fallback priority, either a
CssProvider or a custom object implementing the
StyleProvider 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 StyleProvider 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.
- public void @get (StateFlags state, ...)
Retrieves several style property values from this
for a given state.
- public void add_class (string class_name)
Adds a style class to this, so posterior
calls to @get or any of the gtk_render_*() functions 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 void add_region (string region_name, RegionFlags flags)
Adds a region to this, so posterior calls
to @get or any of the gtk_render_*() functions will make use of this new
region for styling.
- public void cancel_animations (void* region_id)
Stops all running animations for region_id
and all animatable
regions underneath.
- public RGBA get_background_color (StateFlags state)
Gets the background color for a given state.
- public Border get_border (StateFlags state)
Gets the border for a given state as a
Border.
- public RGBA get_border_color (StateFlags state)
Gets the border color for a given state.
- public RGBA get_color (StateFlags state)
Gets the foreground color for a given state.
- public TextDirection get_direction ()
Returns the widget direction used for rendering.
- public unowned FontDescription get_font (StateFlags state)
Returns the font description for a given state.
- public unowned FrameClock? get_frame_clock ()
- public JunctionSides get_junction_sides ()
Returns the sides where rendered elements connect visually with others.
- public Border get_margin (StateFlags state)
Gets the margin for a given state as a
Border.
- public Border get_padding (StateFlags state)
Gets the padding for a given state as a
Border.
- public unowned StyleContext? get_parent ()
- public unowned WidgetPath get_path ()
Returns the widget path used for style matching.
- public Value get_property (string property, StateFlags state)
Gets a style property from this for the
given state.
- public int get_scale ()
Returns the scale used for assets.
- public unowned Screen get_screen ()
Returns the Screen to
which this is attached.
- public unowned CssSection? get_section (string property)
Queries the location in the CSS where property
was defined for
the current this.
- public StateFlags get_state ()
Returns the state used for style matching.
- public void get_style (...)
Retrieves several widget style properties from
this according to the current style.
- public void get_style_property (string property_name, ref Value value)
Gets the value for a widget style property.
- public void get_style_valist (va_list args)
Retrieves several widget style properties from
this according to the current style.
- public void get_valist (StateFlags state, va_list args)
Retrieves several style property values from this
for a given state.
- public bool has_class (string class_name)
Returns true if
this currently has defined the given class name.
- public bool has_region (string region_name, out RegionFlags flags_return)
Returns true if
this has the region defined.
- public void invalidate ()
Invalidates this style information, so it
will be reconstructed again.
- public List<unowned string> list_classes ()
Returns the list of classes currently defined in
this.
- public List<unowned string> list_regions ()
Returns the list of regions currently defined in
this.
- public bool lookup_color (string color_name, out RGBA color)
Looks up and resolves a color name in the this
color map.
- public unowned IconSet? lookup_icon_set (string stock_id)
Looks up stock_id
in the icon factories associated to
this and the default icon factory, returning an icon set if found, otherwise
null.
- public void notify_state_change (Window window, void* region_id, StateType state, bool state_value)
Notifies a state change on this, 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
.
- public void pop_animatable_region ()
Pops an animatable region from this.
- public void push_animatable_region (void* region_id)
Pushes an animatable region, so all further gtk_render_*() calls between
this call and the following pop_animatable_region will
potentially show transition animations for this region if
notify_state_change is called for a given state, and the current theme/style defines transition animations for state changes.
- 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 remove_region (string region_name)
Removes a region from this.
- public void render_activity (Context cr, double x, double y, double width, double height)
Renders an activity indicator (such as in
Spinner).
- 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 Rectangle render_background_get_clip (double x, double y, double width, double height)
Returns the area that will be affected (i.
- public void render_check (Context cr, double x, double y, double width, double height)
- public void render_expander (Context cr, double x, double y, double width, double height)
Renders an expander (as used in
TreeView and Expander) in
the area defined by x
, y
, width
, height
.
- public void render_extension (Context cr, double x, double y, double width, double height, PositionType gap_side)
Renders a extension (as in a
Notebook tab) in the rectangle 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_frame_gap (Context cr, double x, double y, double width, double height, PositionType gap_side, double xy0_gap, double xy1_gap)
Renders a frame around the rectangle defined by (x
, y
, width
, height
), leaving a gap on one side.
- public void render_handle (Context cr, double x, double y, double width, double height)
Renders a handle (as in
HandleBox, Paned and
Window’s resize grip), in the rectangle determined by x
, y
, width
, height
.
- public void render_icon (Context cr, Pixbuf pixbuf, double x, double y)
Renders the icon in pixbuf
at the specified x
and
y
coordinates.
- public Pixbuf render_icon_pixbuf (IconSource source, IconSize size)
Renders the icon specified by source
at the given size
, returning the result in a pixbuf.
- public void render_icon_surface (Context cr, Surface surface, double x, double y)
- public void render_insertion_cursor (Context cr, double x, double y, Layout layout, int index, Direction direction)
- 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
RadioButton), 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 render_slider (Context cr, double x, double y, double width, double height, Orientation orientation)
Renders a slider (as in
Scale) in the rectangle defined by x
, y
, width
, height
.
- public void restore ()
Restores this state to a previous stage.
- public void save ()
- public void scroll_animations (Window window, int dx, int dy)
This function is analogous to
scroll, and should be called together with it so the invalidation areas for any
ongoing animation are scrolled together with it.
- public void set_background (Window window)
Sets the background of window
to the background pattern or
color specified in this for its current state.
- public void set_direction (TextDirection direction)
Sets the reading direction for rendering purposes.
- public void set_frame_clock (FrameClock frame_clock)
Attaches this to the given frame clock.
- public void set_junction_sides (JunctionSides sides)
Sets the sides where rendered elements (mostly through
render_frame) will visually connect with other visual elements.
- public void set_parent (StyleContext? parent)
Sets the parent style context for this.
- public void set_path (WidgetPath path)
- public void set_scale (int scale)
Sets the scale to use when getting image assets for the style.
- public void set_screen (Screen screen)
Attaches this to the given screen.
- public void set_state (StateFlags flags)
Sets the state to be used for style matching.
- public bool state_is_running (StateType state, out double progress)
- public string to_string (StyleContextPrintFlags flags)
Converts the style context into a string representation.