mirror of
https://github.com/ratatui-org/ratatui
synced 2024-11-10 07:04:17 +00:00
Two sizes
This commit is contained in:
parent
4b54fbb3c9
commit
28a3e42a43
3 changed files with 41 additions and 9 deletions
|
@ -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<impl Backend>) -> Result<(), color_eyre::eyre::Error> {
|
||||
fn run(mut terminal: Terminal<impl Backend>) -> 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(());
|
||||
|
|
|
@ -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},
|
||||
|
|
|
@ -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! {"
|
||||
█▀▀▄ ▄▀▀▄▝▜▛▘▄▀▀▄▝▜▛▘█ █ █
|
||||
█▀▀▄ █▀▀█ ▐▌ █▀▀█ ▐▌ ▀▄▄▀ █
|
||||
"}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue