So I've been working on making a lovely little eye-candy calendar widget to display with
my Conky Widgets script, but I ran into a snag...Here's the best version I got before giving up (for now!):
Can you spot the annoyingness yet?
The text is misaligned!
As it turns out, Cairo draws text from an anchor point roughly at the lower left corner of the text being displayed. In this code, the month name/year, days of the week and day numbers are all evenly spaced on a square grid, but they look uneven because they are anchored at that lower-left position.
What I really want is for each element to be centered in a block. So the month/year is centered in a block that spans the top of the widget, and each of the day numbers is centered in a small square, like on a printed calendar.
However, in Cairo, you can't change where a text element is anchored, but you CAN use a function called
cairo_text_extents() to give you some size information about the text block you want to manipulate, and then move to an appropriate start point. (See the
Cairo tutorial for a more detailed explanation.)
I must have spent hours trying to get this function to work before I finally gave in and asked the Conky devs...and got this response: "tolua++ doesn't export any creation functions (or constructors) for C structures, only C++ classes." Basically, the third argument in the cairo_text_extents() function is of the structure
cairo_text_extents_t, which isn't recognised by Lua.
All this roughly translated: as it stands now, we can't do any sophisticated text manipulation using Cairo in Lua. Booooo.
So the calendar is going to one side for the time being. Incidentally, if you would like to grab the Lua code for this widget,
here you go.