From 9ea70e28c639d967f361a35e851fc450d0b797d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orhun=20Parmaks=C4=B1z?= Date: Mon, 10 Feb 2025 01:16:34 +0300 Subject: [PATCH] docs(examples): move widget-impl example to examples folder (#1663) --- Cargo.lock | 9 ++++++ examples/apps/advanced-widget-impl/Cargo.toml | 14 +++++++++ examples/apps/advanced-widget-impl/README.md | 9 ++++++ .../apps/advanced-widget-impl/src/main.rs | 31 +++++++------------ ratatui/Cargo.toml | 5 --- 5 files changed, 43 insertions(+), 25 deletions(-) create mode 100644 examples/apps/advanced-widget-impl/Cargo.toml create mode 100644 examples/apps/advanced-widget-impl/README.md rename ratatui/examples/widget_impl.rs => examples/apps/advanced-widget-impl/src/main.rs (89%) diff --git a/Cargo.lock b/Cargo.lock index fe6da8f4..6a44bfce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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" diff --git a/examples/apps/advanced-widget-impl/Cargo.toml b/examples/apps/advanced-widget-impl/Cargo.toml new file mode 100644 index 00000000..7aafc5a1 --- /dev/null +++ b/examples/apps/advanced-widget-impl/Cargo.toml @@ -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 diff --git a/examples/apps/advanced-widget-impl/README.md b/examples/apps/advanced-widget-impl/README.md new file mode 100644 index 00000000..0a3471f1 --- /dev/null +++ b/examples/apps/advanced-widget-impl/README.md @@ -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 +``` diff --git a/ratatui/examples/widget_impl.rs b/examples/apps/advanced-widget-impl/src/main.rs similarity index 89% rename from ratatui/examples/widget_impl.rs rename to examples/apps/advanced-widget-impl/src/main.rs index 2cead89c..e97eaf8c 100644 --- a/ratatui/examples/widget_impl.rs +++ b/examples/apps/advanced-widget-impl/src/main.rs @@ -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 diff --git a/ratatui/Cargo.toml b/ratatui/Cargo.toml index 08b51158..ae39f163 100644 --- a/ratatui/Cargo.toml +++ b/ratatui/Cargo.toml @@ -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"]