From 9da9c9b092809bde4a718c4eb7a27cfb6001f178 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Fri, 19 Mar 2021 11:25:02 -0700 Subject: [PATCH] extract "percent" function, put header text first --- game/src/sandbox/dashboards/trip_table.rs | 26 +++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/game/src/sandbox/dashboards/trip_table.rs b/game/src/sandbox/dashboards/trip_table.rs index e457bed942..db309f94b1 100644 --- a/game/src/sandbox/dashboards/trip_table.rs +++ b/game/src/sandbox/dashboards/trip_table.rs @@ -36,17 +36,21 @@ impl TripTable { } let total = finished + cancelled + unfinished; + let percent = |x: usize| -> f64 { + if total > 0 { + (x as f64) / (total as f64) * 100.0 + } else { + 0.0 + } + }; + let finished_trips_btn = ctx .style() .btn_tab .text(format!( - "{} ({:.1}%) Finished Trips", + "Finished Trips: {} ({:.1}%)", prettyprint_usize(finished), - if total > 0 { - (finished as f64) / (total as f64) * 100.0 - } else { - 0.0 - } + percent(finished), )) .tooltip(Text::from(Line("Finished Trips"))); @@ -63,7 +67,7 @@ impl TripTable { let cancelled_trips_btn = ctx .style() .btn_tab - .text(format!("{} Cancelled Trips", prettyprint_usize(cancelled))) + .text(format!("Cancelled Trips: {}", prettyprint_usize(cancelled))) .tooltip(Text::from(Line("Cancelled Trips"))); let cancelled_trips_content = Widget::col(vec![ cancelled_trips_table.render(ctx, app), @@ -78,13 +82,9 @@ impl TripTable { .style() .btn_tab .text(format!( - "{} ({:.1}%) Unfinished Trips", + "Unfinished Trips: {} ({:.1}%)", prettyprint_usize(unfinished), - if total > 0 { - (unfinished as f64) / (total as f64) * 100.0 - } else { - 0.0 - } + percent(unfinished) )) .tooltip(Text::from(Line("Unfinished Trips"))); let unfinished_trips_content = Widget::col(vec![