From 2a5eb1707e979b89473fa95c2c9e1770ab021057 Mon Sep 17 00:00:00 2001 From: "G.raud" Date: Sun, 30 Jun 2013 14:26:50 +0200 Subject: [PATCH] njackspa: [bug] fix the fields' widths use remaining space for the larger field because of integer roundings --- njackspa.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/njackspa.c b/njackspa.c index 387f56d..f922d46 100644 --- a/njackspa.c +++ b/njackspa.c @@ -104,6 +104,7 @@ void draw_controls(struct window* window_ptr) long offset; /* first displayed control index */ control_t *control; char fmt[40]; /* buffer for printf format strings */ + int w; /* computed field width */ getmaxyx(window_ptr->window_ptr, rows, cols); offset = (long)window_ptr->index + 3-rows; @@ -118,15 +119,16 @@ void draw_controls(struct window* window_ptr) (window_ptr->selected) ? 4 : 2 : 1; /* emphasized widget (white or normal) */ - /* Name */ + /* Name [ramaining space] */ wattron(window_ptr->window_ptr, COLOR_PAIR(color)); - snprintf(fmt, sizeof(fmt), "%%-%d.%ds", cols/3 - 1, cols/3 -1); + w = cols-2 - (cols/6-2)*4 - 9; + snprintf(fmt, sizeof(fmt), "%%-%d.%ds", w, w); mvwprintw(window_ptr->window_ptr, row, col, fmt, control->name); - /* Separator ':' */ + /* Separator ':' [2] */ wattron(window_ptr->window_ptr, COLOR_PAIR(1)); wprintw(window_ptr->window_ptr, ": "); - /* Active value (bold) */ - snprintf(fmt, sizeof(fmt), "%%%dF", cols/6 - 2); + /* Active value (bold) [c/6-2] */ + snprintf(fmt, sizeof(fmt), "%%%dF", cols/6-2); if (window_ptr->sel == Active) { wattron(window_ptr->window_ptr, WA_BOLD|COLOR_PAIR(high)); wprintw(window_ptr->window_ptr, fmt, *control->val); @@ -137,21 +139,21 @@ void draw_controls(struct window* window_ptr) wprintw(window_ptr->window_ptr, fmt, *control->val); wattroff(window_ptr->window_ptr, WA_BOLD|COLOR_PAIR(color)); } - /* Type */ + /* Type [3] */ wattron(window_ptr->window_ptr, COLOR_PAIR(1)); wprintw( window_ptr->window_ptr, " %s ", (control->type == JACKSPA_TOGGLE) ? "?" : (control->type == JACKSPA_INT) ? "i" : "f" ); - /* Selection (emphasized) */ - snprintf(fmt, sizeof(fmt), "%%-%dF", cols/6 - 2); + /* Selection (emphasized) [c/6-2] */ + snprintf(fmt, sizeof(fmt), "%%-%dF", cols/6-2); if (window_ptr->sel == Active) wattron(window_ptr->window_ptr, COLOR_PAIR(color)); else wattron(window_ptr->window_ptr, COLOR_PAIR(high)); wprintw(window_ptr->window_ptr, fmt, control->sel); - /* Range */ + /* Range [2* (c/6-2) + 4] */ wattron(window_ptr->window_ptr, COLOR_PAIR(1)); - snprintf(fmt, sizeof(fmt), " [%%-%dF~%%%dF]", cols/6 - 2, cols/6 - 2); + snprintf(fmt, sizeof(fmt), " [%%-%dF~%%%dF]", cols/6-2, cols/6-2); wprintw(window_ptr->window_ptr, fmt, control->min, control->max); wattroff(window_ptr->window_ptr, COLOR_PAIR(1)); -- 2.11.4.GIT