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

No border between rows, or bottom border when borders = Borders.LEFT_RIGHT #58

Closed
amirabiri opened this issue May 2, 2022 · 3 comments · Fixed by #60
Closed

No border between rows, or bottom border when borders = Borders.LEFT_RIGHT #58

amirabiri opened this issue May 2, 2022 · 3 comments · Fixed by #60

Comments

@amirabiri
Copy link

amirabiri commented May 2, 2022

I am trying to get this table layout:

+-----------------+-------------+----------+
| Column A        | Column B    | Column C |
+-----------------+-------------+----------+
| Lorem Ipsum...  | 123         | A        |
| Lorem Ipsum...  | 123         | B        |
| Lorem Ipsum...  | 123         | C        |
+-----------------+-------------+----------+

i.e I don't want borders between the rows, as in the default:

+-----------------+-------------+----------+
| Column A        | Column B    | Column C |
+-----------------+-------------+----------+
| Lorem Ipsum...  | 123         | A        |
+-----------------+-------------+----------+
| Lorem Ipsum...  | 123         | B        |
+-----------------+-------------+----------+
| Lorem Ipsum...  | 123         | C        |
+-----------------+-------------+----------+

So I used borders = Borders.LEFT_RIGHT:

borderType = BorderType.ASCII
header {
    row("Column A", "Column B", "Column C")
}
body {
    borders = Borders.LEFT_RIGHT
    for (thing in things) {
        ...
    }
}

What I get now is:

+-----------------+-------------+----------+
| Column A        | Column B    | Column C |
+-----------------+-------------+----------+
| Lorem Ipsum...  | 123         | A        |
| Lorem Ipsum...  | 123         | B        |
| Lorem Ipsum...  | 123         | C        |

i.e the price is the bottom border.

The only way I found to overcome this is to do something really nasty:

borderType = BorderType.ASCII
header {
    row("Column A", "Column B", "Column C")
}
body {
    borders = Borders.LEFT_RIGHT
    for ((idx, thing) in things.withIndex()) {
        row {
            cells(...)
            if (idx == things.lastIndex) {
                borders = Borders.LEFT_RIGHT_BOTTOM
            }
        }
    }
}

Which I assume isn't what we want to demand from the user of the library...

So either I'm missing the really simple way to do this, or it's missing.

@ajalt
Copy link
Owner

ajalt commented May 3, 2022

You're right, a simple way to do that is missing!

TableBuilder has a var outerBorder: Boolean property that you can set to false to force the borders off, but there's no way to force them on.

I'm thinking I could change it to var outerBorder: Borders?= null. When null, it would behave the same way as today, where the individual cells will control their outer border. Setting it to NONE would force the border off, ALL would force them on, and the other Border values would also work similarly.

So you could get what you want with

outerBorder = Borders.ALL
header {
    row("Column A", "Column B", "Column C")
}
body {
    borders = Borders.LEFT_RIGHT
    for (thing in things) {
        ...
    }
}

Does that seem like it would solve your problem?

@amirabiri
Copy link
Author

LOL you are the same author of both Clickt and Mordant! I picked up both of them separately and didn't realize they are from the same author. I was very surprised now to see two response to my last two issues on two totally unrelated repos - from the same user...

Nice Work!

Anyway back on topic, yes that seems like a good idea to me. But I would consider renaming the properties since the names are now becoming somewhat misleading:

table {
    border = ... // outer border of the table
    defaultCellBorder = ... 
}

@ajalt
Copy link
Owner

ajalt commented May 22, 2022

@amirabiri I implemented this change. You should be able to get the output you want with something like this:

tableBorders = Borders.ALL
header {
    row("Column A", "Column B", "Column C")
}
body {
    cellBorders = Borders.LEFT_RIGHT
    for (thing in things) {
        ...
    }
}

I went with the names tableBorders and cellBorders, although I'm open to changing them.
Try out the latest snapshot build and let me know what you think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants