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

2015-06-12 Thread Friedrich Beckmann
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


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

2015-06-12 Thread Colomban Wendling
Hi,

Le 12/06/2015 14:04, Friedrich Beckmann wrote:
 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. […]
 
 […]

 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.

Don't take my words as gospel, but there's something:

First, realize that you can't reliably achieve the same look as the
theme by simply picking background and foreground colors: the theme
might be using gradients, images and whatnot.
If you want to paint it like a text view, you should probably use the
GTK rendering functions, like gtk_render_background() and
gtk_render_layout().

Then, if you don't have an actual GtkTextView to get the style context
from, you'll need to create it yourself faking the one a true text view
would have.  You can probably do that relatively easily with
gtk_style_context_new() and then setting an appropriate widget path with
gtk_style_context_set_path() -- and possibly appropriate classes, as you
already figured out.

Regards,
Colomban


https://developer.gnome.org/gtk3/stable/GtkStyleContext.html#gtk-render-background
https://developer.gnome.org/gtk3/stable/GtkStyleContext.html#gtk-render-layout
https://developer.gnome.org/gtk3/stable/GtkStyleContext.html#gtk-style-context-new
https://developer.gnome.org/gtk3/stable/GtkStyleContext.html#gtk-style-context-set-path
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


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

2015-06-12 Thread Jim Charlton

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

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


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

2015-06-12 Thread Friedrich Beckmann
Thank you for the hint!
 Then, if you don't have an actual GtkTextView to get the style context
 from, you'll need to create it yourself faking the one a true text view
 would have.  You can probably do that relatively easily with
 gtk_style_context_new() and then setting an appropriate widget path with
 gtk_style_context_set_path()




___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list