add pango alignment to wibox.widget.textbox

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
dodo 2011-02-27 23:41:45 +01:00 committed by Uli Schlachter
parent 8b6adbffea
commit 9befc30a7b
1 changed files with 14 additions and 1 deletions

View File

@ -1,6 +1,7 @@
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
-- @author Uli Schlachter -- @author Uli Schlachter
-- @copyright 2010 Uli Schlachter -- @author dodo
-- @copyright 2010, 2011 Uli Schlachter, dodo
-- @release @AWESOME_VERSION@ -- @release @AWESOME_VERSION@
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
@ -35,6 +36,7 @@ end
-- Setup a pango layout for the given textbox and cairo context -- Setup a pango layout for the given textbox and cairo context
local function setup_layout(box, cr, width, height) local function setup_layout(box, cr, width, height)
local layout = layout_create(cr) local layout = layout_create(cr)
layout:set_alignment(box._align)
layout:set_ellipsize(box._ellipsize) layout:set_ellipsize(box._ellipsize)
layout:set_wrap(box._wrap) layout:set_wrap(box._wrap)
layout:set_width(oopango.units_from_number(width)) layout:set_width(oopango.units_from_number(width))
@ -169,6 +171,16 @@ function set_valign(box, mode)
end end
end end
--- Set a textbox' horizontal alignment
-- @param mode Where should the textbox be drawn? "left", "center" or "right"
function set_align(box, mode)
local allowed = { left = true, center = true, right = true }
if allowed[mode] then
box._align = mode
box:emit_signal("widget::updated")
end
end
-- Returns a new textbox -- Returns a new textbox
local function new() local function new()
local ret = base.make_widget() local ret = base.make_widget()
@ -182,6 +194,7 @@ local function new()
ret._ellipsize = "end" ret._ellipsize = "end"
ret._wrap = "word_char" ret._wrap = "word_char"
ret._valign = "center" ret._valign = "center"
ret._align = "left"
return ret return ret
end end