for now, hack around layouting mess by hardcoding window width to make flex wrapping kind of work

This commit is contained in:
Dustin Carlino 2019-12-23 11:05:24 -08:00
parent 47db959155
commit dafcc50479
3 changed files with 17 additions and 5 deletions

View File

@ -32,6 +32,7 @@ struct LayoutStyle {
align_items: Option<AlignItems>,
justify_content: Option<JustifyContent>,
flex_wrap: Option<FlexWrap>,
size: Option<Size<Dimension>>,
padding: Option<Rect<Dimension>>,
margin: Option<Rect<Dimension>>,
}
@ -47,6 +48,9 @@ impl LayoutStyle {
if let Some(x) = self.flex_wrap {
style.flex_wrap = x;
}
if let Some(x) = self.size {
style.size = x;
}
if let Some(x) = self.padding {
style.padding = x;
}
@ -77,9 +81,13 @@ impl ManagedWidget {
self
}
pub fn flex_wrap(mut self) -> ManagedWidget {
pub fn flex_wrap(mut self, ctx: &EventCtx) -> ManagedWidget {
self.style.flex_wrap = Some(FlexWrap::Wrap);
self.style.justify_content = Some(JustifyContent::SpaceAround);
self.style.size = Some(Size {
width: Dimension::Points(ctx.canvas.window_width as f32),
height: Dimension::Undefined,
});
self
}
@ -119,6 +127,7 @@ impl ManagedWidget {
align_items: None,
justify_content: None,
flex_wrap: None,
size: None,
padding: None,
margin: None,
},

View File

@ -127,7 +127,7 @@ pub fn challenges_picker(ctx: &EventCtx) -> Box<dyn State> {
&name,
));
}
col.push(ManagedWidget::row(flex_row).flex_wrap());
col.push(ManagedWidget::row(flex_row).flex_wrap(ctx));
let mut c = Composite::new(ezgui::Composite::fill_screen(
ctx,

View File

@ -226,7 +226,7 @@ fn pick_finished_trips_mode(ctx: &EventCtx) -> (ManagedWidget, Vec<(String, Call
));
}
(ManagedWidget::row(buttons).flex_wrap(), cbs)
(ManagedWidget::row(buttons).flex_wrap(ctx), cbs)
}
fn pick_finished_trips(
@ -264,7 +264,10 @@ fn pick_finished_trips(
cbs.extend(more_cbs);
(
ManagedWidget::col(vec![mode_picker, ManagedWidget::row(buttons).flex_wrap()]),
ManagedWidget::col(vec![
mode_picker,
ManagedWidget::row(buttons).flex_wrap(ctx),
]),
cbs,
)
}
@ -309,7 +312,7 @@ fn pick_bus_route(ctx: &EventCtx, ui: &UI) -> (ManagedWidget, Vec<(String, Callb
));
}
(ManagedWidget::row(buttons).flex_wrap(), cbs)
(ManagedWidget::row(buttons).flex_wrap(ctx), cbs)
}
// TODO Refactor