From 2597c9a56679894f9257c9f2098e5debda82bea9 Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Wed, 27 Jul 2016 23:58:57 -0700 Subject: [PATCH] Add a `center()` convenient method to `TextView` Avoids having to import HAlign --- examples/progress.rs | 5 +++-- src/view/text_view.rs | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) 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);