mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-29 17:34:58 +03:00
better Checkbox::colored
This commit is contained in:
parent
28c3d0ef8e
commit
de45fb5c07
1
data/system/assets/tools/checkbox.svg
Normal file
1
data/system/assets/tools/checkbox.svg
Normal file
@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"><path d="M0 0h24v24H0V0z" fill="black"/><path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41L9 16.17z" fill="white"/></svg>
|
After Width: | Height: | Size: 212 B |
@ -2,7 +2,6 @@ use crate::{
|
|||||||
Btn, Button, Color, EventCtx, GeomBatch, GfxCtx, Line, MultiKey, RewriteColor, ScreenDims,
|
Btn, Button, Color, EventCtx, GeomBatch, GfxCtx, Line, MultiKey, RewriteColor, ScreenDims,
|
||||||
ScreenPt, Text, TextExt, TextSpan, Widget, WidgetImpl, WidgetOutput,
|
ScreenPt, Text, TextExt, TextSpan, Widget, WidgetImpl, WidgetOutput,
|
||||||
};
|
};
|
||||||
use geom::{Polygon, Pt2D, Ring};
|
|
||||||
|
|
||||||
pub struct Checkbox {
|
pub struct Checkbox {
|
||||||
pub(crate) enabled: bool,
|
pub(crate) enabled: bool,
|
||||||
@ -115,48 +114,47 @@ impl Checkbox {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn colored(ctx: &EventCtx, label: &str, color: Color, enabled: bool) -> Widget {
|
pub fn colored(ctx: &EventCtx, label: &str, color: Color, enabled: bool) -> Widget {
|
||||||
let vert_pad = 4.0;
|
let off = Widget::row(vec![
|
||||||
let horiz_pad = 4.0;
|
GeomBatch::screenspace_svg(ctx.prerender, "system/assets/tools/checkbox.svg")
|
||||||
|
.color(RewriteColor::ChangeAll(color.alpha(0.3)))
|
||||||
// TODO What was I thinking...
|
.batch()
|
||||||
let checkmark = Ring::must_new(vec![
|
.centered_vert(),
|
||||||
Pt2D::new(11.4528, 22.1072),
|
label.batch_text(ctx),
|
||||||
Pt2D::new(5.89284, 16.5472),
|
|
||||||
Pt2D::new(3.99951, 18.4272),
|
|
||||||
Pt2D::new(11.4528, 25.8805),
|
|
||||||
Pt2D::new(27.4528, 9.88049),
|
|
||||||
Pt2D::new(25.5728, 8.00049),
|
|
||||||
Pt2D::new(11.4528, 22.1072),
|
|
||||||
])
|
])
|
||||||
.to_polygon()
|
.to_geom(ctx, None);
|
||||||
.translate(0.0, -4.0);
|
let on = Widget::row(vec![
|
||||||
let bounds = checkmark.get_bounds();
|
GeomBatch::screenspace_svg(ctx.prerender, "system/assets/tools/checkbox.svg")
|
||||||
let hitbox = Polygon::rectangle(
|
.color(RewriteColor::Change(Color::BLACK, color))
|
||||||
bounds.width() + 2.0 * horiz_pad,
|
.batch()
|
||||||
bounds.height() + 2.0 * vert_pad,
|
.centered_vert(),
|
||||||
);
|
label.batch_text(ctx),
|
||||||
|
])
|
||||||
|
.to_geom(ctx, None);
|
||||||
|
// Dims should be the same for both
|
||||||
|
let hitbox = off.get_bounds().get_rectangle();
|
||||||
|
|
||||||
let true_btn = Btn::custom(
|
Checkbox::new(
|
||||||
GeomBatch::from(vec![
|
enabled,
|
||||||
(color, hitbox.clone()),
|
Btn::custom(
|
||||||
(Color::WHITE, checkmark.clone()),
|
off.clone(),
|
||||||
]),
|
off.color(RewriteColor::Change(
|
||||||
GeomBatch::from(vec![
|
Color::WHITE,
|
||||||
(color, hitbox.clone()),
|
ctx.style().hovering_color,
|
||||||
(ctx.style().hovering_color, checkmark),
|
)),
|
||||||
]),
|
hitbox.clone(),
|
||||||
hitbox.clone(),
|
)
|
||||||
|
.build(ctx, label, None),
|
||||||
|
Btn::custom(
|
||||||
|
on.clone(),
|
||||||
|
on.color(RewriteColor::Change(
|
||||||
|
Color::WHITE,
|
||||||
|
ctx.style().hovering_color,
|
||||||
|
)),
|
||||||
|
hitbox,
|
||||||
|
)
|
||||||
|
.build(ctx, label, None),
|
||||||
)
|
)
|
||||||
.build(ctx, format!("hide {}", label), None);
|
.named(label)
|
||||||
|
|
||||||
let false_btn = Btn::custom(
|
|
||||||
GeomBatch::from(vec![(color.alpha(0.3), hitbox.clone())]),
|
|
||||||
GeomBatch::from(vec![(color, hitbox.clone())]),
|
|
||||||
hitbox,
|
|
||||||
)
|
|
||||||
.build(ctx, format!("show {}", label), None);
|
|
||||||
|
|
||||||
Checkbox::new(enabled, false_btn, true_btn).named(label)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO These should actually be radio buttons
|
// TODO These should actually be radio buttons
|
||||||
|
@ -322,10 +322,12 @@ pub fn make_legend<T: Yvalue<T>>(
|
|||||||
}
|
}
|
||||||
seen.insert(s.label.clone());
|
seen.insert(s.label.clone());
|
||||||
if opts.filterable {
|
if opts.filterable {
|
||||||
row.push(Widget::row(vec![
|
row.push(Checkbox::colored(
|
||||||
Checkbox::colored(ctx, &s.label, s.color, !opts.disabled.contains(&s.label)),
|
ctx,
|
||||||
Line(&s.label).draw(ctx),
|
&s.label,
|
||||||
]));
|
s.color,
|
||||||
|
!opts.disabled.contains(&s.label),
|
||||||
|
));
|
||||||
} else {
|
} else {
|
||||||
let radius = 15.0;
|
let radius = 15.0;
|
||||||
row.push(Widget::row(vec![
|
row.push(Widget::row(vec![
|
||||||
|
@ -5,8 +5,7 @@ use crate::layer::PickLayer;
|
|||||||
use abstutil::clamp;
|
use abstutil::clamp;
|
||||||
use ezgui::{
|
use ezgui::{
|
||||||
hotkey, Btn, Checkbox, Color, Composite, EventCtx, Filler, GeomBatch, GfxCtx,
|
hotkey, Btn, Checkbox, Color, Composite, EventCtx, Filler, GeomBatch, GfxCtx,
|
||||||
HorizontalAlignment, Key, Line, Outcome, ScreenDims, ScreenPt, Spinner, VerticalAlignment,
|
HorizontalAlignment, Key, Outcome, ScreenDims, ScreenPt, Spinner, VerticalAlignment, Widget,
|
||||||
Widget,
|
|
||||||
};
|
};
|
||||||
use geom::{Distance, Polygon, Pt2D, Ring};
|
use geom::{Distance, Polygon, Pt2D, Ring};
|
||||||
|
|
||||||
@ -431,14 +430,10 @@ fn make_horiz_viz_panel(ctx: &mut EventCtx, app: &App) -> Widget {
|
|||||||
let a = &app.unzoomed_agents;
|
let a = &app.unzoomed_agents;
|
||||||
Widget::custom_row(vec![
|
Widget::custom_row(vec![
|
||||||
Checkbox::colored(ctx, "Car", a.car_color, a.cars).margin_right(8),
|
Checkbox::colored(ctx, "Car", a.car_color, a.cars).margin_right(8),
|
||||||
Line("Car").draw(ctx).margin_right(8),
|
|
||||||
Widget::draw_svg(ctx, "system/assets/timeline/parking.svg").margin_right(24),
|
Widget::draw_svg(ctx, "system/assets/timeline/parking.svg").margin_right(24),
|
||||||
Checkbox::colored(ctx, "Bike", a.bike_color, a.bikes).margin_right(8),
|
Checkbox::colored(ctx, "Bike", a.bike_color, a.bikes).margin_right(24),
|
||||||
Line("Bike").draw(ctx).margin_right(24),
|
Checkbox::colored(ctx, "Bus", a.bus_color, a.buses_and_trains).margin_right(24),
|
||||||
Checkbox::colored(ctx, "Bus", a.bus_color, a.buses_and_trains).margin_right(8),
|
|
||||||
Line("Bus").draw(ctx).margin_right(24),
|
|
||||||
Checkbox::colored(ctx, "Pedestrian", a.ped_color, a.peds).margin_right(8),
|
Checkbox::colored(ctx, "Pedestrian", a.ped_color, a.peds).margin_right(8),
|
||||||
Line("Pedestrian").draw(ctx),
|
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -447,20 +442,10 @@ fn make_vert_viz_panel(ctx: &mut EventCtx, app: &App) -> Widget {
|
|||||||
Widget::col(vec![
|
Widget::col(vec![
|
||||||
Widget::custom_row(vec![
|
Widget::custom_row(vec![
|
||||||
Checkbox::colored(ctx, "Car", a.car_color, a.cars).margin_right(8),
|
Checkbox::colored(ctx, "Car", a.car_color, a.cars).margin_right(8),
|
||||||
Line("Car").draw(ctx).margin_right(8),
|
Widget::draw_svg(ctx, "system/assets/timeline/parking.svg"),
|
||||||
Widget::draw_svg(ctx, "system/assets/timeline/parking.svg").margin_right(24),
|
|
||||||
]),
|
|
||||||
Widget::custom_row(vec![
|
|
||||||
Checkbox::colored(ctx, "Bike", a.bike_color, a.bikes).margin_right(8),
|
|
||||||
Line("Bike").draw(ctx),
|
|
||||||
]),
|
|
||||||
Widget::custom_row(vec![
|
|
||||||
Checkbox::colored(ctx, "Bus", a.bus_color, a.buses_and_trains).margin_right(8),
|
|
||||||
Line("Bus").draw(ctx),
|
|
||||||
]),
|
|
||||||
Widget::custom_row(vec![
|
|
||||||
Checkbox::colored(ctx, "Pedestrian", a.ped_color, a.peds).margin_right(8),
|
|
||||||
Line("Pedestrian").draw(ctx),
|
|
||||||
]),
|
]),
|
||||||
|
Checkbox::colored(ctx, "Bike", a.bike_color, a.bikes),
|
||||||
|
Checkbox::colored(ctx, "Bus", a.bus_color, a.buses_and_trains),
|
||||||
|
Checkbox::colored(ctx, "Pedestrian", a.ped_color, a.peds),
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::app::{App, PerMap};
|
use crate::app::{App, PerMap};
|
||||||
use ezgui::{hotkey, Btn, Checkbox, Color, EventCtx, Key, Line, Text, TextExt, TextSpan, Widget};
|
use ezgui::{hotkey, Btn, Checkbox, Color, EventCtx, Key, Line, Text, TextSpan, Widget};
|
||||||
use geom::{Duration, Pt2D};
|
use geom::{Duration, Pt2D};
|
||||||
use map_model::{AreaID, BuildingID, BusStopID, IntersectionID, LaneID, Map, ParkingLotID, RoadID};
|
use map_model::{AreaID, BuildingID, BusStopID, IntersectionID, LaneID, Map, ParkingLotID, RoadID};
|
||||||
use sim::{AgentID, AgentType, CarID, PedestrianID, TripMode, TripPhaseType};
|
use sim::{AgentID, AgentType, CarID, PedestrianID, TripMode, TripPhaseType};
|
||||||
@ -274,9 +274,8 @@ pub fn checkbox_per_mode(
|
|||||||
color_for_mode(app, m),
|
color_for_mode(app, m),
|
||||||
current_state.contains(&m),
|
current_state.contains(&m),
|
||||||
)
|
)
|
||||||
.margin_right(5),
|
.margin_right(24),
|
||||||
);
|
);
|
||||||
filters.push(m.ongoing_verb().draw_text(ctx).margin_right(10));
|
|
||||||
}
|
}
|
||||||
Widget::custom_row(filters)
|
Widget::custom_row(filters)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user