Button: add a way to get its label

This commit is contained in:
Alexandre Bury 2018-01-12 09:30:49 +01:00
parent 14f2bf636c
commit 0666a8b585

View File

@ -84,6 +84,21 @@ impl Button {
self.enabled self.enabled
} }
/// Returns the label for this button.
///
/// Includes brackets.
///
/// # Examples
///
/// ```rust
/// # use cursive::views::Button;
/// let button = Button::new("Quit", |s| s.quit());
/// assert_eq!(button.label(), "<Quit>");
/// ```
pub fn label(&self) -> &str {
&self.label
}
fn req_size(&self) -> Vec2 { fn req_size(&self) -> Vec2 {
Vec2::new(self.label.width(), 1) Vec2::new(self.label.width(), 1)
} }