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 *statusbar; Statusbar *statusbar;
/** Alignement */ /** Alignement */
int alignment; Alignment alignment;
/** Misc private data */ /** Misc private data */
void *data; void *data;
/** Location on status bar */ /** Location on status bar */

14
draw.c
View File

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

10
draw.h
View File

@ -25,7 +25,13 @@
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Xft/Xft.h> #include <X11/Xft/Xft.h>
enum { AlignLeft, AlignRight, AlignFlex, AlignCenter }; typedef enum
{
AlignLeft,
AlignRight,
AlignFlex,
AlignCenter
} Alignment;
typedef struct 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); Area draw_get_image_size(const char *filename);
Drawable draw_rotate(DrawCtx *, int, double, int, int); Drawable draw_rotate(DrawCtx *, int, double, int, int);
unsigned short textwidth(XftFont *, char *); unsigned short textwidth(XftFont *, char *);
int draw_get_align(const char *); Alignment draw_get_align(const char *);
#endif #endif
// 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

View File

@ -66,8 +66,12 @@ widget_calculate_alignments(Widget *widget)
int int
widget_calculate_offset(int barwidth, int widgetwidth, int offset, int alignment) 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 offset;
}
return barwidth - offset - widgetwidth; return barwidth - offset - widgetwidth;
} }

View File

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

View File

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

View File

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