Expose ButtonBuilder label for a bus_spotting experiment.

This commit is contained in:
Dustin Carlino 2022-07-12 11:01:44 +01:00
parent 18b03139ac
commit 1a9b0715ac
2 changed files with 9 additions and 12 deletions

View File

@ -585,15 +585,19 @@ impl<'b, 'a: 'b, 'c> ButtonBuilder<'a, 'c> {
Widget::new(Box::new(self.build(ctx, action))).named(action)
}
/// Shorthand method to build a default widget whose `action` is derived from the label's text.
pub fn build_def(&self, ctx: &EventCtx) -> Widget {
let action = self
.default_style
/// Get the button's text label, if defined
pub fn get_action(&self) -> Option<&String> {
self.default_style
.label
.as_ref()
.and_then(|label| label.text.as_ref())
.expect("Must set `label_text` before calling build_def");
}
/// Shorthand method to build a default widget whose `action` is derived from the label's text.
pub fn build_def(&self, ctx: &EventCtx) -> Widget {
let action = self
.get_action()
.expect("Must set `label_text` before calling build_def");
self.build_widget(ctx, action)
}

View File

@ -764,13 +764,6 @@ impl Widget {
}
}
pub fn is_btn(&self, name: &str) -> bool {
self.widget
.downcast_ref::<Button>()
.map(|btn| btn.action == name)
.unwrap_or(false)
}
fn find(&self, name: &str) -> Option<&Widget> {
if self.id == Some(name.to_string()) {
return Some(self);