Skip to content

Commit

Permalink
feat(showcase): showcase list widget (#366)
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentin271 authored Jan 14, 2024
1 parent 2b8421a commit b6fb342
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 1 deletion.
9 changes: 9 additions & 0 deletions code/widget-showcase/list.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# A VHS tape. See https://github.com/charmbracelet/vhs
Output "../../src/content/docs/showcase/widgets/list.gif"
Set Theme "Aardvark Blue"
Set Width 800
Set Height 300
Type "cargo run -- -w list" Enter
Sleep 2s
Screenshot "../../src/content/docs/showcase/widgets/list.png"
Sleep 1s
1 change: 1 addition & 0 deletions code/widget-showcase/src/examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ pub mod calendar;
pub mod chart;
pub mod gauge;
pub mod line_gauge;
pub mod list;
pub mod table;
26 changes: 26 additions & 0 deletions code/widget-showcase/src/examples/list.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use ratatui::{
prelude::*,
widgets::{HighlightSpacing, List, ListState},
};

pub fn render(frame: &mut Frame) {
let list = List::new([
Line::from(vec!["✔️ ".green(), "Fork tui-rs 💻".into()]),
Line::from(vec![
"✔️ ".green(),
"Create a ".into(),
"great".italic(),
" mascot 🐀".into(),
]),
Line::from(vec!["✔️ ".green(), "Create a website & book 🕮".into()]),
Line::from(vec!["✔️ ".green(), "Celebrate 500th commit ⭐".into()]),
Line::from(vec!["✔️ ".green(), "Celebrate 1000th commit ✨".into()]),
Line::from(vec!["⌛".yellow(), "Release Ratatui 1.0.0 🎉".bold()]),
])
.highlight_symbol("» ")
.highlight_spacing(HighlightSpacing::Always);

let mut state = ListState::default().with_selected(Some(5));

frame.render_stateful_widget(list, frame.size(), &mut state);
}
2 changes: 2 additions & 0 deletions code/widget-showcase/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ enum Widget {
Chart,
Gauge,
LineGauge,
List,
Table,
}

Expand Down Expand Up @@ -100,6 +101,7 @@ impl App {
Widget::Chart => chart::render(frame),
Widget::Gauge => gauge::render(frame),
Widget::LineGauge => line_gauge::render(frame),
Widget::List => list::render(frame),
Widget::Table => table::render(frame),
}
Ok(())
Expand Down
4 changes: 3 additions & 1 deletion src/content/docs/showcase/widgets/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ https://github.com/ratatui-org/website/issues/249 for information about how to c

![LineGauge](./line_gauge.png)

## List <LinkBadge href="https://docs.rs/ratatui/latest/ratatui/widgets/struct.List.html" text="Docs" /> <LinkBadge text="Help Wanted" href="https://github.com/ratatui-org/website/issues/249" variant="caution" />
## List <LinkBadge href="https://docs.rs/ratatui/latest/ratatui/widgets/struct.List.html" text="Docs" />

![List](./list.png)

## Paragraph <LinkBadge href="https://docs.rs/ratatui/latest/ratatui/widgets/struct.Paragraph.html" text="Docs" /> <LinkBadge text="Help Wanted" href="https://github.com/ratatui-org/website/issues/249" variant="caution" />

Expand Down
3 changes: 3 additions & 0 deletions src/content/docs/showcase/widgets/list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b6fb342

Please sign in to comment.