draw: stop requesting extents
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
34967f7b13
commit
1060470b3f
20
draw.c
20
draw.c
|
@ -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,15 +217,20 @@ 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);
|
||||||
|
|
||||||
|
/* Not enough space, draw nothing */
|
||||||
|
if(ext.width > area.width || ext.height > area.height)
|
||||||
|
return;
|
||||||
|
|
||||||
switch(align)
|
switch(align)
|
||||||
{
|
{
|
||||||
case AlignCenter:
|
case AlignCenter:
|
||||||
area.x += (area.width - ext->width) / 2;
|
area.x += (area.width - ext.width) / 2;
|
||||||
break;
|
break;
|
||||||
case AlignRight:
|
case AlignRight:
|
||||||
area.x += area.width - ext->width;
|
area.x += area.width - ext.width;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -235,10 +239,10 @@ draw_text(draw_context_t *ctx, draw_text_context_t *data,
|
||||||
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
2
draw.h
|
@ -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 *);
|
||||||
|
|
|
@ -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.
|
||||||
|
|
Loading…
Reference in New Issue