rename Widget -> WidgetImpl, ManagedWidget -> Widget

This commit is contained in:
Dustin Carlino 2020-03-20 23:41:07 -07:00
parent 81c5ae3700
commit 7edb8a6190
42 changed files with 390 additions and 454 deletions

View File

@ -10,8 +10,8 @@
use ezgui::{
hotkey, lctrl, Btn, Color, Composite, Drawable, EventCtx, EventLoopMode, GeomBatch, GfxCtx,
HorizontalAlignment, Key, Line, ManagedWidget, Outcome, Plot, PlotOptions, Series, Text,
TextExt, VerticalAlignment, GUI,
HorizontalAlignment, Key, Line, Outcome, Plot, PlotOptions, Series, Text, TextExt,
VerticalAlignment, Widget, GUI,
};
use geom::{Angle, Duration, Polygon, Pt2D, Time};
@ -53,8 +53,8 @@ impl App {
}
let mut c = Composite::new(
ManagedWidget::col(vec![
ManagedWidget::row(vec![{
Widget::col(vec![
Widget::row(vec![{
let mut txt = Text::from(
Line("Here's a bunch of text to force some scrolling.").roboto_bold(),
);
@ -67,17 +67,11 @@ impl App {
);
txt.draw(ctx)
}]),
ManagedWidget::row(vec![
Widget::row(vec![
// Examples of styling widgets
ManagedWidget::col(col1)
.outline(3.0, Color::BLACK)
.margin(5),
ManagedWidget::col(col2)
.outline(3.0, Color::BLACK)
.margin(5),
ManagedWidget::col(col3)
.outline(3.0, Color::BLACK)
.margin(5),
Widget::col(col1).outline(3.0, Color::BLACK).margin(5),
Widget::col(col2).outline(3.0, Color::BLACK).margin(5),
Widget::col(col3).outline(3.0, Color::BLACK).margin(5),
]),
Plot::new_usize(
ctx,
@ -251,7 +245,7 @@ fn setup_scrollable_canvas(ctx: &mut EventCtx) -> Drawable {
fn make_controls(ctx: &mut EventCtx) -> Composite {
Composite::new(
ManagedWidget::col(vec![
Widget::col(vec![
{
let mut txt = Text::from(Line("ezgui demo").roboto_bold());
txt.add(Line(
@ -259,9 +253,9 @@ fn make_controls(ctx: &mut EventCtx) -> Composite {
));
txt.draw(ctx)
},
ManagedWidget::row(vec![
Widget::row(vec![
// This just cycles between two arbitrary buttons
ManagedWidget::custom_checkbox(
Widget::custom_checkbox(
false,
Btn::text_bg1("Pause").build(ctx, "pause the stopwatch", hotkey(Key::Space)),
Btn::text_bg1("Resume").build(ctx, "resume the stopwatch", hotkey(Key::Space)),
@ -271,8 +265,8 @@ fn make_controls(ctx: &mut EventCtx) -> Composite {
Btn::text_fg("Reset")
.build(ctx, "reset the stopwatch", None)
.margin(5),
ManagedWidget::checkbox(ctx, "Draw scrollable canvas", None, true).margin(5),
ManagedWidget::checkbox(ctx, "Show timeseries", lctrl(Key::T), false).margin(5),
Widget::checkbox(ctx, "Draw scrollable canvas", None, true).margin(5),
Widget::checkbox(ctx, "Show timeseries", lctrl(Key::T), false).margin(5),
])
.evenly_spaced(),
"Stopwatch: ...".draw_text(ctx).named("stopwatch"),

View File

@ -27,7 +27,7 @@ pub use crate::event::{hotkey, hotkeys, lctrl, Event, Key, MultiKey};
pub use crate::event_ctx::EventCtx;
pub use crate::geom::{GeomBatch, RewriteColor};
pub use crate::input::UserInput;
pub use crate::managed::{Composite, ManagedWidget, Outcome};
pub use crate::managed::{Composite, Outcome, Widget};
pub use crate::runner::{run, EventLoopMode, Settings, GUI};
pub use crate::screen_geom::{ScreenDims, ScreenPt, ScreenRectangle};
pub use crate::text::{Line, Text, TextExt, TextSpan, HOTKEY_COLOR};
@ -45,6 +45,7 @@ pub use crate::widgets::slider::{ItemSlider, Slider, WarpingItemSlider};
pub(crate) use crate::widgets::text_box::TextBox;
pub use crate::widgets::warper::Warper;
pub use crate::widgets::wizard::{Choice, Wizard, WrappedWizard};
pub(crate) use crate::widgets::WidgetImpl;
pub enum InputResult<T: Clone> {
Canceled,

View File

@ -1,8 +1,7 @@
use crate::widgets::Widget;
use crate::{
Btn, Button, Checkbox, Choice, Color, Drawable, Dropdown, EventCtx, Filler, GeomBatch, GfxCtx,
Histogram, HorizontalAlignment, JustDraw, MultiKey, Plot, PopupMenu, RewriteColor, ScreenDims,
ScreenPt, ScreenRectangle, Slider, Text, TextBox, VerticalAlignment,
ScreenPt, ScreenRectangle, Slider, Text, TextBox, VerticalAlignment, WidgetImpl,
};
use abstutil::Cloneable;
use geom::{Distance, Duration, Polygon};
@ -16,7 +15,7 @@ use stretch::style::{
type Menu = PopupMenu<Box<dyn Cloneable>>;
pub struct ManagedWidget {
pub struct Widget {
widget: WidgetType,
style: LayoutStyle,
rect: ScreenRectangle,
@ -38,8 +37,8 @@ enum WidgetType {
DurationPlot(Plot<Duration>),
UsizePlot(Plot<usize>),
Histogram(Histogram),
Row(Vec<ManagedWidget>),
Column(Vec<ManagedWidget>),
Row(Vec<Widget>),
Column(Vec<Widget>),
Nothing,
}
@ -89,34 +88,34 @@ impl LayoutStyle {
// TODO Maybe I just want margin, not padding. And maybe more granular controls per side. And to
// apply margin to everything in a row or column.
// TODO Row and columns feel backwards when using them.
impl ManagedWidget {
pub fn centered(mut self) -> ManagedWidget {
impl Widget {
pub fn centered(mut self) -> Widget {
self.style.align_items = Some(AlignItems::Center);
self.style.justify_content = Some(JustifyContent::SpaceAround);
self
}
pub fn centered_horiz(self) -> ManagedWidget {
ManagedWidget::row(vec![self]).centered()
pub fn centered_horiz(self) -> Widget {
Widget::row(vec![self]).centered()
}
pub fn centered_vert(self) -> ManagedWidget {
ManagedWidget::col(vec![self]).centered()
pub fn centered_vert(self) -> Widget {
Widget::col(vec![self]).centered()
}
pub fn centered_cross(mut self) -> ManagedWidget {
pub fn centered_cross(mut self) -> Widget {
self.style.align_items = Some(AlignItems::Center);
self
}
pub fn evenly_spaced(mut self) -> ManagedWidget {
pub fn evenly_spaced(mut self) -> Widget {
self.style.justify_content = Some(JustifyContent::SpaceBetween);
self
}
// This one is really weird. percent_width should be LESS than the max_size_percent given to
// the overall Composite, otherwise weird things happen.
pub fn flex_wrap(mut self, ctx: &EventCtx, percent_width: usize) -> ManagedWidget {
pub fn flex_wrap(mut self, ctx: &EventCtx, percent_width: usize) -> Widget {
self.style.size = Some(Size {
width: Dimension::Points(
(ctx.canvas.window_width * (percent_width as f64) / 100.0) as f32,
@ -128,18 +127,18 @@ impl ManagedWidget {
self
}
pub fn bg(mut self, color: Color) -> ManagedWidget {
pub fn bg(mut self, color: Color) -> Widget {
self.style.bg_color = Some(color);
self
}
// Callers have to adjust padding too, probably
pub fn outline(mut self, thickness: f64, color: Color) -> ManagedWidget {
pub fn outline(mut self, thickness: f64, color: Color) -> Widget {
self.style.outline = Some((thickness, color));
self
}
pub fn padding(mut self, pixels: usize) -> ManagedWidget {
pub fn padding(mut self, pixels: usize) -> Widget {
self.style.padding = Some(Rect {
start: Dimension::Points(pixels as f32),
end: Dimension::Points(pixels as f32),
@ -149,7 +148,7 @@ impl ManagedWidget {
self
}
pub fn margin(mut self, pixels: usize) -> ManagedWidget {
pub fn margin(mut self, pixels: usize) -> Widget {
self.style.margin = Some(Rect {
start: Dimension::Points(pixels as f32),
end: Dimension::Points(pixels as f32),
@ -158,7 +157,7 @@ impl ManagedWidget {
});
self
}
pub fn margin_above(mut self, pixels: usize) -> ManagedWidget {
pub fn margin_above(mut self, pixels: usize) -> Widget {
self.style.margin = Some(Rect {
start: Dimension::Undefined,
end: Dimension::Undefined,
@ -168,7 +167,7 @@ impl ManagedWidget {
self
}
pub fn align_left(mut self) -> ManagedWidget {
pub fn align_left(mut self) -> Widget {
self.style.margin = Some(Rect {
start: Dimension::Undefined,
end: Dimension::Auto,
@ -177,7 +176,7 @@ impl ManagedWidget {
});
self
}
pub fn align_right(mut self) -> ManagedWidget {
pub fn align_right(mut self) -> Widget {
self.style.margin = Some(Rect {
start: Dimension::Auto,
end: Dimension::Undefined,
@ -187,7 +186,7 @@ impl ManagedWidget {
self
}
// This doesn't count against the entire container
pub fn align_vert_center(mut self) -> ManagedWidget {
pub fn align_vert_center(mut self) -> Widget {
self.style.margin = Some(Rect {
start: Dimension::Undefined,
end: Dimension::Undefined,
@ -197,7 +196,7 @@ impl ManagedWidget {
self
}
fn abs(mut self, x: f64, y: f64) -> ManagedWidget {
fn abs(mut self, x: f64, y: f64) -> Widget {
self.style.position_type = Some(PositionType::Absolute);
self.style.position = Some(Rect {
start: Dimension::Points(x as f32),
@ -208,16 +207,16 @@ impl ManagedWidget {
self
}
pub fn named(mut self, id: &str) -> ManagedWidget {
pub fn named(mut self, id: &str) -> Widget {
self.id = Some(id.to_string());
self
}
}
// Convenient?? constructors
impl ManagedWidget {
fn new(widget: WidgetType) -> ManagedWidget {
ManagedWidget {
impl Widget {
fn new(widget: WidgetType) -> Widget {
Widget {
widget,
style: LayoutStyle {
bg_color: None,
@ -238,44 +237,40 @@ impl ManagedWidget {
}
// TODO dupe apis!
pub fn draw_batch(ctx: &EventCtx, batch: GeomBatch) -> ManagedWidget {
pub fn draw_batch(ctx: &EventCtx, batch: GeomBatch) -> Widget {
JustDraw::wrap(ctx, batch)
}
pub(crate) fn just_draw(j: JustDraw) -> ManagedWidget {
ManagedWidget::new(WidgetType::Draw(j))
pub(crate) fn just_draw(j: JustDraw) -> Widget {
Widget::new(WidgetType::Draw(j))
}
pub(crate) fn draw_text(ctx: &EventCtx, txt: Text) -> ManagedWidget {
pub(crate) fn draw_text(ctx: &EventCtx, txt: Text) -> Widget {
JustDraw::text(ctx, txt)
}
pub fn draw_svg(ctx: &EventCtx, filename: &str) -> ManagedWidget {
pub fn draw_svg(ctx: &EventCtx, filename: &str) -> Widget {
JustDraw::svg(ctx, filename)
}
// TODO Argh uncomposable APIs
pub fn draw_svg_transform(
ctx: &EventCtx,
filename: &str,
rewrite: RewriteColor,
) -> ManagedWidget {
pub fn draw_svg_transform(ctx: &EventCtx, filename: &str, rewrite: RewriteColor) -> Widget {
JustDraw::svg_transform(ctx, filename, rewrite)
}
pub(crate) fn btn(btn: Button) -> ManagedWidget {
ManagedWidget::new(WidgetType::Btn(btn))
pub(crate) fn btn(btn: Button) -> Widget {
Widget::new(WidgetType::Btn(btn))
}
pub fn slider(label: &str) -> ManagedWidget {
ManagedWidget::new(WidgetType::Slider(label.to_string()))
pub fn slider(label: &str) -> Widget {
Widget::new(WidgetType::Slider(label.to_string()))
}
pub fn menu(label: &str) -> ManagedWidget {
ManagedWidget::new(WidgetType::Menu(label.to_string()))
pub fn menu(label: &str) -> Widget {
Widget::new(WidgetType::Menu(label.to_string()))
}
pub fn filler(label: &str) -> ManagedWidget {
ManagedWidget::new(WidgetType::Filler(label.to_string()))
pub fn filler(label: &str) -> Widget {
Widget::new(WidgetType::Filler(label.to_string()))
}
pub fn checkbox(
@ -283,8 +278,8 @@ impl ManagedWidget {
label: &str,
hotkey: Option<MultiKey>,
enabled: bool,
) -> ManagedWidget {
ManagedWidget::custom_checkbox(
) -> Widget {
Widget::custom_checkbox(
enabled,
Btn::text_fg(format!("{}", label)).build(ctx, label, hotkey.clone()),
Btn::text_fg(format!("{}", label)).build(ctx, label, hotkey),
@ -293,21 +288,17 @@ impl ManagedWidget {
.named(label)
}
// TODO Not typesafe! Gotta pass a button.
pub fn custom_checkbox(
enabled: bool,
false_btn: ManagedWidget,
true_btn: ManagedWidget,
) -> ManagedWidget {
ManagedWidget::new(WidgetType::Checkbox(Checkbox::new(
pub fn custom_checkbox(enabled: bool, false_btn: Widget, true_btn: Widget) -> Widget {
Widget::new(WidgetType::Checkbox(Checkbox::new(
enabled,
false_btn.take_btn(),
true_btn.take_btn(),
)))
}
pub fn text_entry(ctx: &EventCtx, prefilled: String, exclusive_focus: bool) -> ManagedWidget {
pub fn text_entry(ctx: &EventCtx, prefilled: String, exclusive_focus: bool) -> Widget {
// TODO Hardcoded style, max chars
ManagedWidget::new(WidgetType::TextBox(TextBox::new(
Widget::new(WidgetType::TextBox(TextBox::new(
ctx,
50,
prefilled,
@ -320,8 +311,8 @@ impl ManagedWidget {
label: &str,
default_value: T,
choices: Vec<Choice<T>>,
) -> ManagedWidget {
ManagedWidget::new(WidgetType::Dropdown(Dropdown::new(
) -> Widget {
Widget::new(WidgetType::Dropdown(Dropdown::new(
ctx,
label,
default_value,
@ -331,20 +322,20 @@ impl ManagedWidget {
.outline(2.0, Color::WHITE)
}
pub(crate) fn duration_plot(plot: Plot<Duration>) -> ManagedWidget {
ManagedWidget::new(WidgetType::DurationPlot(plot))
pub(crate) fn duration_plot(plot: Plot<Duration>) -> Widget {
Widget::new(WidgetType::DurationPlot(plot))
}
pub(crate) fn usize_plot(plot: Plot<usize>) -> ManagedWidget {
ManagedWidget::new(WidgetType::UsizePlot(plot))
pub(crate) fn usize_plot(plot: Plot<usize>) -> Widget {
Widget::new(WidgetType::UsizePlot(plot))
}
pub(crate) fn histogram(histogram: Histogram) -> ManagedWidget {
ManagedWidget::new(WidgetType::Histogram(histogram))
pub(crate) fn histogram(histogram: Histogram) -> Widget {
Widget::new(WidgetType::Histogram(histogram))
}
pub fn row(widgets: Vec<ManagedWidget>) -> ManagedWidget {
ManagedWidget::new(WidgetType::Row(
pub fn row(widgets: Vec<Widget>) -> Widget {
Widget::new(WidgetType::Row(
widgets
.into_iter()
.filter(|w| match w.widget {
@ -355,8 +346,8 @@ impl ManagedWidget {
))
}
pub fn col(widgets: Vec<ManagedWidget>) -> ManagedWidget {
ManagedWidget::new(WidgetType::Column(
pub fn col(widgets: Vec<Widget>) -> Widget {
Widget::new(WidgetType::Column(
widgets
.into_iter()
.filter(|w| match w.widget {
@ -367,13 +358,13 @@ impl ManagedWidget {
))
}
pub fn nothing() -> ManagedWidget {
ManagedWidget::new(WidgetType::Nothing)
pub fn nothing() -> Widget {
Widget::new(WidgetType::Nothing)
}
}
// Internals
impl ManagedWidget {
impl Widget {
fn event(
&mut self,
ctx: &mut EventCtx,
@ -470,7 +461,7 @@ impl ManagedWidget {
nodes: &mut Vec<Node>,
) {
// TODO Can I use | in the match and "cast" to Widget?
let widget: &dyn Widget = match self.widget {
let widget: &dyn WidgetImpl = match self.widget {
WidgetType::Draw(ref widget) => widget,
WidgetType::Btn(ref widget) => widget,
WidgetType::Checkbox(ref widget) => widget,
@ -684,7 +675,7 @@ impl ManagedWidget {
}
}
fn find(&self, name: &str) -> Option<&ManagedWidget> {
fn find(&self, name: &str) -> Option<&Widget> {
let found = match self.widget {
// TODO Consolidate and just do this
WidgetType::Draw(_)
@ -714,7 +705,7 @@ impl ManagedWidget {
None
}
}
fn find_mut(&mut self, name: &str) -> Option<&mut ManagedWidget> {
fn find_mut(&mut self, name: &str) -> Option<&mut Widget> {
let found = match self.widget {
// TODO Consolidate and just do this
WidgetType::Draw(_)
@ -759,7 +750,7 @@ enum Dims {
}
pub struct CompositeBuilder {
top_level: ManagedWidget,
top_level: Widget,
sliders: HashMap<String, Slider>,
menus: HashMap<String, Menu>,
@ -771,7 +762,7 @@ pub struct CompositeBuilder {
}
pub struct Composite {
top_level: ManagedWidget,
top_level: Widget,
sliders: HashMap<String, Slider>,
menus: HashMap<String, Menu>,
@ -797,7 +788,7 @@ const SCROLL_SPEED: f64 = 5.0;
// TODO These APIs aren't composable. Need a builer pattern or ideally, to scrape all the special
// objects from the tree.
impl Composite {
pub fn new(top_level: ManagedWidget) -> CompositeBuilder {
pub fn new(top_level: Widget) -> CompositeBuilder {
CompositeBuilder {
top_level,
@ -1051,14 +1042,14 @@ impl Composite {
ScreenRectangle::top_left(f.top_left, f.dims)
}
fn find(&self, name: &str) -> &ManagedWidget {
fn find(&self, name: &str) -> &Widget {
if let Some(w) = self.top_level.find(name) {
w
} else {
panic!("Can't find widget {}", name);
}
}
fn find_mut(&mut self, name: &str) -> &mut ManagedWidget {
fn find_mut(&mut self, name: &str) -> &mut Widget {
if let Some(w) = self.top_level.find_mut(name) {
w
} else {
@ -1083,7 +1074,7 @@ impl Composite {
self.recompute_layout(ctx, false);
}
pub fn replace(&mut self, ctx: &mut EventCtx, id: &str, new: ManagedWidget) {
pub fn replace(&mut self, ctx: &mut EventCtx, id: &str, new: Widget) {
*self.find_mut(id) = new;
self.recompute_layout(ctx, true);
}
@ -1145,9 +1136,9 @@ impl CompositeBuilder {
c.container_dims.width * (c.container_dims.width / c.contents_dims.width),
),
);
c.top_level = ManagedWidget::col(vec![
c.top_level = Widget::col(vec![
c.top_level,
ManagedWidget::slider("horiz scrollbar")
Widget::slider("horiz scrollbar")
.abs(top_left.x, top_left.y + c.container_dims.height),
]);
}
@ -1161,9 +1152,9 @@ impl CompositeBuilder {
c.container_dims.height * (c.container_dims.height / c.contents_dims.height),
),
);
c.top_level = ManagedWidget::row(vec![
c.top_level = Widget::row(vec![
c.top_level,
ManagedWidget::slider("vert scrollbar")
Widget::slider("vert scrollbar")
.abs(top_left.x + c.container_dims.width, top_left.y),
]);
}

View File

@ -1,5 +1,5 @@
use crate::assets::Assets;
use crate::{svg, Color, EventCtx, GeomBatch, GfxCtx, ManagedWidget, Prerender, ScreenDims};
use crate::{svg, Color, EventCtx, GeomBatch, GfxCtx, Prerender, ScreenDims, Widget};
use geom::Polygon;
use std::collections::hash_map::DefaultHasher;
use std::fmt::Write;
@ -56,7 +56,7 @@ impl TextSpan {
self
}
pub fn draw(self, ctx: &EventCtx) -> ManagedWidget {
pub fn draw(self, ctx: &EventCtx) -> Widget {
Text::from(self).draw(ctx)
}
}
@ -264,8 +264,8 @@ impl Text {
format!("{:x}", hasher.finish())
}
pub fn draw(self, ctx: &EventCtx) -> ManagedWidget {
ManagedWidget::draw_text(ctx, self)
pub fn draw(self, ctx: &EventCtx) -> Widget {
Widget::draw_text(ctx, self)
}
}
@ -316,17 +316,17 @@ fn render_text(spans: Vec<TextSpan>, tolerance: f32, assets: &Assets) -> GeomBat
}
pub trait TextExt {
fn draw_text(self, ctx: &EventCtx) -> ManagedWidget;
fn draw_text(self, ctx: &EventCtx) -> Widget;
}
impl TextExt for &str {
fn draw_text(self, ctx: &EventCtx) -> ManagedWidget {
fn draw_text(self, ctx: &EventCtx) -> Widget {
Line(self).draw(ctx)
}
}
impl TextExt for String {
fn draw_text(self, ctx: &EventCtx) -> ManagedWidget {
fn draw_text(self, ctx: &EventCtx) -> Widget {
Line(self).draw(ctx)
}
}

View File

@ -1,7 +1,6 @@
use crate::widgets::Widget;
use crate::{
text, Color, Drawable, EventCtx, GeomBatch, GfxCtx, JustDraw, Line, ManagedWidget, MultiKey,
RewriteColor, ScreenDims, ScreenPt, Text,
text, Color, Drawable, EventCtx, GeomBatch, GfxCtx, JustDraw, Line, MultiKey, RewriteColor,
ScreenDims, ScreenPt, Text, Widget, WidgetImpl,
};
use geom::Polygon;
@ -108,7 +107,7 @@ impl Button {
}
}
impl Widget for Button {
impl WidgetImpl for Button {
fn get_dims(&self) -> ScreenDims {
self.dims
}
@ -123,7 +122,7 @@ impl Widget for Button {
// TODO Simplify all of these APIs!
impl Button {
// TODO Extreme wackiness.
pub fn inactive_button<S: Into<String>>(ctx: &mut EventCtx, label: S) -> ManagedWidget {
pub fn inactive_button<S: Into<String>>(ctx: &mut EventCtx, label: S) -> Widget {
let txt_batch = Text::from(Line(label).fg(Color::grey(0.5))).render_ctx(ctx);
let dims = txt_batch.get_dims();
@ -131,7 +130,7 @@ impl Button {
let vert_padding = 8.0;
let mut batch = GeomBatch::new();
batch.add_translated(txt_batch, horiz_padding, vert_padding);
ManagedWidget::just_draw(JustDraw {
Widget::just_draw(JustDraw {
draw: ctx.upload(batch),
top_left: ScreenPt::new(0.0, 0.0),
dims: ScreenDims::new(
@ -142,7 +141,7 @@ impl Button {
.outline(2.0, Color::WHITE)
}
// With a background
pub fn inactive_selected_button<S: Into<String>>(ctx: &EventCtx, label: S) -> ManagedWidget {
pub fn inactive_selected_button<S: Into<String>>(ctx: &EventCtx, label: S) -> Widget {
const HORIZ_PADDING: f64 = 30.0;
const VERT_PADDING: f64 = 10.0;
@ -286,7 +285,7 @@ impl BtnBuilder {
ctx: &EventCtx,
action_tooltip: I,
key: Option<MultiKey>,
) -> ManagedWidget {
) -> Widget {
match self {
BtnBuilder::SVG(path, rewrite_normal, rewrite_hover, maybe_t) => {
let (mut normal, bounds) = GeomBatch::from_svg(ctx, path, RewriteColor::NoOp);
@ -306,7 +305,7 @@ impl BtnBuilder {
if let Some(t) = maybe_t {
btn.tooltip = t;
}
ManagedWidget::btn(btn)
Widget::btn(btn)
}
BtnBuilder::TextFG(_, normal_txt, maybe_t) => {
// TODO Padding here is unfortunate, but I don't understand when the flexbox padding
@ -332,7 +331,7 @@ impl BtnBuilder {
if let Some(t) = maybe_t {
btn.tooltip = t;
}
ManagedWidget::btn(btn).outline(2.0, Color::WHITE)
Widget::btn(btn).outline(2.0, Color::WHITE)
}
BtnBuilder::TextBG {
text,
@ -362,7 +361,7 @@ impl BtnBuilder {
if let Some(t) = maybe_tooltip {
btn.tooltip = t;
}
ManagedWidget::btn(btn)
Widget::btn(btn)
}
BtnBuilder::Custom(normal, hovered, hitbox, maybe_t) => {
let mut btn =
@ -370,13 +369,13 @@ impl BtnBuilder {
if let Some(t) = maybe_t {
btn.tooltip = t;
}
ManagedWidget::btn(btn)
Widget::btn(btn)
}
}
}
// Use the text as the action
pub fn build_def(self, ctx: &EventCtx, hotkey: Option<MultiKey>) -> ManagedWidget {
pub fn build_def(self, ctx: &EventCtx, hotkey: Option<MultiKey>) -> Widget {
match self {
BtnBuilder::SVG(_, _, _, _) => panic!("Can't use build_def on an SVG button"),
BtnBuilder::Custom(_, _, _, _) => panic!("Can't use build_def on a custom button"),

View File

@ -1,5 +1,4 @@
use crate::widgets::Widget;
use crate::{Button, EventCtx, GfxCtx, ScreenDims, ScreenPt};
use crate::{Button, EventCtx, GfxCtx, ScreenDims, ScreenPt, WidgetImpl};
pub struct Checkbox {
pub(crate) enabled: bool,
@ -42,7 +41,7 @@ impl Checkbox {
}
}
impl Widget for Checkbox {
impl WidgetImpl for Checkbox {
fn get_dims(&self) -> ScreenDims {
self.btn.get_dims()
}

View File

@ -1,7 +1,6 @@
use crate::widgets::Widget;
use crate::{
Btn, Button, Choice, Color, EventCtx, GfxCtx, InputResult, PopupMenu, ScreenDims, ScreenPt,
ScreenRectangle,
ScreenRectangle, WidgetImpl,
};
use geom::{Polygon, Pt2D};
use std::any::Any;
@ -114,7 +113,7 @@ impl Dropdown {
}
}
impl Widget for Dropdown {
impl WidgetImpl for Dropdown {
fn get_dims(&self) -> ScreenDims {
self.btn.get_dims()
}

View File

@ -1,5 +1,4 @@
use crate::widgets::Widget;
use crate::{ScreenDims, ScreenPt};
use crate::{ScreenDims, ScreenPt, WidgetImpl};
// Doesn't do anything by itself, just used for widgetsing. Something else reaches in, asks for the
// ScreenRectangle to use.
@ -17,7 +16,7 @@ impl Filler {
}
}
impl Widget for Filler {
impl WidgetImpl for Filler {
fn get_dims(&self) -> ScreenDims {
self.dims
}

View File

@ -1,7 +1,6 @@
use crate::widgets::Widget;
use crate::{
Color, Drawable, EventCtx, GeomBatch, GfxCtx, Line, ManagedWidget, ScreenDims, ScreenPt, Text,
TextExt,
Color, Drawable, EventCtx, GeomBatch, GfxCtx, Line, ScreenDims, ScreenPt, Text, TextExt,
Widget, WidgetImpl,
};
use abstutil::prettyprint_usize;
use geom::{Distance, Duration, Polygon, Pt2D};
@ -18,7 +17,7 @@ pub struct Histogram {
}
impl Histogram {
pub fn new(unsorted_dts: Vec<Duration>, ctx: &EventCtx) -> ManagedWidget {
pub fn new(unsorted_dts: Vec<Duration>, ctx: &EventCtx) -> Widget {
let mut batch = GeomBatch::new();
let mut rect_labels = Vec::new();
@ -83,7 +82,7 @@ impl Histogram {
let dt = min_x + (max_x - min_x) * percent_x;
row.push(dt.to_string().draw_text(ctx));
}
let x_axis = ManagedWidget::row(row);
let x_axis = Widget::row(row);
let num_y_labels = 3;
let mut col = Vec::new();
@ -92,14 +91,11 @@ impl Histogram {
col.push(prettyprint_usize(((max_y as f64) * percent_y) as usize).draw_text(ctx));
}
col.reverse();
let y_axis = ManagedWidget::col(col);
let y_axis = Widget::col(col);
// Don't let the x-axis fill the parent container
ManagedWidget::row(vec![ManagedWidget::col(vec![
ManagedWidget::row(vec![
y_axis.evenly_spaced(),
ManagedWidget::histogram(histogram),
]),
Widget::row(vec![Widget::col(vec![
Widget::row(vec![y_axis.evenly_spaced(), Widget::histogram(histogram)]),
x_axis.evenly_spaced(),
])])
}
@ -119,7 +115,7 @@ impl Histogram {
}
}
impl Widget for Histogram {
impl WidgetImpl for Histogram {
fn get_dims(&self) -> ScreenDims {
self.dims
}

View File

@ -17,7 +17,7 @@ pub mod wizard;
use crate::{EventCtx, ScreenDims, ScreenPt};
use ordered_float::NotNan;
pub trait Widget {
pub trait WidgetImpl {
fn get_dims(&self) -> ScreenDims;
fn set_pos(&mut self, top_left: ScreenPt);
}
@ -35,7 +35,7 @@ pub enum ContainerOrientation {
pub fn stack_vertically(
orientation: ContainerOrientation,
ctx: &EventCtx,
widgets: Vec<&mut dyn Widget>,
widgets: Vec<&mut dyn WidgetImpl>,
) {
assert!(!widgets.is_empty());

View File

@ -1,5 +1,7 @@
use crate::widgets::{stack_vertically, ContainerOrientation, Widget};
use crate::{text, EventCtx, GfxCtx, Line, MultiKey, ScreenDims, ScreenPt, ScreenRectangle, Text};
use crate::widgets::{stack_vertically, ContainerOrientation};
use crate::{
text, EventCtx, GfxCtx, Line, MultiKey, ScreenDims, ScreenPt, ScreenRectangle, Text, WidgetImpl,
};
pub struct ModalMenu {
title: String,
@ -240,7 +242,7 @@ impl ModalMenu {
}
}
impl Widget for ModalMenu {
impl WidgetImpl for ModalMenu {
fn get_dims(&self) -> ScreenDims {
ScreenDims::new(self.dims.width, self.dims.height)
}

View File

@ -1,7 +1,6 @@
use crate::svg;
use crate::widgets::Widget;
use crate::{
Drawable, EventCtx, GeomBatch, GfxCtx, ManagedWidget, RewriteColor, ScreenDims, ScreenPt, Text,
svg, Drawable, EventCtx, GeomBatch, GfxCtx, RewriteColor, ScreenDims, ScreenPt, Text, Widget,
WidgetImpl,
};
// Just draw something. A widget just so widgetsing works.
@ -13,35 +12,35 @@ pub struct JustDraw {
}
impl JustDraw {
pub fn wrap(ctx: &EventCtx, batch: GeomBatch) -> ManagedWidget {
ManagedWidget::just_draw(JustDraw {
pub fn wrap(ctx: &EventCtx, batch: GeomBatch) -> Widget {
Widget::just_draw(JustDraw {
dims: batch.get_dims(),
draw: ctx.upload(batch),
top_left: ScreenPt::new(0.0, 0.0),
})
}
pub fn svg(ctx: &EventCtx, filename: &str) -> ManagedWidget {
pub fn svg(ctx: &EventCtx, filename: &str) -> Widget {
let (batch, bounds) = svg::load_svg(ctx.prerender, filename);
// TODO The dims will be wrong; it'll only look at geometry, not the padding in the image.
ManagedWidget::just_draw(JustDraw {
Widget::just_draw(JustDraw {
dims: ScreenDims::new(bounds.width(), bounds.height()),
draw: ctx.upload(batch),
top_left: ScreenPt::new(0.0, 0.0),
})
}
pub fn svg_transform(ctx: &EventCtx, filename: &str, rewrite: RewriteColor) -> ManagedWidget {
pub fn svg_transform(ctx: &EventCtx, filename: &str, rewrite: RewriteColor) -> Widget {
let (mut batch, bounds) = svg::load_svg(ctx.prerender, filename);
batch.rewrite_color(rewrite);
// TODO The dims will be wrong; it'll only look at geometry, not the padding in the image.
ManagedWidget::just_draw(JustDraw {
Widget::just_draw(JustDraw {
dims: ScreenDims::new(bounds.width(), bounds.height()),
draw: ctx.upload(batch),
top_left: ScreenPt::new(0.0, 0.0),
})
}
pub fn text(ctx: &EventCtx, text: Text) -> ManagedWidget {
pub fn text(ctx: &EventCtx, text: Text) -> Widget {
JustDraw::wrap(ctx, text.render_ctx(ctx))
}
@ -50,7 +49,7 @@ impl JustDraw {
}
}
impl Widget for JustDraw {
impl WidgetImpl for JustDraw {
fn get_dims(&self) -> ScreenDims {
self.dims
}

View File

@ -1,7 +1,6 @@
use crate::widgets::Widget;
use crate::{
Color, Drawable, EventCtx, GeomBatch, GfxCtx, Line, ManagedWidget, ScreenDims, ScreenPt,
ScreenRectangle, Text, TextExt,
Color, Drawable, EventCtx, GeomBatch, GfxCtx, Line, ScreenDims, ScreenPt, ScreenRectangle,
Text, TextExt, Widget, WidgetImpl,
};
use abstutil::prettyprint_usize;
use geom::{Angle, Bounds, Circle, Distance, Duration, FindClosest, PolyLine, Pt2D, Time};
@ -37,7 +36,7 @@ impl<T: 'static + Ord + PartialEq + Copy + core::fmt::Debug + Yvalue<T>> Plot<T>
series: Vec<Series<T>>,
y_zero: T,
opts: PlotOptions,
) -> (Plot<T>, ManagedWidget, ManagedWidget, ManagedWidget) {
) -> (Plot<T>, Widget, Widget, Widget) {
let mut batch = GeomBatch::new();
// TODO Tuned to fit the info panel. Instead these should somehow stretch to fill their
@ -46,12 +45,12 @@ impl<T: 'static + Ord + PartialEq + Copy + core::fmt::Debug + Yvalue<T>> Plot<T>
let height = 0.2 * ctx.canvas.window_height;
let radius = 15.0;
let legend = ManagedWidget::col(
let legend = Widget::col(
series
.iter()
.map(|s| {
ManagedWidget::row(vec![
ManagedWidget::draw_batch(
Widget::row(vec![
Widget::draw_batch(
ctx,
GeomBatch::from(vec![(
s.color,
@ -184,9 +183,9 @@ impl<T: 'static + Ord + PartialEq + Copy + core::fmt::Debug + Yvalue<T>> Plot<T>
for (color, poly) in Text::from(Line(t.to_string())).render_ctx(ctx).consume() {
batch.push(color, poly.rotate(Angle::new_degs(-15.0)));
}
row.push(ManagedWidget::draw_batch(ctx, batch.autocrop()));
row.push(Widget::draw_batch(ctx, batch.autocrop()));
}
let x_axis = ManagedWidget::row(row).padding(10);
let x_axis = Widget::row(row).padding(10);
let num_y_labels = 4;
let mut col = Vec::new();
@ -195,7 +194,7 @@ impl<T: 'static + Ord + PartialEq + Copy + core::fmt::Debug + Yvalue<T>> Plot<T>
col.push(max_y.from_percent(percent_y).prettyprint().draw_text(ctx));
}
col.reverse();
let y_axis = ManagedWidget::col(col).padding(10);
let y_axis = Widget::col(col).padding(10);
(plot, legend, x_axis, y_axis)
}
@ -235,19 +234,12 @@ impl<T: 'static + Ord + PartialEq + Copy + core::fmt::Debug + Yvalue<T>> Plot<T>
}
impl Plot<usize> {
pub fn new_usize(
ctx: &EventCtx,
series: Vec<Series<usize>>,
opts: PlotOptions,
) -> ManagedWidget {
pub fn new_usize(ctx: &EventCtx, series: Vec<Series<usize>>, opts: PlotOptions) -> Widget {
let (plot, legend, x_axis, y_axis) = Plot::new(ctx, series, 0, opts);
// Don't let the x-axis fill the parent container
ManagedWidget::row(vec![ManagedWidget::col(vec![
Widget::row(vec![Widget::col(vec![
legend,
ManagedWidget::row(vec![
y_axis.evenly_spaced(),
ManagedWidget::usize_plot(plot),
]),
Widget::row(vec![y_axis.evenly_spaced(), Widget::usize_plot(plot)]),
x_axis.evenly_spaced(),
])])
}
@ -258,21 +250,18 @@ impl Plot<Duration> {
ctx: &EventCtx,
series: Vec<Series<Duration>>,
opts: PlotOptions,
) -> ManagedWidget {
) -> Widget {
let (plot, legend, x_axis, y_axis) = Plot::new(ctx, series, Duration::ZERO, opts);
// Don't let the x-axis fill the parent container
ManagedWidget::row(vec![ManagedWidget::col(vec![
Widget::row(vec![Widget::col(vec![
legend,
ManagedWidget::row(vec![
y_axis.evenly_spaced(),
ManagedWidget::duration_plot(plot),
]),
Widget::row(vec![y_axis.evenly_spaced(), Widget::duration_plot(plot)]),
x_axis.evenly_spaced(),
])])
}
}
impl<T> Widget for Plot<T> {
impl<T> WidgetImpl for Plot<T> {
fn get_dims(&self) -> ScreenDims {
self.dims
}

View File

@ -1,7 +1,6 @@
use crate::widgets::Widget;
use crate::{
hotkey, text, Choice, EventCtx, GfxCtx, InputResult, Key, Line, ScreenDims, ScreenPt,
ScreenRectangle, Text,
ScreenRectangle, Text, WidgetImpl,
};
use geom::Pt2D;
@ -183,7 +182,7 @@ impl<T: Clone> PopupMenu<T> {
}
}
impl<T: Clone> Widget for PopupMenu<T> {
impl<T: Clone> WidgetImpl for PopupMenu<T> {
fn get_dims(&self) -> ScreenDims {
self.dims
}

View File

@ -1,7 +1,7 @@
use crate::widgets::{stack_vertically, ContainerOrientation, Widget};
use crate::widgets::{stack_vertically, ContainerOrientation};
use crate::{
hotkey, Color, Drawable, EventCtx, EventLoopMode, GeomBatch, GfxCtx, Key, Line, ModalMenu,
MultiKey, ScreenDims, ScreenPt, ScreenRectangle, Text, Warper,
MultiKey, ScreenDims, ScreenPt, ScreenRectangle, Text, Warper, WidgetImpl,
};
use geom::{Polygon, Pt2D};
@ -213,7 +213,7 @@ impl Slider {
}
}
impl Widget for Slider {
impl WidgetImpl for Slider {
fn get_dims(&self) -> ScreenDims {
self.dims
}

View File

@ -1,7 +1,6 @@
use crate::widgets::Widget;
use crate::{
text, Color, EventCtx, GeomBatch, GfxCtx, Key, Line, ScreenDims, ScreenPt, ScreenRectangle,
Text,
Text, WidgetImpl,
};
use geom::Polygon;
@ -118,7 +117,7 @@ impl TextBox {
}
}
impl Widget for TextBox {
impl WidgetImpl for TextBox {
fn get_dims(&self) -> ScreenDims {
self.dims
}

View File

@ -1,6 +1,6 @@
use crate::{
hotkey, Btn, Color, Composite, EventCtx, GfxCtx, HorizontalAlignment, InputResult, Key, Line,
ManagedWidget, MultiKey, Outcome, PopupMenu, Text, VerticalAlignment,
MultiKey, Outcome, PopupMenu, Text, VerticalAlignment, Widget,
};
use abstutil::Cloneable;
use std::collections::VecDeque;
@ -83,15 +83,15 @@ impl Wizard {
if self.tb_comp.is_none() {
self.tb_comp = Some(
Composite::new(
ManagedWidget::col(vec![
ManagedWidget::row(vec![
Widget::col(vec![
Widget::row(vec![
Line(query).roboto_bold().draw(ctx),
Btn::text_fg("X")
.build(ctx, "quit", hotkey(Key::Escape))
.margin(5)
.align_right(),
]),
ManagedWidget::text_entry(ctx, prefilled.unwrap_or_else(String::new), true)
Widget::text_entry(ctx, prefilled.unwrap_or_else(String::new), true)
.named("input"),
Btn::text_bg2("Done").build(ctx, "done", hotkey(Key::Enter)),
])
@ -252,11 +252,11 @@ impl<'a, 'b> WrappedWizard<'a, 'b> {
if let Some(l) = query {
col.push(Line(l).roboto_bold().draw(self.ctx));
}
col.push(ManagedWidget::menu("menu"));
col.push(Widget::menu("menu"));
self.wizard.menu_comp = Some(
Composite::new(
ManagedWidget::row(vec![
ManagedWidget::col(col),
Widget::row(vec![
Widget::col(col),
Btn::text_fg("X")
.build(self.ctx, "quit", hotkey(Key::Escape))
.margin(5),
@ -384,7 +384,7 @@ impl<'a, 'b> WrappedWizard<'a, 'b> {
assert!(self.wizard.ack.is_none());
self.wizard.ack = Some(
Composite::new(
ManagedWidget::col(vec![
Widget::col(vec![
txt.draw(self.ctx),
Btn::text_bg2("OK")
.build(self.ctx, "OK", hotkey(Key::Enter))

View File

@ -4,7 +4,7 @@ use crate::game::{State, Transition};
use crate::managed::{Callback, ManagedGUIState, WrappedComposite};
use crate::sandbox::{GameplayMode, SandboxMode, TutorialState};
use abstutil::Timer;
use ezgui::{hotkey, Btn, Button, Color, Composite, EventCtx, Key, Line, ManagedWidget, Text};
use ezgui::{hotkey, Btn, Button, Color, Composite, EventCtx, Key, Line, Text, Widget};
use geom::{Duration, Time};
use map_model::Map;
use sim::{Scenario, Sim, SimFlags, SimOptions, TripMode};
@ -175,7 +175,7 @@ impl Tab {
}
}
master_col.push(
ManagedWidget::row(flex_row)
Widget::row(flex_row)
.flex_wrap(ctx, 80)
.bg(colors::PANEL_BG)
.padding(10)
@ -210,7 +210,7 @@ impl Tab {
}
}
main_row.push(
ManagedWidget::col(col)
Widget::col(col)
.bg(colors::PANEL_BG)
.padding(10)
.margin(10)
@ -229,7 +229,7 @@ impl Tab {
txt.add(Line(l));
}
main_row.push(
ManagedWidget::col(vec![
Widget::col(vec![
txt.draw(ctx),
Btn::text_fg("Start!")
.build_def(ctx, hotkey(Key::Enter))
@ -252,10 +252,10 @@ impl Tab {
));
}
master_col.push(ManagedWidget::row(main_row));
master_col.push(Widget::row(main_row));
let mut c = WrappedComposite::new(
Composite::new(ManagedWidget::col(master_col))
Composite::new(Widget::col(master_col))
.exact_size_percent(90, 85)
.build(ctx),
)

View File

@ -2,8 +2,8 @@ use crate::app::App;
use crate::colors;
use crate::render::MIN_ZOOM_FOR_DETAIL;
use ezgui::{
Btn, Color, Composite, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment,
ManagedWidget, Outcome, Text, VerticalAlignment,
Btn, Color, Composite, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Outcome,
Text, VerticalAlignment, Widget,
};
use geom::{Circle, Distance, Pt2D};
use map_model::{BuildingID, BusStopID, IntersectionID, LaneID, Map, RoadID};
@ -137,14 +137,14 @@ impl ColorerBuilder {
}
// Build the legend
let mut col = vec![ManagedWidget::row(vec![
let mut col = vec![Widget::row(vec![
self.header.draw(ctx),
Btn::text_fg("X").build_def(ctx, None).align_right(),
])];
for (label, color) in self.prioritized_colors {
col.push(ColorLegend::row(ctx, color, label));
}
let legend = Composite::new(ManagedWidget::col(col).bg(colors::PANEL_BG))
let legend = Composite::new(Widget::col(col).bg(colors::PANEL_BG))
.aligned(HorizontalAlignment::Right, VerticalAlignment::Center)
.build(ctx);
@ -163,7 +163,7 @@ impl ColorerBuilder {
pub struct ColorLegend {}
impl ColorLegend {
pub fn row<S: Into<String>>(ctx: &mut EventCtx, color: Color, label: S) -> ManagedWidget {
pub fn row<S: Into<String>>(ctx: &mut EventCtx, color: Color, label: S) -> Widget {
// TODO This is a little specialized for info panels.
let mut txt = Text::new();
// TODO This is wider than the 0.35 of info panels, because add_wrapped is quite bad at max
@ -171,8 +171,8 @@ impl ColorLegend {
txt.add_wrapped(label.into(), 0.5 * ctx.canvas.window_width);
let radius = 15.0;
ManagedWidget::row(vec![
ManagedWidget::draw_batch(
Widget::row(vec![
Widget::draw_batch(
ctx,
GeomBatch::from(vec![(
color,

View File

@ -8,8 +8,8 @@ use crate::sandbox::{SandboxMode, SpeedControls};
use abstutil::prettyprint_usize;
use ezgui::{
hotkey, Btn, Color, Composite, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key,
Line, ManagedWidget, Outcome, Plot, PlotOptions, RewriteColor, Series, Text, TextExt,
VerticalAlignment,
Line, Outcome, Plot, PlotOptions, RewriteColor, Series, Text, TextExt, VerticalAlignment,
Widget,
};
use geom::{Angle, Circle, Distance, Duration, Polygon, Pt2D, Statistic, Time};
use map_model::{BuildingID, IntersectionID, IntersectionType, Map, Path, PathStep};
@ -192,7 +192,7 @@ impl InfoPanel {
actions,
trip_details,
time: app.primary.sim.time(),
composite: Composite::new(ManagedWidget::col(col).bg(colors::PANEL_BG).padding(10))
composite: Composite::new(Widget::col(col).bg(colors::PANEL_BG).padding(10))
.aligned(
HorizontalAlignment::Percent(0.02),
VerticalAlignment::Percent(0.2),
@ -362,14 +362,9 @@ impl InfoPanel {
}
}
fn info_for(
ctx: &EventCtx,
app: &App,
id: ID,
action_btns: Vec<ManagedWidget>,
) -> Vec<ManagedWidget> {
fn info_for(ctx: &EventCtx, app: &App, id: ID, action_btns: Vec<Widget>) -> Vec<Widget> {
let (map, sim, draw_map) = (&app.primary.map, &app.primary.sim, &app.primary.draw_map);
let header_btns = ManagedWidget::row(vec![
let header_btns = Widget::row(vec![
Btn::svg_def("../data/system/assets/tools/location.svg")
.build(ctx, "jump to object", hotkey(Key::J))
.margin(5),
@ -388,7 +383,7 @@ fn info_for(
// Header
{
let label = if l.is_sidewalk() { "Sidewalk" } else { "Lane" };
rows.push(ManagedWidget::row(vec![
rows.push(Widget::row(vec![
Line(format!("{} #{}", label, id.0)).roboto_bold().draw(ctx),
header_btns,
]));
@ -499,7 +494,7 @@ fn info_for(
format!("Intersection #{} (under construction)", id.0)
}
};
rows.push(ManagedWidget::row(vec![
rows.push(Widget::row(vec![
Line(label).roboto_bold().draw(ctx),
header_btns,
]));
@ -560,7 +555,7 @@ fn info_for(
// Header
{
rows.push(ManagedWidget::row(vec![
rows.push(Widget::row(vec![
Line(format!("Building #{}", id.0)).roboto_bold().draw(ctx),
header_btns,
]));
@ -656,7 +651,7 @@ fn info_for(
VehicleType::Bike => "Bike",
VehicleType::Bus => "Bus",
};
rows.push(ManagedWidget::row(vec![
rows.push(Widget::row(vec![
Line(format!("{} #{}", label, id.0)).roboto_bold().draw(ctx),
header_btns,
]));
@ -676,7 +671,7 @@ fn info_for(
ID::Pedestrian(id) => {
// Header
{
rows.push(ManagedWidget::row(vec![
rows.push(Widget::row(vec![
Line(format!("Pedestrian #{}", id.0))
.roboto_bold()
.draw(ctx),
@ -698,7 +693,7 @@ fn info_for(
ID::PedCrowd(members) => {
// Header
{
rows.push(ManagedWidget::row(vec![
rows.push(Widget::row(vec![
Line("Pedestrian crowd").roboto_bold().draw(ctx),
header_btns,
]));
@ -712,7 +707,7 @@ fn info_for(
ID::BusStop(id) => {
// Header
{
rows.push(ManagedWidget::row(vec![
rows.push(Widget::row(vec![
Line("Bus stop").roboto_bold().draw(ctx),
header_btns,
]));
@ -752,7 +747,7 @@ fn info_for(
ID::Area(id) => {
// Header
{
rows.push(ManagedWidget::row(vec![
rows.push(Widget::row(vec![
Line(format!("Area #{}", id.0)).roboto_bold().draw(ctx),
header_btns,
]));
@ -769,7 +764,7 @@ fn info_for(
ID::ExtraShape(id) => {
// Header
{
rows.push(ManagedWidget::row(vec![
rows.push(Widget::row(vec![
Line(format!("Extra GIS shape #{}", id.0))
.roboto_bold()
.draw(ctx),
@ -789,7 +784,7 @@ fn info_for(
ID::Trip(id) => {
// Header
{
rows.push(ManagedWidget::row(vec![
rows.push(Widget::row(vec![
Line(format!("Trip #{}", id.0)).roboto_bold().draw(ctx),
// No jump-to-object button; this is probably a finished trip.
Btn::text_fg("X")
@ -802,7 +797,7 @@ fn info_for(
ID::Person(id) => {
// Header
{
rows.push(ManagedWidget::row(vec![
rows.push(Widget::row(vec![
Line(format!("Person #{}", id.0)).roboto_bold().draw(ctx),
header_btns,
]));
@ -837,7 +832,7 @@ fn info_for(
.draw_text(ctx),
);
} else {
rows.push(ManagedWidget::row(vec![
rows.push(Widget::row(vec![
format!("{}: ", start_time.ampm_tostring()).draw_text(ctx),
Btn::text_bg1(format!("Trip #{}", t.0))
.build(ctx, format!("examine Trip #{}", t.0), None)
@ -852,10 +847,10 @@ fn info_for(
rows
}
fn make_table(ctx: &EventCtx, rows: Vec<(String, String)>) -> Vec<ManagedWidget> {
fn make_table(ctx: &EventCtx, rows: Vec<(String, String)>) -> Vec<Widget> {
rows.into_iter()
.map(|(k, v)| {
ManagedWidget::row(vec![
Widget::row(vec![
Line(k).roboto_bold().draw(ctx),
// TODO not quite...
v.draw_text(ctx).centered_vert().align_right(),
@ -870,7 +865,7 @@ fn make_table(ctx: &EventCtx, rows: Vec<(String, String)>) -> Vec<ManagedWidget>
keys.add(Line(k).roboto_bold());
values.add(Line(v));
}
vec![ManagedWidget::row(vec![
vec![Widget::row(vec![
keys.draw(ctx),
values.draw(ctx).centered_vert().bg(Color::GREEN),
])]*/
@ -880,7 +875,7 @@ fn throughput<F: Fn(&Analytics, Time) -> BTreeMap<TripMode, Vec<(Time, usize)>>>
ctx: &EventCtx,
app: &App,
get_data: F,
) -> ManagedWidget {
) -> Widget {
let mut series = get_data(app.primary.sim.get_analytics(), app.primary.sim.time())
.into_iter()
.map(|(m, pts)| Series {
@ -903,12 +898,7 @@ fn throughput<F: Fn(&Analytics, Time) -> BTreeMap<TripMode, Vec<(Time, usize)>>>
Plot::new_usize(ctx, series, PlotOptions::new())
}
fn intersection_delay(
ctx: &EventCtx,
app: &App,
i: IntersectionID,
bucket: Duration,
) -> ManagedWidget {
fn intersection_delay(ctx: &EventCtx, app: &App, i: IntersectionID, bucket: Duration) -> Widget {
let get_data = |a: &Analytics, t: Time| {
let mut series: Vec<(Statistic, Vec<(Time, Duration)>)> = Statistic::all()
.into_iter()
@ -967,7 +957,7 @@ fn trip_details(
app: &App,
trip: TripID,
progress_along_path: Option<f64>,
) -> (ManagedWidget, TripDetails) {
) -> (Widget, TripDetails) {
let map = &app.primary.map;
let phases = app.primary.sim.get_analytics().get_trip_phases(trip, map);
let (trip_start, trip_end) = app.primary.sim.trip_endpoints(trip);
@ -1229,9 +1219,7 @@ fn trip_details(
if let Some(t) = trip_end_time {
table.push(("Trip end".to_string(), t.ampm_tostring()));
}
let mut col = vec![ManagedWidget::row(timeline)
.evenly_spaced()
.margin_above(25)];
let mut col = vec![Widget::row(timeline).evenly_spaced().margin_above(25)];
col.extend(make_table(ctx, table));
col.extend(elevation);
if let Some(p) = app.primary.sim.trip_to_person(trip) {
@ -1243,7 +1231,7 @@ fn trip_details(
}
(
ManagedWidget::col(col),
Widget::col(col),
TripDetails {
id: trip,
unzoomed: unzoomed.upload(ctx),
@ -1303,13 +1291,7 @@ fn strip_prefix_usize(x: &String, prefix: &str) -> Option<usize> {
}
}
fn make_elevation(
ctx: &EventCtx,
color: Color,
walking: bool,
path: &Path,
map: &Map,
) -> ManagedWidget {
fn make_elevation(ctx: &EventCtx, color: Color, walking: bool, path: &Path, map: &Map) -> Widget {
let mut pts: Vec<(Distance, Distance)> = Vec::new();
let mut dist = Distance::ZERO;
for step in path.get_steps() {

View File

@ -6,8 +6,7 @@ use crate::render::MIN_ZOOM_FOR_DETAIL;
use abstutil::clamp;
use ezgui::{
hotkey, Btn, Color, Composite, EventCtx, Filler, GeomBatch, GfxCtx, HorizontalAlignment, Key,
Line, ManagedWidget, Outcome, RewriteColor, ScreenDims, ScreenPt, Text, TextExt,
VerticalAlignment,
Line, Outcome, RewriteColor, ScreenDims, ScreenPt, Text, TextExt, VerticalAlignment, Widget,
};
use geom::{Circle, Distance, Polygon, Pt2D, Ring};
@ -275,19 +274,19 @@ fn make_minimap_panel(ctx: &mut EventCtx, app: &App, zoom_lvl: usize) -> Composi
);
Composite::new(
ManagedWidget::row(vec![
ManagedWidget::col(zoom_col).margin(5).centered(),
ManagedWidget::col(vec![
Widget::row(vec![
Widget::col(zoom_col).margin(5).centered(),
Widget::col(vec![
Btn::svg_def("../data/system/assets/minimap/up.svg")
.build(ctx, "pan up", None)
.margin(5)
.centered_horiz(),
ManagedWidget::row(vec![
Widget::row(vec![
Btn::svg_def("../data/system/assets/minimap/left.svg")
.build(ctx, "pan left", None)
.margin(5)
.centered_vert(),
ManagedWidget::filler("minimap"),
Widget::filler("minimap"),
Btn::svg_def("../data/system/assets/minimap/right.svg")
.build(ctx, "pan right", None)
.margin(5)
@ -314,9 +313,9 @@ fn make_minimap_panel(ctx: &mut EventCtx, app: &App, zoom_lvl: usize) -> Composi
.build(ctx)
}
fn make_viz_panel(ctx: &mut EventCtx, app: &App) -> ManagedWidget {
fn make_viz_panel(ctx: &mut EventCtx, app: &App) -> Widget {
let radius = 10.0;
let mut col = vec![ManagedWidget::row(vec![
let mut col = vec![Widget::row(vec![
Btn::svg_def("../data/system/assets/tools/search.svg")
.build(ctx, "search", hotkey(Key::K))
.margin(10),
@ -344,7 +343,7 @@ fn make_viz_panel(ctx: &mut EventCtx, app: &App) -> ManagedWidget {
.centered()];
for (label, color, enabled) in &app.agent_cs.rows {
col.push(
ManagedWidget::row(vec![
Widget::row(vec![
// TODO Make sure the dims of these two fit
if *enabled {
Btn::svg_def("../data/system/assets/tools/visible.svg")
@ -355,7 +354,7 @@ fn make_viz_panel(ctx: &mut EventCtx, app: &App) -> ManagedWidget {
.build(ctx, format!("show {}", label), None)
.margin(3)
},
ManagedWidget::draw_batch(
Widget::draw_batch(
ctx,
GeomBatch::from(vec![(
Color::WHITE.alpha(0.5),
@ -363,7 +362,7 @@ fn make_viz_panel(ctx: &mut EventCtx, app: &App) -> ManagedWidget {
)]),
)
.margin(3),
ManagedWidget::draw_batch(
Widget::draw_batch(
ctx,
GeomBatch::from(vec![(
color.alpha(if *enabled { 1.0 } else { 0.5 }),
@ -389,8 +388,8 @@ fn make_viz_panel(ctx: &mut EventCtx, app: &App) -> ManagedWidget {
// TODO Should the full legend have this icon too?
col.insert(
0,
ManagedWidget::row(vec![
ManagedWidget::draw_svg_transform(
Widget::row(vec![
Widget::draw_svg_transform(
ctx,
"../data/system/assets/tools/layers.svg",
RewriteColor::ChangeAll(Color::BLUE),
@ -402,5 +401,5 @@ fn make_viz_panel(ctx: &mut EventCtx, app: &App) -> ManagedWidget {
}
}
ManagedWidget::col(col).bg(colors::PANEL_BG).padding(5)
Widget::col(col).bg(colors::PANEL_BG).padding(5)
}

View File

@ -9,8 +9,8 @@ use crate::render::MIN_ZOOM_FOR_DETAIL;
use abstutil::{prettyprint_usize, Counter};
use ezgui::{
hotkey, Btn, Button, Color, Composite, Drawable, EventCtx, GeomBatch, GfxCtx, Histogram,
HorizontalAlignment, JustDraw, Key, Line, ManagedWidget, Outcome, Plot, PlotOptions,
RewriteColor, Series, Text, TextExt, VerticalAlignment,
HorizontalAlignment, JustDraw, Key, Line, Outcome, Plot, PlotOptions, RewriteColor, Series,
Text, TextExt, VerticalAlignment, Widget,
};
use geom::{Circle, Distance, Duration, PolyLine, Polygon, Pt2D, Statistic, Time};
use map_model::{BusRouteID, IntersectionID};
@ -283,14 +283,14 @@ impl Overlays {
let c = WrappedComposite::new(
Composite::new(
ManagedWidget::col(vec![
ManagedWidget::row(vec![
Widget::col(vec![
Widget::row(vec![
"Heat Map Layers".draw_text(ctx),
Btn::text_fg("X")
.build(ctx, "close", hotkey(Key::Escape))
.align_right(),
]),
ManagedWidget::row(choices.into_iter().map(|x| x.margin(5)).collect())
Widget::row(choices.into_iter().map(|x| x.margin(5)).collect())
.flex_wrap(ctx, 30),
])
.bg(colors::PANEL_BG)
@ -707,8 +707,8 @@ impl Overlays {
Overlays::TripsHistogram(
now,
Composite::new(
ManagedWidget::col(vec![
ManagedWidget::row(vec![
Widget::col(vec![
Widget::row(vec![
{
let mut txt = Text::from(Line("Are trips "));
txt.append(Line("faster").fg(Color::GREEN));
@ -767,7 +767,7 @@ impl Overlays {
}
let col = vec![
ManagedWidget::row(vec![
Widget::row(vec![
"intersection demand".draw_text(ctx),
Btn::svg_def("../data/system/assets/tools/location.svg")
.build(ctx, "intersection demand", None)
@ -781,7 +781,7 @@ impl Overlays {
app.primary.sim.time(),
i,
batch.upload(ctx),
Composite::new(ManagedWidget::col(col).bg(colors::PANEL_BG))
Composite::new(Widget::col(col).bg(colors::PANEL_BG))
.aligned(HorizontalAlignment::Right, VerticalAlignment::Center)
.build(ctx),
)
@ -793,7 +793,7 @@ impl Overlays {
pub fn bus_passengers(id: BusRouteID, ctx: &mut EventCtx, app: &App) -> Overlays {
let route = app.primary.map.get_br(id);
let mut master_col = vec![ManagedWidget::row(vec![
let mut master_col = vec![Widget::row(vec![
Line(format!("Passengers for {}", route.name))
.roboto_bold()
.draw(ctx),
@ -807,7 +807,7 @@ impl Overlays {
.get_analytics()
.bus_passenger_delays(app.primary.sim.time(), id);
for idx in 0..route.stops.len() {
col.push(ManagedWidget::row(vec![
col.push(Widget::row(vec![
format!("Stop {}", idx + 1).draw_text(ctx),
Btn::svg(
"../data/system/assets/tools/pin.svg",
@ -852,13 +852,13 @@ impl Overlays {
}
let timeline = JustDraw::wrap(ctx, batch);
master_col.push(ManagedWidget::row(vec![
master_col.push(Widget::row(vec![
timeline.margin(5),
ManagedWidget::col(col).margin(5),
Widget::col(col).margin(5),
]));
let mut c = WrappedComposite::new(
Composite::new(ManagedWidget::col(master_col).bg(colors::PANEL_BG))
Composite::new(Widget::col(master_col).bg(colors::PANEL_BG))
.aligned(HorizontalAlignment::Right, VerticalAlignment::Center)
.build(ctx),
);
@ -907,8 +907,8 @@ impl Overlays {
app.primary.sim.time(),
route.id,
Composite::new(
ManagedWidget::col(vec![
ManagedWidget::row(vec![
Widget::col(vec![
Widget::row(vec![
format!("delays for {}", route.name).draw_text(ctx),
Btn::text_fg("X").build_def(ctx, None).align_right(),
]),

View File

@ -3,7 +3,7 @@ use crate::game::Transition;
use crate::managed::WrappedComposite;
use crate::options;
use ezgui::{
hotkey, Btn, Composite, EventCtx, HorizontalAlignment, Key, ManagedWidget, VerticalAlignment,
hotkey, Btn, Composite, EventCtx, HorizontalAlignment, Key, VerticalAlignment, Widget,
};
pub fn tool_panel(ctx: &mut EventCtx) -> WrappedComposite {
@ -18,7 +18,7 @@ pub fn tool_panel(ctx: &mut EventCtx) -> WrappedComposite {
.margin(10),
];
WrappedComposite::new(
Composite::new(ManagedWidget::row(row).bg(colors::PANEL_BG))
Composite::new(Widget::row(row).bg(colors::PANEL_BG))
.aligned(HorizontalAlignment::Left, VerticalAlignment::BottomAboveOSD)
.build(ctx),
)

View File

@ -6,7 +6,7 @@ use crate::helpers::ID;
use crate::render::{dashed_lines, draw_signal_phase, make_signal_diagram, DrawOptions, DrawTurn};
use ezgui::{
hotkey, Btn, Button, Color, Composite, Drawable, EventCtx, GeomBatch, GfxCtx,
HorizontalAlignment, Key, Line, ManagedWidget, Outcome, Text, VerticalAlignment,
HorizontalAlignment, Key, Line, Outcome, Text, VerticalAlignment, Widget,
};
use geom::{Distance, Polygon, Time};
use map_model::{IntersectionID, LaneID, TurnType};
@ -247,7 +247,7 @@ impl TurnExplorer {
fn make_panel(ctx: &mut EventCtx, app: &App, l: LaneID, idx: usize) -> Composite {
let num_turns = app.primary.map.get_turns_from_lane(l).len();
let mut col = vec![ManagedWidget::row(vec![
let mut col = vec![Widget::row(vec![
Text::from(
Line(format!(
"Turns from {}",
@ -257,7 +257,7 @@ impl TurnExplorer {
)
.draw(ctx)
.margin(5),
ManagedWidget::draw_batch(
Widget::draw_batch(
ctx,
GeomBatch::from(vec![(Color::WHITE, Polygon::rectangle(2.0, 50.0))]),
)
@ -328,7 +328,7 @@ impl TurnExplorer {
));
}
Composite::new(ManagedWidget::col(col).bg(colors::PANEL_BG))
Composite::new(Widget::col(col).bg(colors::PANEL_BG))
.aligned(HorizontalAlignment::Center, VerticalAlignment::Top)
.build(ctx)
}

View File

@ -12,7 +12,7 @@ use crate::render::DrawOptions;
use abstutil::Timer;
use ezgui::{
hotkey, lctrl, Btn, Color, Composite, Drawable, EventCtx, EventLoopMode, GeomBatch, GfxCtx,
HorizontalAlignment, Key, Line, ManagedWidget, Outcome, Text, VerticalAlignment, Wizard,
HorizontalAlignment, Key, Line, Outcome, Text, VerticalAlignment, Widget, Wizard,
};
use geom::{Circle, Distance, Duration, Pt2D};
use map_model::{IntersectionID, NORMAL_LANE_THICKNESS};
@ -37,28 +37,23 @@ impl DebugMode {
pub fn new(ctx: &mut EventCtx) -> DebugMode {
DebugMode {
composite: Composite::new(
ManagedWidget::col(vec![
ManagedWidget::row(vec![
Widget::col(vec![
Widget::row(vec![
Line("Debug Mode").roboto_bold().draw(ctx),
Btn::text_fg("X")
.build_def(ctx, hotkey(Key::Escape))
.align_right(),
]),
Text::new().draw(ctx).named("current info"),
ManagedWidget::checkbox(ctx, "show buildings", hotkey(Key::Num1), true),
ManagedWidget::checkbox(ctx, "show intersections", hotkey(Key::Num2), true),
ManagedWidget::checkbox(ctx, "show lanes", hotkey(Key::Num3), true),
ManagedWidget::checkbox(ctx, "show areas", hotkey(Key::Num4), true),
ManagedWidget::checkbox(ctx, "show extra shapes", hotkey(Key::Num5), true),
ManagedWidget::checkbox(ctx, "show labels", hotkey(Key::Num6), false),
ManagedWidget::checkbox(
ctx,
"show route for all agents",
hotkey(Key::R),
false,
),
ManagedWidget::checkbox(ctx, "show dot map of people", hotkey(Key::P), false),
ManagedWidget::col(
Widget::checkbox(ctx, "show buildings", hotkey(Key::Num1), true),
Widget::checkbox(ctx, "show intersections", hotkey(Key::Num2), true),
Widget::checkbox(ctx, "show lanes", hotkey(Key::Num3), true),
Widget::checkbox(ctx, "show areas", hotkey(Key::Num4), true),
Widget::checkbox(ctx, "show extra shapes", hotkey(Key::Num5), true),
Widget::checkbox(ctx, "show labels", hotkey(Key::Num6), false),
Widget::checkbox(ctx, "show route for all agents", hotkey(Key::R), false),
Widget::checkbox(ctx, "show dot map of people", hotkey(Key::P), false),
Widget::col(
vec![
(lctrl(Key::H), "unhide everything"),
(None, "screenshot everything"),

View File

@ -4,8 +4,8 @@ use crate::common::CommonState;
use crate::game::{State, Transition};
use abstutil::prettyprint_usize;
use ezgui::{
hotkey, Btn, Composite, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line,
ManagedWidget, Outcome, Slider, TextExt, VerticalAlignment,
hotkey, Btn, Composite, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line, Outcome,
Slider, TextExt, VerticalAlignment, Widget,
};
use geom::{Circle, Distance, Duration, PolyLine, Time};
use map_model::NORMAL_LANE_THICKNESS;
@ -68,20 +68,20 @@ impl TripsVisualizer {
TripsVisualizer {
composite: Composite::new(
ManagedWidget::col(vec![
ManagedWidget::row(vec![
Widget::col(vec![
Widget::row(vec![
Line("Trips Visualizer").roboto_bold().draw(ctx),
Btn::text_fg("X")
.build_def(ctx, hotkey(Key::Escape))
.align_right(),
]),
"Active trips".draw_text(ctx).named("active trips"),
ManagedWidget::row(vec![
Widget::row(vec![
Btn::text_fg("forwards 30 minutes").build_def(ctx, hotkey(Key::RightArrow)),
Btn::text_fg("backwards 30 minutes").build_def(ctx, hotkey(Key::LeftArrow)),
])
.flex_wrap(ctx, 80),
ManagedWidget::slider("time slider"),
Widget::slider("time slider"),
])
.padding(10)
.bg(colors::PANEL_BG),

View File

@ -7,7 +7,7 @@ use crate::managed::{WrappedComposite, WrappedOutcome};
use abstutil::{prettyprint_usize, Counter, MultiMap};
use ezgui::{
hotkey, lctrl, Btn, Choice, Color, Composite, Drawable, EventCtx, GeomBatch, GfxCtx,
HorizontalAlignment, Key, Line, ManagedWidget, Outcome, Slider, Text, VerticalAlignment,
HorizontalAlignment, Key, Line, Outcome, Slider, Text, VerticalAlignment, Widget,
};
use geom::{Distance, Line, PolyLine, Polygon};
use map_model::{BuildingID, IntersectionID, Map};
@ -552,14 +552,14 @@ impl DotMap {
.collect();
DotMap {
composite: Composite::new(
ManagedWidget::col(vec![
ManagedWidget::row(vec![
Widget::col(vec![
Widget::row(vec![
Line("Dot map of all trips").roboto_bold().draw(ctx),
Btn::text_fg("X")
.build_def(ctx, hotkey(Key::Escape))
.align_right(),
]),
ManagedWidget::slider("time slider"),
Widget::slider("time slider"),
])
.padding(10)
.bg(colors::PANEL_BG),

View File

@ -7,7 +7,7 @@ use crate::helpers::ID;
use crate::render::Renderable;
use ezgui::{
hotkey, Btn, Button, Choice, Color, Composite, EventCtx, GfxCtx, HorizontalAlignment, Key,
ManagedWidget, Outcome, RewriteColor, TextExt, VerticalAlignment,
Outcome, RewriteColor, TextExt, VerticalAlignment, Widget,
};
use map_model::{EditCmd, LaneID, LaneType, Map, RoadID};
use std::collections::BTreeSet;
@ -62,7 +62,7 @@ impl LaneEditor {
hotkey(key),
)
} else {
ManagedWidget::draw_svg_transform(
Widget::draw_svg_transform(
ctx,
&format!("../data/system/assets/edit/{}.svg", icon),
RewriteColor::ChangeAll(Color::WHITE.alpha(0.5)),
@ -79,13 +79,13 @@ impl LaneEditor {
)
.draw_text(ctx)
.centered_horiz(),
ManagedWidget::row(row).centered(),
Widget::row(row).centered(),
Btn::text_fg("Finish").build_def(ctx, hotkey(Key::Escape)),
// TODO Not ready for general use
if app.opts.dev {
Btn::text_fg("Edit entire road").build_def(ctx, hotkey(Key::U))
} else {
ManagedWidget::nothing()
Widget::nothing()
},
if app.primary.map.get_edits().original_lts.contains_key(&l)
|| app.primary.map.get_edits().reversed_lanes.contains(&l)
@ -96,7 +96,7 @@ impl LaneEditor {
},
];
let composite = Composite::new(ManagedWidget::col(col).bg(colors::PANEL_BG).padding(10))
let composite = Composite::new(Widget::col(col).bg(colors::PANEL_BG).padding(10))
.aligned(HorizontalAlignment::Center, VerticalAlignment::Top)
.build(ctx);

View File

@ -17,7 +17,7 @@ use crate::sandbox::{GameplayMode, SandboxMode};
use abstutil::Timer;
use ezgui::{
hotkey, lctrl, Btn, Choice, Color, Composite, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment,
Key, Line, ManagedWidget, Outcome, RewriteColor, ScreenRectangle, Text, VerticalAlignment,
Key, Line, Outcome, RewriteColor, ScreenRectangle, Text, VerticalAlignment, Widget,
WrappedWizard,
};
use geom::Polygon;
@ -331,10 +331,10 @@ fn make_topcenter(ctx: &mut EventCtx, app: &App) -> Composite {
// TODO Support redo. Bit harder here to reset the redo_stack when the edits
// change, because nested other places modify it too.
Composite::new(
ManagedWidget::col(vec![
ManagedWidget::row(vec![
Widget::col(vec![
Widget::row(vec![
Line("Editing map").size(26).draw(ctx).margin(5),
ManagedWidget::draw_batch(
Widget::draw_batch(
ctx,
GeomBatch::from(vec![(Color::WHITE, Polygon::rectangle(2.0, 30.0))]),
)
@ -356,7 +356,7 @@ fn make_topcenter(ctx: &mut EventCtx, app: &App) -> Composite {
lctrl(Key::Z),
)
} else {
ManagedWidget::draw_svg_transform(
Widget::draw_svg_transform(
ctx,
"../data/system/assets/tools/undo.svg",
RewriteColor::ChangeAll(Color::WHITE.alpha(0.5)),

View File

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

View File

@ -10,8 +10,8 @@ use crate::sandbox::{spawn_agents_around, SpeedControls, TimePanel};
use abstutil::Timer;
use ezgui::{
hotkey, lctrl, Btn, Choice, Color, Composite, EventCtx, EventLoopMode, GeomBatch, GfxCtx,
HorizontalAlignment, Key, Line, ManagedWidget, Outcome, RewriteColor, Text, TextExt,
VerticalAlignment,
HorizontalAlignment, Key, Line, Outcome, RewriteColor, Text, TextExt, VerticalAlignment,
Widget,
};
use geom::Duration;
use map_model::{
@ -300,7 +300,7 @@ pub fn make_top_panel(ctx: &mut EventCtx, app: &App, can_undo: bool, can_redo: b
(if can_undo {
Btn::svg_def("../data/system/assets/tools/undo.svg").build(ctx, "undo", lctrl(Key::Z))
} else {
ManagedWidget::draw_svg_transform(
Widget::draw_svg_transform(
ctx,
"../data/system/assets/tools/undo.svg",
RewriteColor::ChangeAll(Color::WHITE.alpha(0.5)),
@ -315,7 +315,7 @@ pub fn make_top_panel(ctx: &mut EventCtx, app: &App, can_undo: bool, can_redo: b
lctrl(Key::Y),
)
} else {
ManagedWidget::draw_svg_transform(
Widget::draw_svg_transform(
ctx,
"../data/system/assets/tools/redo.svg",
RewriteColor::ChangeAll(Color::WHITE.alpha(0.5)),
@ -325,10 +325,10 @@ pub fn make_top_panel(ctx: &mut EventCtx, app: &App, can_undo: bool, can_redo: b
if app.opts.dev {
Btn::text_fg("Export").build_def(ctx, None)
} else {
ManagedWidget::nothing()
Widget::nothing()
},
];
Composite::new(ManagedWidget::row(row).bg(colors::PANEL_BG))
Composite::new(Widget::row(row).bg(colors::PANEL_BG))
.aligned(HorizontalAlignment::Center, VerticalAlignment::Top)
.build(ctx)
}
@ -702,7 +702,7 @@ impl PreviewTrafficSignal {
fn new(ctx: &mut EventCtx, app: &App) -> PreviewTrafficSignal {
PreviewTrafficSignal {
composite: Composite::new(
ManagedWidget::col(vec![
Widget::col(vec![
"Previewing traffic signal".draw_text(ctx),
Btn::text_fg("back to editing").build_def(ctx, hotkey(Key::Escape)),
])

View File

@ -2,8 +2,8 @@ use crate::app::App;
use crate::colors;
use crate::game::{DrawBaselayer, State, Transition};
use ezgui::{
hotkey, Btn, Composite, EventCtx, GfxCtx, HorizontalAlignment, Key, Line, ManagedWidget,
MultiKey, Outcome, Text, VerticalAlignment,
hotkey, Btn, Composite, EventCtx, GfxCtx, HorizontalAlignment, Key, Line, MultiKey, Outcome,
Text, VerticalAlignment, Widget,
};
use std::collections::HashMap;
@ -66,8 +66,8 @@ impl WrappedComposite {
actions: Vec<(Option<MultiKey>, &str)>,
) -> Composite {
Composite::new(
ManagedWidget::col(vec![
ManagedWidget::row(vec![
Widget::col(vec![
Widget::row(vec![
Line(title.into()).roboto_bold().draw(ctx),
Btn::text_fg("X")
.build_def(ctx, hotkey(Key::Escape))
@ -80,7 +80,7 @@ impl WrappedComposite {
}
txt.draw(ctx)
},
ManagedWidget::row(
Widget::row(
actions
.into_iter()
.map(|(key, action)| Btn::text_fg(action).build_def(ctx, key))

View File

@ -2,7 +2,7 @@ use crate::app::App;
use crate::colors;
use crate::game::{State, Transition, WizardState};
use ezgui::{
hotkey, Btn, Choice, Composite, EventCtx, GfxCtx, Key, Line, ManagedWidget, Outcome, TextExt,
hotkey, Btn, Choice, Composite, EventCtx, GfxCtx, Key, Line, Outcome, TextExt, Widget,
};
// TODO SimOptions stuff too
@ -70,23 +70,22 @@ impl OptionsPanel {
pub fn new(ctx: &mut EventCtx, app: &App) -> OptionsPanel {
OptionsPanel {
composite: Composite::new(
ManagedWidget::col(vec![
ManagedWidget::row(vec![
Widget::col(vec![
Widget::row(vec![
Line("Settings").roboto_bold().draw(ctx),
Btn::text_fg("X")
.build_def(ctx, hotkey(Key::Escape))
.align_right(),
]),
ManagedWidget::checkbox(ctx, "Enable developer mode", None, app.opts.dev)
.margin(5),
ManagedWidget::checkbox(
Widget::checkbox(ctx, "Enable developer mode", None, app.opts.dev).margin(5),
Widget::checkbox(
ctx,
"Invert direction of vertical scrolling",
None,
ctx.canvas.invert_scroll,
)
.margin(5),
ManagedWidget::checkbox(
Widget::checkbox(
ctx,
"Use touchpad to pan and hold Control to zoom",
None,
@ -94,19 +93,19 @@ impl OptionsPanel {
)
.margin(5),
// TODO Refactor this pattern somehow, using drop-down menus or radio buttons
ManagedWidget::row(vec![
Widget::row(vec![
"Traffic signal rendering:".draw_text(ctx).margin(5),
Btn::text_fg(format!("{}", app.opts.traffic_signal_style.describe()))
.build(ctx, "change traffic signal style", None)
.margin(5),
]),
ManagedWidget::row(vec![
Widget::row(vec![
"Color scheme:".draw_text(ctx).margin(5),
Btn::text_fg(format!("{}", app.opts.cs_name()))
.build(ctx, "change color scheme", None)
.margin(5),
]),
ManagedWidget::row(vec![
Widget::row(vec![
format!(
"Scale factor for text / UI elements (your monitor is {}):",
ctx.monitor_scale_factor()

View File

@ -8,7 +8,7 @@ use crate::managed::{Callback, ManagedGUIState, WrappedComposite, WrappedOutcome
use crate::sandbox::{GameplayMode, SandboxMode, TutorialPointer};
use ezgui::{
hotkey, hotkeys, Btn, Color, Composite, EventCtx, EventLoopMode, GfxCtx, JustDraw, Key, Line,
ManagedWidget, RewriteColor, Text,
RewriteColor, Text, Widget,
};
use geom::{Duration, Line, Pt2D, Speed};
use instant::Instant;
@ -28,7 +28,7 @@ impl TitleScreen {
TitleScreen {
composite: WrappedComposite::new(
Composite::new(
ManagedWidget::col(vec![
Widget::col(vec![
JustDraw::svg(ctx, "../data/system/assets/pregame/logo.svg").margin(5),
// TODO that nicer font
// TODO Any key
@ -80,7 +80,7 @@ pub fn main_menu(ctx: &mut EventCtx, app: &App) -> Box<dyn State> {
txt.add(Line("Created by Dustin Carlino"));
txt.draw(ctx).centered_horiz()
},
ManagedWidget::row(vec![
Widget::row(vec![
Btn::svg(
"../data/system/assets/pregame/tutorial.svg",
RewriteColor::Change(Color::WHITE, colors::HOVERING),
@ -100,15 +100,15 @@ pub fn main_menu(ctx: &mut EventCtx, app: &App) -> Box<dyn State> {
])
.centered(),
if app.opts.dev {
ManagedWidget::row(vec![
Widget::row(vec![
Btn::text_bg2("INTERNAL DEV TOOLS").build_def(ctx, hotkey(Key::M)),
Btn::text_bg2("INTERNAL A/B TEST MODE").build_def(ctx, hotkey(Key::A)),
])
.centered()
} else {
ManagedWidget::nothing()
Widget::nothing()
},
ManagedWidget::col(vec![
Widget::col(vec![
Btn::text_bg2("About A/B Street").build_def(ctx, None),
built_info::time().draw(ctx),
])
@ -116,7 +116,7 @@ pub fn main_menu(ctx: &mut EventCtx, app: &App) -> Box<dyn State> {
];
let mut c = WrappedComposite::new(
Composite::new(ManagedWidget::col(col).evenly_spaced())
Composite::new(Widget::col(col).evenly_spaced())
.exact_size_percent(90, 85)
.build(ctx),
)
@ -244,7 +244,7 @@ fn about(ctx: &mut EventCtx) -> Box<dyn State> {
ManagedGUIState::fullscreen(
WrappedComposite::new(
Composite::new(ManagedWidget::col(col))
Composite::new(Widget::col(col))
.exact_size_percent(90, 85)
.build(ctx),
)
@ -254,7 +254,7 @@ fn about(ctx: &mut EventCtx) -> Box<dyn State> {
fn proposals_picker(ctx: &mut EventCtx) -> Box<dyn State> {
let mut cbs: Vec<(String, Callback)> = Vec::new();
let mut buttons: Vec<ManagedWidget> = Vec::new();
let mut buttons: Vec<Widget> = Vec::new();
for map_name in abstutil::list_all_objects(abstutil::path_all_maps()) {
for (_, edits) in
abstutil::load_all_objects::<MapEdits>(abstutil::path_all_edits(&map_name))
@ -286,7 +286,7 @@ fn proposals_picker(ctx: &mut EventCtx) -> Box<dyn State> {
let mut c = WrappedComposite::new(
Composite::new(
ManagedWidget::col(vec![
Widget::col(vec![
Btn::svg_def("../data/system/assets/pregame/back.svg")
.build(ctx, "back", hotkey(Key::Escape))
.align_left(),
@ -300,7 +300,7 @@ fn proposals_picker(ctx: &mut EventCtx) -> Box<dyn State> {
txt.add(Line("Contact dabreegster@gmail.com to add your idea here!"));
txt.draw(ctx).centered_horiz().bg(colors::PANEL_BG)
},
ManagedWidget::row(buttons)
Widget::row(buttons)
.flex_wrap(ctx, 80)
.bg(colors::PANEL_BG)
.padding(10),

View File

@ -4,8 +4,8 @@ use crate::options::TrafficSignalStyle;
use crate::render::intersection::make_crosswalk;
use crate::render::{DrawTurnGroup, BIG_ARROW_THICKNESS};
use ezgui::{
hotkey, Btn, Color, Composite, EventCtx, GeomBatch, HorizontalAlignment, Key, Line,
ManagedWidget, Prerender, Text, TextExt, VerticalAlignment,
hotkey, Btn, Color, Composite, EventCtx, GeomBatch, HorizontalAlignment, Key, Line, Prerender,
Text, TextExt, VerticalAlignment, Widget,
};
use geom::{Angle, Circle, Distance, Duration, Line, PolyLine, Polygon, Pt2D};
use map_model::{IntersectionID, Phase, TurnPriority};
@ -244,7 +244,7 @@ pub fn make_signal_diagram(
Btn::text_bg2("Edit entire signal").build_def(ctx, hotkey(Key::E)),
]
} else {
vec![ManagedWidget::row(vec![
vec![Widget::row(vec![
txt_widget,
Btn::text_fg("X")
.build_def(ctx, hotkey(Key::Escape))
@ -255,7 +255,7 @@ pub fn make_signal_diagram(
for (idx, phase) in signal.phases.iter().enumerate() {
// Separator
col.push(
ManagedWidget::draw_batch(
Widget::draw_batch(
ctx,
GeomBatch::from(vec![(
Color::WHITE,
@ -270,7 +270,7 @@ pub fn make_signal_diagram(
if edit_mode {
phase_rows.push(
ManagedWidget::row(vec![
Widget::row(vec![
format!("Phase {}: {}", idx + 1, phase.duration).draw_text(ctx),
Btn::svg_def("../data/system/assets/tools/edit.svg")
.build(
@ -323,13 +323,13 @@ pub fn make_signal_diagram(
);
if idx == selected {
col.push(ManagedWidget::col(phase_rows).bg(Color::hex("#2A2A2A")));
col.push(Widget::col(phase_rows).bg(Color::hex("#2A2A2A")));
} else {
col.extend(phase_rows);
}
}
Composite::new(ManagedWidget::col(col).bg(colors::PANEL_BG))
Composite::new(Widget::col(col).bg(colors::PANEL_BG))
.aligned(HorizontalAlignment::Left, VerticalAlignment::Top)
.max_size_percent(30, 85)
.build(ctx)

View File

@ -9,8 +9,8 @@ use crate::sandbox::SandboxMode;
use abstutil::prettyprint_usize;
use abstutil::Counter;
use ezgui::{
hotkey, Btn, Button, Color, Composite, EventCtx, Histogram, Key, Line, ManagedWidget, Plot,
PlotOptions, Series, Text, TextExt,
hotkey, Btn, Button, Color, Composite, EventCtx, Histogram, Key, Line, Plot, PlotOptions,
Series, Text, TextExt, Widget,
};
use geom::{Duration, Statistic, Time};
use map_model::BusRouteID;
@ -58,11 +58,11 @@ pub fn make(ctx: &mut EventCtx, app: &App, tab: Tab) -> Box<dyn State> {
};
let mut c = WrappedComposite::new(
Composite::new(ManagedWidget::col(vec![
Composite::new(Widget::col(vec![
Btn::svg_def("../data/system/assets/pregame/back.svg")
.build(ctx, "back", hotkey(Key::Escape))
.align_left(),
ManagedWidget::row(tabs).bg(colors::PANEL_BG),
Widget::row(tabs).bg(colors::PANEL_BG),
content.bg(colors::PANEL_BG),
]))
// TODO Want to use exact, but then scrolling breaks. exact_size_percent will fix the
@ -87,7 +87,7 @@ pub fn make(ctx: &mut EventCtx, app: &App, tab: Tab) -> Box<dyn State> {
ManagedGUIState::fullscreen(c)
}
fn trips_summary_prebaked(ctx: &EventCtx, app: &App) -> ManagedWidget {
fn trips_summary_prebaked(ctx: &EventCtx, app: &App) -> Widget {
if app.has_prebaked().is_none() {
return trips_summary_not_prebaked(ctx, app);
}
@ -154,7 +154,7 @@ fn trips_summary_prebaked(ctx: &EventCtx, app: &App) -> ManagedWidget {
}
}
ManagedWidget::col(vec![
Widget::col(vec![
txt.draw(ctx),
finished_trips_plot(ctx, app).bg(colors::SECTION_BG),
"Are trips faster or slower than the baseline?".draw_text(ctx),
@ -190,7 +190,7 @@ fn trips_summary_prebaked(ctx: &EventCtx, app: &App) -> ManagedWidget {
])
}
fn trips_summary_not_prebaked(ctx: &EventCtx, app: &App) -> ManagedWidget {
fn trips_summary_not_prebaked(ctx: &EventCtx, app: &App) -> Widget {
let (all, aborted, per_mode) = app
.primary
.sim
@ -233,7 +233,7 @@ fn trips_summary_not_prebaked(ctx: &EventCtx, app: &App) -> ManagedWidget {
}
}
ManagedWidget::col(vec![
Widget::col(vec![
txt.draw(ctx),
finished_trips_plot(ctx, app).bg(colors::SECTION_BG),
Line("Active agents").roboto_bold().draw(ctx),
@ -253,7 +253,7 @@ fn trips_summary_not_prebaked(ctx: &EventCtx, app: &App) -> ManagedWidget {
])
}
fn finished_trips_plot(ctx: &EventCtx, app: &App) -> ManagedWidget {
fn finished_trips_plot(ctx: &EventCtx, app: &App) -> Widget {
let mut lines: Vec<(String, Color, Option<TripMode>)> = TripMode::all()
.into_iter()
.map(|m| (m.to_string(), color_for_mode(m, app), Some(m)))
@ -305,10 +305,10 @@ fn finished_trips_plot(ctx: &EventCtx, app: &App) -> ManagedWidget {
.collect(),
PlotOptions::new(),
);
ManagedWidget::col(vec!["finished trips".draw_text(ctx), plot.margin(10)])
Widget::col(vec!["finished trips".draw_text(ctx), plot.margin(10)])
}
fn pick_finished_trips_mode(ctx: &EventCtx) -> (ManagedWidget, Vec<(String, Callback)>) {
fn pick_finished_trips_mode(ctx: &EventCtx) -> (Widget, Vec<(String, Callback)>) {
let mut buttons = Vec::new();
let mut cbs: Vec<(String, Callback)> = Vec::new();
@ -326,14 +326,14 @@ fn pick_finished_trips_mode(ctx: &EventCtx) -> (ManagedWidget, Vec<(String, Call
));
}
(ManagedWidget::row(buttons).flex_wrap(ctx, 80), cbs)
(Widget::row(buttons).flex_wrap(ctx, 80), cbs)
}
fn pick_finished_trips(
mode: TripMode,
ctx: &EventCtx,
app: &App,
) -> (ManagedWidget, Vec<(String, Callback)>) {
) -> (Widget, Vec<(String, Callback)>) {
let mut buttons = Vec::new();
let mut cbs: Vec<(String, Callback)> = Vec::new();
@ -373,15 +373,12 @@ fn pick_finished_trips(
cbs.extend(more_cbs);
(
ManagedWidget::col(vec![
mode_picker,
ManagedWidget::row(buttons).flex_wrap(ctx, 80),
]),
Widget::col(vec![mode_picker, Widget::row(buttons).flex_wrap(ctx, 80)]),
cbs,
)
}
fn parking_overhead(ctx: &EventCtx, app: &App) -> ManagedWidget {
fn parking_overhead(ctx: &EventCtx, app: &App) -> Widget {
let mut txt = Text::new();
for line in app.primary.sim.get_analytics().analyze_parking_phases() {
txt.add_wrapped(line, 0.9 * ctx.canvas.window_width);
@ -389,7 +386,7 @@ fn parking_overhead(ctx: &EventCtx, app: &App) -> ManagedWidget {
txt.draw(ctx)
}
fn pick_bus_route(ctx: &EventCtx, app: &App) -> (ManagedWidget, Vec<(String, Callback)>) {
fn pick_bus_route(ctx: &EventCtx, app: &App) -> (Widget, Vec<(String, Callback)>) {
let mut buttons = Vec::new();
let mut cbs: Vec<(String, Callback)> = Vec::new();
@ -416,7 +413,7 @@ fn pick_bus_route(ctx: &EventCtx, app: &App) -> (ManagedWidget, Vec<(String, Cal
));
}
(ManagedWidget::row(buttons).flex_wrap(ctx, 80), cbs)
(Widget::row(buttons).flex_wrap(ctx, 80), cbs)
}
// TODO Refactor

View File

@ -9,7 +9,7 @@ use crate::sandbox::SandboxControls;
use crate::sandbox::SandboxMode;
use ezgui::{
hotkey, lctrl, Btn, Choice, Color, Composite, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment,
Key, Line, ManagedWidget, ScreenRectangle, Text, VerticalAlignment,
Key, Line, ScreenRectangle, Text, VerticalAlignment, Widget,
};
use geom::Polygon;
use map_model::IntersectionID;
@ -83,9 +83,9 @@ pub fn freeform_controller(
scenario_name: &str,
) -> WrappedComposite {
let c = Composite::new(
ManagedWidget::row(vec![
Widget::row(vec![
Line("Sandbox").size(26).draw(ctx).margin(5),
ManagedWidget::draw_batch(
Widget::draw_batch(
ctx,
GeomBatch::from(vec![(Color::WHITE, Polygon::rectangle(2.0, 50.0))]),
)

View File

@ -21,7 +21,7 @@ use crate::sandbox::{SandboxControls, SandboxMode, ScoreCard};
use abstutil::Timer;
use ezgui::{
lctrl, Btn, Color, Composite, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line,
ManagedWidget, Outcome, Text, VerticalAlignment,
Outcome, Text, VerticalAlignment, Widget,
};
use geom::{Duration, Polygon};
use map_model::{EditCmd, EditIntersection, Map, MapEdits};
@ -254,7 +254,7 @@ fn challenge_controller(
ctx: &mut EventCtx,
gameplay: GameplayMode,
title: &str,
extra_rows: Vec<ManagedWidget>,
extra_rows: Vec<Widget>,
) -> WrappedComposite {
// Scrape the description
let mut description = Vec::new();
@ -267,12 +267,12 @@ fn challenge_controller(
}
}
let mut rows = vec![ManagedWidget::row(vec![
let mut rows = vec![Widget::row(vec![
Line(title).size(26).draw(ctx).margin(5),
Btn::svg_def("../data/system/assets/tools/info.svg")
.build(ctx, "instructions", None)
.margin(5),
ManagedWidget::draw_batch(
Widget::draw_batch(
ctx,
GeomBatch::from(vec![(Color::WHITE, Polygon::rectangle(2.0, 50.0))]),
)
@ -285,7 +285,7 @@ fn challenge_controller(
rows.extend(extra_rows);
WrappedComposite::new(
Composite::new(ManagedWidget::col(rows).bg(colors::PANEL_BG))
Composite::new(Widget::col(rows).bg(colors::PANEL_BG))
.aligned(HorizontalAlignment::Center, VerticalAlignment::Top)
.build(ctx),
)
@ -326,7 +326,7 @@ impl FinalScore {
if next.is_some() {
Btn::text_fg("next challenge").build_def(ctx, None)
} else {
ManagedWidget::nothing()
Widget::nothing()
},
Btn::text_fg("try again").build_def(ctx, None),
Btn::text_fg("back to challenges").build_def(ctx, None),
@ -334,7 +334,7 @@ impl FinalScore {
Box::new(FinalScore {
composite: Composite::new(
ManagedWidget::col(vec![txt.draw(ctx), ManagedWidget::row(row).centered()])
Widget::col(vec![txt.draw(ctx), Widget::row(row).centered()])
.bg(colors::PANEL_BG)
.outline(10.0, Color::WHITE)
.padding(10),

View File

@ -7,8 +7,8 @@ use crate::sandbox::gameplay::freeform::Freeform;
use crate::sandbox::SandboxMode;
use abstutil::Timer;
use ezgui::{
hotkey, Btn, Composite, EventCtx, GfxCtx, HorizontalAlignment, Key, Line, ManagedWidget,
Outcome, Text, TextExt, VerticalAlignment,
hotkey, Btn, Composite, EventCtx, GfxCtx, HorizontalAlignment, Key, Line, Outcome, Text,
TextExt, VerticalAlignment, Widget,
};
use geom::{Distance, Duration, PolyLine};
use map_model::{
@ -704,8 +704,8 @@ fn create_swarm(app: &mut App, from: LaneID, to: LaneID, count: usize, duration:
fn make_top_bar(ctx: &mut EventCtx, title: &str, howto: &str) -> Composite {
Composite::new(
ManagedWidget::col(vec![
ManagedWidget::row(vec![
Widget::col(vec![
Widget::row(vec![
Line(title).roboto_bold().draw(ctx),
Btn::text_fg("X")
.build_def(ctx, hotkey(Key::Escape))

View File

@ -12,8 +12,8 @@ use crate::sandbox::{
use abstutil::Timer;
use ezgui::{
hotkey, hotkeys, lctrl, Btn, Button, Color, Composite, EventCtx, GeomBatch, GfxCtx,
HorizontalAlignment, Key, Line, ManagedWidget, Outcome, RewriteColor, ScreenPt, Text, TextExt,
VerticalAlignment,
HorizontalAlignment, Key, Line, Outcome, RewriteColor, ScreenPt, Text, TextExt,
VerticalAlignment, Widget,
};
use geom::{Distance, Duration, PolyLine, Polygon, Pt2D, Statistic, Time};
use map_model::{BuildingID, IntersectionID, IntersectionType, LaneType, Map, RoadID};
@ -886,9 +886,9 @@ impl TutorialState {
}
fn make_top_center(&self, ctx: &mut EventCtx, edit_map: bool) -> Composite {
let mut col = vec![ManagedWidget::row(vec![
let mut col = vec![Widget::row(vec![
Line("Tutorial").size(26).draw(ctx).margin(5),
ManagedWidget::draw_batch(
Widget::draw_batch(
ctx,
GeomBatch::from(vec![(Color::WHITE, Polygon::rectangle(2.0, 50.0))]),
)
@ -917,7 +917,7 @@ impl TutorialState {
{
let task = self.interaction();
if task != Task::Nil {
col.push(ManagedWidget::row(vec![
col.push(Widget::row(vec![
Text::from(
Line(format!(
"Task {}: {}",
@ -945,7 +945,7 @@ impl TutorialState {
);
}
Composite::new(ManagedWidget::col(col).bg(colors::PANEL_BG))
Composite::new(Widget::col(col).bg(colors::PANEL_BG))
.aligned(HorizontalAlignment::Center, VerticalAlignment::Top)
.build(ctx)
}
@ -989,7 +989,7 @@ impl TutorialState {
}
txt.draw(ctx)
},
ManagedWidget::row(vec![
Widget::row(vec![
if self.current.part > 0 {
Btn::svg(
"../data/system/assets/tools/prev.svg",
@ -998,7 +998,7 @@ impl TutorialState {
.build(ctx, "previous message", hotkey(Key::LeftArrow))
.margin(5)
} else {
ManagedWidget::draw_svg_transform(
Widget::draw_svg_transform(
ctx,
"../data/system/assets/tools/prev.svg",
RewriteColor::ChangeAll(Color::WHITE.alpha(0.5)),
@ -1009,7 +1009,7 @@ impl TutorialState {
.centered_vert()
.margin(5),
if self.current.part == self.stage().messages.len() - 1 {
ManagedWidget::draw_svg_transform(
Widget::draw_svg_transform(
ctx,
"../data/system/assets/tools/next.svg",
RewriteColor::ChangeAll(Color::WHITE.alpha(0.5)),
@ -1038,7 +1038,7 @@ impl TutorialState {
Some(
Composite::new(
ManagedWidget::col(col)
Widget::col(col)
.centered()
.bg(colors::PANEL_BG)
.outline(5.0, Color::WHITE)

View File

@ -18,8 +18,7 @@ use crate::render::AgentColorScheme;
pub use crate::sandbox::gameplay::{TutorialPointer, TutorialState};
use ezgui::{
hotkey, lctrl, Btn, Choice, Color, Composite, EventCtx, EventLoopMode, GeomBatch, GfxCtx,
HorizontalAlignment, Key, Line, ManagedWidget, Outcome, Text, TextExt, VerticalAlignment,
Wizard,
HorizontalAlignment, Key, Line, Outcome, Text, TextExt, VerticalAlignment, Widget, Wizard,
};
pub use gameplay::spawner::spawn_agents_around;
pub use gameplay::GameplayMode;
@ -362,30 +361,30 @@ impl AgentMeter {
let mut rows = vec![
"Active agents".draw_text(ctx),
ManagedWidget::row(vec![
ManagedWidget::draw_svg(ctx, "../data/system/assets/meters/pedestrian.svg"),
Widget::row(vec![
Widget::draw_svg(ctx, "../data/system/assets/meters/pedestrian.svg"),
prettyprint_usize(by_mode[&TripMode::Walk]).draw_text(ctx),
ManagedWidget::draw_svg(ctx, "../data/system/assets/meters/bike.svg"),
Widget::draw_svg(ctx, "../data/system/assets/meters/bike.svg"),
prettyprint_usize(by_mode[&TripMode::Bike]).draw_text(ctx),
ManagedWidget::draw_svg(ctx, "../data/system/assets/meters/car.svg"),
Widget::draw_svg(ctx, "../data/system/assets/meters/car.svg"),
prettyprint_usize(by_mode[&TripMode::Drive]).draw_text(ctx),
ManagedWidget::draw_svg(ctx, "../data/system/assets/meters/bus.svg"),
Widget::draw_svg(ctx, "../data/system/assets/meters/bus.svg"),
prettyprint_usize(by_mode[&TripMode::Transit]).draw_text(ctx),
])
.centered(),
// TODO Not sure about this one yet
if app.opts.dev {
ManagedWidget::row(vec![
ManagedWidget::draw_svg(ctx, "../data/system/assets/tools/home.svg"),
Widget::row(vec![
Widget::draw_svg(ctx, "../data/system/assets/tools/home.svg"),
prettyprint_usize(ppl_in_bldg).draw_text(ctx),
format!("Off-map: {}", prettyprint_usize(ppl_off_map)).draw_text(ctx),
])
.centered()
} else {
ManagedWidget::nothing()
Widget::nothing()
},
// Separator
ManagedWidget::draw_batch(
Widget::draw_batch(
ctx,
GeomBatch::from(vec![(
Color::WHITE,
@ -409,14 +408,14 @@ impl AgentMeter {
txt.draw(ctx)
},
{
ManagedWidget::row(vec![
Widget::row(vec![
Btn::text_bg2("more data").build_def(ctx, hotkey(Key::Q)),
if app.has_prebaked().is_some() {
Btn::svg_def("../data/system/assets/meters/trip_histogram.svg")
.build(ctx, "compare trips to baseline", None)
.align_right()
} else {
ManagedWidget::nothing()
Widget::nothing()
},
])
.centered()
@ -428,7 +427,7 @@ impl AgentMeter {
if let Some(ScoreCard { stat, goal }) = show_score {
// Separator
rows.push(
ManagedWidget::draw_batch(
Widget::draw_batch(
ctx,
GeomBatch::from(vec![(
Color::WHITE,
@ -459,7 +458,7 @@ impl AgentMeter {
}
}
let composite = Composite::new(ManagedWidget::col(rows).bg(colors::PANEL_BG).padding(20))
let composite = Composite::new(Widget::col(rows).bg(colors::PANEL_BG).padding(20))
.aligned(HorizontalAlignment::Right, VerticalAlignment::Top)
.build(ctx);

View File

@ -7,8 +7,8 @@ use crate::managed::{WrappedComposite, WrappedOutcome};
use crate::sandbox::{GameplayMode, SandboxMode};
use ezgui::{
hotkey, Btn, Color, Composite, EventCtx, EventLoopMode, GeomBatch, GfxCtx, HorizontalAlignment,
Key, Line, ManagedWidget, Outcome, Plot, PlotOptions, RewriteColor, Series, Slider, Text,
VerticalAlignment,
Key, Line, Outcome, Plot, PlotOptions, RewriteColor, Series, Slider, Text, VerticalAlignment,
Widget,
};
use geom::{Duration, Polygon, Time};
use instant::Instant;
@ -56,7 +56,7 @@ impl SpeedControls {
);
row.push(
ManagedWidget::row(
Widget::row(
vec![
(SpeedSetting::Realtime, "real-time speed"),
(SpeedSetting::Fast, "5x speed"),
@ -95,7 +95,7 @@ impl SpeedControls {
);
row.push(
ManagedWidget::row(
Widget::row(
vec![
Btn::custom(
Text::from(Line("+1h").fg(Color::WHITE).size(21).roboto()).render_ctx(ctx),
@ -143,8 +143,7 @@ impl SpeedControls {
WrappedComposite::new(
Composite::new(
ManagedWidget::row(row.into_iter().map(|x| x.margin(5)).collect())
.bg(colors::PANEL_BG),
Widget::row(row.into_iter().map(|x| x.margin(5)).collect()).bg(colors::PANEL_BG),
)
.aligned(
HorizontalAlignment::Center,
@ -356,7 +355,7 @@ impl JumpToTime {
target,
maybe_mode,
composite: Composite::new(
ManagedWidget::col(vec![
Widget::col(vec![
Btn::text_fg("X")
.build_def(ctx, hotkey(Key::Escape))
.align_right(),
@ -366,17 +365,17 @@ impl JumpToTime {
txt.draw(ctx)
}
.named("target time"),
ManagedWidget::slider("time slider").margin(10),
ManagedWidget::row(vec![
Widget::slider("time slider").margin(10),
Widget::row(vec![
Line("00:00").size(12).roboto().draw(ctx),
ManagedWidget::draw_svg(ctx, "../data/system/assets/speed/sunrise.svg"),
Widget::draw_svg(ctx, "../data/system/assets/speed/sunrise.svg"),
Line("12:00").size(12).roboto().draw(ctx),
ManagedWidget::draw_svg(ctx, "../data/system/assets/speed/sunset.svg"),
Widget::draw_svg(ctx, "../data/system/assets/speed/sunset.svg"),
Line("24:00").size(12).roboto().draw(ctx),
])
.padding(10)
.evenly_spaced(),
ManagedWidget::checkbox(ctx, "Stop when there's a traffic jam", None, false)
Widget::checkbox(ctx, "Stop when there's a traffic jam", None, false)
.padding(10)
.margin(10),
Btn::text_bg2("Go!")
@ -503,7 +502,7 @@ impl TimeWarpScreen {
started: Instant::now(),
traffic_jams,
composite: Composite::new(
ManagedWidget::col(vec![
Widget::col(vec![
Text::new().draw(ctx).named("text"),
Btn::text_bg2("stop now")
.build_def(ctx, hotkey(Key::Escape))
@ -598,7 +597,7 @@ impl TimePanel {
TimePanel {
time: app.primary.sim.time(),
composite: Composite::new(
ManagedWidget::col(vec![
Widget::col(vec![
Text::from(Line(app.primary.sim.time().ampm_tostring()).size(30))
.draw(ctx)
.margin(10)
@ -619,13 +618,13 @@ impl TimePanel {
Polygon::rectangle(percent * width, height),
);
}
ManagedWidget::draw_batch(ctx, batch)
Widget::draw_batch(ctx, batch)
},
ManagedWidget::row(vec![
Widget::row(vec![
Line("00:00").size(12).roboto().draw(ctx),
ManagedWidget::draw_svg(ctx, "../data/system/assets/speed/sunrise.svg"),
Widget::draw_svg(ctx, "../data/system/assets/speed/sunrise.svg"),
Line("12:00").size(12).roboto().draw(ctx),
ManagedWidget::draw_svg(ctx, "../data/system/assets/speed/sunset.svg"),
Widget::draw_svg(ctx, "../data/system/assets/speed/sunset.svg"),
Line("24:00").size(12).roboto().draw(ctx),
])
.padding(10)