size horizontal-divider WRT its parent size, not absolute window size

This commit is contained in:
Michael Kirk 2021-05-14 17:56:01 -07:00
parent 4e8136d4ff
commit 94501e4699
6 changed files with 25 additions and 18 deletions

View File

@ -344,7 +344,7 @@ fn build_panel(ctx: &mut EventCtx, app: &App, start: &Building, isochrone: &Isoc
}
// Start of toolbar
rows.push(Widget::horiz_separator(ctx, 0.3).margin_above(10));
rows.push(Widget::horiz_separator(ctx, 1.0).margin_above(10));
rows.push(options_to_controls(ctx, &isochrone.options));
rows.push(

View File

@ -70,7 +70,7 @@ pub fn ongoing(
{
col.push(Widget::custom_row(vec![
Widget::custom_row(vec![Line("Trip time").secondary().into_widget(ctx)])
.force_width_pct(ctx, col_width),
.force_width_window_pct(ctx, col_width),
Text::from_all(vec![
Line(props.total_time.to_string(&app.opts.units)),
Line(format!(
@ -86,7 +86,7 @@ pub fn ongoing(
{
col.push(Widget::custom_row(vec![
Widget::custom_row(vec![Line("Distance").secondary().into_widget(ctx)])
.force_width_pct(ctx, col_width),
.force_width_window_pct(ctx, col_width),
Text::from_all(vec![
Line(props.dist_crossed.to_string(&app.opts.units)),
Line(format!("/{}", props.total_dist.to_string(&app.opts.units))).secondary(),
@ -100,7 +100,7 @@ pub fn ongoing(
.secondary()
.into_widget(ctx)
.container()
.force_width_pct(ctx, col_width),
.force_width_window_pct(ctx, col_width),
Widget::col(vec![
format!("{} here", props.waiting_here.to_string(&app.opts.units)).text_widget(ctx),
Text::from_all(vec![
@ -128,7 +128,7 @@ pub fn ongoing(
{
col.push(Widget::custom_row(vec![
Widget::custom_row(vec![Line("Purpose").secondary().into_widget(ctx)])
.force_width_pct(ctx, col_width),
.force_width_window_pct(ctx, col_width),
Line(trip.purpose.to_string()).secondary().into_widget(ctx),
]));
}
@ -311,7 +311,7 @@ pub fn finished(
if let Some(end_time) = phases.last().as_ref().and_then(|p| p.end_time) {
col.push(Widget::custom_row(vec![
Widget::custom_row(vec![Line("Trip time").secondary().into_widget(ctx)])
.force_width_pct(ctx, col_width),
.force_width_window_pct(ctx, col_width),
(end_time - trip.departure)
.to_string(&app.opts.units)
.text_widget(ctx),
@ -319,7 +319,7 @@ pub fn finished(
} else {
col.push(Widget::custom_row(vec![
Widget::custom_row(vec![Line("Trip time").secondary().into_widget(ctx)])
.force_width_pct(ctx, col_width),
.force_width_window_pct(ctx, col_width),
"Trip didn't complete before map changes".text_widget(ctx),
]));
}
@ -331,13 +331,13 @@ pub fn finished(
Widget::custom_row(vec![Line("Total waiting time")
.secondary()
.into_widget(ctx)])
.force_width_pct(ctx, col_width),
.force_width_window_pct(ctx, col_width),
waiting.to_string(&app.opts.units).text_widget(ctx),
]));
col.push(Widget::custom_row(vec![
Widget::custom_row(vec![Line("Purpose").secondary().into_widget(ctx)])
.force_width_pct(ctx, col_width),
.force_width_window_pct(ctx, col_width),
Line(trip.purpose.to_string()).secondary().into_widget(ctx),
]));
}
@ -445,7 +445,7 @@ fn describe_problems(
.secondary()
.into_widget(ctx)
.container()
.force_width_pct(ctx, col_width),
.force_width_window_pct(ctx, col_width),
txt.into_widget(ctx),
])
} else {

View File

@ -264,7 +264,7 @@ impl EditScenarioModifiers {
.text("Repeat schedule multiple days")
.build_def(ctx),
]));
rows.push(Widget::horiz_separator(ctx, 0.5));
rows.push(Widget::horiz_separator(ctx, 1.0));
rows.push(
Widget::row(vec![
ctx.style()
@ -418,7 +418,7 @@ impl ChangeMode {
"Departing until:".text_widget(ctx),
Slider::area(ctx, 0.25 * ctx.canvas.window_width, 0.3).named("depart to"),
]),
Widget::horiz_separator(ctx, 0.5),
Widget::horiz_separator(ctx, 1.0),
Widget::row(vec![
"Change to trip type:".text_widget(ctx),
Widget::dropdown(ctx, "to_mode", Some(TripMode::Bike), {

View File

@ -78,9 +78,9 @@ impl Viewer {
.build_widget(ctx, "search"),
ctx.style().btn_plain.text("About").build_def(ctx),
]),
Widget::horiz_separator(ctx, 0.3),
Widget::horiz_separator(ctx, 1.0),
self.calculate_tags(ctx, app),
Widget::horiz_separator(ctx, 0.3),
Widget::horiz_separator(ctx, 1.0),
if let Some(ref b) = self.businesses {
biz_search_panel.unwrap_or_else(|| b.render(ctx).named("Search for businesses"))
} else {

View File

@ -173,7 +173,7 @@ impl<'a> EventCtx<'a> {
.bg(Color::BLACK)
.padding(15)
.outline((5.0, Color::YELLOW))
.force_width_pct(self, Percent::int(30))
.force_width_window_pct(self, Percent::int(30))
.margin_below(5),
GeomBatch::from(vec![(Color::grey(0.5), Polygon::rectangle(10.0, 100.0))])
.into_widget(self)

View File

@ -204,11 +204,15 @@ impl Widget {
self.layout.style.size.width = Dimension::Points(width as f32);
self
}
pub fn force_width_pct(mut self, ctx: &EventCtx, width: Percent) -> Widget {
pub fn force_width_window_pct(mut self, ctx: &EventCtx, width: Percent) -> Widget {
self.layout.style.size.width =
Dimension::Points((ctx.canvas.window_width * width.inner()) as f32);
self
}
pub fn force_width_parent_pct(mut self, width: f64) -> Widget {
self.layout.style.size.width = Dimension::Percent(width as f32);
self
}
/// Needed for force_width.
pub fn get_width_for_forcing(&self) -> f64 {
@ -510,12 +514,15 @@ impl Widget {
(batch, hitbox)
}
pub fn horiz_separator(ctx: &mut EventCtx, pct_width: f64) -> Widget {
pub fn horiz_separator(ctx: &mut EventCtx, pct_container_width: f64) -> Widget {
GeomBatch::from(vec![(
ctx.style().btn_outline.fg,
Polygon::rectangle(pct_width * ctx.canvas.window_width, 2.0),
Polygon::rectangle(0.0, 2.0),
)])
.into_widget(ctx)
.container()
.bg(ctx.style().btn_outline.fg)
.force_width_parent_pct(pct_container_width)
.centered_horiz()
}