Crate too

Crate too 

Source
Expand description

too – a different kind of tui library

§Feature flags

FlagDescriptionDefault
terminalenable the terminal backendtrue
syncenable Send+Sync wrappersfalse
profileenable profiling supportfalse

§Simple examples

§Centering some text:

fn main() -> std::io::Result<()> {
    too::run(|ui| {
        ui.center(|ui| ui.label("hello world"));
    })
}

§A pair of buttons to increment and decrement a counter

fn main() -> std::io::Result<()> {
    let mut counter = 0;
    too::run(|ui| {
        ui.vertical(|ui|{
            ui.horizontal(|ui|{
                if ui.button("add 1").clicked() {
                    counter += 1;
                }
                if ui.button("subtract 1").clicked() {
                    counter -= 1;
                }
            });
            ui.label(counter)
        });
    })
}

§Storing state in a struct

use too::view::Ui;

#[derive(Default)]
struct App {
    value: f32
}

impl App {
    fn view(&mut self, ui: &Ui) {
        ui.slider(&mut value);
    }
}

fn main() -> std::io::Result<()> {
    let mut app = App::default()
    too::run(|ui| app.view(ui))
}

§Storing state seperately from an application

use too::view::Ui;

#[derive(Default)]
struct State {
    value: f32
}

struct App ;

impl App {
    fn view(&self, state: &mut State, ui: &Ui) {
        ui.slider(&mut state.value);
    }
}

fn main() -> std::io::Result<()> {
    let app = App;
    let mut state = State::default();
    too::run(|ui| app.view(&mut state, ui))
}

Some pre-made views are provided in: too::views

Modules§

animation
Interpolated animations
backend
Backend types
helpers
Some convenient types and functions
layout
Layout helpers
lock
Abstraction for providing interior mutability over for a type.
math
Math types and helpers used by this crate
renderer
Things that can be drawn to a surface
term
A terminal backend
view
Types for implementing and interacting with Ui elements
views
Some premade views, with their builders, styles and responses.

Macros§

format_str
Like std::format! but for a Str

Structs§

RunConfig
Configuration for an application
Str
A semver wrapper around a CompactString

Functions§

application
Run an application with the provided RunConfig
run
Run an application with the default RunConfig