draw: stop requesting extents

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2009-08-27 15:38:17 +02:00
parent 34967f7b13
commit 1060470b3f
3 changed files with 23 additions and 19 deletions

38
draw.c
View File

@ -202,12 +202,11 @@ draw_context_init(draw_context_t *d, int phys_screen,
* \param align Text alignment. * \param align Text alignment.
* \param valign Vertical text alignment. * \param valign Vertical text alignment.
* \param area Area to draw to. * \param area Area to draw to.
* \param ext Text extents.
*/ */
void void
draw_text(draw_context_t *ctx, draw_text_context_t *data, draw_text(draw_context_t *ctx, draw_text_context_t *data,
PangoEllipsizeMode ellip, PangoWrapMode wrap, PangoEllipsizeMode ellip, PangoWrapMode wrap,
alignment_t align, alignment_t valign, area_t area, area_t *ext) alignment_t align, alignment_t valign, area_t area)
{ {
pango_layout_set_text(ctx->layout, data->text, data->len); pango_layout_set_text(ctx->layout, data->text, data->len);
pango_layout_set_width(ctx->layout, pango_layout_set_width(ctx->layout,
@ -218,27 +217,32 @@ draw_text(draw_context_t *ctx, draw_text_context_t *data,
pango_layout_set_attributes(ctx->layout, data->attr_list); pango_layout_set_attributes(ctx->layout, data->attr_list);
pango_layout_set_font_description(ctx->layout, globalconf.font->desc); pango_layout_set_font_description(ctx->layout, globalconf.font->desc);
/* only honors alignment if enough space */ PangoRectangle ext;
if(ext->width < area.width) pango_layout_get_pixel_extents(ctx->layout, NULL, &ext);
switch(align)
{ /* Not enough space, draw nothing */
case AlignCenter: if(ext.width > area.width || ext.height > area.height)
area.x += (area.width - ext->width) / 2; return;
break;
case AlignRight: switch(align)
area.x += area.width - ext->width; {
break; case AlignCenter:
default: area.x += (area.width - ext.width) / 2;
break; break;
} case AlignRight:
area.x += area.width - ext.width;
break;
default:
break;
}
switch(valign) switch(valign)
{ {
case AlignCenter: case AlignCenter:
area.y += (area.height - ext->height) / 2; area.y += (area.height - ext.height) / 2;
break; break;
case AlignBottom: case AlignBottom:
area.y += area.height - ext->height; area.y += area.height - ext.height;
break; break;
default: default:
break; break;

2
draw.h
View File

@ -146,7 +146,7 @@ typedef struct
} draw_text_context_t; } draw_text_context_t;
bool draw_text_context_init(draw_text_context_t *, const char *, ssize_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, alignment_t, area_t, area_t *); void draw_text(draw_context_t *, draw_text_context_t *, PangoEllipsizeMode, PangoWrapMode, alignment_t, alignment_t, area_t);
void draw_rectangle(draw_context_t *, area_t, float, bool, const color_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, void draw_rectangle_gradient(draw_context_t *, area_t, float, bool, vector_t,
const color_t *, const color_t *, const color_t *); const color_t *, const color_t *, const color_t *);

View File

@ -191,7 +191,7 @@ textbox_draw(widget_t *widget, draw_context_t *ctx, area_t geometry, wibox_t *p)
else else
geometry.height = 0; geometry.height = 0;
draw_text(ctx, &d->data, d->ellip, d->wrap, d->align, d->valign, geometry, &d->extents); draw_text(ctx, &d->data, d->ellip, d->wrap, d->align, d->valign, geometry);
} }
/** Delete a textbox widget. /** Delete a textbox widget.