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

feat: add Block::title_top and Block::title_top_bottom #940

Merged
merged 1 commit into from Feb 9, 2024

Conversation

joshka
Copy link
Member

@joshka joshka commented Feb 9, 2024

This adds the ability to add titles to the top and bottom of a block
without having to use the Title struct (which will be removed in a
future release - likely v0.28.0).

Fixes a subtle bug if the title was created from a right aligned Line
and was also right aligned. The title would be rendered one cell too far
to the right.

Block::bordered()
    .title_top(Line::raw("A").left_aligned())
    .title_top(Line::raw("B").centered())
    .title_top(Line::raw("C").right_aligned())
    .title_bottom(Line::raw("D").left_aligned())
    .title_bottom(Line::raw("E").centered())
    .title_bottom(Line::raw("F").right_aligned())
    .render(buffer.area, &mut buffer);
// renders
"┌A─────B─────C┐",
"│             │",
"└D─────E─────F┘",

Addresses part of #738

Copy link

codecov bot commented Feb 9, 2024

Codecov Report

Attention: 14 lines in your changes are missing coverage. Please review.

Comparison is base (91040c0) 92.0% compared to head (a0bd2b2) 91.9%.

Files Patch % Lines
src/widgets/block.rs 73.5% 14 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            main    #940     +/-   ##
=======================================
- Coverage   92.0%   91.9%   -0.1%     
=======================================
  Files         61      61             
  Lines      15636   15703     +67     
=======================================
+ Hits       14390   14436     +46     
- Misses      1246    1267     +21     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kdheepak
Copy link
Collaborator

kdheepak commented Feb 9, 2024

When should we mark block::Title as deprecated?

@joshka
Copy link
Member Author

joshka commented Feb 9, 2024

It's a bit complicated. We would have to make everything that calls it work right, but probably before the next major release.

Copy link
Member

@Valentin271 Valentin271 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"┌A─────B──────C",
"│             │",
"└D─────E──────F",

Isn't it weird that C and F and all the way to the right (over the corners) but A and D keeps the corners? I naturally would expect this code to render all four corners the same way.

src/widgets/block.rs Show resolved Hide resolved
@joshka
Copy link
Member Author

joshka commented Feb 9, 2024

Isn't it weird that C and F and all the way to the right (over the corners) but A and D keeps the corners? I naturally would expect this code to render all four corners the same way.

This was a bug and I forgot to update the commit message

This adds the ability to add titles to the top and bottom of a block
without having to use the `Title` struct (which will be removed in a
future release - likely v0.28.0).

Fixes a subtle bug if the title was created from a right aligned Line
and was also right aligned. The title would be rendered one cell too far
to the right.

```rust
Block::bordered()
    .title_top(Line::raw("A").left_aligned())
    .title_top(Line::raw("B").centered())
    .title_top(Line::raw("C").right_aligned())
    .title_bottom(Line::raw("D").left_aligned())
    .title_bottom(Line::raw("E").centered())
    .title_bottom(Line::raw("F").right_aligned())
    .render(buffer.area, &mut buffer);
// renders
"┌A─────B─────C┐",
"│             │",
"└D─────E─────F┘",
```

Addresses part of #738
@joshka joshka merged commit 9182f47 into main Feb 9, 2024
32 of 33 checks passed
@joshka joshka deleted the jm/remove-block-title branch February 9, 2024 20:50
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 this pull request may close these issues.

None yet

4 participants