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