ratatui-org / ratatui

Rust library that's all about cooking up terminal user interfaces (TUIs) 👨‍🍳🐀
https://ratatui.rs
MIT License
8.96k stars 274 forks source link

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

Closed LucasPickering closed 2 months ago

LucasPickering commented 2 months ago

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

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 commented 2 months ago

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 commented 2 months ago

<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 commented 2 months ago

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 commented 2 months ago

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.