Back to Ratatui

v0.26.2

src/content/docs/highlights/v0.26.2.md

latest3.3 KB
Original Source

https://github.com/ratatui/ratatui/releases/tag/v0.26.2

MSRV: 1.74.0 ๐Ÿฆ€

The minimum supported Rust version of Ratatui is updated from 1.70.0 to 1.74.0.


List: Scroll Padding ๐Ÿ“œ

We introduced a new method for List which allows a certain number of items be kept visible above and below the currently selected item while scrolling.

rust
let list = List::new(items).scroll_padding(1);
<details> <summary>Demo of the new behavior</summary>

<center>

(visible on the left side)

</center> </details>

Text: Construct from Iterator ๐Ÿ—๏ธ

Line and Text widgets now implement FromIterator which means you can:

  • Construct Line from an iterator of Span
rust
let line = Line::from_iter(vec!["Hello".blue(), " world!".green()]);
let line: Line = iter::once("Hello".blue())
    .chain(iter::once(" world!".green()))
    .collect();
  • Construct Text from an iterator of Line
rust
let text = Text::from_iter(vec!["The first line", "The second line"]);
let text: Text = iter::once("The first line")
    .chain(iter::once("The second line"))
    .collect();

Text: Push Methods ๐Ÿ“ฅ

We added the following methods to the Text and Line structs:

  • Text::push_line
  • Text::push_span
  • Line::push_span

This allows for adding lines and spans to a text object without having to call methods on the fields directly, which is useful for incremental construction of text objects.

For example:

rust
let mut line = Line::from("Hello, ");
line.push_span(Span::raw("world!"));
line.push_span(" How are you?");

Implement Widget for strings ๐Ÿงถ

Widget is now implemented for &str and String, which makes it easier to render strings with no styles as widgets.

Example usage:

rust
terminal.draw(|f| f.render_widget("Hello World!", f.size()))?;

Span: Rename Methods ๐Ÿ”„

The following Span methods are renamed accordingly to the Rust method naming conventions.

Deprecated usage:

  • Span::to_centered_line
  • Span::to_left_aligned_line
  • Span::to_right_aligned_line

New usage:

  • Span::into_centered_line
  • Span::into_left_aligned_line
  • Span::into_right_aligned_line

Funding ๐Ÿง€

We are happy to share that we have received a funding donation from Radicle!

You can read about the details here.


Other ๐Ÿ’ผ

  • Marked various functions as const (#951)
  • Respect alignment on Line truncation (#987)
  • Don't render scrollbar on zero length track (#964)
  • Fix panic when rendering Text out of bounds (#997)
  • Fix highlight_symbol overflow (#949)
  • Fix Scrollbar thumb not being visible on long lists (#959)
  • Ensure that paragraph correctly renders styled text (#992)
  • Applied clippy (pedantic) suggestions

And lastly, we welcome @EdJoPaTo on board as a maintainer! ๐Ÿฅณ