diff --git a/examples/ratatui-logo.rs b/examples/ratatui-logo.rs index 185e109a..f26c1cf1 100644 --- a/examples/ratatui-logo.rs +++ b/examples/ratatui-logo.rs @@ -20,7 +20,7 @@ use ratatui::{ backend::{Backend, CrosstermBackend}, crossterm::terminal::{disable_raw_mode, enable_raw_mode}, layout::{Constraint, Layout}, - widgets::RatatuiLogo, + widgets::{RatatuiLogo, RatatuiLogoSize}, Terminal, TerminalOptions, Viewport, }; @@ -33,13 +33,13 @@ fn main() -> color_eyre::Result<()> { result } -fn run(mut terminal: Terminal) -> Result<(), color_eyre::eyre::Error> { +fn run(mut terminal: Terminal) -> color_eyre::Result<()> { loop { terminal.draw(|frame| { let [top, bottom] = Layout::vertical([Constraint::Length(1), Constraint::Fill(1)]).areas(frame.area()); frame.render_widget("Powered by", top); - frame.render_widget(RatatuiLogo, bottom); + frame.render_widget(RatatuiLogo::new(RatatuiLogoSize::Tiny), bottom); })?; if matches!(event::read()?, Event::Key(_)) { break Ok(()); diff --git a/src/widgets.rs b/src/widgets.rs index 5aaf004c..617d0fef 100644 --- a/src/widgets.rs +++ b/src/widgets.rs @@ -47,7 +47,7 @@ pub use self::{ clear::Clear, gauge::{Gauge, LineGauge}, list::{List, ListDirection, ListItem, ListState}, - logo::RatatuiLogo, + logo::{RatatuiLogo, Size as RatatuiLogoSize}, paragraph::{Paragraph, Wrap}, scrollbar::{ScrollDirection, Scrollbar, ScrollbarOrientation, ScrollbarState}, sparkline::{RenderDirection, Sparkline}, diff --git a/src/widgets/logo.rs b/src/widgets/logo.rs index fd5a4d11..28f41db3 100644 --- a/src/widgets/logo.rs +++ b/src/widgets/logo.rs @@ -3,14 +3,46 @@ use indoc::indoc; use crate::{buffer::Buffer, layout::Rect, text::Text, widgets::Widget}; /// A fun example of using half block characters to draw a logo -pub struct RatatuiLogo; +pub struct RatatuiLogo { + size: Size, +} + +/// The size of the logo +#[non_exhaustive] +pub enum Size { + /// A tiny logo + Tiny, + /// A small logo + Small, +} impl Widget for RatatuiLogo { fn render(self, area: Rect, buf: &mut Buffer) { - let logo = indoc! {" - █▀▀▄ ▄▀▀▄ ▀█▀ ▄▀▀▄ ▀█▀ █ █ █ - █▀▀▄ █▀▀█ █ █▀▀█ █ ▀▄▄▀ █ - "}; + let logo = match self.size { + Size::Tiny => Self::tiny(), + Size::Small => Self::small(), + }; Text::raw(logo).render(area, buf); } } + +impl RatatuiLogo { + /// Create a new Ratatui logo widget + pub fn new(size: Size) -> Self { + Self { size } + } + + fn tiny() -> &'static str { + indoc! {" + ▛▚▗▀▖▜▘▞▚▝▛▐ ▌▌ + ▛▚▐▀▌▐ ▛▜ ▌▝▄▘▌ + "} + } + + fn small() -> &'static str { + indoc! {" + █▀▀▄ ▄▀▀▄▝▜▛▘▄▀▀▄▝▜▛▘█ █ █ + █▀▀▄ █▀▀█ ▐▌ █▀▀█ ▐▌ ▀▄▄▀ █ + "} + } +}