mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-01 02:33:54 +03:00
replace Btn::pop_up
This commit is contained in:
parent
7797d17ff0
commit
ea39fecf03
@ -273,11 +273,10 @@ fn build_panel(ctx: &mut EventCtx, app: &App, start: &Building, isochrone: &Isoc
|
||||
|
||||
rows.push(Widget::row(vec![
|
||||
"Map:".draw_text(ctx),
|
||||
Btn::pop_up(ctx, Some(nice_map_name(app.map.get_name()))).build(
|
||||
ctx,
|
||||
"change map",
|
||||
lctrl(Key::L),
|
||||
),
|
||||
ctx.style()
|
||||
.btn_popup_light(nice_map_name(app.map.get_name()))
|
||||
.hotkey(lctrl(Key::L))
|
||||
.build_widget(ctx, "change map"),
|
||||
]));
|
||||
|
||||
rows.push(
|
||||
|
@ -32,11 +32,10 @@ impl DevToolsMode {
|
||||
]),
|
||||
Widget::row(vec![
|
||||
"Change map:".draw_text(ctx),
|
||||
Btn::pop_up(ctx, Some(nice_map_name(app.primary.map.get_name()))).build(
|
||||
ctx,
|
||||
"change map",
|
||||
lctrl(Key::L),
|
||||
),
|
||||
ctx.style()
|
||||
.btn_popup_light(nice_map_name(app.primary.map.get_name()))
|
||||
.hotkey(lctrl(Key::L))
|
||||
.build_widget(ctx, "change map"),
|
||||
]),
|
||||
Widget::custom_row(vec![
|
||||
Btn::text_fg("edit a polygon").build_def(ctx, Key::E),
|
||||
|
@ -312,15 +312,20 @@ fn make_panel(ctx: &mut EventCtx, story: &StoryMap, mode: &Mode, dirty: bool) ->
|
||||
Widget::row(vec![
|
||||
Line("Story map editor").small_heading().draw(ctx),
|
||||
Widget::vert_separator(ctx, 30.0),
|
||||
Btn::pop_up(ctx, Some(&story.name)).build(ctx, "load", lctrl(Key::L)),
|
||||
if dirty {
|
||||
Btn::svg_def("system/assets/tools/save.svg").build(ctx, "save", lctrl(Key::S))
|
||||
} else {
|
||||
Widget::draw_svg_transform(
|
||||
ctx,
|
||||
"system/assets/tools/save.svg",
|
||||
RewriteColor::ChangeAlpha(0.5),
|
||||
)
|
||||
ctx.style()
|
||||
.btn_popup_light(&story.name)
|
||||
.hotkey(lctrl(Key::L))
|
||||
.build_widget(ctx, "load"),
|
||||
{
|
||||
let mut save_button = ctx
|
||||
.style()
|
||||
.btn_primary_light_icon("system/assets/tools/save.svg")
|
||||
.hotkey(lctrl(Key::S));
|
||||
if !dirty {
|
||||
save_button = save_button.disabled();
|
||||
}
|
||||
|
||||
save_button.build_widget(ctx, "save")
|
||||
},
|
||||
ctx.style().btn_close_widget(ctx),
|
||||
]),
|
||||
|
@ -750,7 +750,10 @@ fn make_changelist(ctx: &mut EventCtx, app: &App) -> Panel {
|
||||
let edits = app.primary.map.get_edits();
|
||||
let mut col = vec![
|
||||
Widget::row(vec![
|
||||
Btn::pop_up(ctx, Some(&edits.edits_name)).build(ctx, "manage proposals", lctrl(Key::P)),
|
||||
ctx.style()
|
||||
.btn_popup_light(&edits.edits_name)
|
||||
.hotkey(lctrl(Key::P))
|
||||
.build_widget(ctx, "manage proposals"),
|
||||
"autosaved"
|
||||
.draw_text(ctx)
|
||||
.container()
|
||||
|
@ -52,11 +52,9 @@ impl Viewer {
|
||||
]),
|
||||
Widget::row(vec![
|
||||
"Change map:".draw_text(ctx),
|
||||
Btn::pop_up(ctx, Some(nice_map_name(app.map.get_name()))).build(
|
||||
ctx,
|
||||
"change map",
|
||||
lctrl(Key::L),
|
||||
),
|
||||
ctx.style()
|
||||
.btn_light_popup(ctx, Some(nice_map_name(app.map.get_name())))
|
||||
.build(ctx, "change map", lctrl(Key::L)),
|
||||
]),
|
||||
Widget::row(vec![
|
||||
Btn::svg_def("system/assets/tools/settings.svg").build(ctx, "settings", None),
|
||||
|
@ -134,11 +134,9 @@ impl ParkingMapper {
|
||||
]),
|
||||
Widget::row(vec![
|
||||
"Change map:".draw_text(ctx),
|
||||
Btn::pop_up(ctx, Some(nice_map_name(map.get_name()))).build(
|
||||
ctx,
|
||||
"change map",
|
||||
None,
|
||||
),
|
||||
ctx.style()
|
||||
.btn_popup_light(nice_map_name(map.get_name()))
|
||||
.build_widget(ctx, "change map"),
|
||||
]),
|
||||
format!(
|
||||
"{} / {} ways done (you've mapped {})",
|
||||
|
@ -210,55 +210,6 @@ impl Btn {
|
||||
selected_bg_color: Color::grey(0.8),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn pop_up<I: Into<String>>(ctx: &EventCtx, label: Option<I>) -> BtnBuilder {
|
||||
let mut icon_batch = GeomBatch::new();
|
||||
let icon_container = Polygon::rectangle(20.0, 30.0);
|
||||
icon_batch.push(Color::CLEAR, icon_container);
|
||||
|
||||
let icon = GeomBatch::from_svg_contents(
|
||||
include_bytes!("../../icons/arrow_drop_down.svg").to_vec(),
|
||||
)
|
||||
.color(RewriteColor::ChangeAll(ctx.style().outline_color))
|
||||
.autocrop()
|
||||
.centered_on(icon_batch.get_bounds().center());
|
||||
|
||||
icon_batch.append(icon);
|
||||
|
||||
let button_geom = if let Some(label) = label {
|
||||
let text = Text::from(Line(label));
|
||||
let mut text_geom: GeomBatch = text.render(ctx);
|
||||
text_geom.append(icon_batch.translate(text_geom.get_bounds().width() + 8.0, 0.0));
|
||||
text_geom
|
||||
} else {
|
||||
icon_batch
|
||||
};
|
||||
|
||||
let (button_geom, hitbox) = button_geom
|
||||
.batch()
|
||||
.container()
|
||||
.padding(EdgeInsets {
|
||||
top: 4.0,
|
||||
bottom: 4.0,
|
||||
left: 8.0,
|
||||
right: 8.0,
|
||||
})
|
||||
.to_geom(ctx, None);
|
||||
|
||||
let hovered = button_geom.clone().color(RewriteColor::Change(
|
||||
ctx.style().outline_color,
|
||||
ctx.style().hovering_color,
|
||||
));
|
||||
|
||||
let outline = (ctx.style().outline_thickness, ctx.style().outline_color);
|
||||
BtnBuilder::Custom {
|
||||
normal: button_geom,
|
||||
hovered,
|
||||
hitbox,
|
||||
maybe_tooltip: None,
|
||||
maybe_outline: Some(outline),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
@ -799,14 +750,6 @@ pub enum BtnBuilder {
|
||||
unselected_bg_color: Color,
|
||||
selected_bg_color: Color,
|
||||
},
|
||||
Custom {
|
||||
normal: GeomBatch,
|
||||
hovered: GeomBatch,
|
||||
hitbox: Polygon,
|
||||
maybe_tooltip: Option<Text>,
|
||||
// thickness, color
|
||||
maybe_outline: Option<(f64, Color)>,
|
||||
},
|
||||
}
|
||||
|
||||
impl BtnBuilder {
|
||||
@ -816,10 +759,6 @@ impl BtnBuilder {
|
||||
| BtnBuilder::PlainText {
|
||||
ref mut maybe_tooltip,
|
||||
..
|
||||
}
|
||||
| BtnBuilder::Custom {
|
||||
ref mut maybe_tooltip,
|
||||
..
|
||||
} => {
|
||||
assert!(maybe_tooltip.is_none());
|
||||
*maybe_tooltip = Some(tooltip);
|
||||
@ -961,31 +900,6 @@ impl BtnBuilder {
|
||||
false,
|
||||
)
|
||||
}
|
||||
BtnBuilder::Custom {
|
||||
normal,
|
||||
hovered,
|
||||
hitbox,
|
||||
maybe_tooltip,
|
||||
maybe_outline,
|
||||
} => {
|
||||
let button = Button::widget(
|
||||
ctx,
|
||||
normal.clone(),
|
||||
hovered,
|
||||
normal,
|
||||
key.into(),
|
||||
&action.into(),
|
||||
maybe_tooltip,
|
||||
hitbox,
|
||||
false,
|
||||
);
|
||||
|
||||
if let Some(outline) = maybe_outline {
|
||||
button.outline(outline.0, outline.1)
|
||||
} else {
|
||||
button
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -993,7 +907,6 @@ impl BtnBuilder {
|
||||
pub fn build_def<MK: Into<Option<MultiKey>>>(self, ctx: &EventCtx, key: MK) -> Widget {
|
||||
match self {
|
||||
BtnBuilder::SVG { .. } => panic!("Can't use build_def on an SVG button"),
|
||||
BtnBuilder::Custom { .. } => panic!("Can't use build_def on a custom button"),
|
||||
BtnBuilder::TextFG(ref action, _, _)
|
||||
| BtnBuilder::PlainText { ref action, .. }
|
||||
| BtnBuilder::TextBG { ref action, .. } => {
|
||||
|
Loading…
Reference in New Issue
Block a user