8000 Remove `block::Title` and `block::Position`, add `Block::top_title()` and `Block::bottom_title()` for ergonomics · Issue #738 · ratatui/ratatui · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Remove block::Title and block::Position, add Block::top_title() and Block::bottom_title() for ergonomics #738
Closed
@joshka

Description

@joshka

Description

block::Title and block::Position sit weirdly in the API. They can't be included in the prelude as the names would clash pretty annoyingly with many other type names in common use in apps, but also Title does not actually need to exist.

Title has 3 fields - content (Line), alignment and position. But Line already has an alignment field, so the title's alignment is superfluous. Position is a property of where the title is rendered, and so is a property of the Block, not the title itself. So if you remove the superfluous fields, that leaves Title just being a Line.

We should remove Title and Position from the API entirely.

Suggested fixes

Transition to having just:

let block = Block::default()
    .title(Line::from("foo")) // keep for backwards compatibility - equivalent top_title
    .top_title(Line::from("foo").alignment(Alignment::Center))
    .bottom_title(Line::from("bar").alignment(Aligment::Right))

To do this nicely, we'd need to:

  • add top_title<T: Into<Line>>(line: T) and similarly bottom_title(...)
  • mark Title as deprecated
  • mark Title::position() deprecated and point at Block::top_title() / Block::bottom::title
  • mark Position as deprecated`
  • change Block::titles to store top_titles and bottom_titles separately
  • remove title_on_bottom (already deprecated)
  • deprecate and then remove Block::title_position
  • fix up the rendering methods

It's possible that we could add a From<Title> for Line implementation that drops the position and make existing code still work except for things with bottom titles for a while too.

It's a good idea to split this up into a few PRs:

  • add the top_ and bottom_ fields and setters, update the rendering to use these instead of the current titles field (non breaking change)
  • Implement From<Title> for Line
  • Mark all deprecations and write up a transition guide for the change in BREAKING changes
  • Remove existing deprecated setter
  • Change Block::title to accept Into<Line> instead of Into<Title>
  • in a later release remove the deprecated stuff.

The external impact of this is 77 files, so fairly small right now:
https://github.com/search?q=ratatui+AND+block+AND+%22Title%3A%3Afrom%22+AND+%28NOT+repo%3Aratatui-org%2Fratatui%29+AND+%28NOT+is%3Afork%29&type=code

Metadata

Metadata

Assignees

Labels

Type: BugSomething isn't working

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0