Add a center() convenient method to TextView

Avoids having to import HAlign
This commit is contained in:
Alexandre Bury 2016-07-27 23:58:57 -07:00
parent 261d2aac48
commit 2597c9a566
2 changed files with 9 additions and 2 deletions

View File

@ -60,7 +60,7 @@ fn coffee_break(s: &mut Cursive) {
s.pop_layer(); s.pop_layer();
s.add_layer(Dialog::empty() s.add_layer(Dialog::empty()
.title("Preparation complete") .title("Preparation complete")
.content(TextView::new("Now, the real deal!")) .content(TextView::new("Now, the real deal!").center())
.button("Again??", phase_2)); .button("Again??", phase_2));
} }
@ -117,6 +117,7 @@ fn final_step(s: &mut Cursive) {
s.add_layer(Dialog::empty() s.add_layer(Dialog::empty()
.title("Report") .title("Report")
.content(TextView::new("Time travel was a success!\n\ .content(TextView::new("Time travel was a success!\n\
We went forward a few seconds!!")) We went forward a few seconds!!")
.center())
.button("That's it?", |s| s.quit())); .button("That's it?", |s| s.quit()));
} }

View File

@ -101,6 +101,12 @@ impl TextView {
self self
} }
/// Center the text horizontally and vertically inside the view.
pub fn center(mut self) -> Self {
self.align = Align::center();
self
}
/// Replace the text in this view. /// Replace the text in this view.
pub fn set_content(&mut self, content: &str) { pub fn set_content(&mut self, content: &str) {
let content = strip_last_newline(content); let content = strip_last_newline(content);