typedef enum Alignment

This commit is contained in:
Julien Danjou 2008-01-04 19:17:20 +01:00
parent af6ff367eb
commit 1d6613349e
7 changed files with 27 additions and 11 deletions

View File

@ -103,7 +103,7 @@ struct Widget
/** Statusbar */
Statusbar *statusbar;
/** Alignement */
int alignment;
Alignment alignment;
/** Misc private data */
void *data;
/** Location on status bar */

14
draw.c
View File

@ -121,12 +121,18 @@ draw_text(DrawCtx *ctx,
buf[len - 3] = '.';
}
if(align == AlignLeft)
switch(align)
{
case AlignLeft:
cairo_move_to(cr, x + padding, y + font->ascent + (ctx->height - font->height) / 2);
else if(align == AlignRight)
break;
case AlignRight:
cairo_move_to(cr, x + (w - nw) + padding, y + font->ascent + (ctx->height - font->height) / 2);
else
break;
default:
cairo_move_to(cr, x + ((w - nw) / 2) + padding, y + font->ascent + (ctx->height - font->height) / 2);
break;
}
cairo_show_text(cr, buf);
cairo_font_face_destroy(font_face);
@ -309,7 +315,7 @@ textwidth(XftFont *font, char *text)
return MAX(te.x_advance, te.width);
}
int
Alignment
draw_get_align(const char *align)
{
if(!a_strncmp(align, "center", 6))

10
draw.h
View File

@ -25,7 +25,13 @@
#include <X11/Xlib.h>
#include <X11/Xft/Xft.h>
enum { AlignLeft, AlignRight, AlignFlex, AlignCenter };
typedef enum
{
AlignLeft,
AlignRight,
AlignFlex,
AlignCenter
} Alignment;
typedef struct
{
@ -56,7 +62,7 @@ void draw_image_from_argb_data(DrawCtx *, int, int, int, int, int, unsigned char
Area draw_get_image_size(const char *filename);
Drawable draw_rotate(DrawCtx *, int, double, int, int);
unsigned short textwidth(XftFont *, char *);
int draw_get_align(const char *);
Alignment draw_get_align(const char *);
#endif
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

View File

@ -66,8 +66,12 @@ widget_calculate_alignments(Widget *widget)
int
widget_calculate_offset(int barwidth, int widgetwidth, int offset, int alignment)
{
if (alignment == AlignLeft || alignment == AlignFlex)
switch(alignment)
{
case AlignLeft:
case AlignFlex:
return offset;
}
return barwidth - offset - widgetwidth;
}

View File

@ -33,7 +33,7 @@ extern AwesomeConf globalconf;
typedef struct
{
int align;
Alignment align;
XColor fg;
XColor bg;
} Data;

View File

@ -37,7 +37,7 @@ extern AwesomeConf globalconf;
typedef struct
{
Bool show_icons;
int align;
Alignment align;
XColor fg_sel;
XColor bg_sel;
XColor fg;

View File

@ -30,7 +30,7 @@ typedef struct
{
char *text;
int width;
int align;
Alignment align;
XColor fg;
XColor bg;
} Data;