cursive/examples/linear.rs

29 lines
1.1 KiB
Rust
Raw Normal View History

extern crate cursive;
use cursive::Cursive;
2016-07-13 08:19:05 +00:00
use cursive::view::{BoxView, Dialog, LinearLayout, TextView};
use cursive::align::HAlign;
fn main() {
let mut siv = Cursive::new();
2015-06-08 22:38:10 +00:00
// Some description text
2016-07-13 08:19:05 +00:00
let text = "This is a very simple example of linear layout. Two views \
are present, a short title above, and this text. The text \
has a fixed width, and the title is centered horizontally.";
2015-06-08 22:38:10 +00:00
// We'll create a dialog with a TextView serving as a title
2016-07-13 08:19:05 +00:00
siv.add_layer(Dialog::new(LinearLayout::vertical()
.child(TextView::new("Title").h_align(HAlign::Center))
2015-06-08 22:38:10 +00:00
// Box the textview, so it doesn't get too wide.
// A 0 height value means it will be unconstrained.
.child(BoxView::fixed_width(30, TextView::new(text)))
.child(BoxView::fixed_width(30, TextView::new(text)))
.child(BoxView::fixed_width(30, TextView::new(text)))
.child(BoxView::fixed_width(30, TextView::new(text))))
.button("Quit", |s| s.quit())
.h_align(HAlign::Center));
siv.run();
}