-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
78 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
--- | ||
title: Widgets | ||
--- | ||
|
||
In this section we will discuss the widgets implemented for this tutorial: | ||
|
||
```rust | ||
{{#include @code/crates-tui-tutorial-app/src/widgets.rs}} | ||
``` | ||
|
||
We will be discussing a `SearchPage` widget that composes a `SearchResults` widget and a | ||
`SearchPrompt` widget: | ||
|
||
```plain | ||
Name Description Downloads | ||
█ ratatui A library tha 1021083 | ||
ratatui-textarea [deprecated] 1769 | ||
ratatui-macros Macros for Ra 487 | ||
tui-textarea tui-textarea 30526 | ||
ratatui-explorer ratatui-explo 29 | ||
ratatui-image An image widg 1820 | ||
▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ | ||
▏ ▕ | ||
▏ ratatui Sort By: Relevance ▕ | ||
▏ ▕ | ||
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ | ||
``` | ||
|
||
We will be using the `StatefulWidget` pattern. `StatefulWidget` is a Rust in Ratatui that is defined | ||
like so: | ||
|
||
```rust | ||
pub trait StatefulWidget { | ||
type State; | ||
fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State); | ||
} | ||
``` | ||
|
||
For this `StatefulWidget` pattern, we will always have at a minimum two `struct`s for every widget: | ||
|
||
1. the state | ||
2. the widget | ||
|
||
What information you store in each of these structs is generally up to you and your application. We | ||
will show a couple of different examples in this tutorial. |