textbox: stop parsing text on each draw
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
6ae0d554a8
commit
5ad9b2025c
|
@ -33,6 +33,10 @@ typedef struct
|
||||||
size_t len;
|
size_t len;
|
||||||
/** Textbox width */
|
/** Textbox width */
|
||||||
int width;
|
int width;
|
||||||
|
/** Extents */
|
||||||
|
int extents;
|
||||||
|
/** Draw parser data */
|
||||||
|
draw_parser_data_t pdata;
|
||||||
} textbox_data_t;
|
} textbox_data_t;
|
||||||
|
|
||||||
/** Draw a textbox widget.
|
/** Draw a textbox widget.
|
||||||
|
@ -53,7 +57,6 @@ textbox_draw(draw_context_t *ctx, int screen __attribute__ ((unused)),
|
||||||
awesome_type_t type)
|
awesome_type_t type)
|
||||||
{
|
{
|
||||||
textbox_data_t *d = w->widget->data;
|
textbox_data_t *d = w->widget->data;
|
||||||
draw_parser_data_t pdata, *pdata_arg = NULL;
|
|
||||||
|
|
||||||
w->area.height = ctx->height;
|
w->area.height = ctx->height;
|
||||||
|
|
||||||
|
@ -63,17 +66,11 @@ textbox_draw(draw_context_t *ctx, int screen __attribute__ ((unused)),
|
||||||
w->area.width = ctx->width - used;
|
w->area.width = ctx->width - used;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
draw_parser_data_init(&pdata);
|
w->area.width = MIN(d->extents, ctx->width - used);
|
||||||
pdata_arg = &pdata;
|
|
||||||
w->area.width = draw_text_extents(ctx->connection, ctx->phys_screen,
|
|
||||||
globalconf.font, d->text, d->len, &pdata).width;
|
|
||||||
|
|
||||||
if(w->area.width > ctx->width - used)
|
if(d->pdata.bg_image)
|
||||||
w->area.width = ctx->width - used;
|
|
||||||
|
|
||||||
if(pdata.bg_image)
|
|
||||||
w->area.width = MAX(w->area.width,
|
w->area.width = MAX(w->area.width,
|
||||||
pdata.bg_resize ? ((double) pdata.bg_image->width / (double) pdata.bg_image->height) * w->area.height : pdata.bg_image->width);
|
d->pdata.bg_resize ? ((double) d->pdata.bg_image->width / (double) d->pdata.bg_image->height) * w->area.height : d->pdata.bg_image->width);
|
||||||
}
|
}
|
||||||
|
|
||||||
w->area.x = widget_calculate_offset(ctx->width,
|
w->area.x = widget_calculate_offset(ctx->width,
|
||||||
|
@ -82,9 +79,7 @@ textbox_draw(draw_context_t *ctx, int screen __attribute__ ((unused)),
|
||||||
w->widget->align);
|
w->widget->align);
|
||||||
w->area.y = 0;
|
w->area.y = 0;
|
||||||
|
|
||||||
draw_text(ctx, globalconf.font, w->area, d->text, d->len, pdata_arg);
|
draw_text(ctx, globalconf.font, w->area, d->text, d->len, &d->pdata);
|
||||||
if (pdata_arg)
|
|
||||||
draw_parser_data_wipe(pdata_arg);
|
|
||||||
|
|
||||||
return w->area.width;
|
return w->area.width;
|
||||||
}
|
}
|
||||||
|
@ -96,6 +91,7 @@ static void
|
||||||
textbox_destructor(widget_t *w)
|
textbox_destructor(widget_t *w)
|
||||||
{
|
{
|
||||||
textbox_data_t *d = w->data;
|
textbox_data_t *d = w->data;
|
||||||
|
draw_parser_data_wipe(&d->pdata);
|
||||||
p_delete(&d->text);
|
p_delete(&d->text);
|
||||||
p_delete(&d);
|
p_delete(&d);
|
||||||
}
|
}
|
||||||
|
@ -148,10 +144,19 @@ luaA_textbox_newindex(lua_State *L, awesome_token_t token)
|
||||||
if(lua_isnil(L, 3)
|
if(lua_isnil(L, 3)
|
||||||
|| (buf = luaL_checklstring(L, 3, &len)))
|
|| (buf = luaL_checklstring(L, 3, &len)))
|
||||||
{
|
{
|
||||||
|
/* delete */
|
||||||
|
draw_parser_data_wipe(&d->pdata);
|
||||||
p_delete(&d->text);
|
p_delete(&d->text);
|
||||||
if(buf)
|
|
||||||
a_iso2utf8(&d->text, buf, len);
|
/* re-init */
|
||||||
d->len = len;
|
d->len = len;
|
||||||
|
if(buf)
|
||||||
|
{
|
||||||
|
a_iso2utf8(&d->text, buf, len);
|
||||||
|
draw_parser_data_init(&d->pdata);
|
||||||
|
d->extents = draw_text_extents(globalconf.connection, globalconf.default_screen,
|
||||||
|
globalconf.font, d->text, d->len, &d->pdata).width;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case A_TK_WIDTH:
|
case A_TK_WIDTH:
|
||||||
|
|
Loading…
Reference in New Issue