Uli, thank you very much! I checked the bug tracker of lgi before posting, but didn't think to look at closed issues list :) The thing with cairo's toy font API: I have no idea what is that :) But I really should check textbox.lua. The problem is that I think it's very hard to know and understand the possibilities of cairo's and pango's API, because of the lack of examples and documentation (or links to them) in Awesome. May be I'm wrong, but being myself a programmer, I really thought I can learn myself, but here, with Awesome, I always have troubles. Actually the only thing I need in the wm is the possibility to organize "scrollable" (by buttons clicks) desktop at the TV screen, that I've managed to create somehow in 3.4, but, for now, not in 3.5. But enough with complaints! The community of Awesome is really awesome. Thank you, Julien, thank you, Uli, thank you all :)
On Fri, Feb 1, 2013 at 10:25 AM, Uli Schlachter <[email protected]> wrote: > Hi, > > On 31.01.2013 23:35, Vasya Belkin wrote: > > Hi, is it possible to find out text extents, e.g. width/height of string? > > Because the following code gives segmentation fault & I'm not sure, > whether > > this is a bug or not: > > > > local lgi = require 'lgi' > > local cairo = lgi.cairo > > local cr = cairo.Context(nil) > > cr:text_extents("Hello") > > I don't think it is a good idea to pass in nil as the surface to draw to. > However, this still crashes when given a proper cairo surface (at least > with > latest lgi release): > > https://github.com/pavouk/lgi/issues/37 > > > This is an example snippet, but the very same behaviour is observed in > draw > > function of real widget. > > Why are you using cairo's toy font API anyway? Text should be drawn through > Pango and querying the text extents here does work fine. Look at > /usr/share/awesome/lib/wibox/widget/textbox.lua for some examples. > > > Actually I'm trying to create a button with both image (centered) and > text > > (at the bottom), so if somebody has an implementation, please, share it. > > Big hack: > > local foo = wibox.widget.base.make_widget() > local img = wibox.widget.imagebox() > local txt = wibox.widget.textbox() > img:set_image("/tmp/foo.png") > txt:set_text("foo") > txt:set_valign("bottom") > > foo.fit = function(foo, width, height) > local wi, hi = img:fit(width, height) > local wt, ht = txt:fit(width, height) > return math.min(wi, wt), math.min(hi, ht) > end > foo.draw = function(foo, wb, cr, width, height) > wibox.layout.base.draw_widget(wb, cr, img, 0, 0, width, height) > wibox.layout.base.draw_widget(wb, cr, txt, 0, 0, width, height) > end > > This creates a new widget which just paints the img and txt widgets in the > same > spot. Centering the imagebox might need some more magic since this code > should > always draw it at the top, but I bet you'll manage to come up with > something > based on this. :-) > > Cheers, > Uli > -- > - He made himself, me nothing, you nothing out of the dust > - Er machte sich mir nichts, dir nichts aus dem Staub > > -- > To unsubscribe, send mail to [email protected]. >
