refactor separators

This commit is contained in:
Dustin Carlino 2020-08-12 16:46:11 -07:00
parent 9af8aafb44
commit ae18b09b3b
14 changed files with 53 additions and 129 deletions

View File

@ -345,6 +345,24 @@ impl Widget {
batch.autocrop_dims = false;
(batch, hitbox)
}
pub fn horiz_separator(ctx: &mut EventCtx, pct_width: f64) -> Widget {
Widget::draw_batch(
ctx,
GeomBatch::from(vec![(
Color::WHITE,
Polygon::rectangle(pct_width * ctx.canvas.window_width, 2.0),
)]),
)
.centered_horiz()
}
pub fn vert_separator(ctx: &mut EventCtx, height_px: f64) -> Widget {
Widget::draw_batch(
ctx,
GeomBatch::from(vec![(Color::WHITE, Polygon::rectangle(2.0, height_px))]),
)
}
}
// Internals

View File

@ -303,10 +303,7 @@ fn make_panel(ctx: &mut EventCtx, story: &StoryMap, mode: &Mode, dirty: bool) ->
Composite::new(Widget::col(vec![
Widget::row(vec![
Line("Story map editor").small_heading().draw(ctx),
Widget::draw_batch(
ctx,
GeomBatch::from(vec![(Color::WHITE, Polygon::rectangle(2.0, 30.0))]),
),
Widget::vert_separator(ctx, 30.0),
Btn::text_fg(format!("{}", story.name)).build(ctx, "load", lctrl(Key::L)),
if dirty {
Btn::svg_def("system/assets/tools/save.svg").build(ctx, "save", lctrl(Key::S))

View File

@ -22,7 +22,7 @@ pub struct NewTrafficSignalEditor {
side_panel: Composite,
top_panel: Composite,
gameplay: GameplayMode,
_gameplay: GameplayMode,
members: BTreeSet<IntersectionID>,
current_phase: usize,
@ -80,7 +80,7 @@ impl NewTrafficSignalEditor {
let mut editor = NewTrafficSignalEditor {
side_panel: make_side_panel(ctx, app, &members, 0),
top_panel: make_top_panel(ctx, app, false, false),
gameplay,
_gameplay: gameplay,
members,
current_phase: 0,
groups,
@ -434,17 +434,7 @@ fn make_side_panel(
// Use any member for phase duration
let canonical_signal = map.get_traffic_signal(*members.iter().next().unwrap());
for (idx, canonical_phase) in canonical_signal.phases.iter().enumerate() {
// Separator
col.push(
Widget::draw_batch(
ctx,
GeomBatch::from(vec![(
Color::WHITE,
Polygon::rectangle(0.2 * ctx.canvas.window_width, 2.0),
)]),
)
.centered_horiz(),
);
col.push(Widget::horiz_separator(ctx, 0.2));
let unselected_btn = draw_multiple_signals(ctx, app, members, idx);
let mut selected_btn = unselected_btn.clone();
@ -508,17 +498,7 @@ fn make_side_panel(
}
}
// TODO Widget::separator(ctx, pct_width)
col.push(
Widget::draw_batch(
ctx,
GeomBatch::from(vec![(
Color::WHITE,
Polygon::rectangle(0.2 * ctx.canvas.window_width, 2.0),
)]),
)
.centered_horiz(),
);
col.push(Widget::horiz_separator(ctx, 0.2));
col.push(Btn::text_fg("Add new phase").build_def(ctx, None));
Composite::new(Widget::col(col))

View File

@ -874,17 +874,7 @@ fn make_signal_diagram(
];
for (idx, phase) in signal.phases.iter().enumerate() {
// Separator
col.push(
Widget::draw_batch(
ctx,
GeomBatch::from(vec![(
Color::WHITE,
Polygon::rectangle(0.2 * ctx.canvas.window_width, 2.0),
)]),
)
.centered_horiz(),
);
col.push(Widget::horiz_separator(ctx, 0.2));
let phase_btn = {
let mut orig_batch = GeomBatch::new();
@ -969,17 +959,7 @@ fn make_signal_diagram(
}
}
// Separator
col.push(
Widget::draw_batch(
ctx,
GeomBatch::from(vec![(
Color::WHITE,
Polygon::rectangle(0.2 * ctx.canvas.window_width, 2.0),
)]),
)
.centered_horiz(),
);
col.push(Widget::horiz_separator(ctx, 0.2));
col.push(Btn::text_fg("Add new phase").build_def(ctx, None));
col.push(Widget::row(vec![

View File

@ -9,10 +9,10 @@ use crate::helpers::ID;
use crate::sandbox::gameplay::{challenge_header, FinalScore, GameplayMode, GameplayState};
use crate::sandbox::SandboxControls;
use ezgui::{
Btn, Color, Composite, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line, Outcome,
RewriteColor, Text, TextExt, VerticalAlignment, Widget,
Btn, Color, Composite, EventCtx, GfxCtx, HorizontalAlignment, Key, Line, Outcome, RewriteColor,
Text, TextExt, VerticalAlignment, Widget,
};
use geom::{Duration, Polygon, Time};
use geom::{Duration, Time};
use sim::{OrigPersonID, PersonID, TripID};
use std::collections::BTreeMap;
@ -243,15 +243,7 @@ fn make_meter(
txt.append(Line(")"));
Composite::new(Widget::col(vec![
// Separator
Widget::draw_batch(
ctx,
GeomBatch::from(vec![(
Color::WHITE,
Polygon::rectangle(0.2 * ctx.canvas.window_width, 2.0),
)]),
)
.centered_horiz(),
Widget::horiz_separator(ctx, 0.2),
Widget::row(vec![
Btn::svg_def("system/assets/tools/location.svg").build(ctx, "locate VIP", None),
format!("{}/{} trips done", done, trips).draw_text(ctx),

View File

@ -8,10 +8,10 @@ use crate::helpers::ID;
use crate::sandbox::gameplay::{challenge_header, FinalScore, GameplayMode, GameplayState};
use crate::sandbox::{SandboxControls, SandboxMode};
use ezgui::{
Btn, Color, Composite, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line, Outcome,
RewriteColor, Text, VerticalAlignment, Widget,
Btn, Color, Composite, EventCtx, GfxCtx, HorizontalAlignment, Key, Line, Outcome, RewriteColor,
Text, VerticalAlignment, Widget,
};
use geom::{Duration, Polygon, Time};
use geom::{Duration, Time};
use map_model::IntersectionID;
const THRESHOLD: Duration = Duration::const_seconds(20.0 * 60.0);
@ -288,15 +288,7 @@ fn make_meter(
worst: Option<(IntersectionID, Duration)>,
) -> Composite {
Composite::new(Widget::col(vec![
// Separator
Widget::draw_batch(
ctx,
GeomBatch::from(vec![(
Color::WHITE,
Polygon::rectangle(0.2 * ctx.canvas.window_width, 2.0),
)]),
)
.centered_horiz(),
Widget::horiz_separator(ctx, 0.2),
if let Some((_, delay)) = worst {
Widget::row(vec![
Text::from_all(vec![

View File

@ -8,8 +8,8 @@ use crate::sandbox::SandboxControls;
use crate::sandbox::SandboxMode;
use abstutil::Timer;
use ezgui::{
hotkey, lctrl, Btn, Choice, Color, Composite, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment,
Key, Line, Outcome, ScreenRectangle, Spinner, Text, TextExt, VerticalAlignment, Widget,
hotkey, lctrl, Btn, Choice, Color, Composite, EventCtx, GfxCtx, HorizontalAlignment, Key, Line,
Outcome, ScreenRectangle, Spinner, Text, TextExt, VerticalAlignment, Widget,
};
use geom::{Distance, Polygon};
use map_model::{BuildingID, IntersectionID, Position, NORMAL_LANE_THICKNESS};
@ -84,10 +84,7 @@ fn make_top_center(ctx: &mut EventCtx, app: &App) -> Composite {
let rows = vec![
Widget::row(vec![
Line("Sandbox").small_heading().draw(ctx),
Widget::draw_batch(
ctx,
GeomBatch::from(vec![(Color::WHITE, Polygon::rectangle(2.0, 50.0))]),
),
Widget::vert_separator(ctx, 50.0),
"Map:".draw_text(ctx),
Btn::text_fg(format!("{}", nice_map_name(app.primary.map.get_name()))).build(
ctx,

View File

@ -19,7 +19,7 @@ use abstutil::Timer;
use ezgui::{
lctrl, Btn, Color, Composite, EventCtx, GeomBatch, GfxCtx, Key, Line, Outcome, TextExt, Widget,
};
use geom::{Duration, Polygon};
use geom::Duration;
use map_model::{EditCmd, EditIntersection, Map, MapEdits};
use rand_xorshift::XorShiftRng;
use sim::{Analytics, OrigPersonID, Scenario, ScenarioGenerator, ScenarioModifier};
@ -284,10 +284,7 @@ fn challenge_header(ctx: &mut EventCtx, title: &str) -> Widget {
Btn::svg_def("system/assets/tools/info.svg")
.build(ctx, "instructions", None)
.centered_vert(),
Widget::draw_batch(
ctx,
GeomBatch::from(vec![(Color::WHITE, Polygon::rectangle(2.0, 50.0))]),
),
Widget::vert_separator(ctx, 50.0),
Btn::svg_def("system/assets/tools/edit_map.svg")
.build(ctx, "edit map", lctrl(Key::E))
.centered_vert(),

View File

@ -7,10 +7,9 @@ use crate::sandbox::gameplay::freeform::make_change_traffic;
use crate::sandbox::gameplay::{GameplayMode, GameplayState};
use crate::sandbox::{SandboxControls, SandboxMode};
use ezgui::{
hotkey, lctrl, AreaSlider, Btn, Choice, Color, Composite, EventCtx, GeomBatch, GfxCtx,
hotkey, lctrl, AreaSlider, Btn, Choice, Color, Composite, EventCtx, GfxCtx,
HorizontalAlignment, Key, Line, Outcome, Spinner, Text, TextExt, VerticalAlignment, Widget,
};
use geom::Polygon;
use maplit::btreeset;
use sim::{ScenarioModifier, TripMode};
use std::collections::BTreeSet;
@ -114,10 +113,7 @@ fn make_top_center(
let rows = vec![
Widget::row(vec![
Line("Sandbox").small_heading().draw(ctx),
Widget::draw_batch(
ctx,
GeomBatch::from(vec![(Color::WHITE, Polygon::rectangle(2.0, 50.0))]),
),
Widget::vert_separator(ctx, 50.0),
"Map:".draw_text(ctx),
Btn::text_fg(format!("{}", nice_map_name(app.primary.map.get_name()))).build(
ctx,

View File

@ -11,11 +11,10 @@ use crate::sandbox::{
};
use abstutil::Timer;
use ezgui::{
hotkey, hotkeys, lctrl, Btn, Color, Composite, EventCtx, GeomBatch, GfxCtx,
HorizontalAlignment, Key, Line, Outcome, RewriteColor, ScreenPt, Text, TextExt,
VerticalAlignment, Widget,
hotkey, hotkeys, lctrl, Btn, Color, Composite, EventCtx, GfxCtx, HorizontalAlignment, Key,
Line, Outcome, RewriteColor, ScreenPt, Text, TextExt, VerticalAlignment, Widget,
};
use geom::{ArrowCap, Distance, Duration, PolyLine, Polygon, Pt2D, Time};
use geom::{ArrowCap, Distance, Duration, PolyLine, Pt2D, Time};
use map_model::raw::{OriginalBuilding, OriginalIntersection, OriginalRoad};
use map_model::{osm, BuildingID, Map, OriginalLane, Position};
use sim::{
@ -724,10 +723,7 @@ impl TutorialState {
fn make_top_center(&self, ctx: &mut EventCtx, edit_map: bool) -> Composite {
let mut col = vec![Widget::row(vec![
Line("Tutorial").small_heading().draw(ctx),
Widget::draw_batch(
ctx,
GeomBatch::from(vec![(Color::WHITE, Polygon::rectangle(2.0, 50.0))]),
),
Widget::vert_separator(ctx, 50.0),
if self.current.stage == 0 {
Btn::text_fg("<").inactive(ctx)
} else {

View File

@ -6,7 +6,7 @@ use ezgui::{
hotkey, Btn, Color, Composite, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key,
Line, Outcome, Text, TextExt, VerticalAlignment, Widget,
};
use geom::{ArrowCap, Distance, Polygon, Time};
use geom::{ArrowCap, Distance, Time};
use map_model::{LaneID, TurnType};
use sim::{AgentID, DontDrawAgents};
@ -168,10 +168,7 @@ impl TurnExplorer {
.small_heading(),
)
.draw(ctx),
Widget::draw_batch(
ctx,
GeomBatch::from(vec![(Color::WHITE, Polygon::rectangle(2.0, 50.0))]),
),
Widget::vert_separator(ctx, 50.0),
if idx == 0 {
Btn::text_fg("<").inactive(ctx)
} else {

View File

@ -19,11 +19,11 @@ use crate::options::OptionsPanel;
use crate::pregame::MainMenu;
use crate::render::UnzoomedAgents;
use ezgui::{
hotkey, lctrl, Btn, Choice, Color, Composite, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment,
Key, Line, Outcome, Text, TextExt, UpdateType, VerticalAlignment, Widget,
hotkey, lctrl, Btn, Choice, Composite, EventCtx, GfxCtx, HorizontalAlignment, Key, Line,
Outcome, Text, TextExt, UpdateType, VerticalAlignment, Widget,
};
pub use gameplay::{spawn_agents_around, GameplayMode, TutorialPointer, TutorialState};
use geom::{Polygon, Time};
use geom::Time;
use map_model::MapEdits;
use sim::AgentType;
pub use speed::TimeWarpScreen;
@ -325,15 +325,7 @@ impl AgentMeter {
]),
])
.centered(),
// Separator
Widget::draw_batch(
ctx,
GeomBatch::from(vec![(
Color::WHITE,
Polygon::rectangle(0.2 * ctx.canvas.window_width, 2.0),
)]),
)
.centered_horiz(),
Widget::horiz_separator(ctx, 0.2),
Widget::row(vec![
{
let mut txt = Text::new();

View File

@ -397,14 +397,7 @@ impl JumpToTime {
.build(ctx, "jump to time", hotkey(Key::Enter))
.centered_horiz()
.named("jump to time"),
Widget::draw_batch(
ctx,
GeomBatch::from(vec![(
Color::WHITE,
Polygon::rectangle(0.25 * ctx.canvas.window_width, 2.0),
)]),
)
.margin_above(10),
Widget::horiz_separator(ctx, 0.25).margin_above(10),
Btn::text_bg2("Jump to the next delay over 5 minutes")
.build_def(ctx, None)
.centered_horiz(),

View File

@ -9,7 +9,7 @@ use ezgui::{
hotkey, Btn, Checkbox, Color, Composite, Drawable, EventCtx, GeomBatch, GfxCtx,
HorizontalAlignment, Key, Line, Outcome, Text, TextExt, VerticalAlignment, Widget,
};
use geom::{ArrowCap, Polygon};
use geom::ArrowCap;
use map_model::{IntersectionCluster, IntersectionID};
use sim::DontDrawAgents;
use std::collections::BTreeSet;
@ -199,10 +199,7 @@ impl UberTurnViewer {
composite: Composite::new(Widget::col(vec![
Widget::row(vec![
Line("Uber-turn viewer").small_heading().draw(ctx),
Widget::draw_batch(
ctx,
GeomBatch::from(vec![(Color::WHITE, Polygon::rectangle(2.0, 50.0))]),
),
Widget::vert_separator(ctx, 50.0),
if idx == 0 {
Btn::text_fg("<").inactive(ctx)
} else {