diff --git a/examples/progress.rs b/examples/progress.rs index 62591c1..06d7c1e 100644 --- a/examples/progress.rs +++ b/examples/progress.rs @@ -60,7 +60,7 @@ fn coffee_break(s: &mut Cursive) { s.pop_layer(); s.add_layer(Dialog::empty() .title("Preparation complete") - .content(TextView::new("Now, the real deal!")) + .content(TextView::new("Now, the real deal!").center()) .button("Again??", phase_2)); } @@ -117,6 +117,7 @@ fn final_step(s: &mut Cursive) { s.add_layer(Dialog::empty() .title("Report") .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())); } diff --git a/src/view/text_view.rs b/src/view/text_view.rs index 9b9be6a..c437da6 100644 --- a/src/view/text_view.rs +++ b/src/view/text_view.rs @@ -101,6 +101,12 @@ impl TextView { 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. pub fn set_content(&mut self, content: &str) { let content = strip_last_newline(content);