cursive/examples/scroll.rs

35 lines
908 B
Rust
Raw Normal View History

2018-05-22 00:56:20 +00:00
extern crate cursive;
use cursive::traits::Boxable;
2018-06-27 00:40:15 +00:00
use cursive::view::Scrollable;
use cursive::views::{Button, Canvas, Dialog, LinearLayout};
2018-05-22 00:56:20 +00:00
use cursive::Printer;
fn main() {
let mut siv = cursive::Cursive::default();
2018-05-22 02:21:27 +00:00
siv.add_layer(
Dialog::around(
2018-06-27 00:40:15 +00:00
LinearLayout::vertical()
.child(Button::new("Foo", |s| s.add_layer(Dialog::info("Ah"))))
.child(Canvas::new(()).with_draw(draw).fixed_size((120, 40)))
.child(Button::new("Bar", |s| s.add_layer(Dialog::info("Uh"))))
.scrollable()
.scroll_x(true),
2018-05-22 02:21:27 +00:00
).fixed_size((60, 30)),
);
2018-05-22 00:56:20 +00:00
siv.add_global_callback('q', |s| s.quit());
siv.run();
}
fn draw(_: &(), p: &Printer) {
for x in 0..p.size.x {
for y in 0..p.size.y {
2018-05-22 02:21:27 +00:00
let c = (x + 6 * y) % 10;
2018-05-22 00:56:20 +00:00
p.print((x, y), &format!("{}", c));
}
}
}