mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-26 07:52:05 +03:00
add a better bg for tooltips, centralized in one place
This commit is contained in:
parent
e9468b8ebf
commit
51745d2675
@ -204,15 +204,25 @@ impl<'a> GfxCtx<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_mouse_tooltip(&mut self, txt: Text) {
|
pub fn draw_mouse_tooltip(&mut self, txt: Text) {
|
||||||
|
// Add some padding
|
||||||
|
let pad = 5.0;
|
||||||
|
|
||||||
let txt_batch = txt.render_g(self);
|
let txt_batch = txt.render_g(self);
|
||||||
let dims = txt_batch.get_dims();
|
let raw_dims = txt_batch.get_dims();
|
||||||
|
let dims = ScreenDims::new(raw_dims.width + 2.0 * pad, raw_dims.height + 2.0 * pad);
|
||||||
|
|
||||||
// TODO Maybe also consider the cursor as a valid center
|
// TODO Maybe also consider the cursor as a valid center
|
||||||
let pt = dims.top_left_for_corner(
|
let pt = dims.top_left_for_corner(
|
||||||
ScreenPt::new(self.canvas.cursor_x, self.canvas.cursor_y + 20.0),
|
ScreenPt::new(self.canvas.cursor_x, self.canvas.cursor_y + 20.0),
|
||||||
&self.canvas,
|
&self.canvas,
|
||||||
);
|
);
|
||||||
let mut batch = GeomBatch::new();
|
let mut batch = GeomBatch::new();
|
||||||
batch.add_translated(txt_batch, pt.x, pt.y);
|
// TODO Outline?
|
||||||
|
batch.push(
|
||||||
|
Color::BLACK,
|
||||||
|
Polygon::rectangle(dims.width, dims.height).translate(pt.x, pt.y),
|
||||||
|
);
|
||||||
|
batch.add_translated(txt_batch, pt.x + pad, pt.y + pad);
|
||||||
|
|
||||||
// fork_screenspace, but with an even more prominent Z
|
// fork_screenspace, but with an even more prominent Z
|
||||||
self.uniforms.transform = [0.0, 0.0, 1.0];
|
self.uniforms.transform = [0.0, 0.0, 1.0];
|
||||||
|
@ -45,12 +45,11 @@ impl Button {
|
|||||||
draw_normal: ctx.upload(normal),
|
draw_normal: ctx.upload(normal),
|
||||||
draw_hovered: ctx.upload(hovered),
|
draw_hovered: ctx.upload(hovered),
|
||||||
tooltip: if let Some(ref key) = hotkey {
|
tooltip: if let Some(ref key) = hotkey {
|
||||||
let mut txt =
|
let mut txt = Text::from(Line(key.describe()).fg(text::HOTKEY_COLOR).size(20));
|
||||||
Text::from(Line(key.describe()).fg(text::HOTKEY_COLOR).size(20)).with_bg();
|
|
||||||
txt.append(Line(format!(" - {}", tooltip)));
|
txt.append(Line(format!(" - {}", tooltip)));
|
||||||
txt
|
txt
|
||||||
} else {
|
} else {
|
||||||
Text::from(Line(tooltip).size(20)).with_bg()
|
Text::from(Line(tooltip).size(20))
|
||||||
},
|
},
|
||||||
hotkey,
|
hotkey,
|
||||||
hitbox,
|
hitbox,
|
||||||
|
@ -60,8 +60,7 @@ impl Histogram {
|
|||||||
min,
|
min,
|
||||||
max,
|
max,
|
||||||
prettyprint_usize(cnt)
|
prettyprint_usize(cnt)
|
||||||
)))
|
))),
|
||||||
.bg(Color::BLACK),
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -196,7 +196,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 let Some(cursor) = g.canvas.get_cursor_in_screen_space() {
|
||||||
if ScreenRectangle::top_left(self.top_left, self.dims).contains(cursor) {
|
if ScreenRectangle::top_left(self.top_left, self.dims).contains(cursor) {
|
||||||
let radius = Distance::meters(15.0);
|
let radius = Distance::meters(15.0);
|
||||||
let mut txt = Text::new().bg(Color::BLACK);
|
let mut txt = Text::new();
|
||||||
for (label, pt, _) in self.closest.all_close_pts(
|
for (label, pt, _) in self.closest.all_close_pts(
|
||||||
Pt2D::new(cursor.x - self.top_left.x, cursor.y - self.top_left.y),
|
Pt2D::new(cursor.x - self.top_left.x, cursor.y - self.top_left.y),
|
||||||
radius,
|
radius,
|
||||||
|
@ -132,7 +132,7 @@ impl<T: Clone> PopupMenu<T> {
|
|||||||
};
|
};
|
||||||
if let Some(pt) = g.canvas.get_cursor_in_screen_space() {
|
if let Some(pt) = g.canvas.get_cursor_in_screen_space() {
|
||||||
if rect.contains(pt) {
|
if rect.contains(pt) {
|
||||||
let mut txt = Text::new().with_bg();
|
let mut txt = Text::new();
|
||||||
txt.add_wrapped(info.to_string(), 0.5 * g.canvas.window_width);
|
txt.add_wrapped(info.to_string(), 0.5 * g.canvas.window_width);
|
||||||
g.draw_mouse_tooltip(txt);
|
g.draw_mouse_tooltip(txt);
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ impl ObjectDebugger {
|
|||||||
if self.debug_tooltip_key_held {
|
if self.debug_tooltip_key_held {
|
||||||
if let Some(pt) = g.canvas.get_cursor_in_map_space() {
|
if let Some(pt) = g.canvas.get_cursor_in_map_space() {
|
||||||
if let Some(gps) = pt.to_gps(ui.primary.map.get_gps_bounds()) {
|
if let Some(gps) = pt.to_gps(ui.primary.map.get_gps_bounds()) {
|
||||||
let mut txt = Text::new().with_bg();
|
let mut txt = Text::new();
|
||||||
txt.add(Line(pt.to_string()));
|
txt.add(Line(pt.to_string()));
|
||||||
txt.add(Line(gps.to_string()));
|
txt.add(Line(gps.to_string()));
|
||||||
txt.add(Line(format!("{:?}", g.canvas.get_cursor())));
|
txt.add(Line(format!("{:?}", g.canvas.get_cursor())));
|
||||||
|
@ -64,7 +64,7 @@ impl GameplayState for Freeform {
|
|||||||
|
|
||||||
if let Some(ID::Intersection(i)) = ui.primary.current_selection {
|
if let Some(ID::Intersection(i)) = ui.primary.current_selection {
|
||||||
if self.spawn_pts.contains(&i) {
|
if self.spawn_pts.contains(&i) {
|
||||||
let mut txt = Text::new().with_bg();
|
let mut txt = Text::new();
|
||||||
for line in ui.primary.sim.count_trips_involving_border(i).describe() {
|
for line in ui.primary.sim.count_trips_involving_border(i).describe() {
|
||||||
txt.add(Line(line));
|
txt.add(Line(line));
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ impl SpeedControls {
|
|||||||
]
|
]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(s, label)| {
|
.map(|(s, label)| {
|
||||||
let mut tooltip = Text::from(Line(label).size(20)).with_bg();
|
let mut tooltip = Text::from(Line(label).size(20));
|
||||||
tooltip.add(Line(Key::LeftArrow.describe()).fg(Color::GREEN).size(20));
|
tooltip.add(Line(Key::LeftArrow.describe()).fg(Color::GREEN).size(20));
|
||||||
tooltip.append(Line(" - slow down"));
|
tooltip.append(Line(" - slow down"));
|
||||||
tooltip.add(Line(Key::RightArrow.describe()).fg(Color::GREEN).size(20));
|
tooltip.add(Line(Key::RightArrow.describe()).fg(Color::GREEN).size(20));
|
||||||
|
@ -650,7 +650,7 @@ impl GUI for UI {
|
|||||||
if show_tooltip {
|
if show_tooltip {
|
||||||
// TODO Argh, covers up mouseover tooltip.
|
// TODO Argh, covers up mouseover tooltip.
|
||||||
if let Some(cursor) = g.canvas.get_cursor_in_map_space() {
|
if let Some(cursor) = g.canvas.get_cursor_in_map_space() {
|
||||||
g.draw_mouse_tooltip(Text::from(Line(cursor.to_string())).with_bg());
|
g.draw_mouse_tooltip(Text::from(Line(cursor.to_string())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user