add a align option to draw_text
This commit is contained in:
parent
15db0d2824
commit
aed3e569de
14
draw.c
14
draw.c
|
@ -66,6 +66,7 @@ draw_free_context(DrawCtx *ctx)
|
|||
* \param y y coord
|
||||
* \param w width
|
||||
* \param h height
|
||||
* \param align alignment
|
||||
* \param padding padding to add before drawing the text
|
||||
* \param font font to use
|
||||
* \param text text to draw
|
||||
|
@ -73,7 +74,13 @@ draw_free_context(DrawCtx *ctx)
|
|||
* \param bg background color
|
||||
*/
|
||||
void
|
||||
draw_text(DrawCtx *ctx, int x, int y, int w, int h, int padding, XftFont *font, const char *text, XColor fg, XColor bg)
|
||||
draw_text(DrawCtx *ctx,
|
||||
int x, int y,
|
||||
int w, int h,
|
||||
int align,
|
||||
int padding,
|
||||
XftFont *font, const char *text,
|
||||
XColor fg, XColor bg)
|
||||
{
|
||||
int nw = 0;
|
||||
static char buf[256];
|
||||
|
@ -114,7 +121,12 @@ draw_text(DrawCtx *ctx, int x, int y, int w, int h, int padding, XftFont *font,
|
|||
buf[len - 3] = '.';
|
||||
}
|
||||
|
||||
if(align == AlignLeft)
|
||||
cairo_move_to(cr, x + padding, y + font->ascent + (ctx->height - font->height) / 2);
|
||||
else if(align == AlignRight)
|
||||
cairo_move_to(cr, x + (w - nw) + padding, y + font->ascent + (ctx->height - font->height) / 2);
|
||||
else
|
||||
cairo_move_to(cr, x + ((w - nw) / 2) + padding, y + font->ascent + (ctx->height - font->height) / 2);
|
||||
cairo_show_text(cr, buf);
|
||||
|
||||
cairo_font_face_destroy(font_face);
|
||||
|
|
4
draw.h
4
draw.h
|
@ -25,6 +25,8 @@
|
|||
#include <X11/Xlib.h>
|
||||
#include <X11/Xft/Xft.h>
|
||||
|
||||
enum { AlignLeft, AlignRight, AlignFlex, AlignCenter };
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/* Co-ords of upper left corner */
|
||||
|
@ -46,7 +48,7 @@ typedef struct
|
|||
|
||||
DrawCtx *draw_get_context(int, int, int);
|
||||
void draw_free_context(DrawCtx *);
|
||||
void draw_text(DrawCtx *, int, int, int, int, int, XftFont *, const char *, XColor fg, XColor bg);
|
||||
void draw_text(DrawCtx *, int, 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 *);
|
||||
|
|
2
widget.h
2
widget.h
|
@ -27,8 +27,6 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
enum { AlignLeft, AlignRight, AlignFlex };
|
||||
|
||||
typedef Widget *(WidgetConstructor)(Statusbar *, cfg_t *);
|
||||
|
||||
int widget_calculate_offset(int, int, int, int);
|
||||
|
|
|
@ -51,8 +51,11 @@ 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->height / 2, widget->font, sel->name,
|
||||
draw_text(ctx, widget->location, 0,
|
||||
vscreen.statusbar->width - used,
|
||||
vscreen.statusbar->height,
|
||||
AlignLeft,
|
||||
widget->font->height / 2, widget->font, sel->name,
|
||||
d->fg, d->bg);
|
||||
if(sel->isfloating)
|
||||
draw_circle(ctx, widget->location, 0,
|
||||
|
|
|
@ -93,6 +93,7 @@ taglist_draw(Widget *widget,
|
|||
draw_text(ctx,
|
||||
widget->location + widget->width, 0,
|
||||
w, vscreen.statusbar->height,
|
||||
AlignCenter,
|
||||
vscreen.font->height / 2,
|
||||
vscreen.font,
|
||||
tag->name,
|
||||
|
|
|
@ -74,6 +74,7 @@ tasklist_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
|
|||
draw_text(ctx, widget->location + box_width * i, 0,
|
||||
box_width,
|
||||
vscreen.statusbar->height,
|
||||
AlignLeft,
|
||||
widget->font->height / 2, widget->font, c->name,
|
||||
d->fg_sel, d->bg_sel);
|
||||
}
|
||||
|
@ -81,6 +82,7 @@ tasklist_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
|
|||
draw_text(ctx, widget->location + box_width * i, 0,
|
||||
box_width,
|
||||
vscreen.statusbar->height,
|
||||
AlignLeft,
|
||||
widget->font->height / 2, widget->font, c->name,
|
||||
d->fg, d->bg);
|
||||
if(sel->isfloating)
|
||||
|
|
|
@ -51,7 +51,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);
|
||||
AlignCenter, 0, widget->font, d->text, d->fg, d->bg);
|
||||
|
||||
return widget->width;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue