mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-24 01:15:12 +03:00
Share the panel style too for pathfinding. (It was a bigger change, easier to separate)
This commit is contained in:
parent
4264682be8
commit
1e414d0f31
@ -36,7 +36,8 @@ impl Viewer {
|
||||
app: &App,
|
||||
neighborhood: Neighborhood,
|
||||
) -> Box<dyn State<App>> {
|
||||
let panel = Tab::Connectivity.make_panel(
|
||||
let panel = Tab::Connectivity
|
||||
.panel_builder(
|
||||
ctx,
|
||||
app,
|
||||
Widget::col(vec![
|
||||
@ -47,7 +48,8 @@ impl Viewer {
|
||||
"Click a road to add or remove a modal filter".text_widget(ctx),
|
||||
Text::new().into_widget(ctx).named("warnings"),
|
||||
]),
|
||||
);
|
||||
)
|
||||
.build(ctx);
|
||||
|
||||
let mut viewer = Viewer {
|
||||
panel,
|
||||
|
@ -1,6 +1,6 @@
|
||||
use map_gui::tools::CityPicker;
|
||||
use widgetry::{
|
||||
EventCtx, HorizontalAlignment, Key, Panel, State, VerticalAlignment, Widget,
|
||||
EventCtx, HorizontalAlignment, Key, Panel, PanelBuilder, State, VerticalAlignment, Widget,
|
||||
DEFAULT_CORNER_RADIUS,
|
||||
};
|
||||
|
||||
@ -19,7 +19,12 @@ pub trait TakeNeighborhood {
|
||||
}
|
||||
|
||||
impl Tab {
|
||||
pub fn make_panel(self, ctx: &mut EventCtx, app: &App, per_tab_contents: Widget) -> Panel {
|
||||
pub fn panel_builder(
|
||||
self,
|
||||
ctx: &mut EventCtx,
|
||||
app: &App,
|
||||
per_tab_contents: Widget,
|
||||
) -> PanelBuilder {
|
||||
Panel::new_builder(Widget::col(vec![
|
||||
map_gui::tools::app_header(ctx, app, "Low traffic neighborhoods"),
|
||||
Widget::row(vec![
|
||||
@ -38,7 +43,6 @@ impl Tab {
|
||||
per_tab_contents.tab_body(ctx),
|
||||
]))
|
||||
.aligned(HorizontalAlignment::Left, VerticalAlignment::Top)
|
||||
.build(ctx)
|
||||
}
|
||||
|
||||
pub fn must_handle_action<T: TakeNeighborhood + State<App>>(
|
||||
|
@ -67,11 +67,14 @@ impl BrowseRatRuns {
|
||||
|
||||
fn recalculate(&mut self, ctx: &mut EventCtx, app: &App) {
|
||||
if self.rat_runs.paths.is_empty() {
|
||||
self.panel = Tab::RatRuns.make_panel(ctx, app, "No rat runs detected".text_widget(ctx));
|
||||
self.panel = Tab::RatRuns
|
||||
.panel_builder(ctx, app, "No rat runs detected".text_widget(ctx))
|
||||
.build(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
self.panel = Tab::RatRuns.make_panel(
|
||||
self.panel = Tab::RatRuns
|
||||
.panel_builder(
|
||||
ctx,
|
||||
app,
|
||||
Widget::col(vec![
|
||||
@ -109,7 +112,8 @@ impl BrowseRatRuns {
|
||||
.unwrap_or(true),
|
||||
),
|
||||
]),
|
||||
);
|
||||
)
|
||||
.build(ctx);
|
||||
|
||||
let mut draw_path = ToggleZoomed::builder();
|
||||
let color = Color::RED;
|
||||
|
@ -3,10 +3,10 @@ use map_model::NORMAL_LANE_THICKNESS;
|
||||
use sim::{TripEndpoint, TripMode};
|
||||
use widgetry::mapspace::{ObjectID, ToggleZoomed, World};
|
||||
use widgetry::{
|
||||
Color, EventCtx, GfxCtx, HorizontalAlignment, Key, Line, Outcome, Panel, RoundedF64, Spinner,
|
||||
State, Text, VerticalAlignment, Widget,
|
||||
Color, EventCtx, GfxCtx, Line, Outcome, Panel, RoundedF64, Spinner, State, Text, Widget,
|
||||
};
|
||||
|
||||
use super::per_neighborhood::{Tab, TakeNeighborhood};
|
||||
use super::Neighborhood;
|
||||
use crate::app::{App, Transition};
|
||||
use crate::common::{cmp_dist, cmp_duration, InputWaypoints, WaypointID};
|
||||
@ -19,6 +19,12 @@ pub struct RoutePlanner {
|
||||
neighborhood: Neighborhood,
|
||||
}
|
||||
|
||||
impl TakeNeighborhood for RoutePlanner {
|
||||
fn take_neighborhood(self) -> Neighborhood {
|
||||
self.neighborhood
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
enum ID {
|
||||
RouteAfterFilters,
|
||||
@ -44,12 +50,7 @@ impl RoutePlanner {
|
||||
}
|
||||
|
||||
fn update(&mut self, ctx: &mut EventCtx, app: &App) {
|
||||
let mut panel = Panel::new_builder(Widget::col(vec![
|
||||
ctx.style()
|
||||
.btn_outline
|
||||
.text("Back to editing modal filters")
|
||||
.hotkey(Key::Escape)
|
||||
.build_def(ctx),
|
||||
let contents = Widget::col(vec![
|
||||
self.waypoints.get_panel_widget(ctx),
|
||||
Widget::row(vec![
|
||||
Line("Slow-down factor for main roads:")
|
||||
@ -63,8 +64,9 @@ impl RoutePlanner {
|
||||
])
|
||||
.into_widget(ctx),
|
||||
Text::new().into_widget(ctx).named("note"),
|
||||
]))
|
||||
.aligned(HorizontalAlignment::Left, VerticalAlignment::Top)
|
||||
]);
|
||||
let mut panel = Tab::Pathfinding
|
||||
.panel_builder(ctx, app, contents)
|
||||
// Hovering on waypoint cards
|
||||
.ignore_initial_events()
|
||||
.build(ctx);
|
||||
@ -229,20 +231,7 @@ impl State<App> for RoutePlanner {
|
||||
|
||||
let panel_outcome = self.panel.event(ctx);
|
||||
if let Outcome::Clicked(ref x) = panel_outcome {
|
||||
if x == "Back to editing modal filters" {
|
||||
// We'll cache a custom pathfinder per set of avoided roads. Avoid leaking memory
|
||||
// by clearing this out
|
||||
app.primary.map.clear_custom_pathfinder_cache();
|
||||
|
||||
return Transition::ConsumeState(Box::new(|state, ctx, app| {
|
||||
let state = state.downcast::<RoutePlanner>().ok().unwrap();
|
||||
vec![super::connectivity::Viewer::new_state(
|
||||
ctx,
|
||||
app,
|
||||
state.neighborhood,
|
||||
)]
|
||||
}));
|
||||
}
|
||||
return Tab::Pathfinding.must_handle_action::<RoutePlanner>(ctx, app, x);
|
||||
}
|
||||
|
||||
if let Outcome::Changed(ref x) = panel_outcome {
|
||||
@ -278,4 +267,10 @@ impl State<App> for RoutePlanner {
|
||||
|
||||
self.world.draw(g);
|
||||
}
|
||||
|
||||
fn on_destroy(&mut self, _: &mut EventCtx, app: &mut App) {
|
||||
// We'll cache a custom pathfinder per set of avoided roads. Avoid leaking memory by
|
||||
// clearing this out
|
||||
app.primary.map.clear_custom_pathfinder_cache();
|
||||
}
|
||||
}
|
||||
|
@ -75,7 +75,8 @@ pub use crate::widgets::text_box::TextBox;
|
||||
pub use crate::widgets::toggle::Toggle;
|
||||
pub use crate::widgets::DEFAULT_CORNER_RADIUS;
|
||||
pub use crate::widgets::{
|
||||
ClickOutcome, CornerRounding, EdgeInsets, Outcome, Panel, Widget, WidgetImpl, WidgetOutput,
|
||||
ClickOutcome, CornerRounding, EdgeInsets, Outcome, Panel, PanelBuilder, Widget, WidgetImpl,
|
||||
WidgetOutput,
|
||||
};
|
||||
|
||||
mod app_state;
|
||||
|
@ -11,7 +11,7 @@ use abstutil::CloneableAny;
|
||||
use geom::{CornerRadii, Distance, Percent, Polygon};
|
||||
|
||||
use crate::widgets::containers::{Container, Nothing};
|
||||
pub use crate::widgets::panel::Panel;
|
||||
pub use crate::widgets::panel::{Panel, PanelBuilder};
|
||||
use crate::{
|
||||
Button, Choice, Color, DeferDraw, Drawable, Dropdown, EventCtx, GeomBatch, GfxCtx, JustDraw,
|
||||
OutlineStyle, ScreenDims, ScreenPt, ScreenRectangle, Toggle,
|
||||
|
Loading…
Reference in New Issue
Block a user