widgets/textbox.c area.x miscalculation due to variable width

This commit is contained in:
Nikos Ntarmos 2008-01-05 03:44:39 +02:00 committed by Julien Danjou
parent 2476faf85d
commit 64658bcf93
7 changed files with 34 additions and 28 deletions

View File

@ -43,31 +43,32 @@ focustitle_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
{ {
Data *d = widget->data; Data *d = widget->data;
Client *sel = focus_get_current_client(widget->statusbar->screen); Client *sel = focus_get_current_client(widget->statusbar->screen);
Area widget_area = widget->area;
if(widget->area.x < 0) if(widget->area.x < 0)
widget->area.x = widget_calculate_offset(widget->statusbar->width, widget_area.x = widget_calculate_offset(widget->statusbar->width,
0, 0,
offset, offset,
widget->alignment); widget->alignment);
if(widget->area.y < 0) if(widget->area.y < 0)
widget->area.y = 0; widget_area.y = 0;
if(sel) if(sel)
{ {
draw_text(ctx, widget->area.x, widget->area.y, draw_text(ctx, widget_area.x, widget_area.y,
widget->statusbar->width - used, widget->statusbar->width - used,
widget->statusbar->height, widget->statusbar->height,
d->align, d->align,
widget->font->height / 2, widget->font, sel->name, widget->font->height / 2, widget->font, sel->name,
d->fg, d->bg); d->fg, d->bg);
if(sel->isfloating) if(sel->isfloating)
draw_circle(ctx, widget->area.x, widget->area.y, draw_circle(ctx, widget_area.x, widget_area.y,
(widget->font->height + 2) / 4, (widget->font->height + 2) / 4,
sel->ismax, d->fg); sel->ismax, d->fg);
} }
else else
draw_rectangle(ctx, widget->area.x, widget->area.y, draw_rectangle(ctx, widget_area.x, widget_area.y,
widget->statusbar->width - used, widget->statusbar->height, True, d->bg); widget->statusbar->width - used, widget->statusbar->height, True, d->bg);
widget->area.width = widget->statusbar->width - used; widget->area.width = widget->statusbar->width - used;

View File

@ -35,7 +35,7 @@ iconbox_draw(Widget *widget, DrawCtx *ctx, int offset,
int used __attribute__ ((unused))) int used __attribute__ ((unused)))
{ {
Data *d = widget->data; Data *d = widget->data;
Area area = draw_get_image_size(d->image); Area area = draw_get_image_size(d->image), widget_area = widget->area;
if(d->resize) if(d->resize)
widget->area.width = ((double) widget->statusbar->height / area.height) * area.width; widget->area.width = ((double) widget->statusbar->height / area.height) * area.width;
@ -43,15 +43,15 @@ iconbox_draw(Widget *widget, DrawCtx *ctx, int offset,
widget->area.width = area.width; widget->area.width = area.width;
if(widget->area.x < 0) if(widget->area.x < 0)
widget->area.x = widget_calculate_offset(widget->statusbar->width, widget_area.x = widget_calculate_offset(widget->statusbar->width,
widget->area.width, widget->area.width,
offset, offset,
widget->alignment); widget->alignment);
if(widget->area.y < 0) if(widget->area.y < 0)
widget->area.y = 0; widget_area.y = 0;
draw_image(ctx, widget->area.x, widget->area.y, draw_image(ctx, widget_area.x, widget_area.y,
d->resize ? widget->statusbar->height : 0, d->image); d->resize ? widget->statusbar->height : 0, d->image);
return widget->area.width; return widget->area.width;

View File

@ -34,19 +34,20 @@ layoutinfo_draw(Widget *widget,
int used __attribute__ ((unused))) int used __attribute__ ((unused)))
{ {
Tag **curtags = get_current_tags(widget->statusbar->screen); Tag **curtags = get_current_tags(widget->statusbar->screen);
Area widget_area = widget->area;
if(widget->area.x < 0) if(widget->area.x < 0)
widget->area.x = widget_calculate_offset(widget->statusbar->width, widget_area.x = widget_calculate_offset(widget->statusbar->width,
widget->statusbar->height, widget->statusbar->height,
offset, offset,
widget->alignment); widget->alignment);
if(widget->area.y < 0) if(widget->area.y < 0)
widget->area.y = 0; widget_area.y = 0;
widget->area.width = widget->statusbar->height; widget->area.width = widget->statusbar->height;
draw_image(ctx, widget->area.x, widget->area.y, draw_image(ctx, widget_area.x, widget_area.y,
widget->statusbar->height, widget->statusbar->height,
curtags[0]->layout->image); curtags[0]->layout->image);

View File

@ -34,7 +34,7 @@ static int
netwmicon_draw(Widget *widget, DrawCtx *ctx, int offset, netwmicon_draw(Widget *widget, DrawCtx *ctx, int offset,
int used __attribute__ ((unused))) int used __attribute__ ((unused)))
{ {
Area area; Area area, widget_area = widget->area;
Rule* r; Rule* r;
Client *sel = focus_get_current_client(widget->statusbar->screen); Client *sel = focus_get_current_client(widget->statusbar->screen);
NetWMIcon *icon; NetWMIcon *icon;
@ -52,14 +52,14 @@ netwmicon_draw(Widget *widget, DrawCtx *ctx, int offset,
widget->area.width = ((double) widget->statusbar->height / (double) area.height) widget->area.width = ((double) widget->statusbar->height / (double) area.height)
* area.width; * area.width;
if(widget->area.x < 0) if(widget->area.x < 0)
widget->area.x = widget_calculate_offset(widget->statusbar->width, widget_area.x = widget_calculate_offset(widget->statusbar->width,
widget->area.width, widget->area.width,
offset, offset,
widget->alignment); widget->alignment);
if(widget->area.y < 0) if(widget->area.y < 0)
widget->area.y = 0; widget_area.y = 0;
draw_image(ctx, widget->area.x, widget->area.y, draw_image(ctx, widget_area.x, widget_area.y,
widget->statusbar->height, r->icon); widget->statusbar->height, r->icon);
return widget->area.width; return widget->area.width;
@ -75,16 +75,16 @@ netwmicon_draw(Widget *widget, DrawCtx *ctx, int offset,
widget->area.width = ((double) widget->statusbar->height / (double) icon->height) * icon->width; widget->area.width = ((double) widget->statusbar->height / (double) icon->height) * icon->width;
if(widget->area.x < 0) if(widget->area.x < 0)
widget->area.x = widget_calculate_offset(widget->statusbar->width, widget_area.x = widget_calculate_offset(widget->statusbar->width,
widget->area.width, widget->area.width,
offset, offset,
widget->alignment); widget->alignment);
if(widget->area.y < 0) if(widget->area.y < 0)
widget->area.y = 0; widget_area.y = 0;
draw_image_from_argb_data(ctx, draw_image_from_argb_data(ctx,
widget->area.x, widget->area.y, widget_area.x, widget_area.y,
icon->width, icon->height, icon->width, icon->height,
widget->statusbar->height, icon->image); widget->statusbar->height, icon->image);

View File

@ -55,6 +55,7 @@ progressbar_draw(Widget *widget, DrawCtx *ctx, int offset,
int used __attribute__ ((unused))) int used __attribute__ ((unused)))
{ {
int i, width, pwidth, margin_top, pb_height, left_offset; int i, width, pwidth, margin_top, pb_height, left_offset;
Area widget_area = widget->area;
Data *d = widget->data; Data *d = widget->data;
@ -64,17 +65,17 @@ progressbar_draw(Widget *widget, DrawCtx *ctx, int offset,
width = d->width - d->lpadding; width = d->width - d->lpadding;
if(widget->area.x < 0) if(widget->area.x < 0)
widget->area.x = widget_calculate_offset(widget->statusbar->width, widget_area.x = widget_calculate_offset(widget->statusbar->width,
d->width, d->width,
offset, offset,
widget->alignment); widget->alignment);
if(widget->area.y < 0) if(widget->area.y < 0)
widget->area.y = 0; widget_area.y = 0;
margin_top = (int) (widget->statusbar->height * (1 - d->height)) / 2 + 0.5 + widget->area.y; margin_top = (int) (widget->statusbar->height * (1 - d->height)) / 2 + 0.5 + widget_area.y;
pb_height = (int) (widget->statusbar->height * d->height - (d->gap * (d->bars - 1))) / d->bars + 0.5; pb_height = (int) (widget->statusbar->height * d->height - (d->gap * (d->bars - 1))) / d->bars + 0.5;
left_offset = widget->area.x + d->lpadding; left_offset = widget_area.x + d->lpadding;
for(i = 0; i < d->bars; i++) for(i = 0; i < d->bars; i++)
{ {

View File

@ -75,8 +75,7 @@ taglist_draw(Widget *widget,
for(tag = vscreen.tags; tag; tag = tag->next) for(tag = vscreen.tags; tag; tag = tag->next)
widget->area.width += textwidth(vscreen.font, tag->name) + vscreen.font->height; widget->area.width += textwidth(vscreen.font, tag->name) + vscreen.font->height;
if(widget->area.x < 0) widget->area.x = widget_calculate_offset(widget->statusbar->width,
widget->area.x = widget_calculate_offset(widget->statusbar->width,
widget->area.width, widget->area.width,
offset, offset,
widget->alignment); widget->alignment);

View File

@ -40,6 +40,7 @@ textbox_draw(Widget *widget, DrawCtx *ctx, int offset,
int used __attribute__ ((unused))) int used __attribute__ ((unused)))
{ {
Data *d = widget->data; Data *d = widget->data;
Area widget_area = widget->area;
if(d->width) if(d->width)
widget->area.width = d->width; widget->area.width = d->width;
@ -47,13 +48,16 @@ textbox_draw(Widget *widget, DrawCtx *ctx, int offset,
widget->area.width = textwidth(widget->font, d->text); widget->area.width = textwidth(widget->font, d->text);
if(widget->area.x < 0) if(widget->area.x < 0)
widget->area.x = widget_calculate_offset(widget->statusbar->width, widget_area.x = widget_calculate_offset(widget->statusbar->width,
widget->area.width, widget->area.width,
offset, offset,
widget->alignment); widget->alignment);
if(widget->area.y < 0)
widget_area.y = 0;
draw_text(ctx, widget->area.x, 0, widget->area.width, widget->statusbar->height, draw_text(ctx, widget_area.x, widget_area.y, widget->area.width,
d->align, 0, widget->font, d->text, d->fg, d->bg); widget->statusbar->height, d->align, 0, widget->font,
d->text, d->fg, d->bg);
return widget->area.width; return widget->area.width;
} }