mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-23 08:54:30 +03:00
Expose ButtonBuilder label for a bus_spotting experiment.
This commit is contained in:
parent
18b03139ac
commit
1a9b0715ac
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user