Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support cells spanning multiple rows/columns #6

Open
jwodder opened this issue Dec 2, 2021 · 0 comments
Open

Support cells spanning multiple rows/columns #6

jwodder opened this issue Dec 2, 2021 · 0 comments
Labels
c:colspan-rowspan enhancement New feature or request therefor

Comments

@jwodder
Copy link
Owner

jwodder commented Dec 2, 2021

Extend the Cell class from #5 to take colspan: int = 1 and rowspan: int = 1 parameters for producing cells that potentially span multiple columns and/or rows of a table.

  • A multicolumn/multirow cell is passed to a Txtble at the location of the cell's top-left corner. The other cells that are "covered up by"/"merged into" a multicolumn/multirow cell must be completely absent from the data array. For example, a four-column row in which the second cell is two cells wide would be written as ["Foo", Cell("Bar", colspan=2), "Baz"] ("Baz" is here the cell in the fourth column, not the third).

    • If all the cells in a row are "covered" by other cells, the row still has to be present as an empty sequence.
  • By default, the width of a multicolumn cell takes precedence over the widths of the columns it spans.

    • If the multicolumn cell is narrower than the sum of the widths of the columns it spans (plus column separators), the multicolumn cell is widened to fit.
    • If a multicolumn cell's width X is greater than the sum Y of the widths of the N columns it spans, the columns are widened to match by adding ceil((X - Y) / N) spaces to the first (X - Y) % N columns and floor((X - Y) / N) to the rest.
    • If restrict_width=True is set on a multicolumn Cell, the columns it spans will take precedence over it, width-wise.
      • If such a cell's natural width is greater than the columns it spans, its width will be reduced to match.
      • restrict_width has no effect on Cells that span only one column
  • A multicolumn/multirow cell's alignment, padding, etc. is based on that of its upper-left corner.

Some basic test cases for this feature can be found on the feature/span branch.

@jwodder jwodder added enhancement New feature or request therefor c:colspan-rowspan labels Dec 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c:colspan-rowspan enhancement New feature or request therefor
Projects
None yet
Development

No branches or pull requests

1 participant