mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-29 17:34:58 +03:00
adjust plot axes and mouseover
This commit is contained in:
parent
db65e1d41f
commit
4f79339b0f
@ -242,7 +242,7 @@ impl<'a> GfxCtx<'a> {
|
||||
txt: Text,
|
||||
(horiz, vert): (HorizontalAlignment, VerticalAlignment),
|
||||
) {
|
||||
let batch = txt.render(&self.prerender.assets);
|
||||
let batch = txt.render_g(self);
|
||||
let dims = batch.get_dims();
|
||||
let top_left = self.canvas.align_window(dims, horiz, vert);
|
||||
|
||||
@ -253,7 +253,7 @@ impl<'a> GfxCtx<'a> {
|
||||
}
|
||||
|
||||
pub(crate) fn draw_blocking_text_at_screenspace_topleft(&mut self, txt: Text, pt: ScreenPt) {
|
||||
let batch = txt.render(&self.prerender.assets);
|
||||
let batch = txt.render_g(self);
|
||||
self.canvas
|
||||
.mark_covered_area(ScreenRectangle::top_left(pt, batch.get_dims()));
|
||||
let draw = self.upload(batch);
|
||||
@ -262,7 +262,7 @@ impl<'a> GfxCtx<'a> {
|
||||
|
||||
// TODO Rename these draw_nonblocking_text_*
|
||||
pub fn draw_text_at(&mut self, txt: Text, map_pt: Pt2D) {
|
||||
let batch = txt.render(&self.prerender.assets);
|
||||
let batch = txt.render_g(self);
|
||||
let dims = batch.get_dims();
|
||||
let pt = self.canvas.map_to_screen(map_pt);
|
||||
let draw = self.upload(batch);
|
||||
@ -273,7 +273,7 @@ impl<'a> GfxCtx<'a> {
|
||||
}
|
||||
|
||||
pub fn draw_mouse_tooltip(&mut self, txt: Text) {
|
||||
let txt_batch = txt.render(&self.prerender.assets);
|
||||
let txt_batch = txt.render_g(self);
|
||||
let dims = txt_batch.get_dims();
|
||||
// TODO Maybe also consider the cursor as a valid center
|
||||
let pt = dims.top_left_for_corner(
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::assets::Assets;
|
||||
use crate::{svg, Color, GeomBatch, GfxCtx, Prerender, ScreenDims};
|
||||
use crate::{svg, Color, EventCtx, GeomBatch, GfxCtx, Prerender, ScreenDims};
|
||||
use geom::Polygon;
|
||||
use std::collections::hash_map::DefaultHasher;
|
||||
use std::fmt::Write;
|
||||
@ -193,6 +193,9 @@ impl Text {
|
||||
pub fn render_g(self, g: &GfxCtx) -> GeomBatch {
|
||||
self.render(&g.prerender.assets)
|
||||
}
|
||||
pub fn render_ctx(self, ctx: &EventCtx) -> GeomBatch {
|
||||
self.render(&ctx.prerender.assets)
|
||||
}
|
||||
|
||||
pub(crate) fn inner_render(self, assets: &Assets, tolerance: f32) -> GeomBatch {
|
||||
let hash_key = self.hash_key();
|
||||
|
@ -201,7 +201,7 @@ impl Button {
|
||||
const HORIZ_PADDING: f64 = 30.0;
|
||||
const VERT_PADDING: f64 = 10.0;
|
||||
|
||||
let txt_batch = text.render(&ctx.prerender.assets);
|
||||
let txt_batch = text.render_ctx(ctx);
|
||||
let dims = txt_batch.get_dims();
|
||||
let geom = Polygon::rounded_rectangle(
|
||||
dims.width + 2.0 * HORIZ_PADDING,
|
||||
@ -231,9 +231,9 @@ impl Button {
|
||||
let horiz_padding = if padding { 15.0 } else { 0.0 };
|
||||
let vert_padding = if padding { 8.0 } else { 0.0 };
|
||||
|
||||
let unselected_batch = unselected_text.render(&ctx.prerender.assets);
|
||||
let unselected_batch = unselected_text.render_ctx(ctx);
|
||||
let dims = unselected_batch.get_dims();
|
||||
let selected_batch = selected_text.render(&ctx.prerender.assets);
|
||||
let selected_batch = selected_text.render_ctx(ctx);
|
||||
assert_eq!(dims, selected_batch.get_dims());
|
||||
let geom = Polygon::rectangle(
|
||||
dims.width + 2.0 * horiz_padding,
|
||||
@ -250,9 +250,7 @@ impl Button {
|
||||
|
||||
// TODO Extreme wackiness.
|
||||
pub fn inactive_btn(ctx: &EventCtx, txt: Text) -> ManagedWidget {
|
||||
let txt_batch = txt
|
||||
.change_fg(Color::grey(0.5))
|
||||
.render(&ctx.prerender.assets);
|
||||
let txt_batch = txt.change_fg(Color::grey(0.5)).render_ctx(ctx);
|
||||
let dims = txt_batch.get_dims();
|
||||
|
||||
let horiz_padding = 15.0;
|
||||
@ -277,7 +275,7 @@ impl Button {
|
||||
const HORIZ_PADDING: f64 = 30.0;
|
||||
const VERT_PADDING: f64 = 10.0;
|
||||
|
||||
let txt = Text::from(Line(label).fg(Color::BLACK)).render(&ctx.prerender.assets);
|
||||
let txt = Text::from(Line(label).fg(Color::BLACK)).render_ctx(ctx);
|
||||
let dims = txt.get_dims();
|
||||
let mut batch = GeomBatch::from(vec![(
|
||||
Color::WHITE,
|
||||
|
@ -50,7 +50,7 @@ impl JustDraw {
|
||||
}
|
||||
|
||||
pub fn text(ctx: &EventCtx, text: Text) -> ManagedWidget {
|
||||
JustDraw::wrap(ctx, text.render(&ctx.prerender.assets))
|
||||
JustDraw::wrap(ctx, text.render_ctx(ctx))
|
||||
}
|
||||
|
||||
pub(crate) fn draw(&self, g: &mut GfxCtx) {
|
||||
|
@ -4,7 +4,7 @@ use crate::{
|
||||
ScreenRectangle, Text,
|
||||
};
|
||||
use abstutil::prettyprint_usize;
|
||||
use geom::{Bounds, Circle, Distance, Duration, FindClosest, PolyLine, Pt2D, Time};
|
||||
use geom::{Angle, Bounds, Circle, Distance, Duration, FindClosest, PolyLine, Pt2D, Time};
|
||||
|
||||
// The X is always time
|
||||
pub struct Plot<T> {
|
||||
@ -162,12 +162,14 @@ impl<T: 'static + Ord + PartialEq + Copy + core::fmt::Debug + Yvalue<T>> Plot<T>
|
||||
for i in 0..num_x_labels {
|
||||
let percent_x = (i as f64) / ((num_x_labels - 1) as f64);
|
||||
let t = max_x.percent_of(percent_x);
|
||||
row.push(ManagedWidget::draw_text(
|
||||
ctx,
|
||||
Text::from(Line(t.to_string())),
|
||||
));
|
||||
// TODO Need ticks now to actually see where this goes
|
||||
let mut batch = GeomBatch::new();
|
||||
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()));
|
||||
}
|
||||
let x_axis = ManagedWidget::row(row);
|
||||
let x_axis = ManagedWidget::row(row).padding(10);
|
||||
|
||||
let num_y_labels = 4;
|
||||
let mut col = Vec::new();
|
||||
@ -179,7 +181,7 @@ impl<T: 'static + Ord + PartialEq + Copy + core::fmt::Debug + Yvalue<T>> Plot<T>
|
||||
));
|
||||
}
|
||||
col.reverse();
|
||||
let y_axis = ManagedWidget::col(col);
|
||||
let y_axis = ManagedWidget::col(col).padding(10);
|
||||
|
||||
(plot, legend, x_axis, y_axis)
|
||||
}
|
||||
@ -189,7 +191,7 @@ impl<T: 'static + Ord + PartialEq + Copy + core::fmt::Debug + Yvalue<T>> Plot<T>
|
||||
|
||||
if let Some(cursor) = g.canvas.get_cursor_in_screen_space() {
|
||||
if ScreenRectangle::top_left(self.top_left, self.dims).contains(cursor) {
|
||||
let radius = Distance::meters(5.0);
|
||||
let radius = Distance::meters(15.0);
|
||||
let mut txt = Text::new().bg(Color::BLACK);
|
||||
for (label, pt, _) in self.closest.all_close_pts(
|
||||
Pt2D::new(cursor.x - self.top_left.x, cursor.y - self.top_left.y),
|
||||
|
Loading…
Reference in New Issue
Block a user