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

feat(showcase): showcase list widget #366

Merged
merged 1 commit into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()]),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, pretty much this will never happen. All our deps would have to go 1.0 first.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that was just to have something that will pretty much never change ^^

])
.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.