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

Apply dynamic styles to nested table #154

Open
samiraguiar opened this issue Mar 10, 2023 · 4 comments
Open

Apply dynamic styles to nested table #154

samiraguiar opened this issue Mar 10, 2023 · 4 comments

Comments

@samiraguiar
Copy link

Is it possible to have dynamic styles (e.g. different color based on the contents) for nested tables?
I couldn't get it to work and it doesn't seem to be possible because the table is print to a string without styles when nested.

@pinkforest
Copy link
Collaborator

pinkforest commented Mar 10, 2023

Could we sketch some examples of the desired minimal / ideal support(s) ?

@samiraguiar
Copy link
Author

Ideally it would be something like this:

pub fn bool_icon(v: bool) -> Cell {
    if v {
        cell![Fgb -> "✔"]
    } else {
        cell![Frb -> "✘"]
    }
}

...
subtable.add_row(row![ "Enabled?", bool_icon(d.can_connect) ]);
table.add_row(row![ "Details", subtable ]);
...

Or without macros if not possible. When it's not inside a subtable I can workaround it by not using macros:

table.add_row(Row::new(vec![
    Cell::new("Enabled?"),
    bool_icon(d.can_connect),
]));

But with a subtable this doesn't work because it is converted to a string without styles first.

@pinkforest
Copy link
Collaborator

Would you like to try a PR ?

@samiraguiar
Copy link
Author

Sure, I'd love to. I can't make promises on a time frame but I'll take a look when possible

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

No branches or pull requests

2 participants