mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-24 15:02:59 +03:00
Highlight categories of businesses in the osm viewer
This commit is contained in:
parent
34b41a909e
commit
1a630c6361
@ -214,6 +214,14 @@ impl State<App> for Viewer {
|
||||
if self.fixed_object_outline.is_none() && old_id != app.primary.current_selection {
|
||||
self.recalculate_top_panel(ctx, app);
|
||||
}
|
||||
|
||||
let maybe_amenity = ctx
|
||||
.canvas
|
||||
.get_cursor_in_screen_space()
|
||||
.and_then(|_| self.top_panel.currently_hovering().cloned());
|
||||
if let Some(ref mut b) = self.businesses {
|
||||
b.hovering_on_amenity(ctx, app, maybe_amenity);
|
||||
}
|
||||
}
|
||||
|
||||
if ctx.canvas.get_cursor_in_map_space().is_some() && ctx.normal_left_click() {
|
||||
@ -323,6 +331,9 @@ impl State<App> for Viewer {
|
||||
}
|
||||
if let Some(ref b) = self.businesses {
|
||||
g.redraw(&b.highlight);
|
||||
if let Some((_, ref d)) = b.hovering_on_amenity {
|
||||
g.redraw(d);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -331,6 +342,7 @@ struct BusinessSearch {
|
||||
counts: Counter<String>,
|
||||
show: BTreeSet<String>,
|
||||
highlight: Drawable,
|
||||
hovering_on_amenity: Option<(String, Drawable)>,
|
||||
}
|
||||
|
||||
impl BusinessSearch {
|
||||
@ -346,6 +358,7 @@ impl BusinessSearch {
|
||||
counts,
|
||||
show,
|
||||
highlight: ctx.upload(GeomBatch::new()),
|
||||
hovering_on_amenity: None,
|
||||
};
|
||||
|
||||
// Initialize highlight
|
||||
@ -377,6 +390,33 @@ impl BusinessSearch {
|
||||
self.highlight = ctx.upload(batch);
|
||||
}
|
||||
|
||||
fn hovering_on_amenity(&mut self, ctx: &mut EventCtx, app: &App, amenity: Option<String>) {
|
||||
if amenity.is_none() {
|
||||
self.hovering_on_amenity = None;
|
||||
return;
|
||||
}
|
||||
|
||||
let amenity = amenity.unwrap();
|
||||
if self
|
||||
.hovering_on_amenity
|
||||
.as_ref()
|
||||
.map(|(current, _)| current == &amenity)
|
||||
.unwrap_or(false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
let mut batch = GeomBatch::new();
|
||||
if self.counts.get(amenity.clone()) > 0 {
|
||||
for b in app.primary.map.all_buildings() {
|
||||
if b.amenities.iter().any(|(_, a)| a == &amenity) {
|
||||
batch.push(Color::BLUE, b.polygon.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
self.hovering_on_amenity = Some((amenity, ctx.upload(batch)));
|
||||
}
|
||||
|
||||
fn render(&self, ctx: &mut EventCtx) -> Widget {
|
||||
let mut col = Vec::new();
|
||||
col.push(Btn::text_bg2("Hide business search").build_def(ctx, Key::Tab));
|
||||
|
@ -5,7 +5,7 @@ use crate::{
|
||||
|
||||
pub struct Checkbox {
|
||||
pub(crate) enabled: bool,
|
||||
btn: Button,
|
||||
pub(crate) btn: Button,
|
||||
other_btn: Button,
|
||||
}
|
||||
|
||||
|
@ -12,8 +12,9 @@ use geom::{Distance, Percent, Polygon};
|
||||
use crate::widgets::containers::{Container, Nothing};
|
||||
pub use crate::widgets::panel::Panel;
|
||||
use crate::{
|
||||
Button, Choice, Color, DeferDraw, DrawWithTooltips, Drawable, Dropdown, EventCtx, GeomBatch,
|
||||
GfxCtx, JustDraw, Menu, RewriteColor, ScreenDims, ScreenPt, ScreenRectangle, Text, TextBox,
|
||||
Button, Checkbox, Choice, Color, DeferDraw, DrawWithTooltips, Drawable, Dropdown, EventCtx,
|
||||
GeomBatch, GfxCtx, JustDraw, Menu, RewriteColor, ScreenDims, ScreenPt, ScreenRectangle, Text,
|
||||
TextBox,
|
||||
};
|
||||
|
||||
pub mod autocomplete;
|
||||
@ -617,6 +618,10 @@ impl Widget {
|
||||
if btn.hovering {
|
||||
return Some(&btn.action);
|
||||
}
|
||||
} else if let Some(checkbox) = self.widget.downcast_ref::<Checkbox>() {
|
||||
if checkbox.btn.hovering {
|
||||
return Some(&checkbox.btn.action);
|
||||
}
|
||||
} else if let Some(container) = self.widget.downcast_ref::<Container>() {
|
||||
for w in &container.members {
|
||||
if let Some(a) = w.currently_hovering() {
|
||||
|
Loading…
Reference in New Issue
Block a user