diff --git a/src/views/button.rs b/src/views/button.rs index c985b6e..ecd651c 100644 --- a/src/views/button.rs +++ b/src/views/button.rs @@ -25,9 +25,10 @@ pub struct Button { impl Button { /// Creates a new button with the given content and callback. - pub fn new>(label: S, cb: F) -> Self + pub fn new(label: S, cb: F) -> Self where F: 'static + Fn(&mut Cursive) -> R, + S: Into, { let label = label.into(); Self::new_raw(format!("<{}>", label), cb) @@ -99,6 +100,26 @@ impl Button { &self.label } + /// Sets the label to the given value. + /// + /// This will include brackets. + pub fn set_label(&mut self, label: S) + where + S: Into, + { + self.set_label_raw(format!("<{}>", label.into())); + } + + /// Sets the label exactly to the given value. + /// + /// This will not include brackets. + pub fn set_label_raw(&mut self, label: S) + where + S: Into, + { + self.label = label.into(); + } + fn req_size(&self) -> Vec2 { Vec2::new(self.label.width(), 1) }