diff --git a/game/src/common/waypoints.rs b/game/src/common/waypoints.rs index eaffdd530c..5d46f7039a 100644 --- a/game/src/common/waypoints.rs +++ b/game/src/common/waypoints.rs @@ -1,8 +1,8 @@ use geom::{Circle, Distance, FindClosest, Polygon}; use sim::TripEndpoint; use widgetry::{ - Color, ControlState, DragDrop, Drawable, EventCtx, GeomBatch, GfxCtx, Image, Line, Outcome, - StackAxis, Text, Widget, + Color, ControlState, CornerRounding, DragDrop, Drawable, EventCtx, GeomBatch, GfxCtx, Image, + Line, Outcome, StackAxis, Text, Widget, }; use crate::app::App; @@ -69,11 +69,25 @@ impl InputWaypoints { let mut delete_buttons = Vec::new(); for (idx, waypt) in self.waypoints.iter().enumerate() { + let icon = { + let text = Text::from(Line(waypt.order.to_string()).fg(Color::WHITE).bold_body()); + let batch = text.render(ctx); + let bounds = batch.get_bounds(); + let image = Image::from_batch(batch, bounds) + .untinted() + .bg_color(Color::RED) + .padding(10) + .dims(16) + .corner_rounding(CornerRounding::FullyRounded); + image + }; + let waypoint = ctx .style() .btn_plain - .text(format!("{}) {}", waypt.order, waypt.label)) - .padding(16); + .text(&waypt.label) + .image(icon) + .padding(10); let build_batch = |control_state: ControlState| { let batch = waypoint.batch(ctx, control_state); diff --git a/widgetry/src/screen_geom.rs b/widgetry/src/screen_geom.rs index 73c28ca675..2bb11ee345 100644 --- a/widgetry/src/screen_geom.rs +++ b/widgetry/src/screen_geom.rs @@ -187,6 +187,12 @@ impl From for ScreenDims { } } +impl From for ScreenDims { + fn from(square: i64) -> ScreenDims { + ScreenDims::square(square as f64) + } +} + /// (Width, Height) -> ScreenDims impl From<(f64, f64)> for ScreenDims { fn from(width_and_height: (f64, f64)) -> ScreenDims { diff --git a/widgetry/src/widgets/button.rs b/widgetry/src/widgets/button.rs index 876f41a711..fd431802ac 100644 --- a/widgetry/src/widgets/button.rs +++ b/widgetry/src/widgets/button.rs @@ -298,6 +298,13 @@ impl<'b, 'a: 'b, 'c> ButtonBuilder<'a, 'c> { self } + pub fn image(mut self, image: Image<'a, 'c>) -> Self { + // Currently we don't support setting image for other states like "hover", we easily + // could, but the API gets more verbose for a thing we don't currently need. + self.default_style.image = Some(image); + self + } + /// Set the image for the button. If not set, the button will have no image. /// /// This will replace any image previously set.