You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

69 lines
1.7 KiB

  1. #pragma once
  2. #include <stddef.h>
  3. #include "terminal.h"
  4. void grid_swap_row(struct grid *grid, int row_a, int row_b);
  5. struct row *grid_row_alloc(int cols, bool initialize);
  6. void grid_row_free(struct row *row);
  7. void grid_reflow(
  8. struct grid *grid, int new_rows, int new_cols,
  9. int old_screen_rows, int new_screen_rows,
  10. size_t tracking_points_count,
  11. struct coord *const tracking_points[static tracking_points_count],
  12. size_t compose_count,
  13. const struct composed composed[static compose_count]);
  14. static inline int
  15. grid_row_absolute(const struct grid *grid, int row_no)
  16. {
  17. return (grid->offset + row_no) & (grid->num_rows - 1);
  18. }
  19. static inline int
  20. grid_row_absolute_in_view(const struct grid *grid, int row_no)
  21. {
  22. return (grid->view + row_no) & (grid->num_rows - 1);
  23. }
  24. static inline struct row *
  25. _grid_row_maybe_alloc(struct grid *grid, int row_no, bool alloc_if_null)
  26. {
  27. assert(grid->offset >= 0);
  28. int real_row = grid_row_absolute(grid, row_no);
  29. struct row *row = grid->rows[real_row];
  30. if (row == NULL && alloc_if_null) {
  31. row = grid_row_alloc(grid->num_cols, false);
  32. grid->rows[real_row] = row;
  33. }
  34. assert(row != NULL);
  35. return row;
  36. }
  37. static inline struct row *
  38. grid_row(struct grid *grid, int row_no)
  39. {
  40. return _grid_row_maybe_alloc(grid, row_no, false);
  41. }
  42. static inline struct row *
  43. grid_row_and_alloc(struct grid *grid, int row_no)
  44. {
  45. return _grid_row_maybe_alloc(grid, row_no, true);
  46. }
  47. static inline struct row *
  48. grid_row_in_view(struct grid *grid, int row_no)
  49. {
  50. assert(grid->view >= 0);
  51. int real_row = grid_row_absolute_in_view(grid, row_no);
  52. struct row *row = grid->rows[real_row];
  53. assert(row != NULL);
  54. return row;
  55. }