Re: How can I retrieve gtk style context information from textview widget class without a textview widget?



On 15-06-12 05:04 AM, Friedrich Beckmann wrote:
Hi,

I would like to use the style information from the textview widget in another context. I want
to retrieve the text foreground color and the background color as it would be used in a textview widget
and use this style information for rendering inside a drawing area. I figured out that I can modify the
style by adding a style class with gtk_style_context_add_class (), but the textview background
color seems to be specific to the textview widget.

In the adwaita scheme css:

GtkTextView {
   background-color: #f6f6f6; }
   GtkTextView:backdrop {
     background-color: #f6f6f6; }

Is there a way to retrieve this information of the background-color similar to the class mechanism?
I would need the same style context as if I was in a textview widget.

Friedrich




_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
I don't have a complete solution for you, but you can get the background color from gtk_style_context_get_background_color().
For example...

GtkWidget *win = NULL;
GdkRGBA color1;
GdkRGBA color2;

GtkStyleContext *context1;

...
...
gtk_widget_show_all (win);

context1 = gtk_widget_get_style_context (win);
gtk_style_context_get_background_color(context1, GTK_STATE_NORMAL, &color1);
printf("%f\n%f\n%f\n", ( color1.red ), ( color1.green), ( color1.blue));

The colors are decimal numbers between 0.0 and 1.0. To change the background color...

color2.red = 1.0;
color2.green = 0.1;
color2.blue = 0.1;
color2.alpha = 1.0;

gtk_widget_override_background_color (win, GTK_STATE_NORMAL, &color2);

jim...



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]