style row header

This commit is contained in:
Michael Kirk 2021-09-09 15:08:52 -07:00 committed by Dustin Carlino
parent 09fcca8533
commit 577192bb89
3 changed files with 31 additions and 4 deletions

View File

@ -1,8 +1,8 @@
use geom::{Circle, Distance, FindClosest, Polygon}; use geom::{Circle, Distance, FindClosest, Polygon};
use sim::TripEndpoint; use sim::TripEndpoint;
use widgetry::{ use widgetry::{
Color, ControlState, DragDrop, Drawable, EventCtx, GeomBatch, GfxCtx, Image, Line, Outcome, Color, ControlState, CornerRounding, DragDrop, Drawable, EventCtx, GeomBatch, GfxCtx, Image,
StackAxis, Text, Widget, Line, Outcome, StackAxis, Text, Widget,
}; };
use crate::app::App; use crate::app::App;
@ -69,11 +69,25 @@ impl InputWaypoints {
let mut delete_buttons = Vec::new(); let mut delete_buttons = Vec::new();
for (idx, waypt) in self.waypoints.iter().enumerate() { 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 let waypoint = ctx
.style() .style()
.btn_plain .btn_plain
.text(format!("{}) {}", waypt.order, waypt.label)) .text(&waypt.label)
.padding(16); .image(icon)
.padding(10);
let build_batch = |control_state: ControlState| { let build_batch = |control_state: ControlState| {
let batch = waypoint.batch(ctx, control_state); let batch = waypoint.batch(ctx, control_state);

View File

@ -187,6 +187,12 @@ impl From<f64> for ScreenDims {
} }
} }
impl From<i64> for ScreenDims {
fn from(square: i64) -> ScreenDims {
ScreenDims::square(square as f64)
}
}
/// (Width, Height) -> ScreenDims /// (Width, Height) -> ScreenDims
impl From<(f64, f64)> for ScreenDims { impl From<(f64, f64)> for ScreenDims {
fn from(width_and_height: (f64, f64)) -> ScreenDims { fn from(width_and_height: (f64, f64)) -> ScreenDims {

View File

@ -298,6 +298,13 @@ impl<'b, 'a: 'b, 'c> ButtonBuilder<'a, 'c> {
self 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. /// Set the image for the button. If not set, the button will have no image.
/// ///
/// This will replace any image previously set. /// This will replace any image previously set.