I have some GtkTextTable*mom_tagtable;
which is the tag table of a GtkTextBuffer *mom_obtextbuf;
(which is shown in two text views GtkWidget *mom_tview1;
& GtkWidget*mom_tview2;
). I'm using GTK3.21 on Linux/Debian/Sid and it is for the same (free software, GPLv3) application than in this other question: the expjs branch (on github
) of the MELT monitor. BTW all the GTK code is in one C99 file gui.c. I have a few dozen of text tags:
static GtkTextTag *mom_tag_toptitle; // tag for top text
static GtkTextTag *mom_tag_objtitle; // tag for object title line
static GtkTextTag *mom_tag_objsubtitle; // tag for object subtitle line
static GtkTextTag *mom_tag_idstart; // tag for first characters of objids
/* etc .... */
I don't want to build my GUI using GtkBuilder
(I prefer coding manually, because most of the code could be later generated by my application). I would like to customize the appearance of the tags and of all my app in the same textual file. It seems that GTK CSS stylesheets could be useful.
Actually, it looks that GTK3 has or had several ways to describe the look&feel and theme of an application in textual files (GtkBuilder which also defines the GUI and I don't want to have that, GTK-CSS stylesheets, obsolete Gtk resource files, obsolete GtkUIManager, etc...) and that it is transitioning to the GTK CSS framework but the transition did not complete in GTK3.20.
I'm currently initializing these tags using hard-coded look & feel:
mom_tag_toptitle =
gtk_text_buffer_create_tag (mom_obtextbuf,
"toptitle",
"justification", GTK_JUSTIFY_CENTER,
"pixels-above-lines", 2,
"pixels-below-lines", 4,
"foreground", "navy",
"paragraph-background", "lightyellow",
"font", "Helvetica Bold", "scale", 1.5, NULL);
mom_tag_objtitle =
gtk_text_buffer_create_tag (mom_obtextbuf,
"objtitle",
"justification", GTK_JUSTIFY_CENTER,
"pixels-above-lines", 4,
"pixels-below-lines", 2,
"foreground", "brown",
"font", "Sans Bold",
"paragraph-background", "lightcyan",
"scale", 1.3, NULL);
mom_tag_objsubtitle =
gtk_text_buffer_create_tag (mom_obtextbuf,
"objsubtitle",
"justification", GTK_JUSTIFY_CENTER,
"pixels-above-lines", 1,
"pixels-below-lines", 1,
"foreground", "chocolate4",
"font", "Sans Bold",
"paragraph-background", "lightgoldenrod",
"scale", 1.15, NULL);
mom_tag_idstart =
gtk_text_buffer_create_tag (mom_obtextbuf,
"idstart",
"font", "Courier Bold",
"foreground", "darkgreen", NULL);
I am not happy with that approach, and I would like these tags to have an appearance (font, size, colors) described in some external textual file (and likewise for the widgets around the textviews).
So my question is:
How to customize GtkTextTag
-s thru GTK CSS stylesheets?
I was thinking of creating some "fake" GtkWidgetPath (should I create one such path per gtk text tag) and using it to retrieve the style information in the GTK CSS but I am not sure at all it is the right approach.
I also don't understand exactly how two different text views showing the same text buffers can have different styles for the same text (I hope it is not possible, but I am not sure why).
This might be a related question, but it looks quite different to mine.
PS. I am not specifically focused on GTK3 CSS, but I do want to have if possible one single text file describing the appearance of my entire GTK3 application.