How to make a "marquee" GtkLabel?

Is it possible to animate the contents of a GtkLabel to be scrolling as a “marquee” (similarly to what the deprecated HTML tag <marquee> did)?

I found out that the most promising way in GTK4 was to put my label as a child of a GtkViewport, but I can’t figure out how to animate the scrolling using CSS… What I did find was a way to use g_timeout_add to update the viewport’s adjustment manually. Is this the correct approach or is there a better solution?

Thank you.

That’s a perfectly adequate solution, though you really want to use gtk_widget_add_tick_callback() instead of g_timeout_add(), as tick callbacks will be synchronised to GTK’s frame cycle.

1 Like