mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-12 20:23:35 +00:00
Add Button::set_label
This commit is contained in:
parent
0666a8b585
commit
56f81eee7c
@ -25,9 +25,10 @@ pub struct Button {
|
||||
|
||||
impl Button {
|
||||
/// Creates a new button with the given content and callback.
|
||||
pub fn new<F, R, S: Into<String>>(label: S, cb: F) -> Self
|
||||
pub fn new<F, R, S>(label: S, cb: F) -> Self
|
||||
where
|
||||
F: 'static + Fn(&mut Cursive) -> R,
|
||||
S: Into<String>,
|
||||
{
|
||||
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<S>(&mut self, label: S)
|
||||
where
|
||||
S: Into<String>,
|
||||
{
|
||||
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<S>(&mut self, label: S)
|
||||
where
|
||||
S: Into<String>,
|
||||
{
|
||||
self.label = label.into();
|
||||
}
|
||||
|
||||
fn req_size(&self) -> Vec2 {
|
||||
Vec2::new(self.label.width(), 1)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user