[]Struct gtk::StyleContext

pub struct StyleContext(_, _);

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 GtkStyleProviders. Style providers can be either attached explicitly to the context through StyleContextExt::add_provider, or to the screen through StyleContext::add_provider_for_screen. The resulting style is a combination of all providers’ information in priority order.

For GTK+ widgets, any StyleContext returned by WidgetExt::get_style_context will already have a WidgetPath, a gdk::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 StyleContextExt::set_path and possibly StyleContextExt::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 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.

Implements

StyleContextExt, glib::object::ObjectExt, StyleContextExtManual

Implementations

impl StyleContext[src]

pub fn new() -> StyleContext[src]

Creates a standalone StyleContext, this style context won’t be attached to any widget, so you may want to call StyleContextExt::set_path yourself.

This function is only useful when using the theming layer separated from GTK+, if you are using StyleContext to theme GtkWidgets, use WidgetExt::get_style_context in order to get a style context ready to theme the widget.

Returns

A newly created StyleContext.

pub fn add_provider_for_screen<P: IsA<StyleProvider>>(
    screen: &Screen,
    provider: &P,
    priority: u32
)
[src]

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

GTK+ uses this to make styling information from Settings available.

Note: If both priorities are the same, A StyleProvider added through StyleContextExt::add_provider takes precedence over another added through this function.

screen

a gdk::Screen

provider

a 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

pub fn remove_provider_for_screen<P: IsA<StyleProvider>>(
    screen: &Screen,
    provider: &P
)
[src]

Removes provider from the global style providers list in screen.

screen

a gdk::Screen

provider

a StyleProvider

pub fn reset_widgets(screen: &Screen)[src]

This function recomputes the styles for all widgets under a particular gdk::Screen. 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 Settings object.

screen

a gdk::Screen

Trait Implementations

impl Clone for StyleContext

impl Debug for StyleContext

impl Default for StyleContext[src]

impl Display for StyleContext[src]

impl Eq for StyleContext

impl Hash for StyleContext

impl Ord for StyleContext

impl<T: ObjectType> PartialEq<T> for StyleContext

impl<T: ObjectType> PartialOrd<T> for StyleContext

impl StaticType for StyleContext

Auto Trait Implementations

impl RefUnwindSafe for StyleContext

impl !Send for StyleContext

impl !Sync for StyleContext

impl Unpin for StyleContext

impl UnwindSafe for StyleContext

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<Super, Sub> CanDowncast<Sub> for Super where
    Sub: IsA<Super>,
    Super: IsA<Super>, 

impl<T> Cast for T where
    T: ObjectType, 

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ObjectExt for T where
    T: ObjectType, 

impl<'a, T> ToGlibContainerFromSlice<'a, *const GList> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<List>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<'a, T> ToGlibContainerFromSlice<'a, *const GPtrArray> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<PtrArray>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<'a, T> ToGlibContainerFromSlice<'a, *mut GArray> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<Array>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<'a, T> ToGlibContainerFromSlice<'a, *mut GList> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<List>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<'a, T> ToGlibContainerFromSlice<'a, *mut GPtrArray> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<PtrArray>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T> ToValue for T where
    T: SetValue + ?Sized

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.