Skip to content
This repository has been archived by the owner on Aug 6, 2023. It is now read-only.

Ability to right-align columns in a table #295

Closed
popey456963 opened this issue May 20, 2020 · 2 comments
Closed

Ability to right-align columns in a table #295

popey456963 opened this issue May 20, 2020 · 2 comments

Comments

@popey456963
Copy link

Is your feature request related to a problem? Please describe.
There are times when I want to right-align text in a table, e.g. numbers.

Describe the solution you'd like
Ability to right-align text

Describe alternatives you've considered
Adding spacing is tricky, as we don't exactly know how wide the column is from within our application.

@thorlucas
Copy link

I agree this should be an important feature, as well as center-aligning. From a technical perspective it shouldn't be too rough to implement. We have the string and can get the length of it (.length() or .chars().count()), and we also have the column spacing provided during rendering.

@leebenson
Copy link

@fdehau, are there any plans to add alignment? An obvious use-case is numeric data column for more spreadsheet-like tabular layouts.

I experimented with a DIY approach using pad, but the issue I ran into was calculating a specific column size when using percentage widths. I tried using f.size() and factoring margins/padding manually, but the logic got unwieldy trying to preempt dimensions in userland.

Would be ideal to have this baked into render calculations. Perhaps Text could offer a .align(Alignment::Right), using the existing Alignment struct in a layout?

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

No branches or pull requests

4 participants