docs(widgets): move the logo example to widgets (#1543)

related #1512 

Also updates the code to make it consistent with the other examples
This commit is contained in:
Orhun Parmaksız 2024-12-03 22:30:35 +03:00 committed by GitHub
parent ce4856a65f
commit 17bba14540
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 18 deletions

View File

@ -1,6 +1,7 @@
//! # [Ratatui] Logo example
//! # [Ratatui] `RatatuiLogo` example
//!
//! The latest version of this example is available in the [examples] folder in the repository.
//! The latest version of this example is available in the [widget 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
@ -10,17 +11,17 @@
//! library you are using.
//!
//! [Ratatui]: https://github.com/ratatui/ratatui
//! [examples]: https://github.com/ratatui/ratatui/blob/main/examples
//! [widget examples]: https://github.com/ratatui/ratatui/blob/main/ratatui-widgets/examples
//! [examples readme]: https://github.com/ratatui/ratatui/blob/main/examples/README.md
use std::env::args;
use color_eyre::Result;
use crossterm::event::{self, Event};
use ratatui::{
crossterm::event::{self, Event},
layout::{Constraint, Layout},
widgets::{RatatuiLogo, RatatuiLogoSize},
DefaultTerminal, TerminalOptions, Viewport,
DefaultTerminal, Frame, TerminalOptions, Viewport,
};
fn main() -> Result<()> {
@ -39,16 +40,21 @@ fn main() -> Result<()> {
result
}
/// Run the application.
fn run(mut terminal: DefaultTerminal, size: RatatuiLogoSize) -> Result<()> {
loop {
terminal.draw(|frame| {
use Constraint::{Fill, Length};
let [top, bottom] = Layout::vertical([Length(1), Fill(1)]).areas(frame.area());
frame.render_widget("Powered by", top);
frame.render_widget(RatatuiLogo::new(size), bottom);
})?;
terminal.draw(|frame| draw(frame, size))?;
if matches!(event::read()?, Event::Key(_)) {
break Ok(());
}
}
}
/// Draw the UI with a logo.
fn draw(frame: &mut Frame, size: RatatuiLogoSize) {
let [top, bottom] =
Layout::vertical([Constraint::Length(1), Constraint::Fill(1)]).areas(frame.area());
frame.render_widget("Powered by", top);
frame.render_widget(RatatuiLogo::new(size), bottom);
}

View File

@ -14,10 +14,10 @@ use ratatui_core::{buffer::Buffer, layout::Rect, text::Text, widgets::Widget};
/// argument:
///
/// ```shell
/// cargo run --example ratatui-logo [size]
/// cargo run --example logo [size]
/// ```
///
/// [Ratatui-logo]: https://github.com/ratatui/ratatui/blob/main/examples/ratatui-logo.rs
/// [Ratatui-logo]: https://github.com/ratatui/ratatui/blob/main/ratatui-widgets/examples/logo.rs
///
/// ## Tiny (default, 2x15 characters)
///

View File

@ -271,11 +271,6 @@ name = "popup"
required-features = ["crossterm"]
doc-scrape-examples = true
[[example]]
name = "ratatui-logo"
required-features = ["crossterm"]
doc-scrape-examples = true
[[example]]
name = "scrollbar"
required-features = ["crossterm"]