docs(examples): move widget-impl example to examples folder (#1663)

This commit is contained in:
Orhun Parmaksız 2025-02-10 01:16:34 +03:00 committed by GitHub
parent 774ab788d4
commit 9ea70e28c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 43 additions and 25 deletions

9
Cargo.lock generated
View File

@ -17,6 +17,15 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "advanced-widget-impl"
version = "0.0.0"
dependencies = [
"color-eyre",
"crossterm",
"ratatui",
]
[[package]]
name = "aho-corasick"
version = "1.1.3"

View File

@ -0,0 +1,14 @@
[package]
name = "advanced-widget-impl"
publish = false
license.workspace = true
edition.workspace = true
rust-version.workspace = true
[dependencies]
color-eyre.workspace = true
crossterm.workspace = true
ratatui = { workspace = true, features = ["unstable-widget-ref"] }
[lints]
workspace = true

View File

@ -0,0 +1,9 @@
# Advanced Widget Implementation demo
This example shows how to render the `Widget` trait in different ways.
To run this demo:
```shell
cargo run -p advanced-widget-impl
```

View File

@ -1,21 +1,14 @@
//! # [Ratatui] Widgets implementation examples
//!
//! This example demonstrates various ways to implement widget traits in Ratatui on a type, a
//! reference, and a mutable reference. It also shows how to use the `WidgetRef` trait to render
//! boxed widgets.
//!
//! The latest version of this example is available in the [examples] folder in the repository.
//!
//! Please note that the examples are designed to be run against the `main` branch of the Github
//! repository. This means that you may not be able to compile with the latest release version on
//! crates.io, or the one that you have installed locally.
//!
//! See the [examples readme] for more information on finding examples that match the version of the
//! library you are using.
//!
//! [Ratatui]: https://github.com/ratatui/ratatui
//! [examples]: https://github.com/ratatui/ratatui/blob/main/examples
//! [examples readme]: https://github.com/ratatui/ratatui/blob/main/examples/README.md
/// A Ratatui example that demonstrates how to implement the `Widget` trait.
///
/// This example demonstrates various ways to implement `Widget` traits in Ratatui on a type, a
/// reference, and a mutable reference. It also shows how to use the `WidgetRef` trait to
/// render boxed widgets.
///
/// This example runs with the Ratatui library code in the branch that you are currently
/// reading. See the [`latest`] branch for the code which works with the most recent Ratatui
/// release.
///
/// [`latest`]: https://github.com/ratatui/ratatui/tree/latest
use std::time::{Duration, Instant};
use color_eyre::Result;
@ -40,7 +33,6 @@ fn main() -> Result<()> {
struct App {
should_quit: bool,
timer: Timer,
#[cfg(feature = "unstable-widget-ref")]
boxed_squares: BoxedSquares,
green_square: RightAlignedSquare,
}
@ -93,7 +85,6 @@ impl Widget for &mut App {
self.timer.render(timer, buf);
// render a boxed widget containing red and blue squares
#[cfg(feature = "unstable-widget-ref")]
self.boxed_squares.render(squares, buf);
// render a mutable reference to the green square widget

View File

@ -149,11 +149,6 @@ name = "scrollbar-widget"
required-features = ["crossterm"]
doc-scrape-examples = true
[[example]]
name = "widget_impl"
required-features = ["crossterm", "unstable-widget-ref"]
doc-scrape-examples = true
[[test]]
name = "state_serde"
required-features = ["serde"]