mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
grid: reflow: use macro print_spacer() to insert multi-column character spacers
This commit is contained in:
parent
f962fb236e
commit
b0798ad0be
1 changed files with 11 additions and 8 deletions
19
grid.c
19
grid.c
|
|
@ -183,6 +183,13 @@ grid_reflow(struct grid *grid, int new_rows, int new_cols,
|
|||
} \
|
||||
} while(0)
|
||||
|
||||
#define print_spacer() \
|
||||
do { \
|
||||
new_row->cells[new_col_idx].wc = CELL_MULT_COL_SPACER; \
|
||||
new_row->cells[new_col_idx].attrs = old_cell->attrs; \
|
||||
new_row->cells[new_col_idx].attrs.clean = 1; \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Keep track of empty cells. If the old line ends with a
|
||||
* string of empty cells, we don't need to, nor do we want to,
|
||||
|
|
@ -231,11 +238,8 @@ grid_reflow(struct grid *grid, int new_rows, int new_cols,
|
|||
/* Out of columns on current row in new grid? */
|
||||
if (new_col_idx + max(1, wcwidth(old_cell->wc)) > new_cols) {
|
||||
/* Pad to end-of-line with spacers, then line-wrap */
|
||||
for (;new_col_idx < new_cols; new_col_idx++) {
|
||||
new_row->cells[new_col_idx] = (struct cell){};
|
||||
new_row->cells[new_col_idx].wc = CELL_MULT_COL_SPACER;
|
||||
new_row->cells[new_col_idx].attrs.clean = 1;
|
||||
}
|
||||
for (;new_col_idx < new_cols; new_col_idx++)
|
||||
print_spacer();
|
||||
line_wrap();
|
||||
}
|
||||
|
||||
|
|
@ -262,9 +266,7 @@ grid_reflow(struct grid *grid, int new_rows, int new_cols,
|
|||
* subsequent cells */
|
||||
for (size_t i = 0; i < width - 1; i++) {
|
||||
assert(new_col_idx < new_cols);
|
||||
new_row->cells[new_col_idx] = (struct cell){};
|
||||
new_row->cells[new_col_idx].wc = CELL_MULT_COL_SPACER;
|
||||
new_row->cells[new_col_idx].attrs.clean = 1;
|
||||
print_spacer();
|
||||
new_col_idx++;
|
||||
}
|
||||
}
|
||||
|
|
@ -278,6 +280,7 @@ grid_reflow(struct grid *grid, int new_rows, int new_cols,
|
|||
line_wrap();
|
||||
}
|
||||
|
||||
#undef print_spacer
|
||||
#undef line_wrap
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue