diff options
-rw-r--r-- | widget_text.c | 14 | ||||
-rw-r--r-- | widget_text.h | 4 |
2 files changed, 13 insertions, 5 deletions
diff --git a/widget_text.c b/widget_text.c index 5f3c2c9..2bbb7ae 100644 --- a/widget_text.c +++ b/widget_text.c @@ -85,6 +85,11 @@ void widget_text_scroll(void *Self) if (pad < 0) pad = 0; break; + case ALIGN_AUTOMATIC: + if (len <= width) { + pad = 0; + break; + } case ALIGN_MARQUEE: pad = width - T->scroll; T->scroll++; @@ -219,7 +224,7 @@ void widget_text_update(void *Self) /* if there's a marquee scroller active, it has its own */ /* update callback timer, so we do nothing here; otherwise */ /* we simply call this scroll callback directly */ - if (T->align != ALIGN_MARQUEE) { + if (T->align != ALIGN_MARQUEE || T->align != ALIGN_AUTOMATIC) { widget_text_scroll(Self); } } @@ -279,6 +284,9 @@ int widget_text_init(WIDGET * Self) case 'M': Text->align = ALIGN_MARQUEE; break; + case 'A': + Text->align = ALIGN_AUTOMATIC; + break; default: error("widget %s has unknown alignment '%s', using 'Left'", section, c); Text->align = ALIGN_LEFT; @@ -292,7 +300,7 @@ int widget_text_init(WIDGET * Self) Text->update = 10; /* marquee scroller speed: interval (msec), default 500msec */ - if (Text->align == ALIGN_MARQUEE) { + if (Text->align == ALIGN_MARQUEE || Text->align == ALIGN_AUTOMATIC) { cfg_number(section, "speed", 500, 10, -1, &(Text->speed)); } @@ -306,7 +314,7 @@ int widget_text_init(WIDGET * Self) timer_add(widget_text_update, Self, Text->update, Text->update == 0); /* a marquee scroller has its own timer and callback */ - if (Text->align == ALIGN_MARQUEE) { + if (Text->align == ALIGN_MARQUEE || Text->align == ALIGN_AUTOMATIC) { timer_add(widget_text_scroll, Self, Text->speed, 0); } diff --git a/widget_text.h b/widget_text.h index 17dd9d4..b3bd0a6 100644 --- a/widget_text.h +++ b/widget_text.h @@ -30,7 +30,7 @@ #include "property.h" -typedef enum { ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT, ALIGN_MARQUEE } TEXT_ALIGN; +typedef enum { ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT, ALIGN_MARQUEE, ALIGN_AUTOMATIC } TEXT_ALIGN; typedef struct WIDGET_TEXT { PROPERTY prefix; /* label on the left side */ @@ -41,7 +41,7 @@ typedef struct WIDGET_TEXT { char *buffer; /* string with 'width+1' bytes allocated */ int width; /* field width */ int precision; /* number of digits after the decimal point */ - TEXT_ALIGN align; /* alignment: L(eft), C(enter), R(ight), M(arquee) */ + TEXT_ALIGN align; /* alignment: L(eft), C(enter), R(ight), M(arquee), A(utomatic) */ int update; /* update interval */ int scroll; /* marquee starting point */ int speed; /* marquee scrolling speed */ |