I don’t think there is a way to do that automatically.
Pango (the GTK text renderer) supports properties like font-stretch and letter-spacing, which are also exposed to CSS, that could be something to explore.
void update_font_stretch(GtkEntry *entry) {
PangoLayout *layout = gtk_entry_get_layout(entry);
// Get the width of the GtkEntry widget
int widget_width = gtk_widget_get_allocated_width(GTK_WIDGET(entry));
// Get the current text width and height (height is not used here)
int text_width, text_height;
pango_layout_get_size(layout, &text_width, &text_height);
text_width /= PANGO_SCALE;
// Calculate the desired stretch factor
double stretch_factor = (text_width > widget_width) ? (double)widget_width / text_width : 1.0;
// Create a Pango attribute for font stretch
PangoAttrList *attr_list = pango_attr_list_new();
PangoAttribute *attr = pango_attr_stretch_new((PangoStretch)(PANGO_STRETCH_NORMAL * stretch_factor));
pango_attr_list_insert(attr_list, attr);
gtk_entry_set_attributes(entry, attr_list);
pango_attr_list_unref(attr_list);
}
I called this function when every time user pressed something. But it did not work. Can you help me get it right