[i’m not using gtksourceview but i tagged it because sourceview also does stuff with textview styling]
i’m looking for the equivalant of this dom code:
const view = document.createElement("textarea");
view.style.fontSize = some_value;
the docs Gtk – 4.0: Text Widget Overview have two examples of setting style for a textview:
1:
/* Change default font and color throughout the widget */
provider = gtk_css_provider_new ();
gtk_css_provider_load_from_data (provider,
"textview {"
" font: 15px serif;"
" color: green;"
"}",
-1);
context = gtk_widget_get_style_context (view);
gtk_style_context_add_provider (context,
GTK_STYLE_PROVIDER (provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
here, it accepts a full css string, and there doesn’t seem to be a way to change it dynamically. in theeory, one could template the string at runtime, but that would be ew, just disgusting to do
also this api is deprecated, the docs say “The relevant API has been moved to GtkWidget
where applicable”, but this is just a link to the Widget class, not any style method
2:
/* Change left margin throughout the widget */
gtk_text_view_set_left_margin (GTK_TEXT_VIEW (view), 30);
/* Use a tag to change the color for just one part of the widget */
tag = gtk_text_buffer_create_tag (buffer, "blue_foreground",
"foreground", "blue",
NULL);
gtk_text_buffer_get_iter_at_offset (buffer, &start, 7);
gtk_text_buffer_get_iter_at_offset (buffer, &end, 12);
gtk_text_buffer_apply_tag (buffer, tag, &start, &end);
this one looks good: TextTag has a :scale property, which is what i need.
i tried it, and it seems to work at first, but if i type something at the end or beginning of the text, it types outside of the tag, and so the new text is not scaled correctly
i could remove and reapply the tag on the whole view on each change, but that would probably mess with asian input methods, screen keyboards, screen readers, etc
so… this looks like a basic thing, but i’ve spent an hour failing, what am i missing here?