draw_text don't pad with font->height / 2 by default: padding is now an arg
This commit is contained in:
parent
9bc998bb76
commit
0eb4743385
14
draw.c
14
draw.c
|
@ -54,7 +54,7 @@ draw_free_context(DrawCtx *ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
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;
|
int nw = 0;
|
||||||
static char buf[256];
|
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;
|
cairo_t *cr;
|
||||||
|
|
||||||
draw_rectangle(ctx, x, y, w, h, True, bg);
|
draw_rectangle(ctx, x, y, w, h, True, bg);
|
||||||
if(!a_strlen(text))
|
|
||||||
|
olen = len = a_strlen(text);
|
||||||
|
|
||||||
|
if(!len)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
surface = cairo_xlib_surface_create(globalconf.display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
|
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_font_size(cr, font->height);
|
||||||
cairo_set_source_rgb(cr, fg.red / 65535.0, fg.green / 65535.0, fg.blue / 65535.0);
|
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))
|
if(len >= sizeof(buf))
|
||||||
len = sizeof(buf) - 1;
|
len = sizeof(buf) - 1;
|
||||||
memcpy(buf, text, len);
|
memcpy(buf, text, len);
|
||||||
buf[len] = 0;
|
buf[len] = 0;
|
||||||
while(len && (nw = textwidth(font, buf)) > w)
|
while(len && (nw = (textwidth(font, buf)) + padding * 2) > w)
|
||||||
buf[--len] = 0;
|
buf[--len] = 0;
|
||||||
if(nw > w)
|
if(nw > w)
|
||||||
return; /* too long */
|
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] = '.';
|
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_show_text(cr, buf);
|
||||||
|
|
||||||
cairo_font_face_destroy(font_face);
|
cairo_font_face_destroy(font_face);
|
||||||
|
@ -271,7 +273,7 @@ textwidth(XftFont *font, char *text)
|
||||||
cairo_surface_destroy(surface);
|
cairo_surface_destroy(surface);
|
||||||
cairo_font_face_destroy(font_face);
|
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
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
||||||
|
|
2
draw.h
2
draw.h
|
@ -43,7 +43,7 @@ typedef struct
|
||||||
|
|
||||||
DrawCtx *draw_get_context(int, int, int);
|
DrawCtx *draw_get_context(int, int, int);
|
||||||
void draw_free_context(DrawCtx *);
|
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_rectangle(DrawCtx *, int, int, int, int, Bool, XColor);
|
||||||
void draw_circle(DrawCtx *, int, int, int, Bool, XColor);
|
void draw_circle(DrawCtx *, int, int, int, Bool, XColor);
|
||||||
void draw_image(DrawCtx *, int, int, int, const char *);
|
void draw_image(DrawCtx *, int, int, int, const char *);
|
||||||
|
|
|
@ -52,7 +52,7 @@ focustitle_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
|
||||||
if(sel)
|
if(sel)
|
||||||
{
|
{
|
||||||
draw_text(ctx, widget->location, 0, vscreen.statusbar->width - used,
|
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);
|
d->fg, d->bg);
|
||||||
if(sel->isfloating)
|
if(sel->isfloating)
|
||||||
draw_circle(ctx, widget->location, 0,
|
draw_circle(ctx, widget->location, 0,
|
||||||
|
@ -61,7 +61,7 @@ focustitle_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
draw_text(ctx, widget->location, 0, vscreen.statusbar->width - used,
|
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);
|
d->fg, d->bg);
|
||||||
|
|
||||||
widget->width = vscreen.statusbar->width - used;
|
widget->width = vscreen.statusbar->width - used;
|
||||||
|
|
|
@ -74,7 +74,7 @@ taglist_draw(Widget *widget,
|
||||||
widget->width = 0;
|
widget->width = 0;
|
||||||
|
|
||||||
for(tag = vscreen.tags; tag; tag = tag->next)
|
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->location = widget_calculate_offset(widget->statusbar->width,
|
||||||
widget->width,
|
widget->width,
|
||||||
|
@ -84,15 +84,17 @@ taglist_draw(Widget *widget,
|
||||||
widget->width = 0;
|
widget->width = 0;
|
||||||
for(tag = vscreen.tags; tag; tag = tag->next)
|
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)
|
if(tag->selected)
|
||||||
colors = vscreen.colors_selected;
|
colors = vscreen.colors_selected;
|
||||||
else if(isurgent(tag))
|
else if(isurgent(tag))
|
||||||
colors = vscreen.colors_urgent;
|
colors = vscreen.colors_urgent;
|
||||||
else
|
else
|
||||||
colors = vscreen.colors_normal;
|
colors = vscreen.colors_normal;
|
||||||
draw_text(ctx, widget->location + widget->width, 0, w,
|
draw_text(ctx,
|
||||||
vscreen.statusbar->height,
|
widget->location + widget->width, 0,
|
||||||
|
w, vscreen.statusbar->height,
|
||||||
|
vscreen.font->height / 2,
|
||||||
vscreen.font,
|
vscreen.font,
|
||||||
tag->name,
|
tag->name,
|
||||||
colors[ColFG],
|
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)
|
if(ev->button == b->button && CLEANMASK(ev->state) == b->mod && b->func)
|
||||||
for(tag = vscreen.tags; tag; tag = tag->next, i++)
|
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
|
if(widget->statusbar->position == BarTop
|
||||||
|| widget->statusbar->position == BarBot)
|
|| widget->statusbar->position == BarBot)
|
||||||
if(ev->x >= widget->location + prev_width
|
if(ev->x >= widget->location + prev_width
|
||||||
|
|
|
@ -55,6 +55,7 @@ textbox_draw(Widget *widget, DrawCtx *ctx, int offset,
|
||||||
widget->alignment);
|
widget->alignment);
|
||||||
|
|
||||||
draw_text(ctx, widget->location, 0, widget->width, widget->statusbar->height,
|
draw_text(ctx, widget->location, 0, widget->width, widget->statusbar->height,
|
||||||
|
0,
|
||||||
widget->font, d->text, d->fg, d->bg);
|
widget->font, d->text, d->fg, d->bg);
|
||||||
|
|
||||||
return widget->width;
|
return widget->width;
|
||||||
|
|
Loading…
Reference in New Issue