mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-28 03:35:51 +03:00
tiny refactor of rounded_rectangle. pad time panel
This commit is contained in:
parent
c4c4a5be08
commit
67ebb76f94
@ -424,24 +424,13 @@ impl ManagedWidget {
|
||||
{
|
||||
let mut batch = GeomBatch::new();
|
||||
if let Some(c) = self.style.bg_color {
|
||||
batch.push(
|
||||
c,
|
||||
Polygon::rounded_rectangle(
|
||||
Distance::meters(width),
|
||||
Distance::meters(height),
|
||||
Distance::meters(5.0),
|
||||
),
|
||||
);
|
||||
batch.push(c, Polygon::rounded_rectangle(width, height, 5.0));
|
||||
}
|
||||
if let Some(c) = self.style.outline_color {
|
||||
batch.push(
|
||||
c,
|
||||
Polygon::rounded_rectangle(
|
||||
Distance::meters(width),
|
||||
Distance::meters(height),
|
||||
Distance::meters(5.0),
|
||||
)
|
||||
.to_outline(Distance::meters(10.0)),
|
||||
Polygon::rounded_rectangle(width, height, 5.0)
|
||||
.to_outline(Distance::meters(10.0)),
|
||||
);
|
||||
}
|
||||
self.bg = Some(DrawBoth::new(ctx, batch, Vec::new()));
|
||||
|
@ -4,7 +4,7 @@ use crate::{
|
||||
text, Color, DrawBoth, EventCtx, GeomBatch, GfxCtx, Line, MultiKey, RewriteColor, ScreenDims,
|
||||
ScreenPt, Text,
|
||||
};
|
||||
use geom::{Distance, Polygon};
|
||||
use geom::Polygon;
|
||||
|
||||
pub struct Button {
|
||||
pub action: String,
|
||||
@ -138,9 +138,9 @@ impl Button {
|
||||
let img_rect =
|
||||
Polygon::rectangle(dims.width, dims.height).translate(HORIZ_PADDING, VERT_PADDING);
|
||||
let bg = Polygon::rounded_rectangle(
|
||||
Distance::meters(dims.width + 2.0 * HORIZ_PADDING),
|
||||
Distance::meters(dims.height + 2.0 * VERT_PADDING),
|
||||
Distance::meters(VERT_PADDING),
|
||||
dims.width + 2.0 * HORIZ_PADDING,
|
||||
dims.height + 2.0 * VERT_PADDING,
|
||||
VERT_PADDING,
|
||||
);
|
||||
|
||||
let normal = DrawBoth::new(
|
||||
@ -246,9 +246,9 @@ impl Button {
|
||||
) -> Button {
|
||||
let dims = ctx.text_dims(&text);
|
||||
let geom = Polygon::rounded_rectangle(
|
||||
Distance::meters(dims.width + 2.0 * HORIZ_PADDING),
|
||||
Distance::meters(dims.height + 2.0 * VERT_PADDING),
|
||||
Distance::meters(VERT_PADDING),
|
||||
dims.width + 2.0 * HORIZ_PADDING,
|
||||
dims.height + 2.0 * VERT_PADDING,
|
||||
VERT_PADDING,
|
||||
);
|
||||
let draw_text = vec![(text, ScreenPt::new(HORIZ_PADDING, VERT_PADDING))];
|
||||
|
||||
|
@ -628,14 +628,7 @@ impl Overlays {
|
||||
|
||||
let y_len = ctx.default_line_height() * (route.stops.len() as f64);
|
||||
let mut batch = GeomBatch::new();
|
||||
batch.push(
|
||||
Color::CYAN,
|
||||
Polygon::rounded_rectangle(
|
||||
Distance::meters(15.0),
|
||||
Distance::meters(y_len),
|
||||
Distance::meters(4.0),
|
||||
),
|
||||
);
|
||||
batch.push(Color::CYAN, Polygon::rounded_rectangle(15.0, y_len, 4.0));
|
||||
for (_, stop_idx, percent_next_stop) in ui.primary.sim.status_of_buses(route.id) {
|
||||
// TODO Line it up right in the middle of the line of text. This is probably a bit wrong.
|
||||
let base_percent_y = if stop_idx == route.stops.len() - 1 {
|
||||
|
@ -5,7 +5,7 @@ use ezgui::{
|
||||
hotkey, Button, Color, EventCtx, EventLoopMode, GeomBatch, GfxCtx, HorizontalAlignment, Key,
|
||||
Line, ManagedWidget, RewriteColor, Text, VerticalAlignment, Wizard,
|
||||
};
|
||||
use geom::{Distance, Duration, Line, Pt2D, Time};
|
||||
use geom::{Duration, Polygon, Time};
|
||||
use std::time::Instant;
|
||||
|
||||
pub struct SpeedControls {
|
||||
@ -387,32 +387,29 @@ impl TimePanel {
|
||||
time: ui.primary.sim.time(),
|
||||
composite: ezgui::Composite::new(
|
||||
ManagedWidget::col(vec![
|
||||
ManagedWidget::draw_text(
|
||||
ManagedWidget::row(vec![ManagedWidget::draw_text(
|
||||
ctx,
|
||||
Text::from(Line(ui.primary.sim.time().ampm_tostring()).size(30)),
|
||||
)
|
||||
.centered(),
|
||||
.centered()])
|
||||
.padding(10),
|
||||
{
|
||||
let mut batch = GeomBatch::new();
|
||||
// This is manually tuned
|
||||
let width = 300.0;
|
||||
let y1 = 5.0;
|
||||
let height = Distance::meters(15.0);
|
||||
let height = 15.0;
|
||||
// Just clamp past 24 hours
|
||||
let percent = ui.primary.sim.time().to_percent(Time::END_OF_DAY).min(1.0);
|
||||
|
||||
// TODO rounded
|
||||
batch.push(
|
||||
Color::WHITE,
|
||||
Line::new(Pt2D::new(0.0, y1), Pt2D::new(width, y1))
|
||||
.make_polygons(height),
|
||||
);
|
||||
if let Some(l) =
|
||||
Line::maybe_new(Pt2D::new(0.0, y1), Pt2D::new(percent * width, y1))
|
||||
{
|
||||
batch.push(Color::grey(0.5), l.make_polygons(height));
|
||||
batch.push(Color::WHITE, Polygon::rectangle(width, height));
|
||||
if percent != 0.0 {
|
||||
batch.push(
|
||||
Color::grey(0.5),
|
||||
Polygon::rectangle(percent * width, height),
|
||||
);
|
||||
}
|
||||
ManagedWidget::draw_batch(ctx, batch).padding(5)
|
||||
ManagedWidget::draw_batch(ctx, batch)
|
||||
},
|
||||
ManagedWidget::row(vec![
|
||||
ManagedWidget::draw_text(ctx, Text::from(Line("00:00").size(12).roboto())),
|
||||
@ -421,10 +418,11 @@ impl TimePanel {
|
||||
ManagedWidget::draw_svg(ctx, "assets/speed/sunset.svg"),
|
||||
ManagedWidget::draw_text(ctx, Text::from(Line("24:00").size(12).roboto())),
|
||||
])
|
||||
.padding(10)
|
||||
.evenly_spaced(),
|
||||
])
|
||||
.bg(Color::hex("#4C4C4C"))
|
||||
.padding(10),
|
||||
.padding(10)
|
||||
.bg(Color::hex("#4C4C4C")),
|
||||
)
|
||||
.aligned(HorizontalAlignment::Left, VerticalAlignment::Top)
|
||||
.build(ctx),
|
||||
|
@ -229,14 +229,11 @@ impl Polygon {
|
||||
Some(Polygon::rectangle(width, height).translate(x1, y1))
|
||||
}
|
||||
|
||||
// Top-left at the origin; use translate
|
||||
pub fn rounded_rectangle(width: Distance, height: Distance, radius: Distance) -> Polygon {
|
||||
assert!(2.0 * radius <= width);
|
||||
assert!(2.0 * radius <= height);
|
||||
// Top-left at the origin. Doesn't take Distance, because this is usually pixels, actually.
|
||||
pub fn rounded_rectangle(w: f64, h: f64, r: f64) -> Polygon {
|
||||
assert!(2.0 * r <= w);
|
||||
assert!(2.0 * r <= h);
|
||||
|
||||
let w = width.inner_meters();
|
||||
let h = height.inner_meters();
|
||||
let r = radius.inner_meters();
|
||||
let mut pts = vec![];
|
||||
|
||||
const RESOLUTION: usize = 5;
|
||||
@ -245,7 +242,7 @@ impl Polygon {
|
||||
let angle = Angle::new_degs(
|
||||
angle1_degs + (angle2_degs - angle1_degs) * ((i as f64) / (RESOLUTION as f64)),
|
||||
);
|
||||
pts.push(center.project_away(radius, angle.invert_y()));
|
||||
pts.push(center.project_away(Distance::meters(r), angle.invert_y()));
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user