Back to Seed Clases

Gtk


Classes

Interfaces

Structs

Unions

Enums

GObject.Object
parent-child marker Gtk.StyleContext

Class Gtk.StyleContext

Import line: Gtk = imports.gi.Gtk;
GIR File: Gtk-3.0.gir
C documentation: GtkStyleContext
Class : StyleContext
Extends: GObject.Object
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 be also
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 gtk_style_context_set_screen(), as well
as updating the context yourself using gtk_style_context_invalidate()
whenever any of the conditions change, such as a change in the
GtkSettings:gtk-theme-name setting or a hierarchy change in the rendered
widget.

Transition animations

GtkStyleContext has built-in support for state change transitions.
Note that these animations respect the GtkSettings:gtk-enable-animations
setting.


For simple widgets where state changes affect the whole widget area,
calling gtk_style_context_notify_state_change() with a NULL region
is sufficient to trigger the transition animation. And GTK+ already
does that when gtk_widget_set_state() or gtk_widget_set_state_flags()
are called.


If a widget needs to declare several animatable regions (i.e. not
affecting the whole widget area), its GtkWidget::draw signal handler
needs to wrap the render operations for the different regions with
calls to gtk_style_context_push_animatable_region() and
gtk_style_context_pop_animatable_region(). These functions take an
identifier for the region which must be unique within the style context.
For simple widgets with a fixed set of animatable regions, using an
enumeration works well:


Using an enumeration to identify animatable regions

enum {
REGION_ENTRY,
REGION_BUTTON_UP,
REGION_BUTTON_DOWN
};
...
gboolean
spin_button_draw (GtkWidget *widget,
cairo_t *cr)
{
GtkStyleContext *context;
context = gtk_widget_get_style_context (widget);
gtk_style_context_push_animatable_region (context,
GUINT_TO_POINTER (REGION_ENTRY));
gtk_render_background (cr, 0, 0, 100, 30);
gtk_render_frame (cr, 0, 0, 100, 30);
gtk_style_context_pop_animatable_region (context);
...
}



For complex widgets with an arbitrary number of animatable regions, it
is up to the implementation to come up with a way to uniquely identify
each animatable region. Using pointers to internal structs is one way
to achieve this:


Using struct pointers to identify animatable regions

void
notebook_draw_tab (GtkWidget *widget,
NotebookPage *page,
cairo_t *cr)
{
gtk_style_context_push_animatable_region (context, page);
gtk_render_extension (cr, page->x, page->y, page->width, page->height);
gtk_style_context_pop_animatable_region (context);
}



The widget also needs to notify the style context about a state change
for a given animatable region so the animation is triggered.


Triggering a state change animation on a region

gboolean
notebook_motion_notify (GtkWidget *widget,
GdkEventMotion *event)
{
GtkStyleContext *context;
NotebookPage *page;
context = gtk_widget_get_style_context (widget);
page = find_page_under_pointer (widget, event);
gtk_style_context_notify_state_change (context,
gtk_widget_get_window (widget),
page,
GTK_STATE_PRELIGHT,
TRUE);
...
}



gtk_style_context_notify_state_change() accepts NULL region IDs as a
special value, in this case, the whole widget area will be updated
by the animation.



Style classes and regions

Widgets can add style classes to their context, which can be used
to associate different styles by class (see ). Theme engines can also use style classes to vary their
rendering. GTK+ has a number of predefined style classes:




Style class
Macro
Used by




button
GTK_STYLE_CLASS_BUTTON
GtkButton, GtkToggleButton, GtkRadioButton, GtkCheckButton


default
GTK_STYLE_CLASS_DEFAULT
GtkButton


check
GTK_STYLE_CLASS_CHECK
GtkCheckButton, GtkCheckMenuItem, GtkCellRendererToggle


radio
GTK_STYLE_CLASS_RADIO
GtkRadioButton, GtkRadioMenuItem, GtkCellRendererToggle


arrow
GTK_STYLE_CLASS_ARROW
GtkArrow


calendar
GTK_STYLE_CLASS_CALENDAR
GtkCalendar


entry
GTK_STYLE_CLASS_ENTRY
GtkEntry


cell
GTK_STYLE_CLASS_CELL
GtkCellRendererToggle


menu
GTK_STYLE_CLASS_MENU
GtkMenu, GtkMenuItem, GtkCheckMenuItem, GtkRadioMenuItem


expander
GTK_STYLE_CLASS_EXPANDER
GtkExpander


tooltip
GTK_STYLE_CLASS_TOOLTIP
GtkTooltip


frame
GTK_STYLE_CLASS_FRAME
GtkFrame


scrolled-window

GtkScrolledWindow


viewport

GtkViewport


trough
GTK_STYLE_CLASS_TROUGH
GtkScrollbar, GtkProgressBar, GtkScale


progressbar
GTK_STYLE_CLASS_PROGRESSBAR
GtkProgressBar, GtkCellRendererProgress


slider
GTK_STYLE_CLASS_SLIDER
GtkScrollbar, GtkScale


menuitem
GTK_STYLE_CLASS_MENUITEM
GtkMenuItem


popup

GtkMenu


accelerator
GTK_STYLE_CLASS_ACCELERATOR
GtkAccelLabel


menubar
GTK_STYLE_CLASS_MENUBAR
GtkMenuBar


toolbar
GTK_STYLE_CLASS_TOOLBAR
GtkToolbar


dock
GTK_STYLE_CLASS_DOCK
GtkHandleBox


notebook

GtkNotebook


background
GTK_STYLE_CLASS_BACKGROUND
GtkWindow


rubberband
GTK_STYLE_CLASS_RUBBERBAND



header
GTK_STYLE_CLASS_HEADER



grip
GTK_STYLE_CLASS_GRIP
GtkWindow


spinner
GTK_STYLE_CLASS_SPINNER
GtkSpinner






Widgets can also add regions with flags to their context.
The regions used by GTK+ widgets are:




Region
Flags
Macro
Used by




row
even, odd
GTK_STYLE_REGION_ROW
GtkTreeView


column
first, last, sorted
GTK_STYLE_REGION_COLUMN
GtkTreeView


column-header

GTK_STYLE_REGION_COLUMN_HEADER



tab
even, odd, first, last
GTK_STYLE_REGION_TAB
GtkNotebook







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 theming engines 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.


If a custom theming engine is needed, you probably want to implement a
GtkStyleProvider yourself so it points to your GtkThemingEngine
implementation, as GtkCssProvider uses gtk_theming_engine_load()
which loads the theming engine module from the standard paths.

Properties
Properties Defined By
Methods / Constructors
Method / Constructor Defined By
Events - usage syntax: this.signals.EVENTNAME.connect( Function )
Event Defined By
Used by These Methods / Signals / Properties
Class / Namespace Method / Signal / Properties
Gtk
Method
Gtk.render_activity (StyleContext context, Context cr, gdouble x, gdouble y, gdouble width, gdouble height) : none
Renders an activity area (Such as in GtkSpinner or the
fill line in GtkRange), the state GTK_STATE_FLAG_ACTIVE
determines whether there is activity going on.
Gtk
Method
Gtk.render_arrow (StyleContext context, Context cr, gdouble angle, gdouble x, gdouble y, gdouble size) : none
Renders an arrow pointing to angle.
Gtk
Method
Gtk.render_background (StyleContext context, Context cr, gdouble x, gdouble y, gdouble width, gdouble height) : none
Renders the background of an element.
Gtk
Method
Gtk.render_check (StyleContext context, Context cr, gdouble x, gdouble y, gdouble width, gdouble height) : none
Renders a checkmark (as in a GtkCheckButton).
Gtk
Method
Gtk.render_expander (StyleContext context, Context cr, gdouble x, gdouble y, gdouble width, gdouble height) : none
Renders an expander (as used in GtkTreeView and GtkExpander) in the area
defined by x, y, width, height.
Gtk
Method
Gtk.render_extension (StyleContext context, Context cr, gdouble x, gdouble y, gdouble width, gdouble height, PositionType gap_side) : none
Renders a extension (as in a GtkNotebook tab) in the rectangle
defined by x, y, width, height.
Gtk
Method
Gtk.render_focus (StyleContext context, Context cr, gdouble x, gdouble y, gdouble width, gdouble height) : none
Renders a focus indicator on the rectangle determined by x, y, width, height.
Gtk
Method
Gtk.render_frame (StyleContext context, Context cr, gdouble x, gdouble y, gdouble width, gdouble height) : none
Renders a frame around the rectangle defined by x, y, width, height.
Gtk
Method
Gtk.render_frame_gap (StyleContext context, Context cr, gdouble x, gdouble y, gdouble width, gdouble height, PositionType gap_side, gdouble xy0_gap, gdouble xy1_gap) : none
Renders a frame around the rectangle defined by (x, y, width, height),
leaving a gap on one side.
Gtk
Method
Gtk.render_handle (StyleContext context, Context cr, gdouble x, gdouble y, gdouble width, gdouble height) : none
Renders a handle (as in GtkHandleBox, GtkPaned and
GtkWindow's resize grip), in the rectangle
determined by x, y, width, height.
Gtk
Method
Gtk.render_icon_pixbuf (StyleContext context, IconSource source, gint32 size) : GdkPixbuf.Pixbuf
Renders the icon specified by source at the given size, returning the result
in a pixbuf.
Gtk
Method
Gtk.render_layout (StyleContext context, Context cr, gdouble x, gdouble y, Layout layout) : none
Renders layout on the coordinates x, y
Gtk
Method
Gtk.render_line (StyleContext context, Context cr, gdouble x0, gdouble y0, gdouble x1, gdouble y1) : none
Renders a line from (x0, y0) to (x1, y1).
Gtk
Method
Gtk.render_option (StyleContext context, Context cr, gdouble x, gdouble y, gdouble width, gdouble height) : none
Renders an option mark (as in a GtkRadioButton), the GTK_STATE_FLAG_ACTIVE
state will determine whether the option is on or off, and
GTK_STATE_FLAG_INCONSISTENT whether it should be marked as undefined.
Gtk
Method
Gtk.render_slider (StyleContext context, Context cr, gdouble x, gdouble y, gdouble width, gdouble height, Orientation orientation) : none
Renders a slider (as in GtkScale) in the rectangle defined by x, y,
or horizontal.
Gtk.IconInfo
Method
load_symbolic_for_context (StyleContext context, Object out_values) : GdkPixbuf.Pixbuf
Loads an icon, modifying it to match the system colors for the foreground,
success, warning and error colors provided.
Gtk.IconSet
Method
render_icon_pixbuf (StyleContext context, gint32 size) : GdkPixbuf.Pixbuf
Renders an icon using gtk_render_icon_pixbuf().
Gtk.NumerableIcon
Property
style_context : Gtk.StyleContext
Gtk.NumerableIcon
Method
Gtk.NumerableIcon.new_with_style_context (Icon base_icon, StyleContext context) : Gio.Icon
Creates a new GtkNumerableIcon which will themed according
to the passed GtkStyleContext.
Gtk.NumerableIcon
Method
get_style_context () : Gtk.StyleContext
Returns the GtkStyleContext used by the icon for theming,
or NULL if there's none.
Gtk.NumerableIcon
Method
set_style_context (StyleContext style) : none
Updates the icon to fetch theme information from the
given GtkStyleContext.
Gtk.Style
Property
context : Gtk.StyleContext
Gtk.Widget
Method
get_style_context () : Gtk.StyleContext
Returns the style context associated to widget.
Documentation generated by Introspection Doc Generator Loosely Based on JsDoc Toolkit on Sat Apr 16 2011 17:13:58 GMT+0800 (HKT)