Cairo in tooltips


Since the new tooltips API allows us to put custom widgets
in a tooltip, I thought it would be nice to make that widget
be a drawing area showing an alpha transparent Cairo drawing.
So I wrote testcairotooltips.c for fun. You can see how it
looks like [1] or even download it [2]. (I built it in gtk+/tests
so the archive also contains a small patch for

The rectangle drawing code is from cairo snippets. My first
idea was to put a balloon, but I don't know how to draw it quickly
yet since I've just started learning Cairo for real. But perhaps
the "container" drawing doesn't have to be drawn in code at all;
instead it could be loaded from a .svg with librsvg and cached
at program startup or idle time. Then some text could be rendered
over that context with Pango.

While this approach could be taken instead of the usual (mostly)
boring tooltips, a program could have something like a help mode
which would turn on extended tooltips showing more text and some
small images to help the user. This is just an idea of course.

I think that this is useful and gives more pleasant experience
to the user, thus not just useless eye candy. If you think that
it is a good idea to suggest the developers to consider making
such tooltips then perhaps it would be good to make it even easier
in the API. For instance, calling:

gtk_widget_create_tooltip_cairo_context (GtkWidget *widget, cairo_t *cr)

and a query-tooltip-draw signal (instead of query-tooltip for this
purpose) would be enough, while internally a window with the alpha
colormap would be set with drawing area for which this Cairo context
is created.

(I'm CC-ing gtk-app-devel-list since I guess there might be people
interested to hear this.)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]