Trait gtk::prelude::StyleContextExt[][src]

pub trait StyleContextExt: 'static {
Show methods fn add_class(&self, class_name: &str);
fn add_provider<P: IsA<StyleProvider>>(&self, provider: &P, priority: u32);
fn border(&self, state: StateFlags) -> Border;
fn color(&self, state: StateFlags) -> RGBA;
fn frame_clock(&self) -> Option<FrameClock>;
fn junction_sides(&self) -> JunctionSides;
fn margin(&self, state: StateFlags) -> Border;
fn padding(&self, state: StateFlags) -> Border;
fn parent(&self) -> Option<StyleContext>;
fn path(&self) -> Option<WidgetPath>;
fn style_property_for_state(
        &self,
        property: &str,
        state: StateFlags
    ) -> Value;
fn scale(&self) -> i32;
fn screen(&self) -> Option<Screen>;
fn section(&self, property: &str) -> Option<CssSection>;
fn state(&self) -> StateFlags;
fn style_property(&self, property_name: &str) -> Value;
fn has_class(&self, class_name: &str) -> bool;
fn list_classes(&self) -> Vec<GString>;
fn lookup_color(&self, color_name: &str) -> Option<RGBA>;
fn remove_class(&self, class_name: &str);
fn remove_provider<P: IsA<StyleProvider>>(&self, provider: &P);
fn restore(&self);
fn save(&self);
fn set_frame_clock(&self, frame_clock: &FrameClock);
fn set_junction_sides(&self, sides: JunctionSides);
fn set_parent<P: IsA<StyleContext>>(&self, parent: Option<&P>);
fn set_path(&self, path: &WidgetPath);
fn set_scale(&self, scale: i32);
fn set_screen(&self, screen: &Screen);
fn set_state(&self, flags: StateFlags);
fn to_string(&self, flags: StyleContextPrintFlags) -> Option<GString>;
fn direction(&self) -> TextDirection;
fn set_direction(&self, direction: TextDirection);
fn paint_clock(&self) -> Option<FrameClock>;
fn set_paint_clock(&self, paint_clock: Option<&FrameClock>);
fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_direction_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId;
fn connect_paint_clock_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId;
fn connect_parent_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId;
fn connect_screen_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId;
}
Expand description

Trait containing all StyleContext methods.

Implementors

StyleContext

Required methods

Adds a style class to self, so posterior calls to gtk_style_context_get() or any of the gtk_render_*() functions will make use of this new class for styling.

In the CSS file format, a Entry defining a “search” class, would be matched by:

⚠️ The following code is in CSS ⚠️

entry.search { ... }

While any widget defining a “search” class would be matched by:

⚠️ The following code is in CSS ⚠️

.search { ... }

class_name

class name to use in styling

Adds a style provider to self, to be used in style construction. Note that a style provider added by this function only affects the style of the widget to which self belongs. If you want to affect the style of all widgets, use StyleContext::add_provider_for_screen().

Note: If both priorities are the same, a StyleProvider added through this function takes precedence over another added through StyleContext::add_provider_for_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

Gets the border for a given state as a Border.

See style_property_for_state() and STYLE_PROPERTY_BORDER_WIDTH for details.

state

state to retrieve the border for

Returns

border

return value for the border settings

Gets the foreground color for a given state.

See style_property_for_state() and STYLE_PROPERTY_COLOR for details.

state

state to retrieve the color for

Returns

color

return value for the foreground color

Returns the gdk::FrameClock to which self is attached.

Returns

a gdk::FrameClock, or None if self does not have an attached frame clock.

Returns the sides where rendered elements connect visually with others.

Returns

the junction sides

Gets the margin for a given state as a Border. See gtk_style_property_get() and STYLE_PROPERTY_MARGIN for details.

state

state to retrieve the border for

Returns

margin

return value for the margin settings

Gets the padding for a given state as a Border. See gtk_style_context_get() and STYLE_PROPERTY_PADDING for details.

state

state to retrieve the padding for

Returns

padding

return value for the padding settings

Gets the parent context set via set_parent(). See that function for details.

Returns

the parent context or None

Returns the widget path used for style matching.

Returns

A WidgetPath

Gets a style property from self for the given state.

Note that not all CSS properties that are supported by GTK+ can be retrieved in this way, since they may not be representable as glib::Value. GTK+ defines macros for a number of properties that can be used with this function.

Note that passing a state other than the current state of self is not recommended unless the style context has been saved with save().

When value is no longer needed, [glib::Value::unset()][crate::glib::Value::unset()] must be called to free any allocated memory.

property

style property name

state

state to retrieve the property value for

Returns

value

return location for the style property value

Returns the scale used for assets.

Returns

the scale

Returns the gdk::Screen to which self is attached.

Returns

a gdk::Screen.

Queries the location in the CSS where property was defined for the current self. Note that the state to be queried is taken from state().

If the location is not available, None will be returned. The location might not be available for various reasons, such as the property being overridden, property not naming a supported CSS property or tracking of definitions being disabled for performance reasons.

Shorthand CSS properties cannot be queried for a location and will always return None.

property

style property name

Returns

None or the section where a value for property was defined

Returns the state used for style matching.

This method should only be used to retrieve the StateFlags to pass to StyleContext methods, like padding(). If you need to retrieve the current state of a Widget, use WidgetExt::state_flags().

Returns

the state flags

Gets the value for a widget style property.

When value is no longer needed, [glib::Value::unset()][crate::glib::Value::unset()] must be called to free any allocated memory.

property_name

the name of the widget style property

Returns

value

Return location for the property value

Returns true if self currently has defined the given class name.

class_name

a class name

Returns

true if self has class_name defined

Returns the list of classes currently defined in self.

Returns

a GList of strings with the currently defined classes. The contents of the list are owned by GTK+, but you must free the list itself with g_list_free() when you are done with it.

Looks up and resolves a color name in the self color map.

color_name

color name to lookup

Returns

true if color_name was found and resolved, false otherwise

color

Return location for the looked up color

Removes class_name from self.

class_name

class name to remove

Removes provider from the style providers list in self.

provider

a StyleProvider

Restores self state to a previous stage. See save().

Saves the self state, so temporary modifications done through add_class(), remove_class(), set_state(), etc. can quickly be reverted in one go through restore().

The matching call to restore() must be done before GTK returns to the main loop.

Attaches self to the given frame clock.

The frame clock is used for the timing of animations.

If you are using a StyleContext returned from WidgetExt::style_context(), you do not need to call this yourself.

frame_clock

a gdk::FrameClock

Sets the sides where rendered elements (mostly through render_frame()) will visually connect with other visual elements.

This is merely a hint that may or may not be honored by themes.

Container widgets are expected to set junction hints as appropriate for their children, so it should not normally be necessary to call this function manually.

sides

sides where rendered elements are visually connected to other elements

Sets the parent style context for self. The parent style context is used to implement inheritance of properties.

If you are using a StyleContext returned from WidgetExt::style_context(), the parent will be set for you.

parent

the new parent or None

Sets the WidgetPath used for style matching. As a consequence, the style will be regenerated to match the new given path.

If you are using a StyleContext returned from WidgetExt::style_context(), you do not need to call this yourself.

path

a WidgetPath

Sets the scale to use when getting image assets for the style.

scale

scale

Attaches self to the given screen.

The screen is used to add style information from “global” style providers, such as the screen’s Settings instance.

If you are using a StyleContext returned from WidgetExt::style_context(), you do not need to call this yourself.

screen

a gdk::Screen

Sets the state to be used for style matching.

flags

state to represent

This is supported on crate feature v3_20 only.

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 self. 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.

flags

Flags that determine what to print

Returns

a newly allocated string representing self

The ::changed signal is emitted when there is a change in the StyleContext.

For a StyleContext returned by WidgetExt::style_context(), the signal::Widget::style-updated signal/vfunc might be more convenient to use.

This signal is useful when using the theming layer standalone.

Implementors