GtkStyleContext and Foreign Drawing

Hello,

I am looking at the Foreign Drawing example in gtk3-demo. I have to draw GtkListBoxRows so I added this code:

window_context = get_style (NULL, "window");
list_context = get_style (window_context, "list");
row_context = get_style (list_context, "row.activatable:hover");

draw_style_common (row_context, cr, 0, 0, 500, 50, NULL, NULL, NULL, NULL);

cairo_surface_write_to_png (surface, "listboxrow-hover-bg.png");

Anyway it works with Adwaita or Numix but with Arc-Dark I don’t get the correct color. What am I doing wrong?
Thanks in advance!

To answer my own question,

first, the window style context needs the .background class:

window_context = get_style (NULL, "window.background")

Then all style contexts must be painted in order:

window_context = get_style (NULL, "window.background");
list_context = get_style (window_context, "list");
row_context = get_style (list_context, "row.activatable:hover");

draw_style_common (window_context, cr, 0, 0, 500, 50, NULL, NULL, NULL, NULL);
draw_style_common (list_context, cr, 0, 0, 500, 50, NULL, NULL, NULL, NULL);
draw_style_common (row_context, cr, 0, 0, 500, 50, NULL, NULL, NULL, NULL);

cairo_surface_write_to_png (surface, "listboxrow-hover-bg.png");

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.