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 block titles in top-right and bottom-right #1090

Closed
LucasPickering opened this issue May 6, 2024 · 4 comments
Closed

Support block titles in top-right and bottom-right #1090

LucasPickering opened this issue May 6, 2024 · 4 comments
Labels
Type: Enhancement New feature or request

Comments

@LucasPickering
Copy link

Problem

I have a use case for adding a title to the top-right of a block. The block already has a primary title in the top-left, but I'd like to add some secondary information to the top-right. The label could go in the bottom-left, but with the layout of my TUI, that makes it harder to notice. Top-right would make it the most discoverable.

Solution

  • Add four new variants to block::Position: TopLeft, TopRight, BottomRight, BottomLeft
  • Deprecate the existing variants Top and Bottom
  • Update Block to support the new variants, and treat Top and Bottom the same as TopLeft and BottomLeft, respectively
  • Some time in the future, remove the Top and Bottom variants

Alternatives

You can manually write text on top of the block border, so this functionality is current possible, just inconvenient.

Additional context

#738 proposes to remove Position in favor of methods directly on Block: Block::top_title and Block::bottom_title. This would conflict with my proposal. We could just add 4 methods to Block for titles, but that feels very inflexible and verbose. Instead, I propose updating the signature of Block::title to the following:

fn title<T: Into<Line>>(self, title: T, position: Position) -> Self;

This would keep the flexibility of having positions be defined in an enum, while still eliminating the redundancy of the Title type.

@joshka
Copy link
Member

joshka commented May 6, 2024

fn title<T: Into>(self, title: T, position: Position) -> Self;

<pre-coffee-josh>
This change would be a "break the world" type change, so it is very likely not the right approach. The underlying idea is sound however. Likely title_at or something similar would work.

@joshka
Copy link
Member

joshka commented May 6, 2024

<post-coffee-josh>
So the idea with removing block::Title is that Line already has an indication of Left/Center/Right as part of it. For the block titles it doesn't seem like there's any possible use of this field other than positioning. Which leaves the position really only needing top / bottom. What's your thoughts on this?

@LucasPickering
Copy link
Author

You know, it never occurred to me to use the alignment field for this. The functionality I want is already possible, and would continue to work with the other proposal. I'm going to close this. Thanks!

@joshka
Copy link
Member

joshka commented May 7, 2024

The alignment field on title also does the same thing. The overlap in having a Title that contains a Line which both have alignment is where the removal proposal comes from.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants