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 <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2012-12-24 14:54:10 +04:00
parent 75d165b7c7
commit 33cac494c0
3 changed files with 32 additions and 5 deletions

View File

@ -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);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -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 ****************************************************************************/

View File

@ -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);
}
/* }}} */