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
Backendtrait - Bevy Examples: Show you how to get started with the great game engine, also check out bevy_ratatui
§Feature Flags
unicodefonts: Enables embedded-graphics-unicodefonts (automatically activates embedded-graphics, is the default feature)bdf-parser: EnablesBdfbackend for bitmap fonts (bdf-parser)embedded-ttf: EnablesEmbeddedTTFbackend for TrueType fonts (automatically activates embedded-graphics) (embedded-ttf)cosmic-text: EnablesCosmicTextbackend for advanced text shaping (cosmic-text)embedded-graphics: EnablesEmbeddedGraphicsbackend
§Performance
Generally faster than running ratatui in a terminal with crossterm. Expect hundreds of fps on a normal workload.
§Available Backends
| Backend | Feature | Description |
|---|---|---|
EmbeddedGraphics | embedded-graphics | Uses embedded-graphics font atlases |
EmbeddedTTF | embedded-ttf | TrueType font rendering via RustType |
Bdf | bdf-parser | Bitmap Distribution Format fonts |
CosmicText | cosmic-text | Advanced 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;unicodefontspub use embedded_ttf;embedded-ttfpub use rusttype;embedded-ttf
Structs§
- Bdf
bdf-parser - Raster backend for bitmap fonts parsed from BDF data.
- Blink
Config - Blink configuration for text modifiers and cursor.
- Blink
Timing - Timing parameters for a single blink pattern.
- Cosmic
Text cosmic-text - Raster backend built on
cosmic-text. - Cursor
Config - Cursor appearance and blink behavior.
- Embedded
Graphics embedded-graphics - Raster backend built on
embedded-graphicsmono fonts. - EmbeddedTTF
embedded-ttf - Raster backend built on
embedded-ttfandrusttype. - RgbPixmap
- An RGB pixmap backed by a flat byte buffer.
- Soft
Backend - A software-rendering
Backendfor Ratatui.
Enums§
- Cursor
Style - How the cursor is rendered on the pixmap.
Traits§
- Raster
Backend - Trait implemented by font rasterizers used by
SoftBackend.