reduce verbosity of constructing text widgets [rebuild]

This commit is contained in:
Dustin Carlino 2020-03-13 23:06:52 -07:00
parent 8f285be4fe
commit fedacfe202
31 changed files with 256 additions and 395 deletions

View File

@ -10,7 +10,7 @@
use ezgui::{ use ezgui::{
hotkey, lctrl, Button, Color, Composite, Drawable, EventCtx, EventLoopMode, GeomBatch, GfxCtx, hotkey, lctrl, Button, Color, Composite, Drawable, EventCtx, EventLoopMode, GeomBatch, GfxCtx,
HorizontalAlignment, Key, Line, ManagedWidget, Outcome, Plot, PlotOptions, Series, Text, HorizontalAlignment, Key, Line, ManagedWidget, Outcome, Plot, PlotOptions, Series, Text,
VerticalAlignment, GUI, TextExt, VerticalAlignment, GUI,
}; };
use geom::{Angle, Duration, Polygon, Pt2D, Time}; use geom::{Angle, Duration, Polygon, Pt2D, Time};
@ -42,36 +42,18 @@ impl App {
fn make_timeseries_panel(&self, ctx: &mut EventCtx) -> Composite { fn make_timeseries_panel(&self, ctx: &mut EventCtx) -> Composite {
// Make a table with 3 columns. // Make a table with 3 columns.
let mut col1 = vec![ManagedWidget::draw_text( let mut col1 = vec![Line("Time").roboto_bold().draw(ctx)];
ctx, let mut col2 = vec![Line("Linear").roboto_bold().draw(ctx)];
Text::from(Line("Time").roboto_bold()), let mut col3 = vec![Line("Quadratic").roboto_bold().draw(ctx)];
)];
let mut col2 = vec![ManagedWidget::draw_text(
ctx,
Text::from(Line("Linear").roboto_bold()),
)];
let mut col3 = vec![ManagedWidget::draw_text(
ctx,
Text::from(Line("Quadratic").roboto_bold()),
)];
for s in 0..(self.elapsed.inner_seconds() as usize) { for s in 0..(self.elapsed.inner_seconds() as usize) {
col1.push(ManagedWidget::draw_text( col1.push(Duration::seconds(s as f64).to_string().draw_text(ctx));
ctx, col2.push(s.to_string().draw_text(ctx));
Text::from(Line(Duration::seconds(s as f64).to_string())), col3.push(s.pow(2).to_string().draw_text(ctx));
));
col2.push(ManagedWidget::draw_text(
ctx,
Text::from(Line(s.to_string())),
));
col3.push(ManagedWidget::draw_text(
ctx,
Text::from(Line(s.pow(2).to_string())),
));
} }
let mut c = Composite::new( let mut c = Composite::new(
ManagedWidget::col(vec![ ManagedWidget::col(vec![
ManagedWidget::row(vec![ManagedWidget::draw_text(ctx, { ManagedWidget::row(vec![{
let mut txt = Text::from( let mut txt = Text::from(
Line("Here's a bunch of text to force some scrolling.").roboto_bold(), Line("Here's a bunch of text to force some scrolling.").roboto_bold(),
); );
@ -82,8 +64,8 @@ impl App {
) )
.fg(Color::RED), .fg(Color::RED),
); );
txt txt.draw(ctx)
})]), }]),
ManagedWidget::row(vec![ ManagedWidget::row(vec![
// Examples of styling widgets // Examples of styling widgets
ManagedWidget::col(col1) ManagedWidget::col(col1)
@ -159,11 +141,9 @@ impl GUI for App {
self.controls.replace( self.controls.replace(
ctx, ctx,
"stopwatch", "stopwatch",
ManagedWidget::draw_text( format!("Stopwatch: {}", self.elapsed)
ctx, .draw_text(ctx)
Text::from(Line(format!("Stopwatch: {}", self.elapsed))), .named("stopwatch"),
)
.named("stopwatch"),
); );
} }
_ => unreachable!(), _ => unreachable!(),
@ -181,11 +161,9 @@ impl GUI for App {
self.controls.replace( self.controls.replace(
ctx, ctx,
"stopwatch", "stopwatch",
ManagedWidget::draw_text( format!("Stopwatch: {}", self.elapsed)
ctx, .draw_text(ctx)
Text::from(Line(format!("Stopwatch: {}", self.elapsed))), .named("stopwatch"),
)
.named("stopwatch"),
); );
} }
@ -273,13 +251,13 @@ fn setup_scrollable_canvas(ctx: &mut EventCtx) -> Drawable {
fn make_controls(ctx: &mut EventCtx) -> Composite { fn make_controls(ctx: &mut EventCtx) -> Composite {
Composite::new( Composite::new(
ManagedWidget::col(vec![ ManagedWidget::col(vec![
ManagedWidget::draw_text(ctx, { {
let mut txt = Text::from(Line("ezgui demo").roboto_bold()); let mut txt = Text::from(Line("ezgui demo").roboto_bold());
txt.add(Line( txt.add(Line(
"Click and drag to pan, use touchpad or scroll wheel to zoom", "Click and drag to pan, use touchpad or scroll wheel to zoom",
)); ));
txt txt.draw(ctx)
}), },
ManagedWidget::row(vec![ ManagedWidget::row(vec![
// This just cycles between two arbitrary buttons // This just cycles between two arbitrary buttons
ManagedWidget::custom_checkbox( ManagedWidget::custom_checkbox(
@ -320,7 +298,7 @@ fn make_controls(ctx: &mut EventCtx) -> Composite {
ManagedWidget::checkbox(ctx, "Show timeseries", lctrl(Key::T), false).margin(5), ManagedWidget::checkbox(ctx, "Show timeseries", lctrl(Key::T), false).margin(5),
]) ])
.evenly_spaced(), .evenly_spaced(),
ManagedWidget::draw_text(ctx, Text::from(Line("Stopwatch: ..."))).named("stopwatch"), "Stopwatch: ...".draw_text(ctx).named("stopwatch"),
]) ])
.bg(Color::grey(0.4)), .bg(Color::grey(0.4)),
) )

View File

@ -29,7 +29,7 @@ pub use crate::input::UserInput;
pub use crate::managed::{Composite, ManagedWidget, Outcome}; pub use crate::managed::{Composite, ManagedWidget, Outcome};
pub use crate::runner::{run, EventLoopMode, Settings, GUI}; pub use crate::runner::{run, EventLoopMode, Settings, GUI};
pub use crate::screen_geom::{ScreenDims, ScreenPt, ScreenRectangle}; pub use crate::screen_geom::{ScreenDims, ScreenPt, ScreenRectangle};
pub use crate::text::{Line, Text, TextSpan, HOTKEY_COLOR}; pub use crate::text::{Line, Text, TextExt, TextSpan, HOTKEY_COLOR};
pub use crate::widgets::{ pub use crate::widgets::{
Autocomplete, Button, Choice, Filler, Histogram, ItemSlider, JustDraw, ModalMenu, Plot, Autocomplete, Button, Choice, Filler, Histogram, ItemSlider, JustDraw, ModalMenu, Plot,
PlotOptions, Series, Slider, Warper, WarpingItemSlider, Wizard, WrappedWizard, PlotOptions, Series, Slider, Warper, WarpingItemSlider, Wizard, WrappedWizard,

View File

@ -247,7 +247,7 @@ impl ManagedWidget {
ManagedWidget::new(WidgetType::Draw(j)) ManagedWidget::new(WidgetType::Draw(j))
} }
pub fn draw_text(ctx: &EventCtx, txt: Text) -> ManagedWidget { pub(crate) fn draw_text(ctx: &EventCtx, txt: Text) -> ManagedWidget {
JustDraw::text(ctx, txt) JustDraw::text(ctx, txt)
} }

View File

@ -1,5 +1,5 @@
use crate::assets::Assets; use crate::assets::Assets;
use crate::{svg, Color, EventCtx, GeomBatch, GfxCtx, Prerender, ScreenDims}; use crate::{svg, Color, EventCtx, GeomBatch, GfxCtx, ManagedWidget, Prerender, ScreenDims};
use geom::Polygon; use geom::Polygon;
use std::collections::hash_map::DefaultHasher; use std::collections::hash_map::DefaultHasher;
use std::fmt::Write; use std::fmt::Write;
@ -55,6 +55,10 @@ impl TextSpan {
self.font = Font::RobotoBold; self.font = Font::RobotoBold;
self self
} }
pub fn draw(self, ctx: &EventCtx) -> ManagedWidget {
Text::from(self).draw(ctx)
}
} }
// TODO What's the better way of doing this? Also "Line" is a bit of a misnomer // TODO What's the better way of doing this? Also "Line" is a bit of a misnomer
@ -259,6 +263,10 @@ impl Text {
hasher.write(format!("{:?}", self).as_ref()); hasher.write(format!("{:?}", self).as_ref());
format!("{:x}", hasher.finish()) format!("{:x}", hasher.finish())
} }
pub fn draw(self, ctx: &EventCtx) -> ManagedWidget {
ManagedWidget::draw_text(ctx, self)
}
} }
fn render_text(spans: Vec<TextSpan>, tolerance: f32, assets: &Assets) -> GeomBatch { fn render_text(spans: Vec<TextSpan>, tolerance: f32, assets: &Assets) -> GeomBatch {
@ -305,3 +313,19 @@ fn render_text(spans: Vec<TextSpan>, tolerance: f32, assets: &Assets) -> GeomBat
Err(err) => panic!("render_text({}): {}", contents, err), Err(err) => panic!("render_text({}): {}", contents, err),
} }
} }
pub trait TextExt {
fn draw_text(self, ctx: &EventCtx) -> ManagedWidget;
}
impl TextExt for &str {
fn draw_text(self, ctx: &EventCtx) -> ManagedWidget {
Line(self).draw(ctx)
}
}
impl TextExt for String {
fn draw_text(self, ctx: &EventCtx) -> ManagedWidget {
Line(self).draw(ctx)
}
}

View File

@ -1,6 +1,7 @@
use crate::layout::Widget; use crate::layout::Widget;
use crate::{ use crate::{
Color, Drawable, EventCtx, GeomBatch, GfxCtx, Line, ManagedWidget, ScreenDims, ScreenPt, Text, Color, Drawable, EventCtx, GeomBatch, GfxCtx, Line, ManagedWidget, ScreenDims, ScreenPt, Text,
TextExt,
}; };
use abstutil::prettyprint_usize; use abstutil::prettyprint_usize;
use geom::{Distance, Duration, Polygon, Pt2D}; use geom::{Distance, Duration, Polygon, Pt2D};
@ -80,10 +81,7 @@ impl Histogram {
for i in 0..num_x_labels { for i in 0..num_x_labels {
let percent_x = (i as f64) / ((num_x_labels - 1) as f64); let percent_x = (i as f64) / ((num_x_labels - 1) as f64);
let dt = min_x + (max_x - min_x) * percent_x; let dt = min_x + (max_x - min_x) * percent_x;
row.push(ManagedWidget::draw_text( row.push(dt.to_string().draw_text(ctx));
ctx,
Text::from(Line(dt.to_string())),
));
} }
let x_axis = ManagedWidget::row(row); let x_axis = ManagedWidget::row(row);
@ -91,12 +89,7 @@ impl Histogram {
let mut col = Vec::new(); let mut col = Vec::new();
for i in 0..num_y_labels { for i in 0..num_y_labels {
let percent_y = (i as f64) / ((num_y_labels - 1) as f64); let percent_y = (i as f64) / ((num_y_labels - 1) as f64);
col.push(ManagedWidget::draw_text( col.push(prettyprint_usize(((max_y as f64) * percent_y) as usize).draw_text(ctx));
ctx,
Text::from(Line(prettyprint_usize(
((max_y as f64) * percent_y) as usize,
))),
));
} }
col.reverse(); col.reverse();
let y_axis = ManagedWidget::col(col); let y_axis = ManagedWidget::col(col);

View File

@ -1,7 +1,7 @@
use crate::layout::Widget; use crate::layout::Widget;
use crate::{ use crate::{
Color, Drawable, EventCtx, GeomBatch, GfxCtx, Line, ManagedWidget, ScreenDims, ScreenPt, Color, Drawable, EventCtx, GeomBatch, GfxCtx, Line, ManagedWidget, ScreenDims, ScreenPt,
ScreenRectangle, Text, ScreenRectangle, Text, TextExt,
}; };
use abstutil::prettyprint_usize; use abstutil::prettyprint_usize;
use geom::{Angle, Bounds, Circle, Distance, Duration, FindClosest, PolyLine, Pt2D, Time}; use geom::{Angle, Bounds, Circle, Distance, Duration, FindClosest, PolyLine, Pt2D, Time};
@ -59,7 +59,7 @@ impl<T: 'static + Ord + PartialEq + Copy + core::fmt::Debug + Yvalue<T>> Plot<T>
.to_polygon(), .to_polygon(),
)]), )]),
), ),
ManagedWidget::draw_text(ctx, Text::from(Line(&s.label))), s.label.clone().draw_text(ctx),
]) ])
}) })
.collect(), .collect(),
@ -192,10 +192,7 @@ impl<T: 'static + Ord + PartialEq + Copy + core::fmt::Debug + Yvalue<T>> Plot<T>
let mut col = Vec::new(); let mut col = Vec::new();
for i in 0..num_y_labels { for i in 0..num_y_labels {
let percent_y = (i as f64) / ((num_y_labels - 1) as f64); let percent_y = (i as f64) / ((num_y_labels - 1) as f64);
col.push(ManagedWidget::draw_text( col.push(max_y.from_percent(percent_y).prettyprint().draw_text(ctx));
ctx,
Text::from(Line(max_y.from_percent(percent_y).prettyprint())),
));
} }
col.reverse(); col.reverse();
let y_axis = ManagedWidget::col(col).padding(10); let y_axis = ManagedWidget::col(col).padding(10);

View File

@ -86,7 +86,7 @@ impl Wizard {
Composite::new( Composite::new(
ManagedWidget::col(vec![ ManagedWidget::col(vec![
ManagedWidget::row(vec![ ManagedWidget::row(vec![
ManagedWidget::draw_text(ctx, Text::from(Line(query).roboto_bold())), Line(query).roboto_bold().draw(ctx),
// TODO nice text button // TODO nice text button
ManagedWidget::btn(Button::text_bg( ManagedWidget::btn(Button::text_bg(
Text::from(Line("X").fg(Color::BLACK)), Text::from(Line("X").fg(Color::BLACK)),
@ -265,10 +265,7 @@ impl<'a, 'b> WrappedWizard<'a, 'b> {
} }
let mut col = Vec::new(); let mut col = Vec::new();
if let Some(l) = query { if let Some(l) = query {
col.push(ManagedWidget::draw_text( col.push(Line(l).roboto_bold().draw(self.ctx));
self.ctx,
Text::from(Line(l).roboto_bold()),
));
} }
col.push(ManagedWidget::menu("menu")); col.push(ManagedWidget::menu("menu"));
self.wizard.menu_comp = Some( self.wizard.menu_comp = Some(
@ -410,7 +407,7 @@ impl<'a, 'b> WrappedWizard<'a, 'b> {
self.wizard.ack = Some( self.wizard.ack = Some(
Composite::new( Composite::new(
ManagedWidget::col(vec![ ManagedWidget::col(vec![
ManagedWidget::draw_text(self.ctx, txt), txt.draw(self.ctx),
ManagedWidget::btn(Button::text_bg( ManagedWidget::btn(Button::text_bg(
Text::from(Line("OK")), Text::from(Line("OK")),
Color::grey(0.6), Color::grey(0.6),

View File

@ -150,7 +150,7 @@ impl Tab {
master_col.push({ master_col.push({
let mut txt = Text::from(Line("A/B STREET").size(100)); let mut txt = Text::from(Line("A/B STREET").size(100));
txt.add(Line("CHALLENGES").size(50)); txt.add(Line("CHALLENGES").size(50));
ManagedWidget::draw_text(ctx, txt).centered_horiz() txt.draw(ctx).centered_horiz()
}); });
// First list challenges // First list challenges
@ -233,7 +233,7 @@ impl Tab {
} }
main_row.push( main_row.push(
ManagedWidget::col(vec![ ManagedWidget::col(vec![
ManagedWidget::draw_text(ctx, txt), txt.draw(ctx),
WrappedComposite::text_button(ctx, "Start!", hotkey(Key::Enter)).margin(10), WrappedComposite::text_button(ctx, "Start!", hotkey(Key::Enter)).margin(10),
]) ])
.bg(colors::PANEL_BG) .bg(colors::PANEL_BG)

View File

@ -139,7 +139,7 @@ impl ColorerBuilder {
// Build the legend // Build the legend
let mut col = vec![ManagedWidget::row(vec![ let mut col = vec![ManagedWidget::row(vec![
ManagedWidget::draw_text(ctx, self.header), self.header.draw(ctx),
WrappedComposite::text_button(ctx, "X", None).align_right(), WrappedComposite::text_button(ctx, "X", None).align_right(),
])]; ])];
for (label, color) in self.prioritized_colors { for (label, color) in self.prioritized_colors {
@ -182,7 +182,7 @@ impl ColorLegend {
) )
.margin(5) .margin(5)
.centered_vert(), .centered_vert(),
ManagedWidget::draw_text(ctx, txt), txt.draw(ctx),
]) ])
} }
} }

View File

@ -9,7 +9,7 @@ use crate::sandbox::{SandboxMode, SpeedControls};
use abstutil::prettyprint_usize; use abstutil::prettyprint_usize;
use ezgui::{ use ezgui::{
hotkey, Button, Color, Composite, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, hotkey, Button, Color, Composite, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment,
Key, Line, ManagedWidget, Outcome, Plot, PlotOptions, RewriteColor, Series, Text, Key, Line, ManagedWidget, Outcome, Plot, PlotOptions, RewriteColor, Series, Text, TextExt,
VerticalAlignment, VerticalAlignment,
}; };
use geom::{Angle, Circle, Distance, Duration, Polygon, Pt2D, Statistic, Time}; use geom::{Angle, Circle, Distance, Duration, Polygon, Pt2D, Statistic, Time};
@ -400,16 +400,10 @@ fn info_for(
{ {
let label = if l.is_sidewalk() { "Sidewalk" } else { "Lane" }; let label = if l.is_sidewalk() { "Sidewalk" } else { "Lane" };
rows.push(ManagedWidget::row(vec![ rows.push(ManagedWidget::row(vec![
ManagedWidget::draw_text( Line(format!("{} #{}", label, id.0)).roboto_bold().draw(ctx),
ctx,
Text::from(Line(format!("{} #{}", label, id.0)).roboto_bold()),
),
header_btns, header_btns,
])); ]));
rows.push(ManagedWidget::draw_text( rows.push(format!("@ {}", r.get_name()).draw_text(ctx));
ctx,
Text::from(Line(format!("@ {}", r.get_name()))),
));
} }
rows.extend(action_btns); rows.extend(action_btns);
@ -477,7 +471,7 @@ fn info_for(
prettyprint_usize(sim.get_analytics().thruput_stats.count_per_road.get(r.id)) prettyprint_usize(sim.get_analytics().thruput_stats.count_per_road.get(r.id))
))); )));
txt.add(Line(format!("In 20 minute buckets:"))); txt.add(Line(format!("In 20 minute buckets:")));
rows.push(ManagedWidget::draw_text(ctx, txt)); rows.push(txt.draw(ctx));
let r = app.primary.map.get_l(id).parent; let r = app.primary.map.get_l(id).parent;
rows.push( rows.push(
@ -504,7 +498,7 @@ fn info_for(
} }
}; };
rows.push(ManagedWidget::row(vec![ rows.push(ManagedWidget::row(vec![
ManagedWidget::draw_text(ctx, Text::from(Line(label).roboto_bold())), Line(label).roboto_bold().draw(ctx),
header_btns, header_btns,
])); ]));
} }
@ -540,7 +534,7 @@ fn info_for(
) )
))); )));
txt.add(Line(format!("In 20 minute buckets:"))); txt.add(Line(format!("In 20 minute buckets:")));
rows.push(ManagedWidget::draw_text(ctx, txt)); rows.push(txt.draw(ctx));
rows.push( rows.push(
throughput(ctx, app, move |a, t| { throughput(ctx, app, move |a, t| {
@ -553,7 +547,7 @@ fn info_for(
let mut txt = Text::from(Line("")); let mut txt = Text::from(Line(""));
txt.add(Line("Delay").roboto_bold()); txt.add(Line("Delay").roboto_bold());
txt.add(Line(format!("In 20 minute buckets:"))); txt.add(Line(format!("In 20 minute buckets:")));
rows.push(ManagedWidget::draw_text(ctx, txt)); rows.push(txt.draw(ctx));
rows.push(intersection_delay(ctx, app, id, Duration::minutes(20)).margin(10)); rows.push(intersection_delay(ctx, app, id, Duration::minutes(20)).margin(10));
} }
@ -565,10 +559,7 @@ fn info_for(
// Header // Header
{ {
rows.push(ManagedWidget::row(vec![ rows.push(ManagedWidget::row(vec![
ManagedWidget::draw_text( Line(format!("Building #{}", id.0)).roboto_bold().draw(ctx),
ctx,
Text::from(Line(format!("Building #{}", id.0)).roboto_bold()),
),
header_btns, header_btns,
])); ]));
} }
@ -639,15 +630,12 @@ fn info_for(
} }
if !txt.is_empty() { if !txt.is_empty() {
rows.push(ManagedWidget::draw_text(ctx, txt)) rows.push(txt.draw(ctx))
} }
let people = sim.bldg_to_people(id); let people = sim.bldg_to_people(id);
if !people.is_empty() { if !people.is_empty() {
rows.push(ManagedWidget::draw_text( rows.push(format!("{} people inside right now", people.len()).draw_text(ctx));
ctx,
Text::from(Line(format!("{} people inside right now", people.len()))),
));
// TODO Show buttons to examine first 3, or a ...More button // TODO Show buttons to examine first 3, or a ...More button
for p in people { for p in people {
rows.push( rows.push(
@ -673,10 +661,7 @@ fn info_for(
VehicleType::Bus => "Bus", VehicleType::Bus => "Bus",
}; };
rows.push(ManagedWidget::row(vec![ rows.push(ManagedWidget::row(vec![
ManagedWidget::draw_text( Line(format!("{} #{}", label, id.0)).roboto_bold().draw(ctx),
ctx,
Text::from(Line(format!("{} #{}", label, id.0)).roboto_bold()),
),
header_btns, header_btns,
])); ]));
} }
@ -689,17 +674,16 @@ fn info_for(
for line in extra { for line in extra {
txt.add(Line(line)); txt.add(Line(line));
} }
rows.push(ManagedWidget::draw_text(ctx, txt)); rows.push(txt.draw(ctx));
} }
} }
ID::Pedestrian(id) => { ID::Pedestrian(id) => {
// Header // Header
{ {
rows.push(ManagedWidget::row(vec![ rows.push(ManagedWidget::row(vec![
ManagedWidget::draw_text( Line(format!("Pedestrian #{}", id.0))
ctx, .roboto_bold()
Text::from(Line(format!("Pedestrian #{}", id.0)).roboto_bold()), .draw(ctx),
),
header_btns, header_btns,
])); ]));
} }
@ -712,17 +696,14 @@ fn info_for(
for line in extra { for line in extra {
txt.add(Line(line)); txt.add(Line(line));
} }
rows.push(ManagedWidget::draw_text(ctx, txt)); rows.push(txt.draw(ctx));
} }
} }
ID::PedCrowd(members) => { ID::PedCrowd(members) => {
// Header // Header
{ {
rows.push(ManagedWidget::row(vec![ rows.push(ManagedWidget::row(vec![
ManagedWidget::draw_text( Line("Pedestrian crowd").roboto_bold().draw(ctx),
ctx,
Text::from(Line("Pedestrian crowd").roboto_bold()),
),
header_btns, header_btns,
])); ]));
} }
@ -730,13 +711,13 @@ fn info_for(
let mut txt = Text::new(); let mut txt = Text::new();
txt.add(Line(format!("Crowd of {}", members.len()))); txt.add(Line(format!("Crowd of {}", members.len())));
rows.push(ManagedWidget::draw_text(ctx, txt)) rows.push(txt.draw(ctx))
} }
ID::BusStop(id) => { ID::BusStop(id) => {
// Header // Header
{ {
rows.push(ManagedWidget::row(vec![ rows.push(ManagedWidget::row(vec![
ManagedWidget::draw_text(ctx, Text::from(Line("Bus stop").roboto_bold())), Line("Bus stop").roboto_bold().draw(ctx),
header_btns, header_btns,
])); ]));
} }
@ -770,16 +751,13 @@ fn info_for(
txt.add(Line(format!(" Waiting: {}", hgram.describe()))); txt.add(Line(format!(" Waiting: {}", hgram.describe())));
} }
} }
rows.push(ManagedWidget::draw_text(ctx, txt)) rows.push(txt.draw(ctx))
} }
ID::Area(id) => { ID::Area(id) => {
// Header // Header
{ {
rows.push(ManagedWidget::row(vec![ rows.push(ManagedWidget::row(vec![
ManagedWidget::draw_text( Line(format!("Area #{}", id.0)).roboto_bold().draw(ctx),
ctx,
Text::from(Line(format!("Area #{}", id.0)).roboto_bold()),
),
header_btns, header_btns,
])); ]));
} }
@ -796,10 +774,9 @@ fn info_for(
// Header // Header
{ {
rows.push(ManagedWidget::row(vec![ rows.push(ManagedWidget::row(vec![
ManagedWidget::draw_text( Line(format!("Extra GIS shape #{}", id.0))
ctx, .roboto_bold()
Text::from(Line(format!("Extra GIS shape #{}", id.0)).roboto_bold()), .draw(ctx),
),
header_btns, header_btns,
])); ]));
} }
@ -817,10 +794,7 @@ fn info_for(
// Header // Header
{ {
rows.push(ManagedWidget::row(vec![ rows.push(ManagedWidget::row(vec![
ManagedWidget::draw_text( Line(format!("Trip #{}", id.0)).roboto_bold().draw(ctx),
ctx,
Text::from(Line(format!("Trip #{}", id.0)).roboto_bold()),
),
// No jump-to-object button; this is probably a finished trip. // No jump-to-object button; this is probably a finished trip.
WrappedComposite::text_button(ctx, "X", hotkey(Key::Escape)).align_right(), WrappedComposite::text_button(ctx, "X", hotkey(Key::Escape)).align_right(),
])); ]));
@ -831,10 +805,7 @@ fn info_for(
// Header // Header
{ {
rows.push(ManagedWidget::row(vec![ rows.push(ManagedWidget::row(vec![
ManagedWidget::draw_text( Line(format!("Person #{}", id.0)).roboto_bold().draw(ctx),
ctx,
Text::from(Line(format!("Person #{}", id.0)).roboto_bold()),
),
header_btns, header_btns,
])); ]));
} }
@ -856,46 +827,26 @@ fn info_for(
&format!("examine Building #{}", b.0), &format!("examine Building #{}", b.0),
ctx, ctx,
)), )),
PersonState::Trip(t) => ManagedWidget::draw_text( PersonState::Trip(t) => format!("Currently doing Trip #{}", t.0).draw_text(ctx),
ctx, PersonState::OffMap => "Currently outside the map boundaries".draw_text(ctx),
Text::from(Line(format!("Currently doing Trip #{}", t.0))), PersonState::Limbo => "Currently in limbo -- they broke out of the Matrix! Woops. \
), (A bug occurred)"
PersonState::OffMap => ManagedWidget::draw_text( .draw_text(ctx),
ctx,
Text::from(Line("Currently outside the map boundaries")),
),
PersonState::Limbo => ManagedWidget::draw_text(
ctx,
Text::from(Line(
"Currently in limbo -- they broke out of the Matrix! Woops. (A bug \
occurred)",
)),
),
}); });
rows.push(ManagedWidget::draw_text( rows.push(Line("Schedule").roboto_bold().draw(ctx));
ctx,
Text::from(Line("Schedule").roboto_bold()),
));
for t in &person.trips { for t in &person.trips {
// TODO Still maybe unsafe? Check if trip has actually started or not // TODO Still maybe unsafe? Check if trip has actually started or not
// TODO Say where the trip goes, no matter what? // TODO Say where the trip goes, no matter what?
let start_time = app.primary.sim.trip_start_time(*t); let start_time = app.primary.sim.trip_start_time(*t);
if app.primary.sim.time() < start_time { if app.primary.sim.time() < start_time {
rows.push(ManagedWidget::draw_text( rows.push(
ctx, format!("{}: Trip #{} will start", start_time.ampm_tostring(), t.0)
Text::from(Line(format!( .draw_text(ctx),
"{}: Trip #{} will start", );
start_time.ampm_tostring(),
t.0
))),
));
} else { } else {
rows.push(ManagedWidget::row(vec![ rows.push(ManagedWidget::row(vec![
ManagedWidget::draw_text( format!("{}: ", start_time.ampm_tostring()).draw_text(ctx),
ctx,
Text::from(Line(format!("{}: ", start_time.ampm_tostring(),))),
),
ManagedWidget::btn(Button::text_bg( ManagedWidget::btn(Button::text_bg(
Text::from(Line(format!("Trip #{}", t.0))), Text::from(Line(format!("Trip #{}", t.0))),
colors::SECTION_BG, colors::SECTION_BG,
@ -919,11 +870,9 @@ fn make_table(ctx: &EventCtx, rows: Vec<(String, String)>) -> Vec<ManagedWidget>
rows.into_iter() rows.into_iter()
.map(|(k, v)| { .map(|(k, v)| {
ManagedWidget::row(vec![ ManagedWidget::row(vec![
ManagedWidget::draw_text(ctx, Text::from(Line(k).roboto_bold())), Line(k).roboto_bold().draw(ctx),
// TODO not quite... // TODO not quite...
ManagedWidget::draw_text(ctx, Text::from(Line(v))) v.draw_text(ctx).centered_vert().align_right(),
.centered_vert()
.align_right(),
]) ])
}) })
.collect() .collect()
@ -936,8 +885,8 @@ fn make_table(ctx: &EventCtx, rows: Vec<(String, String)>) -> Vec<ManagedWidget>
values.add(Line(v)); values.add(Line(v));
} }
vec![ManagedWidget::row(vec![ vec![ManagedWidget::row(vec![
ManagedWidget::draw_text(ctx, keys), keys.draw(ctx),
ManagedWidget::draw_text(ctx, values).centered_vert().bg(Color::GREEN), values.draw(ctx).centered_vert().bg(Color::GREEN),
])]*/ ])]*/
} }

View File

@ -454,14 +454,12 @@ fn make_viz_panel(ctx: &mut EventCtx, acs: &AgentColorScheme) -> ManagedWidget {
)]), )]),
) )
.margin(3), .margin(3),
ManagedWidget::draw_text( Text::from(if *enabled {
ctx, Line(label)
Text::from(if *enabled { } else {
Line(label) Line(label).fg(Color::WHITE.alpha(0.5))
} else { })
Line(label).fg(Color::WHITE.alpha(0.5)) .draw(ctx)
}),
)
.margin(3), .margin(3),
]) ])
.centered_cross(), .centered_cross(),

View File

@ -9,7 +9,7 @@ use abstutil::{prettyprint_usize, Counter};
use ezgui::{ use ezgui::{
hotkey, Button, Color, Composite, Drawable, EventCtx, GeomBatch, GfxCtx, Histogram, hotkey, Button, Color, Composite, Drawable, EventCtx, GeomBatch, GfxCtx, Histogram,
HorizontalAlignment, JustDraw, Key, Line, ManagedWidget, Outcome, Plot, PlotOptions, HorizontalAlignment, JustDraw, Key, Line, ManagedWidget, Outcome, Plot, PlotOptions,
RewriteColor, Series, Text, VerticalAlignment, RewriteColor, Series, Text, TextExt, VerticalAlignment,
}; };
use geom::{Circle, Distance, Duration, PolyLine, Polygon, Pt2D, Statistic, Time}; use geom::{Circle, Distance, Duration, PolyLine, Polygon, Pt2D, Statistic, Time};
use map_model::{BusRouteID, IntersectionID}; use map_model::{BusRouteID, IntersectionID};
@ -308,7 +308,7 @@ impl Overlays {
Composite::new( Composite::new(
ManagedWidget::col(vec![ ManagedWidget::col(vec![
ManagedWidget::row(vec![ ManagedWidget::row(vec![
ManagedWidget::draw_text(ctx, Text::from(Line("Heat Map Layers"))), "Heat Map Layers".draw_text(ctx),
WrappedComposite::text_button(ctx, "X", hotkey(Key::Escape)).align_right(), WrappedComposite::text_button(ctx, "X", hotkey(Key::Escape)).align_right(),
]), ]),
ManagedWidget::row(choices).flex_wrap(ctx, 20), ManagedWidget::row(choices).flex_wrap(ctx, 20),
@ -613,7 +613,7 @@ impl Overlays {
Composite::new( Composite::new(
ManagedWidget::col(vec![ ManagedWidget::col(vec![
ManagedWidget::row(vec![ ManagedWidget::row(vec![
ManagedWidget::draw_text(ctx, { {
let mut txt = Text::from(Line("Are trips ")); let mut txt = Text::from(Line("Are trips "));
txt.append(Line("faster").fg(Color::GREEN)); txt.append(Line("faster").fg(Color::GREEN));
txt.append(Line(", ")); txt.append(Line(", "));
@ -621,8 +621,8 @@ impl Overlays {
txt.append(Line(", or ")); txt.append(Line(", or "));
txt.append(Line("the same").fg(Color::YELLOW)); txt.append(Line("the same").fg(Color::YELLOW));
txt.append(Line("?")); txt.append(Line("?"));
txt txt.draw(ctx)
}) }
.margin(10), .margin(10),
WrappedComposite::text_button(ctx, "X", None).align_right(), WrappedComposite::text_button(ctx, "X", None).align_right(),
]), ]),
@ -672,7 +672,7 @@ impl Overlays {
let col = vec![ let col = vec![
ManagedWidget::row(vec![ ManagedWidget::row(vec![
ManagedWidget::draw_text(ctx, Text::from(Line("intersection demand"))), "intersection demand".draw_text(ctx),
ManagedWidget::btn(Button::rectangle_svg( ManagedWidget::btn(Button::rectangle_svg(
"../data/system/assets/tools/locate.svg", "../data/system/assets/tools/locate.svg",
"intersection demand", "intersection demand",
@ -702,10 +702,9 @@ impl Overlays {
pub fn bus_passengers(id: BusRouteID, ctx: &mut EventCtx, app: &App) -> Overlays { pub fn bus_passengers(id: BusRouteID, ctx: &mut EventCtx, app: &App) -> Overlays {
let route = app.primary.map.get_br(id); let route = app.primary.map.get_br(id);
let mut master_col = vec![ManagedWidget::row(vec![ let mut master_col = vec![ManagedWidget::row(vec![
ManagedWidget::draw_text( Line(format!("Passengers for {}", route.name))
ctx, .roboto_bold()
Text::from(Line(format!("Passengers for {}", route.name)).roboto_bold()), .draw(ctx),
),
WrappedComposite::text_button(ctx, "X", None).align_right(), WrappedComposite::text_button(ctx, "X", None).align_right(),
])]; ])];
let mut col = Vec::new(); let mut col = Vec::new();
@ -717,7 +716,7 @@ impl Overlays {
.bus_passenger_delays(app.primary.sim.time(), id); .bus_passenger_delays(app.primary.sim.time(), id);
for idx in 0..route.stops.len() { for idx in 0..route.stops.len() {
col.push(ManagedWidget::row(vec![ col.push(ManagedWidget::row(vec![
ManagedWidget::draw_text(ctx, Text::from(Line(format!("Stop {}", idx + 1)))), format!("Stop {}", idx + 1).draw_text(ctx),
ManagedWidget::btn(Button::rectangle_svg( ManagedWidget::btn(Button::rectangle_svg(
"../data/system/assets/tools/locate.svg", "../data/system/assets/tools/locate.svg",
&format!("Stop {}", idx + 1), &format!("Stop {}", idx + 1),
@ -726,16 +725,14 @@ impl Overlays {
ctx, ctx,
)), )),
if let Some(hgram) = delay_per_stop.remove(&route.stops[idx]) { if let Some(hgram) = delay_per_stop.remove(&route.stops[idx]) {
ManagedWidget::draw_text( format!(
ctx, ": {} (avg {})",
Text::from(Line(format!( hgram.count(),
": {} (avg {})", hgram.select(Statistic::Mean)
hgram.count(),
hgram.select(Statistic::Mean)
))),
) )
.draw_text(ctx)
} else { } else {
ManagedWidget::draw_text(ctx, Text::from(Line(": nobody"))) ": nobody".draw_text(ctx)
}, },
])); ]));
} }
@ -822,10 +819,7 @@ impl Overlays {
Composite::new( Composite::new(
ManagedWidget::col(vec![ ManagedWidget::col(vec![
ManagedWidget::row(vec![ ManagedWidget::row(vec![
ManagedWidget::draw_text( format!("delays for {}", route.name).draw_text(ctx),
ctx,
Text::from(Line(format!("delays for {}", route.name))),
),
WrappedComposite::text_button(ctx, "X", None).align_right(), WrappedComposite::text_button(ctx, "X", None).align_right(),
]), ]),
Plot::new_duration(ctx, series, PlotOptions::new()).margin(10), Plot::new_duration(ctx, series, PlotOptions::new()).margin(10),

View File

@ -249,28 +249,24 @@ impl TurnExplorer {
let num_turns = app.primary.map.get_turns_from_lane(l).len(); let num_turns = app.primary.map.get_turns_from_lane(l).len();
let mut col = vec![ManagedWidget::row(vec![ let mut col = vec![ManagedWidget::row(vec![
ManagedWidget::draw_text( Text::from(
ctx, Line(format!(
Text::from( "Turns from {}",
Line(format!( app.primary.map.get_parent(l).get_name()
"Turns from {}", ))
app.primary.map.get_parent(l).get_name() .size(26),
))
.size(26),
),
) )
.draw(ctx)
.margin(5), .margin(5),
ManagedWidget::draw_batch( ManagedWidget::draw_batch(
ctx, ctx,
GeomBatch::from(vec![(Color::WHITE, Polygon::rectangle(2.0, 50.0))]), GeomBatch::from(vec![(Color::WHITE, Polygon::rectangle(2.0, 50.0))]),
) )
.margin(5), .margin(5),
ManagedWidget::draw_text( Text::from(Line(format!("{}/{}", idx, num_turns)).size(20))
ctx, .draw(ctx)
Text::from(Line(format!("{}/{}", idx, num_turns)).size(20)), .margin(5)
) .centered_vert(),
.margin(5)
.centered_vert(),
if idx == 0 { if idx == 0 {
Button::inactive_button(ctx, "<") Button::inactive_button(ctx, "<")
} else { } else {

View File

@ -38,10 +38,10 @@ impl DebugMode {
composite: Composite::new( composite: Composite::new(
ManagedWidget::col(vec![ ManagedWidget::col(vec![
ManagedWidget::row(vec![ ManagedWidget::row(vec![
ManagedWidget::draw_text(ctx, Text::from(Line("Debug Mode").roboto_bold())), Line("Debug Mode").roboto_bold().draw(ctx),
WrappedComposite::text_button(ctx, "X", hotkey(Key::Escape)).align_right(), WrappedComposite::text_button(ctx, "X", hotkey(Key::Escape)).align_right(),
]), ]),
ManagedWidget::draw_text(ctx, Text::new()).named("current info"), Text::new().draw(ctx).named("current info"),
ManagedWidget::row( ManagedWidget::row(
vec![ vec![
(hotkey(Key::Num1), "toggle buildings"), (hotkey(Key::Num1), "toggle buildings"),
@ -96,11 +96,8 @@ impl DebugMode {
if let routes::AllRoutesViewer::Active(ref traces) = self.all_routes { if let routes::AllRoutesViewer::Active(ref traces) = self.all_routes {
txt.add(Line(format!("Showing {} routes", traces.len()))); txt.add(Line(format!("Showing {} routes", traces.len())));
} }
self.composite.replace( self.composite
ctx, .replace(ctx, "current info", txt.draw(ctx).named("current info"));
"current info",
ManagedWidget::draw_text(ctx, txt).named("current info"),
);
} }
} }

View File

@ -6,7 +6,7 @@ use crate::managed::WrappedComposite;
use abstutil::prettyprint_usize; use abstutil::prettyprint_usize;
use ezgui::{ use ezgui::{
hotkey, Composite, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line, ManagedWidget, hotkey, Composite, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line, ManagedWidget,
Outcome, Slider, Text, VerticalAlignment, Outcome, Slider, TextExt, VerticalAlignment,
}; };
use geom::{Circle, Distance, Duration, PolyLine, Time}; use geom::{Circle, Distance, Duration, PolyLine, Time};
use map_model::NORMAL_LANE_THICKNESS; use map_model::NORMAL_LANE_THICKNESS;
@ -71,14 +71,10 @@ impl TripsVisualizer {
composite: Composite::new( composite: Composite::new(
ManagedWidget::col(vec![ ManagedWidget::col(vec![
ManagedWidget::row(vec![ ManagedWidget::row(vec![
ManagedWidget::draw_text( Line("Trips Visualizer").roboto_bold().draw(ctx),
ctx,
Text::from(Line("Trips Visualizer").roboto_bold()),
),
WrappedComposite::text_button(ctx, "X", hotkey(Key::Escape)).align_right(), WrappedComposite::text_button(ctx, "X", hotkey(Key::Escape)).align_right(),
]), ]),
ManagedWidget::draw_text(ctx, Text::from(Line("Active trips"))) "Active trips".draw_text(ctx).named("active trips"),
.named("active trips"),
ManagedWidget::row(vec![ ManagedWidget::row(vec![
WrappedComposite::text_button( WrappedComposite::text_button(
ctx, ctx,
@ -160,13 +156,11 @@ impl State for TripsVisualizer {
self.composite.replace( self.composite.replace(
ctx, ctx,
"active trips", "active trips",
ManagedWidget::draw_text( format!(
ctx, "{} active trips",
Text::from(Line(format!( prettyprint_usize(self.active_trips.len()),
"{} active trips",
prettyprint_usize(self.active_trips.len()),
))),
) )
.draw_text(ctx)
.named("active trips"), .named("active trips"),
); );
} }

View File

@ -554,10 +554,7 @@ impl DotMap {
composite: Composite::new( composite: Composite::new(
ManagedWidget::col(vec![ ManagedWidget::col(vec![
ManagedWidget::row(vec![ ManagedWidget::row(vec![
ManagedWidget::draw_text( Line("Dot map of all trips").roboto_bold().draw(ctx),
ctx,
Text::from(Line("Dot map of all trips").roboto_bold()),
),
WrappedComposite::text_button(ctx, "X", hotkey(Key::Escape)).align_right(), WrappedComposite::text_button(ctx, "X", hotkey(Key::Escape)).align_right(),
]), ]),
ManagedWidget::slider("time slider"), ManagedWidget::slider("time slider"),

View File

@ -7,8 +7,8 @@ use crate::helpers::ID;
use crate::managed::WrappedComposite; use crate::managed::WrappedComposite;
use crate::render::Renderable; use crate::render::Renderable;
use ezgui::{ use ezgui::{
hotkey, Button, Choice, Color, Composite, EventCtx, GfxCtx, HorizontalAlignment, Key, Line, hotkey, Button, Choice, Color, Composite, EventCtx, GfxCtx, HorizontalAlignment, Key,
ManagedWidget, Outcome, RewriteColor, Text, VerticalAlignment, ManagedWidget, Outcome, RewriteColor, TextExt, VerticalAlignment,
}; };
use map_model::{EditCmd, LaneID, LaneType, Map, RoadID}; use map_model::{EditCmd, LaneID, LaneType, Map, RoadID};
use std::collections::BTreeSet; use std::collections::BTreeSet;
@ -76,13 +76,11 @@ impl LaneEditor {
} }
let col = vec![ let col = vec![
ManagedWidget::draw_text( format!(
ctx, "Convert this lane of {} to what type?",
Text::from(Line(format!( app.primary.map.get_parent(l).get_name()
"Convert this lane of {} to what type?",
app.primary.map.get_parent(l).get_name()
))),
) )
.draw_text(ctx)
.centered_horiz(), .centered_horiz(),
ManagedWidget::row(row).centered(), ManagedWidget::row(row).centered(),
WrappedComposite::text_button(ctx, "Finish", hotkey(Key::Escape)), WrappedComposite::text_button(ctx, "Finish", hotkey(Key::Escape)),

View File

@ -333,7 +333,7 @@ fn make_topcenter(ctx: &mut EventCtx, app: &App) -> Composite {
Composite::new( Composite::new(
ManagedWidget::col(vec![ ManagedWidget::col(vec![
ManagedWidget::row(vec![ ManagedWidget::row(vec![
ManagedWidget::draw_text(ctx, Text::from(Line("Editing map").size(26))).margin(5), Line("Editing map").size(26).draw(ctx).margin(5),
ManagedWidget::draw_batch( ManagedWidget::draw_batch(
ctx, ctx,
GeomBatch::from(vec![(Color::WHITE, Polygon::rectangle(2.0, 30.0))]), GeomBatch::from(vec![(Color::WHITE, Polygon::rectangle(2.0, 30.0))]),

View File

@ -8,7 +8,7 @@ use crate::render::DrawIntersection;
use abstutil::Timer; use abstutil::Timer;
use ezgui::{ use ezgui::{
hotkey, Button, Color, Composite, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line, hotkey, Button, Color, Composite, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line,
ManagedWidget, Outcome, Text, VerticalAlignment, ManagedWidget, Outcome, Text, TextExt, VerticalAlignment,
}; };
use geom::Polygon; use geom::Polygon;
use map_model::{ use map_model::{
@ -52,7 +52,7 @@ impl StopSignEditor {
let composite = Composite::new( let composite = Composite::new(
ManagedWidget::col(vec![ ManagedWidget::col(vec![
ManagedWidget::draw_text(ctx, Text::from(Line("Stop sign editor"))), "Stop sign editor".draw_text(ctx),
if ControlStopSign::new(&app.primary.map, id) if ControlStopSign::new(&app.primary.map, id)
!= app.primary.map.get_stop_sign(id).clone() != app.primary.map.get_stop_sign(id).clone()
{ {

View File

@ -11,7 +11,8 @@ use crate::sandbox::{spawn_agents_around, SpeedControls, TimePanel};
use abstutil::Timer; use abstutil::Timer;
use ezgui::{ use ezgui::{
hotkey, lctrl, Choice, Color, Composite, EventCtx, EventLoopMode, GeomBatch, GfxCtx, hotkey, lctrl, Choice, Color, Composite, EventCtx, EventLoopMode, GeomBatch, GfxCtx,
HorizontalAlignment, Key, Line, ManagedWidget, Outcome, RewriteColor, Text, VerticalAlignment, HorizontalAlignment, Key, Line, ManagedWidget, Outcome, RewriteColor, Text, TextExt,
VerticalAlignment,
}; };
use geom::Duration; use geom::Duration;
use map_model::{ use map_model::{
@ -709,7 +710,7 @@ impl PreviewTrafficSignal {
PreviewTrafficSignal { PreviewTrafficSignal {
composite: Composite::new( composite: Composite::new(
ManagedWidget::col(vec![ ManagedWidget::col(vec![
ManagedWidget::draw_text(ctx, Text::from(Line("Previewing traffic signal"))), "Previewing traffic signal".draw_text(ctx),
WrappedComposite::text_button(ctx, "back to editing", hotkey(Key::Escape)), WrappedComposite::text_button(ctx, "back to editing", hotkey(Key::Escape)),
]) ])
.bg(colors::PANEL_BG) .bg(colors::PANEL_BG)

View File

@ -115,16 +115,16 @@ impl WrappedComposite {
Composite::new( Composite::new(
ManagedWidget::col(vec![ ManagedWidget::col(vec![
ManagedWidget::row(vec![ ManagedWidget::row(vec![
ManagedWidget::draw_text(ctx, Text::from(Line(title.into()).roboto_bold())), Line(title.into()).roboto_bold().draw(ctx),
WrappedComposite::text_button(ctx, "X", hotkey(Key::Escape)).align_right(), WrappedComposite::text_button(ctx, "X", hotkey(Key::Escape)).align_right(),
]), ]),
ManagedWidget::draw_text(ctx, { {
let mut txt = Text::new(); let mut txt = Text::new();
for l in info { for l in info {
txt.add(Line(l)); txt.add(Line(l));
} }
txt txt.draw(ctx)
}), },
ManagedWidget::row( ManagedWidget::row(
actions actions
.into_iter() .into_iter()

View File

@ -2,7 +2,9 @@ use crate::app::App;
use crate::colors; use crate::colors;
use crate::game::{State, Transition, WizardState}; use crate::game::{State, Transition, WizardState};
use crate::managed::WrappedComposite; use crate::managed::WrappedComposite;
use ezgui::{hotkey, Choice, Composite, EventCtx, GfxCtx, Key, Line, ManagedWidget, Outcome, Text}; use ezgui::{
hotkey, Choice, Composite, EventCtx, GfxCtx, Key, Line, ManagedWidget, Outcome, Text, TextExt,
};
// TODO SimOptions stuff too // TODO SimOptions stuff too
#[derive(Clone)] #[derive(Clone)]
@ -71,7 +73,7 @@ impl OptionsPanel {
composite: Composite::new( composite: Composite::new(
ManagedWidget::col(vec![ ManagedWidget::col(vec![
ManagedWidget::row(vec![ ManagedWidget::row(vec![
ManagedWidget::draw_text(ctx, Text::from(Line("Settings").roboto_bold())), Line("Settings").roboto_bold().draw(ctx),
WrappedComposite::text_button(ctx, "X", hotkey(Key::Escape)).align_right(), WrappedComposite::text_button(ctx, "X", hotkey(Key::Escape)).align_right(),
]), ]),
ManagedWidget::checkbox(ctx, "Enable developer mode", None, app.opts.dev) ManagedWidget::checkbox(ctx, "Enable developer mode", None, app.opts.dev)
@ -91,11 +93,7 @@ impl OptionsPanel {
) )
.margin(5), .margin(5),
ManagedWidget::row(vec![ ManagedWidget::row(vec![
ManagedWidget::draw_text( "Traffic signal rendering:".draw_text(ctx).margin(5),
ctx,
Text::from(Line("Traffic signal rendering:")),
)
.margin(5),
// TODO Refactor this pattern somehow, using drop-down menus or radio // TODO Refactor this pattern somehow, using drop-down menus or radio
// buttons // buttons
WrappedComposite::nice_text_button( WrappedComposite::nice_text_button(
@ -110,7 +108,7 @@ impl OptionsPanel {
.margin(5), .margin(5),
]), ]),
ManagedWidget::row(vec![ ManagedWidget::row(vec![
ManagedWidget::draw_text(ctx, Text::from(Line("Color scheme:"))).margin(5), "Color scheme:".draw_text(ctx).margin(5),
WrappedComposite::nice_text_button( WrappedComposite::nice_text_button(
ctx, ctx,
Text::from(Line(format!("{}", app.opts.cs_name()))), Text::from(Line(format!("{}", app.opts.cs_name()))),
@ -120,11 +118,9 @@ impl OptionsPanel {
.margin(5), .margin(5),
]), ]),
ManagedWidget::row(vec![ ManagedWidget::row(vec![
ManagedWidget::draw_text( "Scale factor for text / UI elements:"
ctx, .draw_text(ctx)
Text::from(Line("Scale factor for text / UI elements:")), .margin(5),
)
.margin(5),
WrappedComposite::nice_text_button( WrappedComposite::nice_text_button(
ctx, ctx,
Text::from(Line(format!("{}", ctx.get_scale_factor()))), Text::from(Line(format!("{}", ctx.get_scale_factor()))),

View File

@ -86,7 +86,7 @@ pub fn main_menu(ctx: &mut EventCtx, app: &App) -> Box<dyn State> {
{ {
let mut txt = Text::from(Line("A/B STREET").size(100)); let mut txt = Text::from(Line("A/B STREET").size(100));
txt.add(Line("Created by Dustin Carlino")); txt.add(Line("Created by Dustin Carlino"));
ManagedWidget::draw_text(ctx, txt).centered_horiz() txt.draw(ctx).centered_horiz()
}, },
ManagedWidget::row(vec![ ManagedWidget::row(vec![
WrappedComposite::svg_button( WrappedComposite::svg_button(
@ -121,7 +121,7 @@ pub fn main_menu(ctx: &mut EventCtx, app: &App) -> Box<dyn State> {
}, },
ManagedWidget::col(vec![ ManagedWidget::col(vec![
WrappedComposite::text_bg_button(ctx, "About A/B Street", None), WrappedComposite::text_bg_button(ctx, "About A/B Street", None),
ManagedWidget::draw_text(ctx, built_info::time()), built_info::time().draw(ctx),
]) ])
.centered(), .centered(),
]; ];
@ -253,9 +253,7 @@ fn about(ctx: &mut EventCtx) -> Box<dyn State> {
"people is probably coincidental, except for PedestrianID(42). ", "people is probably coincidental, except for PedestrianID(42). ",
)); ));
txt.add(Line("Have the appropriate amount of fun.")); txt.add(Line("Have the appropriate amount of fun."));
ManagedWidget::draw_text(ctx, txt) txt.draw(ctx).centered_horiz().align_vert_center()
.centered_horiz()
.align_vert_center()
}, },
]; ];
@ -319,9 +317,7 @@ fn proposals_picker(ctx: &mut EventCtx) -> Box<dyn State> {
"These are proposed changes to Seattle made by community members.", "These are proposed changes to Seattle made by community members.",
)); ));
txt.add(Line("Contact dabreegster@gmail.com to add your idea here!")); txt.add(Line("Contact dabreegster@gmail.com to add your idea here!"));
ManagedWidget::draw_text(ctx, txt) txt.draw(ctx).centered_horiz().bg(colors::PANEL_BG)
.centered_horiz()
.bg(colors::PANEL_BG)
}, },
ManagedWidget::row(buttons) ManagedWidget::row(buttons)
.flex_wrap(ctx, 80) .flex_wrap(ctx, 80)

View File

@ -6,7 +6,7 @@ use crate::render::intersection::make_crosswalk;
use crate::render::{DrawTurnGroup, BIG_ARROW_THICKNESS}; use crate::render::{DrawTurnGroup, BIG_ARROW_THICKNESS};
use ezgui::{ use ezgui::{
hotkey, Button, Color, Composite, EventCtx, GeomBatch, HorizontalAlignment, Key, Line, hotkey, Button, Color, Composite, EventCtx, GeomBatch, HorizontalAlignment, Key, Line,
ManagedWidget, Prerender, Text, VerticalAlignment, ManagedWidget, Prerender, Text, TextExt, VerticalAlignment,
}; };
use geom::{Angle, Circle, Distance, Duration, Line, PolyLine, Polygon, Pt2D}; use geom::{Angle, Circle, Distance, Duration, Line, PolyLine, Polygon, Pt2D};
use map_model::{IntersectionID, Phase, TurnPriority}; use map_model::{IntersectionID, Phase, TurnPriority};
@ -221,7 +221,7 @@ pub fn make_signal_diagram(
let bbox = Polygon::rectangle(zoom * bounds.width(), zoom * bounds.height()); let bbox = Polygon::rectangle(zoom * bounds.width(), zoom * bounds.height());
let signal = app.primary.map.get_traffic_signal(i); let signal = app.primary.map.get_traffic_signal(i);
let txt_widget = ManagedWidget::draw_text(ctx, { let txt_widget = {
let mut txt = Text::from(Line(format!("Intersection #{}", i.0)).roboto_bold()); let mut txt = Text::from(Line(format!("Intersection #{}", i.0)).roboto_bold());
let mut road_names = BTreeSet::new(); let mut road_names = BTreeSet::new();
@ -237,8 +237,8 @@ pub fn make_signal_diagram(
txt.add(Line(format!("{} phases", signal.phases.len())).roboto_bold()); txt.add(Line(format!("{} phases", signal.phases.len())).roboto_bold());
txt.add(Line(format!("Signal offset: {}", signal.offset))); txt.add(Line(format!("Signal offset: {}", signal.offset)));
txt.add(Line(format!("One cycle lasts {}", signal.cycle_length()))); txt.add(Line(format!("One cycle lasts {}", signal.cycle_length())));
txt txt.draw(ctx)
}); };
let mut col = if edit_mode { let mut col = if edit_mode {
vec![ vec![
txt_widget, txt_widget,
@ -270,10 +270,7 @@ pub fn make_signal_diagram(
if edit_mode { if edit_mode {
phase_rows.push( phase_rows.push(
ManagedWidget::row(vec![ ManagedWidget::row(vec![
ManagedWidget::draw_text( format!("Phase {}: {}", idx + 1, phase.duration).draw_text(ctx),
ctx,
Text::from(Line(format!("Phase {}: {}", idx + 1, phase.duration))),
),
WrappedComposite::svg_button( WrappedComposite::svg_button(
ctx, ctx,
"../data/system/assets/tools/edit.svg", "../data/system/assets/tools/edit.svg",
@ -290,10 +287,7 @@ pub fn make_signal_diagram(
.centered(), .centered(),
); );
} else { } else {
phase_rows.push(ManagedWidget::draw_text( phase_rows.push(format!("Phase {}: {}", idx + 1, phase.duration).draw_text(ctx));
ctx,
Text::from(Line(format!("Phase {}: {}", idx + 1, phase.duration))),
));
} }
let mut orig_batch = GeomBatch::new(); let mut orig_batch = GeomBatch::new();

View File

@ -10,7 +10,7 @@ use abstutil::prettyprint_usize;
use abstutil::Counter; use abstutil::Counter;
use ezgui::{ use ezgui::{
hotkey, Button, Color, Composite, EventCtx, Histogram, Key, Line, ManagedWidget, Plot, hotkey, Button, Color, Composite, EventCtx, Histogram, Key, Line, ManagedWidget, Plot,
PlotOptions, Series, Text, PlotOptions, Series, Text, TextExt,
}; };
use geom::{Duration, Statistic, Time}; use geom::{Duration, Statistic, Time};
use map_model::BusRouteID; use map_model::BusRouteID;
@ -159,12 +159,9 @@ fn trips_summary_prebaked(ctx: &EventCtx, app: &App) -> ManagedWidget {
} }
ManagedWidget::col(vec![ ManagedWidget::col(vec![
ManagedWidget::draw_text(ctx, txt), txt.draw(ctx),
finished_trips_plot(ctx, app).bg(colors::SECTION_BG), finished_trips_plot(ctx, app).bg(colors::SECTION_BG),
ManagedWidget::draw_text( "Are trips faster or slower than the baseline?".draw_text(ctx),
ctx,
Text::from(Line("Are trips faster or slower than the baseline?")),
),
Histogram::new( Histogram::new(
app.primary app.primary
.sim .sim
@ -173,7 +170,7 @@ fn trips_summary_prebaked(ctx: &EventCtx, app: &App) -> ManagedWidget {
ctx, ctx,
) )
.bg(colors::SECTION_BG), .bg(colors::SECTION_BG),
ManagedWidget::draw_text(ctx, Text::from(Line("Active agents").roboto_bold())), Line("Active agents").roboto_bold().draw(ctx),
Plot::new_usize( Plot::new_usize(
ctx, ctx,
vec![ vec![
@ -241,9 +238,9 @@ fn trips_summary_not_prebaked(ctx: &EventCtx, app: &App) -> ManagedWidget {
} }
ManagedWidget::col(vec![ ManagedWidget::col(vec![
ManagedWidget::draw_text(ctx, txt), txt.draw(ctx),
finished_trips_plot(ctx, app).bg(colors::SECTION_BG), finished_trips_plot(ctx, app).bg(colors::SECTION_BG),
ManagedWidget::draw_text(ctx, Text::from(Line("Active agents").roboto_bold())), Line("Active agents").roboto_bold().draw(ctx),
Plot::new_usize( Plot::new_usize(
ctx, ctx,
vec![Series { vec![Series {
@ -312,10 +309,7 @@ fn finished_trips_plot(ctx: &EventCtx, app: &App) -> ManagedWidget {
.collect(), .collect(),
PlotOptions::new(), PlotOptions::new(),
); );
ManagedWidget::col(vec![ ManagedWidget::col(vec!["finished trips".draw_text(ctx), plot.margin(10)])
ManagedWidget::draw_text(ctx, Text::from(Line("finished trips"))),
plot.margin(10),
])
} }
fn pick_finished_trips_mode(ctx: &EventCtx) -> (ManagedWidget, Vec<(String, Callback)>) { fn pick_finished_trips_mode(ctx: &EventCtx) -> (ManagedWidget, Vec<(String, Callback)>) {
@ -396,7 +390,7 @@ fn parking_overhead(ctx: &EventCtx, app: &App) -> ManagedWidget {
for line in app.primary.sim.get_analytics().analyze_parking_phases() { for line in app.primary.sim.get_analytics().analyze_parking_phases() {
txt.add_wrapped(line, 0.9 * ctx.canvas.window_width); txt.add_wrapped(line, 0.9 * ctx.canvas.window_width);
} }
ManagedWidget::draw_text(ctx, txt) txt.draw(ctx)
} }
fn pick_bus_route(ctx: &EventCtx, app: &App) -> (ManagedWidget, Vec<(String, Callback)>) { fn pick_bus_route(ctx: &EventCtx, app: &App) -> (ManagedWidget, Vec<(String, Callback)>) {

View File

@ -84,13 +84,14 @@ pub fn freeform_controller(
) -> WrappedComposite { ) -> WrappedComposite {
let c = Composite::new( let c = Composite::new(
ManagedWidget::row(vec![ ManagedWidget::row(vec![
ManagedWidget::draw_text(ctx, Text::from(Line("Sandbox").size(26))).margin(5), Line("Sandbox").size(26).draw(ctx).margin(5),
ManagedWidget::draw_batch( ManagedWidget::draw_batch(
ctx, ctx,
GeomBatch::from(vec![(Color::WHITE, Polygon::rectangle(2.0, 50.0))]), GeomBatch::from(vec![(Color::WHITE, Polygon::rectangle(2.0, 50.0))]),
) )
.margin(5), .margin(5),
ManagedWidget::draw_text(ctx, Text::from(Line("Map:").size(18).roboto_bold())) Text::from(Line("Map:").size(18).roboto_bold())
.draw(ctx)
.margin(5), .margin(5),
WrappedComposite::nice_text_button( WrappedComposite::nice_text_button(
ctx, ctx,
@ -103,7 +104,8 @@ pub fn freeform_controller(
"change map", "change map",
) )
.margin(5), .margin(5),
ManagedWidget::draw_text(ctx, Text::from(Line("Traffic:").size(18).roboto_bold())) Text::from(Line("Traffic:").size(18).roboto_bold())
.draw(ctx)
.margin(5), .margin(5),
WrappedComposite::nice_text_button( WrappedComposite::nice_text_button(
ctx, ctx,

View File

@ -268,7 +268,7 @@ fn challenge_controller(
} }
let mut rows = vec![ManagedWidget::row(vec![ let mut rows = vec![ManagedWidget::row(vec![
ManagedWidget::draw_text(ctx, Text::from(Line(title).size(26))).margin(5), Line(title).size(26).draw(ctx).margin(5),
WrappedComposite::svg_button(ctx, "../data/system/assets/tools/info.svg", "info", None) WrappedComposite::svg_button(ctx, "../data/system/assets/tools/info.svg", "info", None)
.margin(5), .margin(5),
ManagedWidget::draw_batch( ManagedWidget::draw_batch(
@ -337,13 +337,10 @@ impl FinalScore {
Box::new(FinalScore { Box::new(FinalScore {
composite: Composite::new( composite: Composite::new(
ManagedWidget::col(vec![ ManagedWidget::col(vec![txt.draw(ctx), ManagedWidget::row(row).centered()])
ManagedWidget::draw_text(ctx, txt), .bg(colors::PANEL_BG)
ManagedWidget::row(row).centered(), .outline(10.0, Color::WHITE)
]) .padding(10),
.bg(colors::PANEL_BG)
.outline(10.0, Color::WHITE)
.padding(10),
) )
.aligned(HorizontalAlignment::Center, VerticalAlignment::Center) .aligned(HorizontalAlignment::Center, VerticalAlignment::Center)
.build(ctx), .build(ctx),

View File

@ -9,7 +9,7 @@ use crate::sandbox::SandboxMode;
use abstutil::Timer; use abstutil::Timer;
use ezgui::{ use ezgui::{
hotkey, Composite, EventCtx, GfxCtx, HorizontalAlignment, Key, Line, ManagedWidget, Outcome, hotkey, Composite, EventCtx, GfxCtx, HorizontalAlignment, Key, Line, ManagedWidget, Outcome,
Text, VerticalAlignment, Text, TextExt, VerticalAlignment,
}; };
use geom::{Distance, Duration, PolyLine}; use geom::{Distance, Duration, PolyLine};
use map_model::{ use map_model::{
@ -707,10 +707,10 @@ fn make_top_bar(ctx: &mut EventCtx, title: &str, howto: &str) -> Composite {
Composite::new( Composite::new(
ManagedWidget::col(vec![ ManagedWidget::col(vec![
ManagedWidget::row(vec![ ManagedWidget::row(vec![
ManagedWidget::draw_text(ctx, Text::from(Line(title).roboto_bold())), Line(title).roboto_bold().draw(ctx),
WrappedComposite::text_button(ctx, "X", hotkey(Key::Escape)).align_right(), WrappedComposite::text_button(ctx, "X", hotkey(Key::Escape)).align_right(),
]), ]),
ManagedWidget::draw_text(ctx, Text::from(Line(howto))), howto.draw_text(ctx),
]) ])
.padding(10) .padding(10)
.bg(colors::PANEL_BG), .bg(colors::PANEL_BG),

View File

@ -13,7 +13,7 @@ use crate::sandbox::{
use abstutil::Timer; use abstutil::Timer;
use ezgui::{ use ezgui::{
hotkey, hotkeys, lctrl, Button, Color, Composite, EventCtx, GeomBatch, GfxCtx, hotkey, hotkeys, lctrl, Button, Color, Composite, EventCtx, GeomBatch, GfxCtx,
HorizontalAlignment, Key, Line, ManagedWidget, Outcome, RewriteColor, ScreenPt, Text, HorizontalAlignment, Key, Line, ManagedWidget, Outcome, RewriteColor, ScreenPt, Text, TextExt,
VerticalAlignment, VerticalAlignment,
}; };
use geom::{Distance, Duration, PolyLine, Polygon, Pt2D, Statistic, Time}; use geom::{Distance, Duration, PolyLine, Polygon, Pt2D, Statistic, Time};
@ -888,19 +888,15 @@ 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![ManagedWidget::row(vec![ let mut col = vec![ManagedWidget::row(vec![
ManagedWidget::draw_text(ctx, Text::from(Line("Tutorial").size(26))).margin(5), Line("Tutorial").size(26).draw(ctx).margin(5),
ManagedWidget::draw_batch( ManagedWidget::draw_batch(
ctx, ctx,
GeomBatch::from(vec![(Color::WHITE, Polygon::rectangle(2.0, 50.0))]), GeomBatch::from(vec![(Color::WHITE, Polygon::rectangle(2.0, 50.0))]),
) )
.margin(5), .margin(5),
ManagedWidget::draw_text( Text::from(Line(format!("{}/{}", self.current.stage + 1, self.stages.len())).size(20))
ctx, .draw(ctx)
Text::from( .margin(5),
Line(format!("{}/{}", self.current.stage + 1, self.stages.len())).size(20),
),
)
.margin(5),
if self.current.stage == 0 { if self.current.stage == 0 {
Button::inactive_button(ctx, "<") Button::inactive_button(ctx, "<")
} else { } else {
@ -930,17 +926,15 @@ impl TutorialState {
let task = self.interaction(); let task = self.interaction();
if task != Task::Nil { if task != Task::Nil {
col.push(ManagedWidget::row(vec![ col.push(ManagedWidget::row(vec![
ManagedWidget::draw_text( Text::from(
ctx, Line(format!(
Text::from( "Task {}: {}",
Line(format!( self.current.stage + 1,
"Task {}: {}", self.stage().task.label()
self.current.stage + 1, ))
self.stage().task.label() .roboto_bold(),
)) )
.roboto_bold(), .draw(ctx),
),
),
WrappedComposite::svg_button( WrappedComposite::svg_button(
ctx, ctx,
"../data/system/assets/tools/info.svg", "../data/system/assets/tools/info.svg",
@ -950,7 +944,7 @@ impl TutorialState {
.centered_vert() .centered_vert()
.align_right(), .align_right(),
])); ]));
col.push(ManagedWidget::draw_text(ctx, task.top_txt(ctx, self)).margin(5)); col.push(task.top_txt(ctx, self).draw(ctx).margin(5));
} }
} }
if edit_map { if edit_map {
@ -999,7 +993,7 @@ impl TutorialState {
msg_panel: if let Some((ref lines, _)) = self.lines() { msg_panel: if let Some((ref lines, _)) = self.lines() {
let mut col = vec![ let mut col = vec![
ManagedWidget::draw_text(ctx, { {
let mut txt = Text::new(); let mut txt = Text::new();
txt.add(Line(self.stage().task.label()).roboto_bold()); txt.add(Line(self.stage().task.label()).roboto_bold());
txt.add(Line("")); txt.add(Line(""));
@ -1007,8 +1001,8 @@ impl TutorialState {
for l in lines { for l in lines {
txt.add(Line(*l)); txt.add(Line(*l));
} }
txt txt.draw(ctx)
}), },
ManagedWidget::row(vec![ ManagedWidget::row(vec![
if self.current.part > 0 { if self.current.part > 0 {
WrappedComposite::svg_button( WrappedComposite::svg_button(
@ -1025,16 +1019,10 @@ impl TutorialState {
RewriteColor::ChangeAll(Color::WHITE.alpha(0.5)), RewriteColor::ChangeAll(Color::WHITE.alpha(0.5)),
) )
}, },
ManagedWidget::draw_text( format!("{}/{}", self.current.part + 1, self.stage().messages.len())
ctx, .draw_text(ctx)
Text::from(Line(format!( .centered_vert()
"{}/{}", .margin(5),
self.current.part + 1,
self.stage().messages.len()
))),
)
.centered_vert()
.margin(5),
if self.current.part == self.stage().messages.len() - 1 { if self.current.part == self.stage().messages.len() - 1 {
ManagedWidget::draw_svg_transform( ManagedWidget::draw_svg_transform(
ctx, ctx,

View File

@ -18,7 +18,8 @@ use crate::render::AgentColorScheme;
pub use crate::sandbox::gameplay::{TutorialPointer, TutorialState}; pub use crate::sandbox::gameplay::{TutorialPointer, TutorialState};
use ezgui::{ use ezgui::{
hotkey, lctrl, Choice, Color, Composite, EventCtx, EventLoopMode, GeomBatch, GfxCtx, hotkey, lctrl, Choice, Color, Composite, EventCtx, EventLoopMode, GeomBatch, GfxCtx,
HorizontalAlignment, Key, Line, ManagedWidget, Outcome, Text, VerticalAlignment, Wizard, HorizontalAlignment, Key, Line, ManagedWidget, Outcome, Text, TextExt, VerticalAlignment,
Wizard,
}; };
pub use gameplay::spawner::spawn_agents_around; pub use gameplay::spawner::spawn_agents_around;
pub use gameplay::GameplayMode; pub use gameplay::GameplayMode;
@ -360,39 +361,24 @@ impl AgentMeter {
let (finished, unfinished, by_mode, ppl_in_bldg, ppl_off_map) = app.primary.sim.num_trips(); let (finished, unfinished, by_mode, ppl_in_bldg, ppl_off_map) = app.primary.sim.num_trips();
let mut rows = vec![ let mut rows = vec![
ManagedWidget::draw_text(ctx, Text::from(Line("Active agents"))), "Active agents".draw_text(ctx),
ManagedWidget::row(vec![ ManagedWidget::row(vec![
ManagedWidget::draw_svg(ctx, "../data/system/assets/meters/pedestrian.svg"), ManagedWidget::draw_svg(ctx, "../data/system/assets/meters/pedestrian.svg"),
ManagedWidget::draw_text( prettyprint_usize(by_mode[&TripMode::Walk]).draw_text(ctx),
ctx,
Text::from(Line(prettyprint_usize(by_mode[&TripMode::Walk]))),
),
ManagedWidget::draw_svg(ctx, "../data/system/assets/meters/bike.svg"), ManagedWidget::draw_svg(ctx, "../data/system/assets/meters/bike.svg"),
ManagedWidget::draw_text( prettyprint_usize(by_mode[&TripMode::Bike]).draw_text(ctx),
ctx,
Text::from(Line(prettyprint_usize(by_mode[&TripMode::Bike]))),
),
ManagedWidget::draw_svg(ctx, "../data/system/assets/meters/car.svg"), ManagedWidget::draw_svg(ctx, "../data/system/assets/meters/car.svg"),
ManagedWidget::draw_text( prettyprint_usize(by_mode[&TripMode::Drive]).draw_text(ctx),
ctx,
Text::from(Line(prettyprint_usize(by_mode[&TripMode::Drive]))),
),
ManagedWidget::draw_svg(ctx, "../data/system/assets/meters/bus.svg"), ManagedWidget::draw_svg(ctx, "../data/system/assets/meters/bus.svg"),
ManagedWidget::draw_text( prettyprint_usize(by_mode[&TripMode::Transit]).draw_text(ctx),
ctx,
Text::from(Line(prettyprint_usize(by_mode[&TripMode::Transit]))),
),
]) ])
.centered(), .centered(),
// TODO Not sure about this one yet // TODO Not sure about this one yet
if app.opts.dev { if app.opts.dev {
ManagedWidget::row(vec![ ManagedWidget::row(vec![
ManagedWidget::draw_svg(ctx, "../data/system/assets/tools/home.svg"), ManagedWidget::draw_svg(ctx, "../data/system/assets/tools/home.svg"),
ManagedWidget::draw_text(ctx, Text::from(Line(prettyprint_usize(ppl_in_bldg)))), prettyprint_usize(ppl_in_bldg).draw_text(ctx),
ManagedWidget::draw_text( format!("Off-map: {}", prettyprint_usize(ppl_off_map)).draw_text(ctx),
ctx,
Text::from(Line(format!("Off-map: {}", prettyprint_usize(ppl_off_map)))),
),
]) ])
.centered() .centered()
} else { } else {
@ -420,7 +406,7 @@ impl AgentMeter {
prettyprint_usize(finished), prettyprint_usize(finished),
pct as usize pct as usize
))); )));
ManagedWidget::draw_text(ctx, txt) txt.draw(ctx)
}, },
{ {
ManagedWidget::row(vec![ ManagedWidget::row(vec![
@ -473,7 +459,7 @@ impl AgentMeter {
txt.append(Line("same as baseline")); txt.append(Line("same as baseline"));
} }
txt.add(Line(format!("Goal: {} faster", goal)).size(20)); txt.add(Line(format!("Goal: {} faster", goal)).size(20));
rows.push(ManagedWidget::draw_text(ctx, txt)); rows.push(txt.draw(ctx));
} }
} }

View File

@ -357,19 +357,19 @@ impl JumpToTime {
composite: Composite::new( composite: Composite::new(
ManagedWidget::col(vec![ ManagedWidget::col(vec![
WrappedComposite::text_button(ctx, "X", hotkey(Key::Escape)).align_right(), WrappedComposite::text_button(ctx, "X", hotkey(Key::Escape)).align_right(),
ManagedWidget::draw_text(ctx, { {
let mut txt = Text::from(Line("Jump to what time?").roboto_bold()); let mut txt = Text::from(Line("Jump to what time?").roboto_bold());
txt.add(Line(target.ampm_tostring())); txt.add(Line(target.ampm_tostring()));
txt txt.draw(ctx)
}) }
.named("target time"), .named("target time"),
ManagedWidget::slider("time slider").margin(10), ManagedWidget::slider("time slider").margin(10),
ManagedWidget::row(vec![ ManagedWidget::row(vec![
ManagedWidget::draw_text(ctx, Text::from(Line("00:00").size(12).roboto())), Line("00:00").size(12).roboto().draw(ctx),
ManagedWidget::draw_svg(ctx, "../data/system/assets/speed/sunrise.svg"), ManagedWidget::draw_svg(ctx, "../data/system/assets/speed/sunrise.svg"),
ManagedWidget::draw_text(ctx, Text::from(Line("12:00").size(12).roboto())), Line("12:00").size(12).roboto().draw(ctx),
ManagedWidget::draw_svg(ctx, "../data/system/assets/speed/sunset.svg"), ManagedWidget::draw_svg(ctx, "../data/system/assets/speed/sunset.svg"),
ManagedWidget::draw_text(ctx, Text::from(Line("24:00").size(12).roboto())), Line("24:00").size(12).roboto().draw(ctx),
]) ])
.padding(10) .padding(10)
.evenly_spaced(), .evenly_spaced(),
@ -378,7 +378,7 @@ impl JumpToTime {
.margin(10), .margin(10),
WrappedComposite::text_bg_button(ctx, "Go!", hotkey(Key::Enter)) WrappedComposite::text_bg_button(ctx, "Go!", hotkey(Key::Enter))
.centered_horiz(), .centered_horiz(),
ManagedWidget::draw_text(ctx, Text::from(Line("Active agents").roboto_bold())), Line("Active agents").roboto_bold().draw(ctx),
// TODO Sync the slider / plot. // TODO Sync the slider / plot.
Plot::new_usize( Plot::new_usize(
ctx, ctx,
@ -453,15 +453,15 @@ impl State for JumpToTime {
self.composite.replace( self.composite.replace(
ctx, ctx,
"target time", "target time",
ManagedWidget::draw_text(ctx, { {
let mut txt = Text::from(Line("Jump to what time?").roboto_bold()); let mut txt = Text::from(Line("Jump to what time?").roboto_bold());
txt.add(Line(target.ampm_tostring())); txt.add(Line(target.ampm_tostring()));
// TODO The panel jumps too much and the slider position changes place. // TODO The panel jumps too much and the slider position changes place.
/*if target < app.primary.sim.time() { /*if target < app.primary.sim.time() {
txt.add(Line("(Going back in time will reset to midnight, then simulate forwards)")); txt.add(Line("(Going back in time will reset to midnight, then simulate forwards)"));
}*/ }*/
txt txt.draw(ctx)
}) }
.named("target time"), .named("target time"),
); );
} }
@ -500,7 +500,7 @@ impl TimeWarpScreen {
traffic_jams, traffic_jams,
composite: Composite::new( composite: Composite::new(
ManagedWidget::col(vec![ ManagedWidget::col(vec![
ManagedWidget::draw_text(ctx, Text::new()).named("text"), Text::new().draw(ctx).named("text"),
WrappedComposite::text_bg_button(ctx, "stop now", hotkey(Key::Escape)) WrappedComposite::text_bg_button(ctx, "stop now", hotkey(Key::Escape))
.centered_horiz(), .centered_horiz(),
]) ])
@ -548,11 +548,8 @@ impl State for TimeWarpScreen {
Duration::realtime_elapsed(self.started) Duration::realtime_elapsed(self.started)
))); )));
self.composite.replace( self.composite
ctx, .replace(ctx, "text", txt.draw(ctx).named("text"));
"text",
ManagedWidget::draw_text(ctx, txt).named("text"),
);
} }
if app.primary.sim.time() == self.target { if app.primary.sim.time() == self.target {
return Transition::Pop; return Transition::Pop;
@ -597,12 +594,10 @@ impl TimePanel {
time: app.primary.sim.time(), time: app.primary.sim.time(),
composite: Composite::new( composite: Composite::new(
ManagedWidget::col(vec![ ManagedWidget::col(vec![
ManagedWidget::draw_text( Text::from(Line(app.primary.sim.time().ampm_tostring()).size(30))
ctx, .draw(ctx)
Text::from(Line(app.primary.sim.time().ampm_tostring()).size(30)), .margin(10)
) .centered_horiz(),
.margin(10)
.centered_horiz(),
{ {
let mut batch = GeomBatch::new(); let mut batch = GeomBatch::new();
// This is manually tuned // This is manually tuned
@ -622,11 +617,11 @@ impl TimePanel {
ManagedWidget::draw_batch(ctx, batch) ManagedWidget::draw_batch(ctx, batch)
}, },
ManagedWidget::row(vec![ ManagedWidget::row(vec![
ManagedWidget::draw_text(ctx, Text::from(Line("00:00").size(12).roboto())), Line("00:00").size(12).roboto().draw(ctx),
ManagedWidget::draw_svg(ctx, "../data/system/assets/speed/sunrise.svg"), ManagedWidget::draw_svg(ctx, "../data/system/assets/speed/sunrise.svg"),
ManagedWidget::draw_text(ctx, Text::from(Line("12:00").size(12).roboto())), Line("12:00").size(12).roboto().draw(ctx),
ManagedWidget::draw_svg(ctx, "../data/system/assets/speed/sunset.svg"), ManagedWidget::draw_svg(ctx, "../data/system/assets/speed/sunset.svg"),
ManagedWidget::draw_text(ctx, Text::from(Line("24:00").size(12).roboto())), Line("24:00").size(12).roboto().draw(ctx),
]) ])
.padding(10) .padding(10)
.evenly_spaced(), .evenly_spaced(),