Thanks for reporting, you are right. Indeed my NIm GTK3 version was working fine, but in the old C code was a bug: Here is the working version:
// https://stackoverflow.com/questions/30791670/how-to-style-a-gtklabel-with-css
// gcc `pkg-config gtk+-3.0 --cflags` test.c -o test `pkg-config --libs gtk+-3.0`
#include <gtk/gtk.h>
int main(int argc, char *argv[]) {
gtk_init(&argc, &argv);
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
GtkWidget *label = gtk_label_new("Label OiOlOx");
GtkCssProvider *cssProvider = gtk_css_provider_new();
//char *data = "label {color: green;}";
char *data = "label {font-family: monospace;}";
gtk_css_provider_load_from_data(cssProvider, data, -1, NULL);
//gtk_style_context_add_provider(gtk_widget_get_style_context(window),
gtk_style_context_add_provider(gtk_widget_get_style_context(label),
GTK_STYLE_PROVIDER(cssProvider),
GTK_STYLE_PROVIDER_PRIORITY_USER);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
gtk_container_add(GTK_CONTAINER(window), label);
gtk_widget_show_all(window);
gtk_main();
}
For the books: For GTK3 there is not much, I am aware of a Python GTK3 book, based on the GTK2 book of A. Krause. I have seen a few pages, would not recommend. But GTK4 is out for more than a year now. There is a free C book, see GitHub - ToshioCP/Gtk4-tutorial: GTK 4 tutorial for beginners. There is my GTK4 Nim one, at least a start: GTK4 for Graphical User Interfaces. And there are the Michi B youtube videos. For more see