From bafc778ee79ae16ee037f753c9a13555e889e737 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Wed, 26 Sep 2012 15:19:33 +0400 Subject: [PATCH] Horizontal centering of multi-line label: center each line independently. Signed-off-by: Andrew Borodin --- lib/widget/label.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/widget/label.c b/lib/widget/label.c index ad519fbb8..6b84ea96a 100644 --- a/lib/widget/label.c +++ b/lib/widget/label.c @@ -75,21 +75,27 @@ label_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d { char *p = l->text; int y = 0; - gboolean disabled = (w->options & W_DISABLED) != 0; + gboolean disabled; + align_crt_t align; if (l->text == NULL) return MSG_HANDLED; + disabled = (w->options & W_DISABLED) != 0; + if (l->transparent) tty_setcolor (disabled ? DISABLED_COLOR : DEFAULT_COLOR); else tty_setcolor (disabled ? DISABLED_COLOR : h->color[DLG_COLOR_NORMAL]); + align = (w->pos_flags & WPOS_CENTER_HORZ) != 0 ? J_CENTER_LEFT : J_LEFT; + while (TRUE) { char *q; char c = '\0'; + q = strchr (p, '\n'); if (q != NULL) { @@ -98,7 +104,7 @@ label_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d } widget_move (w, y, 0); - tty_print_string (str_fit_to_term (p, w->cols, J_LEFT)); + tty_print_string (str_fit_to_term (p, w->cols, align)); if (q == NULL) break;