From 33cac494c08098b757f6021515ed0e2f02136910 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Mon, 24 Dec 2012 14:54:10 +0400 Subject: [PATCH] WHLine: allow draw text over horizontal line. * (hline_set_text): new function. * (file_progress_show_total): use hline_set_text to show processed files counter. Signed-off-by: Andrew Borodin --- lib/widget/hline.c | 27 +++++++++++++++++++++++++++ lib/widget/hline.h | 2 ++ src/filemanager/filegui.c | 8 +++----- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/lib/widget/hline.c b/lib/widget/hline.c index 22ea76725..b094e01c3 100644 --- a/lib/widget/hline.c +++ b/lib/widget/hline.c @@ -41,6 +41,7 @@ #include "lib/tty/tty.h" #include "lib/tty/color.h" #include "lib/skin.h" +#include "lib/strutil.h" #include "lib/widget.h" /*** global variables ****************************************************************************/ @@ -98,6 +99,15 @@ hline_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d widget_move (w, 0, w->cols - 1); tty_print_alt_char (ACS_RTEE, FALSE); } + + if (l->text != NULL) + { + int text_width; + + text_width = str_term_width1 (l->text); + widget_move (w, 0, (w->cols - text_width) / 2); + tty_print_string (l->text); + } return MSG_HANDLED; default: @@ -119,6 +129,7 @@ hline_new (int y, int x, int width) l = g_new (WHLine, 1); w = WIDGET (l); init_widget (w, y, x, lines, width < 0 ? 1 : width, hline_callback, NULL); + l->text = NULL; l->auto_adjust_cols = (width < 0); l->transparent = FALSE; widget_want_cursor (w, FALSE); @@ -128,3 +139,19 @@ hline_new (int y, int x, int width) } /* --------------------------------------------------------------------------------------------- */ + +void +hline_set_text (WHLine * l, const char *text) +{ + g_free (l->text); + + if (text == NULL || *text == '\0') + l->text = NULL; + else + l->text = g_strdup (text); + + if (WIDGET (l)->owner != NULL) + send_message (l, NULL, MSG_DRAW, 0, NULL); +} + +/* --------------------------------------------------------------------------------------------- */ diff --git a/lib/widget/hline.h b/lib/widget/hline.h index 0f0c1977c..5f78e809f 100644 --- a/lib/widget/hline.h +++ b/lib/widget/hline.h @@ -17,6 +17,7 @@ typedef struct { Widget widget; + char *text; gboolean auto_adjust_cols; /* Compute widget.cols from parent width? */ gboolean transparent; /* Paint in the default color fg/bg */ } WHLine; @@ -26,6 +27,7 @@ typedef struct /*** declarations of public functions ************************************************************/ WHLine *hline_new (int y, int x, int width); +void hline_set_text (WHLine * l, const char *text); /*** inline functions ****************************************************************************/ diff --git a/src/filemanager/filegui.c b/src/filemanager/filegui.c index 9d7338b8a..b9fcfeb9a 100644 --- a/src/filemanager/filegui.c +++ b/src/filemanager/filegui.c @@ -248,7 +248,7 @@ typedef struct WLabel *total_files_processed_label; WLabel *time_label; - WLabel *total_bytes_label; + WHLine *total_bytes_label; /* Query replace dialog */ WDialog *replace_dlg; @@ -745,9 +745,7 @@ file_op_context_create_ui (FileOpContext * ctx, gboolean with_eta, if (verbose && dialog_type == FILEGUI_DIALOG_MULTI_ITEM) { - add_widget (ui->op_dlg, hline_new (y, -1, -1)); - - ui->total_bytes_label = label_new (y++, x + 15, ""); + ui->total_bytes_label = hline_new (y++, -1, -1); add_widget (ui->op_dlg, ui->total_bytes_label); if (file_op_compute_totals) @@ -978,7 +976,7 @@ file_progress_show_total (FileOpTotalContext * tctx, FileOpContext * ctx, uintma g_snprintf (buffer, BUF_TINY, _(" Total: %s/%s "), buffer2, buffer3); } - label_set_text (ui->total_bytes_label, buffer); + hline_set_text (ui->total_bytes_label, buffer); } /* }}} */ -- 2.11.4.GIT