From 26c446fa8254e40b4e1740455860ce1d15a6999e Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 25 Aug 2009 17:35:57 +0200 Subject: [PATCH] textbox: add valign Signed-off-by: Julien Danjou --- common/tokenize.gperf | 1 + draw.c | 15 ++++++++++++++- draw.h | 2 +- widgets/textbox.c | 13 ++++++++++--- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/common/tokenize.gperf b/common/tokenize.gperf index e35b21f8..48bbde71 100644 --- a/common/tokenize.gperf +++ b/common/tokenize.gperf @@ -111,6 +111,7 @@ top transient_for type urgent +valign version vertical visible diff --git a/draw.c b/draw.c index f79e9937..c997cbcf 100644 --- a/draw.c +++ b/draw.c @@ -200,6 +200,7 @@ draw_context_init(draw_context_t *d, int phys_screen, * \param ellip Ellipsize mode. * \param wrap Wrap mode. * \param align Text alignment. + * \param valign Vertical text alignment. * \param margin Margin to respect when drawing text. * \param area Area to draw to. * \param ext Text extents. @@ -207,7 +208,7 @@ draw_context_init(draw_context_t *d, int phys_screen, void draw_text(draw_context_t *ctx, draw_text_context_t *data, PangoEllipsizeMode ellip, PangoWrapMode wrap, - alignment_t align, padding_t *margin, area_t area, area_t *ext) + alignment_t align, alignment_t valign, padding_t *margin, area_t area, area_t *ext) { int x, y; @@ -240,6 +241,18 @@ draw_text(draw_context_t *ctx, draw_text_context_t *data, break; } + switch(valign) + { + case AlignCenter: + y += (area.height - ext->height) / 2; + break; + case AlignBottom: + y += area.height - ext->height; + break; + default: + break; + } + cairo_move_to(ctx->cr, x, y); cairo_set_source_rgba(ctx->cr, diff --git a/draw.h b/draw.h index 0124838b..d1752b21 100644 --- a/draw.h +++ b/draw.h @@ -159,7 +159,7 @@ typedef struct } draw_text_context_t; bool draw_text_context_init(draw_text_context_t *, const char *, ssize_t); -void draw_text(draw_context_t *, draw_text_context_t *, PangoEllipsizeMode, PangoWrapMode, alignment_t, padding_t *, area_t, area_t *); +void draw_text(draw_context_t *, draw_text_context_t *, PangoEllipsizeMode, PangoWrapMode, alignment_t, alignment_t, padding_t *, area_t, area_t *); void draw_rectangle(draw_context_t *, area_t, float, bool, const color_t *); void draw_rectangle_gradient(draw_context_t *, area_t, float, bool, vector_t, const color_t *, const color_t *, const color_t *); diff --git a/widgets/textbox.c b/widgets/textbox.c index 269167b4..74578da6 100644 --- a/widgets/textbox.c +++ b/widgets/textbox.c @@ -41,7 +41,7 @@ typedef struct color_t color; } border; /** Text alignment */ - alignment_t align; + alignment_t align, valign; /** Margin */ padding_t margin; /** Background color */ @@ -128,8 +128,7 @@ textbox_draw(widget_t *widget, draw_context_t *ctx, area_t geometry, wibox_t *p) } } - geometry.y += (geometry.height - textbox_geometry(widget, ctx->phys_screen).height) / 2; - draw_text(ctx, &d->data, d->ellip, d->wrap, d->align, &d->margin, geometry, &d->extents); + draw_text(ctx, &d->data, d->ellip, d->wrap, d->align, d->valign, &d->margin, geometry, &d->extents); } /** Delete a textbox widget. @@ -200,6 +199,9 @@ luaA_textbox_index(lua_State *L, awesome_token_t token) case A_TK_ALIGN: lua_pushstring(L, draw_align_tostr(d->align)); return 1; + case A_TK_VALIGN: + lua_pushstring(L, draw_align_tostr(d->valign)); + return 1; case A_TK_BORDER_WIDTH: lua_pushnumber(L, d->border.width); return 1; @@ -285,6 +287,10 @@ luaA_textbox_newindex(lua_State *L, awesome_token_t token) if((buf = luaL_checklstring(L, 3, &len))) d->align = draw_align_fromstr(buf, len); break; + case A_TK_VALIGN: + if((buf = luaL_checklstring(L, 3, &len))) + d->valign = draw_align_fromstr(buf, len); + break; case A_TK_BORDER_COLOR: if((buf = luaL_checklstring(L, 3, &len))) color_init_reply(color_init_unchecked(&d->border.color, buf, len)); @@ -381,6 +387,7 @@ widget_textbox(widget_t *w) textbox_data_t *d = w->data = p_new(textbox_data_t, 1); d->ellip = PANGO_ELLIPSIZE_END; + d->valign = AlignCenter; return w; }