Class: Gtk::StyleContext

Inherits:
Object
  • Object
show all
Defined in:
(unknown)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.add_provider_for_display(display, provider, priority) ⇒ nil

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

GTK uses this to make styling information from GtkSettings available.

Note: If both priorities are the same, A GtkStyleProvider added through [methodGtk.StyleContext.add_provider] takes precedence over another added through this function.

Parameters:

  • display (Gdk::Display)

    a GdkDisplay

  • provider (Gtk::StyleProvider)

    a GtkStyleProvider

  • priority (Integer)

    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

Returns:

  • (nil)

.remove_provider_for_display(display, provider) ⇒ nil

Removes provider from the global style providers list in display.

Parameters:

  • display (Gdk::Display)

    a GdkDisplay

  • provider (Gtk::StyleProvider)

    a GtkStyleProvider

Returns:

  • (nil)

Instance Method Details

#add_class(class_name) ⇒ nil

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 GtkEntry defining a “search” class, would be matched by:

entry.search { ... }

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

.search { ... }

Parameters:

  • class_name (String)

    class name to use in styling

Returns:

  • (nil)

#add_provider(provider, priority) ⇒ nil

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 [funcGtk.StyleContext.add_provider_for_display].

Note: If both priorities are the same, a GtkStyleProvider added through this function takes precedence over another added through [funcGtk.StyleContext.add_provider_for_display].

Parameters:

  • provider (Gtk::StyleProvider)

    a GtkStyleProvider

  • priority (Integer)

    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

Returns:

  • (nil)

#displayGdk::Display

Returns display.

Returns:

  • (Gdk::Display)

    display

#display=(display) ⇒ Gdk::Display

Parameters:

  • display (Gdk::Display)

Returns:

  • (Gdk::Display)

    display

  • (Gdk::Display)

    display

#get_border(border) ⇒ nil

Gets the border for a given state as a GtkBorder.

Parameters:

  • border (Gtk::Border)

    return value for the border settings

Returns:

  • (nil)

#get_color(color) ⇒ nil

Gets the foreground color for a given state.

Parameters:

  • color (Gdk::RGBA)

    return value for the foreground color

Returns:

  • (nil)

#get_margin(margin) ⇒ nil

Gets the margin for a given state as a GtkBorder.

Parameters:

  • margin (Gtk::Border)

    return value for the margin settings

Returns:

  • (nil)

#get_padding(padding) ⇒ nil

Gets the padding for a given state as a GtkBorder.

Parameters:

  • padding (Gtk::Border)

    return value for the padding settings

Returns:

  • (nil)

#has_class(class_name) ⇒ Boolean

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

Parameters:

  • class_name (String)

    a class name

Returns:

  • (Boolean)

    true if context has class_name defined

#lookup_color(color_name, color) ⇒ Boolean

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

Parameters:

  • color_name (String)

    color name to lookup

  • color (Gdk::RGBA)

    Return location for the looked up color

Returns:

  • (Boolean)

    true if color_name was found and resolved, false otherwise

#remove_class(class_name) ⇒ nil

Removes class_name from context.

Parameters:

  • class_name (String)

    class name to remove

Returns:

  • (nil)

#remove_provider(provider) ⇒ nil

Removes provider from the style providers list in context.

Parameters:

Returns:

  • (nil)

#restorenil

Restores context state to a previous stage.

See [methodGtk.StyleContext.save].

Returns:

  • (nil)

#savenil

Saves the context state.

This allows temporary modifications done through [methodGtk.StyleContext.add_class], [methodGtk.StyleContext.remove_class], [methodGtk.StyleContext.set_state] to be quickly reverted in one go through [methodGtk.StyleContext.restore].

The matching call to [methodGtk.StyleContext.restore] must be done before GTK returns to the main loop.

Returns:

  • (nil)

#scaleInteger

Returns the scale used for assets.

Returns:

  • (Integer)

    the scale

#scale=(scale) ⇒ nil

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

Parameters:

  • scale (Integer)

    scale

Returns:

  • (nil)

#stateGtk::StateFlags

Returns the state used for style matching.

This method should only be used to retrieve the GtkStateFlags to pass to GtkStyleContext methods, like [methodGtk.StyleContext.get_padding]. If you need to retrieve the current state of a GtkWidget, use [methodGtk.Widget.get_state_flags].

Returns:

#state=(flags) ⇒ nil

Sets the state to be used for style matching.

Parameters:

Returns:

  • (nil)

#to_string(flags) ⇒ String

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.

Parameters:

Returns:

  • (String)

    a newly allocated string representing context