cursive/examples/linear.rs

39 lines
1.3 KiB
Rust
Raw Normal View History

extern crate cursive;
use cursive::align::HAlign;
use cursive::traits::*;
2018-01-16 02:55:27 +00:00
use cursive::views::{Dialog, DummyView, LinearLayout, TextView};
2018-06-11 06:29:10 +00:00
use cursive::Cursive;
2018-01-16 02:55:27 +00:00
// This example uses a LinearLayout to stick multiple views next to each other.
fn main() {
let mut siv = Cursive::default();
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
2017-10-12 23:38:55 +00:00
siv.add_layer(
Dialog::around(
LinearLayout::vertical()
.child(TextView::new("Title").h_align(HAlign::Center))
2018-01-16 02:55:27 +00:00
// Dummy views can be used for spacing
.child(DummyView.fixed_height(1))
// Disabling scrolling means the view cannot shrink.
// Try resizing the window, and see what happens!
.child(TextView::new(text).scrollable(false))
.child(TextView::new(text))
.child(TextView::new(text))
.child(TextView::new(text))
// Give everything a fixed width so it doesn't get too wide
.fixed_width(30),
2017-10-12 23:38:55 +00:00
).button("Quit", |s| s.quit())
.h_align(HAlign::Center),
);
siv.run();
}