Skip to main content

Crate soft_ratatui

Crate soft_ratatui 

Source
Expand description

§Ratatui Software Backend

A collection of software rendering backends for Ratatui that turn terminal UIs into RGB pixmaps. Perfect for embedding Ratatui into game engines, GUIs, or wherever else.

§Features

  • Multiple Font Backends: Choose from various font rendering technologies
  • Flexible Output: Get raw RGB data or RGBA with color-to-alpha support
  • Real-time Updates: Efficient redrawing, perfect for video games
  • Ratatui Compatible: Full implementation of Ratatui’s Backend trait
  • Bevy Examples: Show you how to get started with the great game engine, also check out bevy_ratatui

§Feature Flags

§Performance

Generally faster than running ratatui in a terminal with crossterm. Expect hundreds of fps on a normal workload.

§Available Backends

BackendFeatureDescription
EmbeddedGraphicsembedded-graphicsUses embedded-graphics font atlases
EmbeddedTTFembedded-ttfTrueType font rendering via RustType
Bdfbdf-parserBitmap Distribution Format fonts
CosmicTextcosmic-textAdvanced text shaping and layout

§Quick Start

cargo add soft_ratatui
cargo add ratatui

§Minimal Example

use soft_ratatui::embedded_graphics_unicodefonts::{
    mono_8x13_atlas, mono_8x13_bold_atlas, mono_8x13_italic_atlas,
};
use ratatui::Terminal;
use ratatui::widgets::{Block, Borders, Paragraph, Wrap};
use soft_ratatui::{EmbeddedGraphics, SoftBackend};

fn main() {
    let font_regular = mono_8x13_atlas();
    let font_italic = mono_8x13_italic_atlas();
    let font_bold = mono_8x13_bold_atlas();
    let backend = SoftBackend::<EmbeddedGraphics>::new(
        100,
        50,
        font_regular,
        Some(font_bold),
        Some(font_italic),
    );
    let mut terminal = Terminal::new(backend).unwrap();
    terminal.clear();

    let _ = terminal.draw(|frame| {
        let area = frame.area();
        let textik = format!("Hello soft! The window area is {}", area);
        frame.render_widget(
            Paragraph::new(textik)
                .block(Block::new().title("Ratatui").borders(Borders::ALL))
                .wrap(Wrap { trim: false }),
            area,
        );
    });
}

§Usage Patterns

§Getting Rendered Output


// Get raw RGB data (3 bytes per pixel: R, G, B)
let rgb_data = backend.get_pixmap_data();

// Get RGBA data (4 bytes per pixel: R, G, B, A)
let rgba_data = backend.get_pixmap_data_as_rgba();

// Get RGBA data with one of the colors set to fully transparent
let transparent_rgba =
    backend.rgb_pixmap.to_rgba_with_color_as_transparent(&(255, 0, 255));

// Get dimensions
let width = backend.get_pixmap_width();
let height = backend.get_pixmap_height();

§Examples

See the examples/ directory for complete working examples with different backends and font configurations.

§License

This project is licensed under the MIT and Apache2.0 license.

Re-exports§

pub use embedded_graphics_unicodefonts;unicodefonts
pub use embedded_ttf;embedded-ttf
pub use rusttype;embedded-ttf

Structs§

Bdfbdf-parser
Raster backend for bitmap fonts parsed from BDF data.
BlinkConfig
Blink configuration for text modifiers and cursor.
BlinkTiming
Timing parameters for a single blink pattern.
CosmicTextcosmic-text
Raster backend built on cosmic-text.
CursorConfig
Cursor appearance and blink behavior.
EmbeddedGraphicsembedded-graphics
Raster backend built on embedded-graphics mono fonts.
EmbeddedTTFembedded-ttf
Raster backend built on embedded-ttf and rusttype.
RgbPixmap
An RGB pixmap backed by a flat byte buffer.
SoftBackend
A software-rendering Backend for Ratatui.

Enums§

CursorStyle
How the cursor is rendered on the pixmap.

Traits§

RasterBackend
Trait implemented by font rasterizers used by SoftBackend.