diff options
-rw-r--r-- | include/visio.h | 6 | ||||
-rw-r--r-- | mbbsd/visio.c | 40 |
2 files changed, 39 insertions, 7 deletions
diff --git a/include/visio.h b/include/visio.h index 37aa9cce..676aad9a 100644 --- a/include/visio.h +++ b/include/visio.h @@ -37,6 +37,7 @@ // CONSTANT DEFINITION ------------------------------------------------- #define VCOL_MAXW (INT16_MAX) +#define VCOL_MAXPRI (INT16_MAX) #define VFILL_DEFAULT (0x00) // #define VFILL_NO_ANSI VFILL_DEFAULT @@ -58,10 +59,13 @@ typedef void * VREFSCR; typedef long VREFCUR; typedef short VCOLW; -typedef struct { +typedef short VCOLPRI; + +typedef struct VCOL { char *attr; // default attribute VCOLW minw; // minimal width VCOLW maxw; // max width + VCOLPRI pri; // priority (higher expands first) struct { char has_ansi; // field data have ANSI escapes diff --git a/mbbsd/visio.c b/mbbsd/visio.c index 27b6cbf9..ea6701e4 100644 --- a/mbbsd/visio.c +++ b/mbbsd/visio.c @@ -638,7 +638,8 @@ vs_footer(const char *caption, const char *msg) void vs_cols_layout(const VCOL *cols, VCOLW *ws, int n) { - int i, tw, d = 0; + int i, tw; + VCOLPRI pri1 = cols[0].pri; memset(ws, 0, sizeof(VCOLW) * n); // first run, calculate minimal size @@ -651,22 +652,49 @@ vs_cols_layout(const VCOL *cols, VCOLW *ws, int n) tw += ws[i]; } + if (tw < MAX_COL) { + // calculate highest priorities + // (pri1 already set to col[0].pri) + for (i = 1; i < n; i++) + { + if (cols[i].pri > pri1) + pri1 = cols[i].pri; + } + } + // try to iterate through all. while (tw < MAX_COL) { - // TODO process priority? char run = 0; - d++; + + // also update pri2 here for next run. + VCOLPRI pri2 = cols[0].pri; + for (i = 0; i < n; i++) { - // increase fields if still ok. - if (cols[i].maxw - cols[i].minw < d) + // if reach max, skip. + if (ws[i] >= cols[i].maxw) continue; + + // lower priority, update pri2 and skip. + if (cols[i].pri < pri1) + { + if (cols[i].pri > pri2) + pri2 = cols[i].pri; + continue; + } + + // now increase fields ws[i] ++; if (++tw >= MAX_COL) break; run ++; } + // if no more fields... - if (!run) break; + if (!run) { + if (pri1 <= pri2) // no more priorities + break; + pri1 = pri2; // try lower priority. + } } } |