mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Add scroll example
This commit is contained in:
parent
5eddc1b89a
commit
3bc07661d0
31
examples/scroll.rs
Normal file
31
examples/scroll.rs
Normal file
@ -0,0 +1,31 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::traits::Boxable;
|
||||
use cursive::views::{Canvas, Dialog, ScrollView, LinearLayout, Button};
|
||||
use cursive::Printer;
|
||||
|
||||
fn main() {
|
||||
let mut siv = cursive::Cursive::default();
|
||||
|
||||
siv.add_layer(Dialog::around(
|
||||
ScrollView::new(
|
||||
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"))))
|
||||
).scroll_x(true),
|
||||
).fixed_size((60, 30)));
|
||||
|
||||
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 {
|
||||
let c = (x + 6*y) % 10;
|
||||
p.print((x, y), &format!("{}", c));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user