mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-25 01:40:19 -05:00
wip: grid is now represented as a grid, not a linear array
The grid is now represented with an array of row *pointers*. Each row contains an array of cells (the row's columns). The main point of having row pointers is we can now move rows around almost for free. This is useful when scrolling with scroll margins for example, where we previously had to copy the lines in the margins. Now it's just a matter of swapping two pointers.
This commit is contained in:
parent
98db7f58cb
commit
4e25019ba6
8 changed files with 457 additions and 81 deletions
28
grid.h
28
grid.h
|
|
@ -3,6 +3,34 @@
|
|||
#include <stddef.h>
|
||||
#include "terminal.h"
|
||||
|
||||
static inline struct row *
|
||||
grid_row(struct grid *grid, int row)
|
||||
{
|
||||
assert(grid->offset >= 0);
|
||||
return grid->rows[(grid->offset + row + grid->num_rows) % grid->num_rows];
|
||||
}
|
||||
|
||||
static inline void
|
||||
grid_swap_row(struct grid *grid, int row_a, int row_b)
|
||||
{
|
||||
assert(grid->offset >= 0);
|
||||
assert(row_a != row_b);
|
||||
assert(row_a >= 0);
|
||||
assert(row_b >= 0);
|
||||
|
||||
int real_a = (grid->offset + row_a + grid->num_rows) % grid->num_rows;
|
||||
int real_b = (grid->offset + row_b + grid->num_rows) % grid->num_rows;
|
||||
|
||||
struct row *tmp = grid->rows[real_a];
|
||||
grid->rows[real_a] = grid->rows[real_b];
|
||||
grid->rows[real_b] = tmp;
|
||||
|
||||
grid->rows[real_a]->dirty = true;
|
||||
grid->rows[real_b]->dirty = true;
|
||||
}
|
||||
|
||||
#if 0
|
||||
struct cell *grid_get_range(struct grid *grid, int start, int *length);
|
||||
void grid_memclear(struct grid *grid, int start, int length);
|
||||
void grid_memmove(struct grid *grid, int dst, int src, int length);
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue