draw_text don't pad with font->height / 2 by default: padding is now an arg

This commit is contained in:
Julien Danjou 2007-12-30 14:42:51 +01:00
parent 9bc998bb76
commit 0eb4743385
5 changed files with 19 additions and 14 deletions

14
draw.c
View File

@ -54,7 +54,7 @@ draw_free_context(DrawCtx *ctx)
}
void
draw_text(DrawCtx *ctx, int x, int y, int w, int h, XftFont *font, const char *text, XColor fg, XColor bg)
draw_text(DrawCtx *ctx, int x, int y, int w, int h, int padding, XftFont *font, const char *text, XColor fg, XColor bg)
{
int nw = 0;
static char buf[256];
@ -64,7 +64,10 @@ draw_text(DrawCtx *ctx, int x, int y, int w, int h, XftFont *font, const char *t
cairo_t *cr;
draw_rectangle(ctx, x, y, w, h, True, bg);
if(!a_strlen(text))
olen = len = a_strlen(text);
if(!len)
return;
surface = cairo_xlib_surface_create(globalconf.display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
@ -74,12 +77,11 @@ draw_text(DrawCtx *ctx, int x, int y, int w, int h, XftFont *font, const char *t
cairo_set_font_size(cr, font->height);
cairo_set_source_rgb(cr, fg.red / 65535.0, fg.green / 65535.0, fg.blue / 65535.0);
olen = len = a_strlen(text);
if(len >= sizeof(buf))
len = sizeof(buf) - 1;
memcpy(buf, text, len);
buf[len] = 0;
while(len && (nw = textwidth(font, buf)) > w)
while(len && (nw = (textwidth(font, buf)) + padding * 2) > w)
buf[--len] = 0;
if(nw > w)
return; /* too long */
@ -93,7 +95,7 @@ draw_text(DrawCtx *ctx, int x, int y, int w, int h, XftFont *font, const char *t
buf[len - 3] = '.';
}
cairo_move_to(cr, x + font->height / 2, y + font->ascent + (ctx->height - font->height) / 2);
cairo_move_to(cr, x + padding, y + font->ascent + (ctx->height - font->height) / 2);
cairo_show_text(cr, buf);
cairo_font_face_destroy(font_face);
@ -271,7 +273,7 @@ textwidth(XftFont *font, char *text)
cairo_surface_destroy(surface);
cairo_font_face_destroy(font_face);
return MAX(te.x_advance, te.width) + font->height;
return MAX(te.x_advance, te.width);
}
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

2
draw.h
View File

@ -43,7 +43,7 @@ typedef struct
DrawCtx *draw_get_context(int, int, int);
void draw_free_context(DrawCtx *);
void draw_text(DrawCtx *, int, int, int, int, XftFont *, const char *, XColor fg, XColor bg);
void draw_text(DrawCtx *, int, int, int, int, int, XftFont *, const char *, XColor fg, XColor bg);
void draw_rectangle(DrawCtx *, int, int, int, int, Bool, XColor);
void draw_circle(DrawCtx *, int, int, int, Bool, XColor);
void draw_image(DrawCtx *, int, int, int, const char *);

View File

@ -52,7 +52,7 @@ focustitle_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
if(sel)
{
draw_text(ctx, widget->location, 0, vscreen.statusbar->width - used,
vscreen.statusbar->height, widget->font, sel->name,
vscreen.statusbar->height, widget->font->height / 2, widget->font, sel->name,
d->fg, d->bg);
if(sel->isfloating)
draw_circle(ctx, widget->location, 0,
@ -61,7 +61,7 @@ focustitle_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
}
else
draw_text(ctx, widget->location, 0, vscreen.statusbar->width - used,
vscreen.statusbar->height, widget->font, NULL,
vscreen.statusbar->height, widget->font->height / 2, widget->font, NULL,
d->fg, d->bg);
widget->width = vscreen.statusbar->width - used;

View File

@ -74,7 +74,7 @@ taglist_draw(Widget *widget,
widget->width = 0;
for(tag = vscreen.tags; tag; tag = tag->next)
widget->width += textwidth(vscreen.font, tag->name);
widget->width += textwidth(vscreen.font, tag->name) + vscreen.font->height;
widget->location = widget_calculate_offset(widget->statusbar->width,
widget->width,
@ -84,15 +84,17 @@ taglist_draw(Widget *widget,
widget->width = 0;
for(tag = vscreen.tags; tag; tag = tag->next)
{
w = textwidth(vscreen.font, tag->name);
w = textwidth(vscreen.font, tag->name) + vscreen.font->height;
if(tag->selected)
colors = vscreen.colors_selected;
else if(isurgent(tag))
colors = vscreen.colors_urgent;
else
colors = vscreen.colors_normal;
draw_text(ctx, widget->location + widget->width, 0, w,
vscreen.statusbar->height,
draw_text(ctx,
widget->location + widget->width, 0,
w, vscreen.statusbar->height,
vscreen.font->height / 2,
vscreen.font,
tag->name,
colors[ColFG],
@ -119,7 +121,7 @@ taglist_button_press(Widget *widget, XButtonPressedEvent *ev)
if(ev->button == b->button && CLEANMASK(ev->state) == b->mod && b->func)
for(tag = vscreen.tags; tag; tag = tag->next, i++)
{
width = textwidth(vscreen.font, tag->name);
width = textwidth(vscreen.font, tag->name) + vscreen.font->height;
if(widget->statusbar->position == BarTop
|| widget->statusbar->position == BarBot)
if(ev->x >= widget->location + prev_width

View File

@ -55,6 +55,7 @@ textbox_draw(Widget *widget, DrawCtx *ctx, int offset,
widget->alignment);
draw_text(ctx, widget->location, 0, widget->width, widget->statusbar->height,
0,
widget->font, d->text, d->fg, d->bg);
return widget->width;