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.autocrop_dims = false;
(batch, hitbox) (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 // Internals

View File

@ -303,10 +303,7 @@ fn make_panel(ctx: &mut EventCtx, story: &StoryMap, mode: &Mode, dirty: bool) ->
Composite::new(Widget::col(vec![ Composite::new(Widget::col(vec![
Widget::row(vec![ Widget::row(vec![
Line("Story map editor").small_heading().draw(ctx), Line("Story map editor").small_heading().draw(ctx),
Widget::draw_batch( Widget::vert_separator(ctx, 30.0),
ctx,
GeomBatch::from(vec![(Color::WHITE, Polygon::rectangle(2.0, 30.0))]),
),
Btn::text_fg(format!("{}", story.name)).build(ctx, "load", lctrl(Key::L)), Btn::text_fg(format!("{}", story.name)).build(ctx, "load", lctrl(Key::L)),
if dirty { if dirty {
Btn::svg_def("system/assets/tools/save.svg").build(ctx, "save", lctrl(Key::S)) 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, side_panel: Composite,
top_panel: Composite, top_panel: Composite,
gameplay: GameplayMode, _gameplay: GameplayMode,
members: BTreeSet<IntersectionID>, members: BTreeSet<IntersectionID>,
current_phase: usize, current_phase: usize,
@ -80,7 +80,7 @@ impl NewTrafficSignalEditor {
let mut editor = NewTrafficSignalEditor { let mut editor = NewTrafficSignalEditor {
side_panel: make_side_panel(ctx, app, &members, 0), side_panel: make_side_panel(ctx, app, &members, 0),
top_panel: make_top_panel(ctx, app, false, false), top_panel: make_top_panel(ctx, app, false, false),
gameplay, _gameplay: gameplay,
members, members,
current_phase: 0, current_phase: 0,
groups, groups,
@ -434,17 +434,7 @@ fn make_side_panel(
// Use any member for phase duration // Use any member for phase duration
let canonical_signal = map.get_traffic_signal(*members.iter().next().unwrap()); let canonical_signal = map.get_traffic_signal(*members.iter().next().unwrap());
for (idx, canonical_phase) in canonical_signal.phases.iter().enumerate() { for (idx, canonical_phase) in canonical_signal.phases.iter().enumerate() {
// Separator col.push(Widget::horiz_separator(ctx, 0.2));
col.push(
Widget::draw_batch(
ctx,
GeomBatch::from(vec![(
Color::WHITE,
Polygon::rectangle(0.2 * ctx.canvas.window_width, 2.0),
)]),
)
.centered_horiz(),
);
let unselected_btn = draw_multiple_signals(ctx, app, members, idx); let unselected_btn = draw_multiple_signals(ctx, app, members, idx);
let mut selected_btn = unselected_btn.clone(); let mut selected_btn = unselected_btn.clone();
@ -508,17 +498,7 @@ fn make_side_panel(
} }
} }
// TODO Widget::separator(ctx, pct_width) col.push(Widget::horiz_separator(ctx, 0.2));
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(Btn::text_fg("Add new phase").build_def(ctx, None)); col.push(Btn::text_fg("Add new phase").build_def(ctx, None));
Composite::new(Widget::col(col)) Composite::new(Widget::col(col))

View File

@ -874,17 +874,7 @@ fn make_signal_diagram(
]; ];
for (idx, phase) in signal.phases.iter().enumerate() { for (idx, phase) in signal.phases.iter().enumerate() {
// Separator col.push(Widget::horiz_separator(ctx, 0.2));
col.push(
Widget::draw_batch(
ctx,
GeomBatch::from(vec![(
Color::WHITE,
Polygon::rectangle(0.2 * ctx.canvas.window_width, 2.0),
)]),
)
.centered_horiz(),
);
let phase_btn = { let phase_btn = {
let mut orig_batch = GeomBatch::new(); let mut orig_batch = GeomBatch::new();
@ -969,17 +959,7 @@ fn make_signal_diagram(
} }
} }
// Separator col.push(Widget::horiz_separator(ctx, 0.2));
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(Btn::text_fg("Add new phase").build_def(ctx, None)); col.push(Btn::text_fg("Add new phase").build_def(ctx, None));
col.push(Widget::row(vec![ 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::gameplay::{challenge_header, FinalScore, GameplayMode, GameplayState};
use crate::sandbox::SandboxControls; use crate::sandbox::SandboxControls;
use ezgui::{ use ezgui::{
Btn, Color, Composite, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line, Outcome, Btn, Color, Composite, EventCtx, GfxCtx, HorizontalAlignment, Key, Line, Outcome, RewriteColor,
RewriteColor, Text, TextExt, VerticalAlignment, Widget, Text, TextExt, VerticalAlignment, Widget,
}; };
use geom::{Duration, Polygon, Time}; use geom::{Duration, Time};
use sim::{OrigPersonID, PersonID, TripID}; use sim::{OrigPersonID, PersonID, TripID};
use std::collections::BTreeMap; use std::collections::BTreeMap;
@ -243,15 +243,7 @@ fn make_meter(
txt.append(Line(")")); txt.append(Line(")"));
Composite::new(Widget::col(vec![ Composite::new(Widget::col(vec![
// Separator Widget::horiz_separator(ctx, 0.2),
Widget::draw_batch(
ctx,
GeomBatch::from(vec![(
Color::WHITE,
Polygon::rectangle(0.2 * ctx.canvas.window_width, 2.0),
)]),
)
.centered_horiz(),
Widget::row(vec![ Widget::row(vec![
Btn::svg_def("system/assets/tools/location.svg").build(ctx, "locate VIP", None), Btn::svg_def("system/assets/tools/location.svg").build(ctx, "locate VIP", None),
format!("{}/{} trips done", done, trips).draw_text(ctx), 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::gameplay::{challenge_header, FinalScore, GameplayMode, GameplayState};
use crate::sandbox::{SandboxControls, SandboxMode}; use crate::sandbox::{SandboxControls, SandboxMode};
use ezgui::{ use ezgui::{
Btn, Color, Composite, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line, Outcome, Btn, Color, Composite, EventCtx, GfxCtx, HorizontalAlignment, Key, Line, Outcome, RewriteColor,
RewriteColor, Text, VerticalAlignment, Widget, Text, VerticalAlignment, Widget,
}; };
use geom::{Duration, Polygon, Time}; use geom::{Duration, Time};
use map_model::IntersectionID; use map_model::IntersectionID;
const THRESHOLD: Duration = Duration::const_seconds(20.0 * 60.0); const THRESHOLD: Duration = Duration::const_seconds(20.0 * 60.0);
@ -288,15 +288,7 @@ fn make_meter(
worst: Option<(IntersectionID, Duration)>, worst: Option<(IntersectionID, Duration)>,
) -> Composite { ) -> Composite {
Composite::new(Widget::col(vec![ Composite::new(Widget::col(vec![
// Separator Widget::horiz_separator(ctx, 0.2),
Widget::draw_batch(
ctx,
GeomBatch::from(vec![(
Color::WHITE,
Polygon::rectangle(0.2 * ctx.canvas.window_width, 2.0),
)]),
)
.centered_horiz(),
if let Some((_, delay)) = worst { if let Some((_, delay)) = worst {
Widget::row(vec![ Widget::row(vec![
Text::from_all(vec![ Text::from_all(vec![

View File

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

View File

@ -19,7 +19,7 @@ use abstutil::Timer;
use ezgui::{ use ezgui::{
lctrl, Btn, Color, Composite, EventCtx, GeomBatch, GfxCtx, Key, Line, Outcome, TextExt, Widget, 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 map_model::{EditCmd, EditIntersection, Map, MapEdits};
use rand_xorshift::XorShiftRng; use rand_xorshift::XorShiftRng;
use sim::{Analytics, OrigPersonID, Scenario, ScenarioGenerator, ScenarioModifier}; 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") Btn::svg_def("system/assets/tools/info.svg")
.build(ctx, "instructions", None) .build(ctx, "instructions", None)
.centered_vert(), .centered_vert(),
Widget::draw_batch( Widget::vert_separator(ctx, 50.0),
ctx,
GeomBatch::from(vec![(Color::WHITE, Polygon::rectangle(2.0, 50.0))]),
),
Btn::svg_def("system/assets/tools/edit_map.svg") Btn::svg_def("system/assets/tools/edit_map.svg")
.build(ctx, "edit map", lctrl(Key::E)) .build(ctx, "edit map", lctrl(Key::E))
.centered_vert(), .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::gameplay::{GameplayMode, GameplayState};
use crate::sandbox::{SandboxControls, SandboxMode}; use crate::sandbox::{SandboxControls, SandboxMode};
use ezgui::{ 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, HorizontalAlignment, Key, Line, Outcome, Spinner, Text, TextExt, VerticalAlignment, Widget,
}; };
use geom::Polygon;
use maplit::btreeset; use maplit::btreeset;
use sim::{ScenarioModifier, TripMode}; use sim::{ScenarioModifier, TripMode};
use std::collections::BTreeSet; use std::collections::BTreeSet;
@ -114,10 +113,7 @@ fn make_top_center(
let rows = vec![ let rows = vec![
Widget::row(vec![ Widget::row(vec![
Line("Sandbox").small_heading().draw(ctx), Line("Sandbox").small_heading().draw(ctx),
Widget::draw_batch( Widget::vert_separator(ctx, 50.0),
ctx,
GeomBatch::from(vec![(Color::WHITE, Polygon::rectangle(2.0, 50.0))]),
),
"Map:".draw_text(ctx), "Map:".draw_text(ctx),
Btn::text_fg(format!("{}", nice_map_name(app.primary.map.get_name()))).build( Btn::text_fg(format!("{}", nice_map_name(app.primary.map.get_name()))).build(
ctx, ctx,

View File

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

View File

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

View File

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

View File

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

View File

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