Be compatible to oopango 1.0

Some idiot broke the API in oopango git. Work-around this by checking which
version of oopango we have.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2010-10-06 15:11:20 +02:00
parent 9b40f19f5c
commit bddecffe97
2 changed files with 27 additions and 4 deletions

View file

@ -44,7 +44,14 @@ local function set_font(f)
-- Create a temporary surface that we need for computing the size :(
local surface = capi.oocairo.image_surface_create("argb32", 1, 1)
local cr = capi.oocairo.context_create(surface)
local layout = capi.oopango.cairo.layout_create(cr)
local layout
-- Api breakage in oopango
if capi.oopango.cairo_layout_create then
layout = capi.oopango.cairo_layout_create(cr)
else
layout = capi.oopango.cairo.layout_create(cr)
end
layout:set_font_description(font)
local width, height = layout:get_pixel_size()

View file

@ -15,9 +15,26 @@ local pairs = pairs
module("wibox.widget.textbox")
local function layout_create(cr)
if oopango.cairo_layout_create then
return oopango.cairo_layout_create(cr)
end
return oopango.cairo.layout_create(cr)
end
local function update_and_show(cr, layout)
if oopango.cairo_update_layout then
oopango.cairo_update_layout(cr, layout)
oopango.cairo_show_layout(cr, layout)
else
oopango.cairo.update_layout(cr, layout)
oopango.cairo.show_layout(cr, layout)
end
end
-- Setup a pango layout for the given textbox and cairo context
local function setup_layout(box, cr, width, height)
local layout = oopango.cairo.layout_create(cr)
local layout = layout_create(cr)
layout:set_ellipsize(box.ellipsize)
layout:set_wrap(box.wrap)
layout:set_width(oopango.units_from_number(width))
@ -82,8 +99,7 @@ function draw(box, wibox, cr, width, height)
local layout = setup_layout(box, cr, width, height)
oopango.cairo.update_layout(cr, layout)
oopango.cairo.show_layout(cr, layout)
update_and_show(cr, layout)
end
--- Fit the given textbox