draw text beneath Sliders, not in the ModalMenu

This commit is contained in:
Dustin Carlino 2019-06-20 14:26:49 -07:00
parent 220d3d57ab
commit 6738de2488
7 changed files with 53 additions and 56 deletions

View File

@ -91,7 +91,6 @@ impl ABTestMode {
));
}
txt.add_line(state.ui.primary.sim.summary());
txt.add_line(mode.speed.modal_status_line());
mode.menu.handle_event(ctx, Some(txt));
ctx.canvas.handle_event(ctx.input);

View File

@ -218,22 +218,6 @@ impl SpeedControls {
}
}
pub fn modal_status_line(&self) -> String {
if let State::Running {
ref speed_description,
..
} = self.state
{
format!(
"Speed: {} / desired {:.2}x",
speed_description,
self.desired_speed()
)
} else {
format!("Speed: paused / desired {:.2}x", self.desired_speed())
}
}
// Returns the amount of simulation time to step, if running.
pub fn event(
&mut self,
@ -296,7 +280,24 @@ impl SpeedControls {
}
pub fn draw(&self, g: &mut GfxCtx) {
self.slider.draw(g);
let mut txt = Text::new();
if let State::Running {
ref speed_description,
..
} = self.state
{
txt.add_line(format!(
"Speed: {} / desired {:.2}x",
speed_description,
self.desired_speed()
))
} else {
txt.add_line(format!(
"Speed: paused / desired {:.2}x",
self.desired_speed()
))
}
self.slider.draw(g, Some(txt));
}
pub fn pause(&mut self) {

View File

@ -93,8 +93,6 @@ impl TripsVisualizer {
"{} active trips",
prettyprint_usize(self.active_trips.len())
));
txt.add_line(format!("At {}", time));
txt.add_line(self.speed.modal_status_line());
self.menu.handle_event(ctx, Some(txt));
ctx.canvas.handle_event(ctx.input);
@ -186,7 +184,8 @@ impl TripsVisualizer {
batch.draw(g);
self.menu.draw(g);
self.time_slider.draw(g);
self.time_slider
.draw(g, Some(Text::from_line(format!("At {}", time))));
self.speed.draw(g);
CommonState::draw_osd(g, ui, ui.primary.current_selection);
}

View File

@ -161,7 +161,6 @@ impl SandboxMode {
let mut txt = Text::prompt("Sandbox Mode");
txt.add_line(state.ui.primary.sim.summary());
txt.add_line(mode.speed.modal_status_line());
if let Some(trip) = mode.following {
txt.add_line(format!("Following {}", trip));
}

View File

@ -194,15 +194,12 @@ impl<'a> GfxCtx<'a> {
VerticalAlignment::Center => (self.canvas.window_height - height) / 2.0,
VerticalAlignment::Bottom => self.canvas.window_height - height,
};
self.canvas
.covered_areas
.borrow_mut()
.push(text::draw_text_bubble(
self,
ScreenPt::new(x1, y1),
txt,
(width, height),
));
self.canvas.mark_covered_area(text::draw_text_bubble(
self,
ScreenPt::new(x1, y1),
txt,
(width, height),
));
}
pub fn get_screen_bounds(&self) -> Bounds {
@ -237,7 +234,8 @@ impl<'a> GfxCtx<'a> {
pub fn draw_text_at_screenspace_topleft(&mut self, txt: &Text, pt: ScreenPt) {
let dims = self.text_dims(&txt);
text::draw_text_bubble(self, pt, txt, dims);
self.canvas
.mark_covered_area(text::draw_text_bubble(self, pt, txt, dims));
}
pub fn draw_mouse_tooltip(&mut self, txt: &Text) {

View File

@ -22,7 +22,6 @@ struct Geometry {
row_height: f64,
top_left: ScreenPt,
first_choice_row: ScreenRectangle,
total_height: f64,
}
#[derive(Clone)]
@ -93,7 +92,6 @@ impl Position {
x2: top_left.x + total_width,
y2: top_left.y + prompt_height + row_height,
},
total_height,
}
}
}
@ -281,12 +279,6 @@ impl<T: Clone> Menu<T> {
}
}
}
g.canvas.mark_covered_area(ScreenRectangle {
x1: self.geom.top_left.x,
y1: self.geom.top_left.y,
x2: self.geom.first_choice_row.x2,
y2: self.geom.top_left.y + self.geom.total_height,
});
g.draw_text_at_screenspace_topleft(&txt, self.geom.top_left);
}

View File

@ -99,7 +99,7 @@ impl Slider {
false
}
pub fn draw(&self, g: &mut GfxCtx) {
pub fn draw(&self, g: &mut GfxCtx, label: Option<Text>) {
g.fork_screenspace();
// A nice background for the entire thing
@ -155,6 +155,16 @@ impl Slider {
},
&self.slider_geom(),
);
if let Some(ref txt) = label {
g.draw_text_at_screenspace_topleft(
txt,
ScreenPt::new(
self.top_left.x,
self.top_left.y + BAR_HEIGHT + 2.0 * VERT_PADDING,
),
);
}
}
fn slider_geom(&self) -> Polygon {
@ -174,8 +184,8 @@ pub struct ItemSlider<T> {
items: Vec<(T, Text)>,
slider: Slider,
menu: ModalMenu,
menu_title: String,
noun: String,
prev: String,
next: String,
first: String,
@ -208,8 +218,8 @@ impl<T> ItemSlider<T> {
items,
slider: Slider::new(None),
menu: ModalMenu::new(menu_title, choices, ctx),
menu_title: menu_title.to_string(),
noun: noun.to_string(),
prev,
next,
first,
@ -219,19 +229,9 @@ impl<T> ItemSlider<T> {
// Returns true if the value changed.
pub fn event(&mut self, ctx: &mut EventCtx) -> bool {
let current = {
let idx = self.slider.get_value(self.items.len());
let mut txt = Text::prompt(&self.menu_title);
txt.add_line(format!(
"{}/{}",
abstutil::prettyprint_usize(idx + 1),
abstutil::prettyprint_usize(self.items.len())
));
txt.extend(&self.items[idx].1);
self.menu.handle_event(ctx, Some(txt));
idx
};
self.menu.handle_event(ctx, None);
let current = self.slider.get_value(self.items.len());
if current != self.items.len() - 1 && self.menu.action(&self.next) {
self.slider.set_value(ctx, current + 1, self.items.len());
} else if current != self.items.len() - 1 && self.menu.action(&self.last) {
@ -249,7 +249,16 @@ impl<T> ItemSlider<T> {
pub fn draw(&self, g: &mut GfxCtx) {
self.menu.draw(g);
self.slider.draw(g);
let idx = self.slider.get_value(self.items.len());
let mut txt = Text::from_line(format!(
"{} {}/{}",
self.noun,
abstutil::prettyprint_usize(idx + 1),
abstutil::prettyprint_usize(self.items.len())
));
txt.extend(&self.items[idx].1);
self.slider.draw(g, Some(txt));
}
pub fn get(&self) -> (usize, &T) {