blit-ui 0.1.0

an experimental immediate-mode ui library
Documentation
  • Coverage
  • 40.7%
    105 out of 258 items documented4 out of 40 items with examples
  • Size
  • Source code size: 332.5 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 5.0 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 2s Average build duration of successful builds.
  • all releases: 2s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • nicoburniske/blit
    3 3 1
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • nicoburniske

blit

blit is an experimental immediate-mode ui toolkit for rust.

the core is ~5k lines of no_std, zero-dependency rust with a fast, composable api for layout, interaction and animation.

https://github.com/user-attachments/assets/0350260c-592f-4337-b541-9762faf7a96d

try it

terminal:

nix develop --command cargo run --example tui-demo

desktop + CPU:

nix develop --command cargo run --release --example desktop-demo

desktop + GPU:

nix develop --command cargo run -p blit-demo --no-default-features --features gpu --release --example desktop-demo

example

each frame, blit:

  • builds widgets into a tree of nodes
  • solves layouts and assigns final rectangles
  • paints each node (usually recording draw commands) with its resolved area
use blit::KeyboardEvent;
use blit_tui::{
    Ui,
    interact,
    color::Color,
    layout::{Align, Justify, flex},
    text::{Text, HorizontalAlign, TextAttributes, TextOptions},
    widgets::block::{Block, Border},
};

fn main() -> std::io::Result<()> {
    blit_tui::run(|ui| {
        // layout arranges the root's children in a column
        // pad insets children while painted content keeps the full box
        let mut root = ui.layout(flex::column().gap(1)).pad(1);

        let quit = root
            // the header sizes itself to its contents
            .child()
            // the header returns whether its button was clicked
            .build(|ui: Ui<'_>| {
                let mut header = ui
                    .layout(flex::row().align(Align::Start).justify(Justify::SpaceBetween))
                    .pad(1);

                // insert draws content directly on the node
                header.insert(Block::new().border(Border::new(Color::BLUE)));

                // title
                header
                    .child()
                    .insert(Text::new("hello from blit!").attributes(TextAttributes::BOLD));

                header
                    .child()
                    .item(flex::item().width(8).height(1))
                    .build(|mut ui: Ui<'_>| {
                        let press = ui.interact(interact::press());

                        ui.insert(Block::new().background(Color::BLUE));
                        ui.insert(
                            Text::new("quit")
                                .options(TextOptions::new().horizontal_align(HorizontalAlign::Center)),
                        );

                        press.clicked
                    })
            });
        let quit_key = root.interact(interact::keyboard(|input| match input {
            KeyboardEvent::Text("q") => Some(()),
            _ => None,
        }));
        if quit || quit_key.is_some() {
            root.context_mut().quit = true;
        }
    })
}

install

tui:

cargo add blit-ui blit-tui

desktop (pick cpu or gpu):

cargo add blit-ui blit-gui blit-gui-widget blit-text-parley
cargo add blit-desktop --features cpu

blit-ui exposes its library as blit, so import it with use blit::....

crates

  • blit-ui: the core
  • blit-widget: layouts, widgets and interactions
  • blit-tui: runs blit in a terminal
  • blit-desktop: runs blit in a native window (macos + wayland)

for custom backends:

  • blit-gui: 2d drawing commands
  • blit-cpu and blit-gpu: renderers for blit-gui
  • blit-text-parley: text layout with parley
  • blit-gui-widget: widgets that need blit-gui, like text input

acknowledgments

blit wouldn't exist without the people who shared their work and ideas so openly.

thank you