gtkmm 4.16.0
|
This object stores styling information affecting a widget defined by WidgetPath. More...
#include <gtkmm/stylecontext.h>
Public Types | |
enum class | PrintFlags { NONE = 0x0 , RECURSE = 1 << 0 , SHOW_STYLE = 1 << 1 , SHOW_CHANGE = 1 << 2 } |
Public Member Functions | |
StyleContext (StyleContext &&src) noexcept | |
StyleContext & | operator= (StyleContext &&src) noexcept |
~StyleContext () noexcept override | |
GtkStyleContext * | gobj () |
Provides access to the underlying C GObject. | |
const GtkStyleContext * | gobj () const |
Provides access to the underlying C GObject. | |
GtkStyleContext * | gobj_copy () |
Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. | |
void | add_provider (const Glib::RefPtr< StyleProvider > &provider, guint priority) |
Adds a style provider to context, to be used in style construction. | |
void | remove_provider (const Glib::RefPtr< StyleProvider > &provider) |
Removes provider from the style providers list in context. | |
void | context_save () |
Saves the context state. | |
void | context_restore () |
Restores context state to a previous stage. | |
void | set_state (StateFlags flags) |
Sets the state to be used for style matching. | |
StateFlags | get_state () const |
Returns the state used for style matching. | |
void | set_scale (int scale) |
Sets the scale to use when getting image assets for the style. | |
int | get_scale () const |
Returns the scale used for assets. | |
void | add_class (const Glib::ustring &class_name) |
Adds a style class to context, so later uses of the style context will make use of this new class for styling. | |
void | remove_class (const Glib::ustring &class_name) |
Removes class_name from context. | |
bool | has_class (const Glib::ustring &class_name) |
Returns true if context currently has defined the given class name. | |
void | set_display (const Glib::RefPtr< Gdk::Display > &display) |
Attaches context to the given display. | |
Glib::RefPtr< Gdk::Display > | get_display () |
Returns the Gdk::Display to which context is attached. | |
Glib::RefPtr< const Gdk::Display > | get_display () const |
Returns the Gdk::Display to which context is attached. | |
bool | lookup_color (const Glib::ustring &color_name, Gdk::RGBA &color) |
Looks up and resolves a color name in the context color map. | |
Gdk::RGBA | get_color () const |
Gets the foreground color for a given state. | |
Border | get_border () const |
Border | get_padding () const |
Border | get_margin () const |
void | render_check (const Cairo::RefPtr< Cairo::Context > &cr, double x, double y, double width, double height) |
Renders a checkmark (as in a Gtk::CheckButton ). | |
void | render_option (const Cairo::RefPtr< Cairo::Context > &cr, double x, double y, double width, double height) |
Renders an option mark (as in a radio button), the Gtk::StateFlags::CHECKED state will determine whether the option is on or off, and Gtk::StateFlags::INCONSISTENT whether it should be marked as undefined. | |
void | render_arrow (const Cairo::RefPtr< Cairo::Context > &cr, double angle, double x, double y, double size) |
Renders an arrow pointing to angle. | |
void | render_background (const Cairo::RefPtr< Cairo::Context > &cr, double x, double y, double width, double height) |
Renders the background of an element. | |
void | render_frame (const Cairo::RefPtr< Cairo::Context > &cr, double x, double y, double width, double height) |
Renders a frame around the rectangle defined by x, y, width, height. | |
void | render_expander (const Cairo::RefPtr< Cairo::Context > &cr, double x, double y, double width, double height) |
Renders an expander (as used in Gtk::TreeView and Gtk::Expander ) in the area defined by x, y, width, height. | |
void | render_focus (const Cairo::RefPtr< Cairo::Context > &cr, double x, double y, double width, double height) |
Renders a focus indicator on the rectangle determined by x, y, width, height. | |
void | render_layout (const Cairo::RefPtr< Cairo::Context > &cr, double x, double y, const Glib::RefPtr< Pango::Layout > &layout) |
Renders layout on the coordinates x, y. | |
void | render_line (const Cairo::RefPtr< Cairo::Context > &cr, double x0, double y0, double x1, double y1) |
Renders a line from (x0, y0) to (x1, y1). | |
void | render_handle (const Cairo::RefPtr< Cairo::Context > &cr, double x, double y, double width, double height) |
Renders a handle (as in Gtk::Paned and Gtk::Window ’s resize grip), in the rectangle determined by x, y, width, height. | |
void | render_activity (const Cairo::RefPtr< Cairo::Context > &cr, double x, double y, double width, double height) |
Renders an activity indicator (such as in Gtk::Spinner ). | |
void | render_icon (const Cairo::RefPtr< Cairo::Context > &cr, const Glib::RefPtr< Gdk::Texture > &texture, double x, double y) |
Renders the icon in texture at the specified x and y coordinates. | |
Glib::ustring | to_string (PrintFlags flags) const |
Converts the style context into a string representation. | |
Glib::PropertyProxy< Glib::RefPtr< Gdk::Display > > | property_display () |
The display of the style context. | |
Glib::PropertyProxy_ReadOnly< Glib::RefPtr< Gdk::Display > > | property_display () const |
The display of the style context. | |
Static Public Member Functions | |
static GType | get_type () |
Get the GType for this class, for use with the underlying GObject type system. | |
static void | add_provider_for_display (const Glib::RefPtr< Gdk::Display > &display, const Glib::RefPtr< StyleProvider > &provider, guint priority) |
Adds a global style provider to display, which will be used in style construction for all Gtk::StyleContexts under display. | |
static void | remove_provider_for_display (const Glib::RefPtr< Gdk::Display > &display, const Glib::RefPtr< StyleProvider > &provider) |
Removes provider from the global style providers list in display. | |
Protected Member Functions | |
StyleContext () | |
Related Symbols | |
(Note that these are not member symbols.) | |
Glib::RefPtr< Gtk::StyleContext > | wrap (GtkStyleContext *object, bool take_copy=false) |
A Glib::wrap() method for this object. | |
This object 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 display through add_provider_for_display(). The resulting style is a combination of all providers' information in priority order.
For GTK+ widgets, any StyleContext returned by Widget::get_style_context() will already have a WidgetPath, a Gdk::Display and RTL/LTR information set, The style context will be also updated automatically if any of these settings change on the widget.
StyleContext has built-in support for state change transitions. Note that these animations respect the Settings::property_gtk_enable_animations() setting.
For simple widgets where state changes affect the whole widget area, calling notify_state_change() with a no region is sufficient to trigger the transition animation. And GTK+ already does that when Widget::set_state() or Widget::set_state_flags() are called.
If a widget needs to declare several animatable regions (i.e. not affecting the whole widget area), its Widget::signal_draw() signal handler needs to wrap the render operations for the different regions with calls to push_animatable_region() and pop_animatable_region(). These methods 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.
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 objects is one way to achieve this.
The widget also needs to notify the style context about a state change for a given animatable region so the animation is triggered. notify_state_change() can take no region IDs, meaning that the whole widget area will be updated by the animation.
|
noexcept |
|
overridenoexcept |
|
protected |
Adds a style class to context, so later uses of the style context will make use of this new class for styling.
In the CSS file format, a Gtk::Entry
defining a “search” class, would be matched by:
[C example ellipted]
While any widget defining a “search” class would be matched by:
[C example ellipted] Deprecated: 4.10: Use Gtk::Widget::add_css_class() instead
class_name | Class name to use in styling. |
void Gtk::StyleContext::add_provider | ( | const Glib::RefPtr< StyleProvider > & | provider, |
guint | 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 add_provider_for_display().
Gtk::StyleProvider
added through this function takes precedence over another added through add_provider_for_display().Deprecated: 4.10: Use style classes instead
provider | A Gtk::StyleProvider . |
priority | The priority of the style provider. The lower it is, the earlier it will be used in the style construction. Typically this will be in the range between GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and GTK_STYLE_PROVIDER_PRIORITY_USER. |
|
static |
Adds a global style provider to display, which will be used in style construction for all Gtk::StyleContexts
under display.
GTK uses this to make styling information from Gtk::Settings
available.
Gtk::StyleProvider
added through add_provider() takes precedence over another added through this function.display | A Gdk::Display . |
provider | A Gtk::StyleProvider . |
priority | The priority of the style provider. The lower it is, the earlier it will be used in the style construction. Typically this will be in the range between GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and GTK_STYLE_PROVIDER_PRIORITY_USER. |
void Gtk::StyleContext::context_restore | ( | ) |
Restores context state to a previous stage.
See save().
Deprecated: 4.10: This API will be removed in GTK 5
void Gtk::StyleContext::context_save | ( | ) |
Saves the context state.
This allows temporary modifications done through add_class(), remove_class(), set_state() to be quickly reverted in one go through restore().
The matching call to restore() must be done before GTK returns to the main loop.
Deprecated: 4.10: This API will be removed in GTK 5
Border Gtk::StyleContext::get_border | ( | ) | const |
Gdk::RGBA Gtk::StyleContext::get_color | ( | ) | const |
Gets the foreground color for a given state.
Glib::RefPtr< Gdk::Display > Gtk::StyleContext::get_display | ( | ) |
Returns the Gdk::Display
to which context is attached.
Deprecated: 4.10: Use Gtk::Widget::get_display() instead
Gdk::Display
. Glib::RefPtr< const Gdk::Display > Gtk::StyleContext::get_display | ( | ) | const |
Returns the Gdk::Display
to which context is attached.
Deprecated: 4.10: Use Gtk::Widget::get_display() instead
Gdk::Display
. Border Gtk::StyleContext::get_margin | ( | ) | const |
Border Gtk::StyleContext::get_padding | ( | ) | const |
int Gtk::StyleContext::get_scale | ( | ) | const |
Returns the scale used for assets.
Deprecated: 4.10: Use Gtk::Widget::get_scale_factor() instead
StateFlags Gtk::StyleContext::get_state | ( | ) | const |
Returns the state used for style matching.
This method should only be used to retrieve the Gtk::StateFlags
to pass to Gtk::StyleContext
methods, like get_padding(). If you need to retrieve the current state of a Gtk::Widget
, use Gtk::Widget::get_state_flags().
Deprecated: 4.10: Use Gtk::Widget::get_state_flags() instead
|
static |
Get the GType for this class, for use with the underlying GObject type system.
|
inline |
Provides access to the underlying C GObject.
|
inline |
Provides access to the underlying C GObject.
GtkStyleContext * Gtk::StyleContext::gobj_copy | ( | ) |
Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.
bool Gtk::StyleContext::has_class | ( | const Glib::ustring & | class_name | ) |
Returns true
if context currently has defined the given class name.
Deprecated: 4.10: Use Gtk::Widget::has_css_class() instead
class_name | A class name. |
true
if context has class_name defined. Looks up and resolves a color name in the context color map.
Deprecated: 4.10: This api will be removed in GTK 5
color_name | Color name to lookup. |
color | Return location for the looked up color. |
true
if color_name was found and resolved, false
otherwise.
|
noexcept |
Glib::PropertyProxy< Glib::RefPtr< Gdk::Display > > Gtk::StyleContext::property_display | ( | ) |
The display of the style context.
Glib::PropertyProxy_ReadOnly< Glib::RefPtr< Gdk::Display > > Gtk::StyleContext::property_display | ( | ) | const |
The display of the style context.
Removes class_name from context.
Deprecated: 4.10: Use Gtk::Widget::remove_css_class() instead
class_name | Class name to remove. |
void Gtk::StyleContext::remove_provider | ( | const Glib::RefPtr< StyleProvider > & | provider | ) |
Removes provider from the style providers list in context.
Deprecated: 4.10
provider | A Gtk::StyleProvider . |
|
static |
Removes provider from the global style providers list in display.
display | A Gdk::Display . |
provider | A Gtk::StyleProvider . |
void Gtk::StyleContext::render_activity | ( | const Cairo::RefPtr< Cairo::Context > & | cr, |
double | x, | ||
double | y, | ||
double | width, | ||
double | height | ||
) |
Renders an activity indicator (such as in Gtk::Spinner
).
The state Gtk::StateFlags::CHECKED determines whether there is activity going on.
Deprecated: 4.10
cr | A cairo_t . |
x | X origin of the rectangle. |
y | Y origin of the rectangle. |
width | Rectangle width. |
height | Rectangle height. |
void Gtk::StyleContext::render_arrow | ( | const Cairo::RefPtr< Cairo::Context > & | cr, |
double | angle, | ||
double | x, | ||
double | y, | ||
double | size | ||
) |
Renders an arrow pointing to angle.
Typical arrow rendering at 0, 1⁄2 π;, π; and 3⁄2 π:
Deprecated: 4.10
cr | A cairo_t . |
angle | Arrow angle from 0 to 2 * G_PI, being 0 the arrow pointing to the north. |
x | X origin of the render area. |
y | Y origin of the render area. |
size | Square side for render area. |
void Gtk::StyleContext::render_background | ( | const Cairo::RefPtr< Cairo::Context > & | cr, |
double | x, | ||
double | y, | ||
double | width, | ||
double | height | ||
) |
Renders the background of an element.
Typical background rendering, showing the effect of background-image
, border-width
and border-radius
:
Deprecated: 4.10
cr | A cairo_t . |
x | X origin of the rectangle. |
y | Y origin of the rectangle. |
width | Rectangle width. |
height | Rectangle height. |
void Gtk::StyleContext::render_check | ( | const Cairo::RefPtr< Cairo::Context > & | cr, |
double | x, | ||
double | y, | ||
double | width, | ||
double | height | ||
) |
Renders a checkmark (as in a Gtk::CheckButton
).
The Gtk::StateFlags::CHECKED state determines whether the check is on or off, and Gtk::StateFlags::INCONSISTENT determines whether it should be marked as undefined.
Typical checkmark rendering:
Deprecated: 4.10
cr | A cairo_t . |
x | X origin of the rectangle. |
y | Y origin of the rectangle. |
width | Rectangle width. |
height | Rectangle height. |
void Gtk::StyleContext::render_expander | ( | const Cairo::RefPtr< Cairo::Context > & | cr, |
double | x, | ||
double | y, | ||
double | width, | ||
double | height | ||
) |
Renders an expander (as used in Gtk::TreeView
and Gtk::Expander
) in the area defined by x, y, width, height.
The state Gtk::StateFlags::CHECKED determines whether the expander is collapsed or expanded.
Typical expander rendering:
Deprecated: 4.10
cr | A cairo_t . |
x | X origin of the rectangle. |
y | Y origin of the rectangle. |
width | Rectangle width. |
height | Rectangle height. |
void Gtk::StyleContext::render_focus | ( | const Cairo::RefPtr< Cairo::Context > & | cr, |
double | x, | ||
double | y, | ||
double | width, | ||
double | height | ||
) |
Renders a focus indicator on the rectangle determined by x, y, width, height.
Typical focus rendering:
Deprecated: 4.10
cr | A cairo_t . |
x | X origin of the rectangle. |
y | Y origin of the rectangle. |
width | Rectangle width. |
height | Rectangle height. |
void Gtk::StyleContext::render_frame | ( | const Cairo::RefPtr< Cairo::Context > & | cr, |
double | x, | ||
double | y, | ||
double | width, | ||
double | height | ||
) |
Renders a frame around the rectangle defined by x, y, width, height.
Examples of frame rendering, showing the effect of border-image
, border-color
, border-width
, border-radius
and junctions:
Deprecated: 4.10
cr | A cairo_t . |
x | X origin of the rectangle. |
y | Y origin of the rectangle. |
width | Rectangle width. |
height | Rectangle height. |
void Gtk::StyleContext::render_handle | ( | const Cairo::RefPtr< Cairo::Context > & | cr, |
double | x, | ||
double | y, | ||
double | width, | ||
double | height | ||
) |
Renders a handle (as in Gtk::Paned
and Gtk::Window
’s resize grip), in the rectangle determined by x, y, width, height.
Handles rendered for the paned and grip classes:
Deprecated: 4.10
cr | A cairo_t . |
x | X origin of the rectangle. |
y | Y origin of the rectangle. |
width | Rectangle width. |
height | Rectangle height. |
void Gtk::StyleContext::render_icon | ( | const Cairo::RefPtr< Cairo::Context > & | cr, |
const Glib::RefPtr< Gdk::Texture > & | texture, | ||
double | x, | ||
double | y | ||
) |
Renders the icon in texture at the specified x and y coordinates.
This function will render the icon in texture at exactly its size, regardless of scaling factors, which may not be appropriate when drawing on displays with high pixel densities.
Deprecated: 4.10
cr | A cairo_t . |
texture | A Gdk::Texture containing the icon to draw. |
x | X position for the texture. |
y | Y position for the texture. |
void Gtk::StyleContext::render_layout | ( | const Cairo::RefPtr< Cairo::Context > & | cr, |
double | x, | ||
double | y, | ||
const Glib::RefPtr< Pango::Layout > & | layout | ||
) |
Renders layout on the coordinates x, y.
Deprecated: 4.10
cr | A cairo_t . |
x | X origin. |
y | Y origin. |
layout | The Pango::Layout to render. |
void Gtk::StyleContext::render_line | ( | const Cairo::RefPtr< Cairo::Context > & | cr, |
double | x0, | ||
double | y0, | ||
double | x1, | ||
double | y1 | ||
) |
Renders a line from (x0, y0) to (x1, y1).
Deprecated: 4.10
cr | A cairo_t . |
x0 | X coordinate for the origin of the line. |
y0 | Y coordinate for the origin of the line. |
x1 | X coordinate for the end of the line. |
y1 | Y coordinate for the end of the line. |
void Gtk::StyleContext::render_option | ( | const Cairo::RefPtr< Cairo::Context > & | cr, |
double | x, | ||
double | y, | ||
double | width, | ||
double | height | ||
) |
Renders an option mark (as in a radio button), the Gtk::StateFlags::CHECKED state will determine whether the option is on or off, and Gtk::StateFlags::INCONSISTENT whether it should be marked as undefined.
Typical option mark rendering:
Deprecated: 4.10
cr | A cairo_t . |
x | X origin of the rectangle. |
y | Y origin of the rectangle. |
width | Rectangle width. |
height | Rectangle height. |
void Gtk::StyleContext::set_display | ( | const Glib::RefPtr< Gdk::Display > & | display | ) |
Attaches context to the given display.
The display is used to add style information from “global” style providers, such as the display's Gtk::Settings
instance.
If you are using a Gtk::StyleContext
returned from Gtk::Widget::get_style_context(), you do not need to call this yourself.
Deprecated: 4.10: You should not use this api
display | A Gdk::Display . |
void Gtk::StyleContext::set_scale | ( | int | scale | ) |
Sets the scale to use when getting image assets for the style.
Deprecated: 4.10: You should not use this api
scale | Scale. |
void Gtk::StyleContext::set_state | ( | StateFlags | flags | ) |
Sets the state to be used for style matching.
Deprecated: 4.10: You should not use this api
flags | State to represent. |
Glib::ustring Gtk::StyleContext::to_string | ( | PrintFlags | flags | ) | const |
Converts the style context into a string representation.
The string representation always includes information about the name, state, id, visibility and style classes of the CSS node that is backing context. Depending on the flags, more information may be included.
This function is intended for testing and debugging of the CSS implementation in GTK. There are no guarantees about the format of the returned string, it may change.
Deprecated: 4.10: This api will be removed in GTK 5
flags | Flags that determine what to print. |
|
related |
A Glib::wrap() method for this object.
object | The C instance. |
take_copy | False if the result should take ownership of the C instance. True if it should take a new copy or ref. |