Add helper Layout::top_down_justified(align)

This commit is contained in:
Emil Ernerfeldt 2020-12-13 19:45:30 +01:00
parent b7d1584f44
commit 41e4acfd4f
3 changed files with 10 additions and 11 deletions

View file

@ -60,13 +60,10 @@ pub fn combo_box(
let frame = Frame::popup(ui.style());
let frame_margin = frame.margin;
frame.show(ui, |ui| {
ui.with_layout(
Layout::top_down(Align::left()).with_cross_justify(true),
|ui| {
ui.with_layout(Layout::top_down_justified(Align::left()), |ui| {
ui.set_min_width(button_response.rect.width() - 2.0 * frame_margin.x);
menu_contents(ui);
},
);
});
})
});

View file

@ -166,6 +166,11 @@ impl Layout {
}
}
/// Top-down layout justifed so that buttons etc fill the full available width.
pub fn top_down_justified(cross_align: Align) -> Self {
Self::top_down(cross_align).with_cross_justify(true)
}
pub fn bottom_up(cross_align: Align) -> Self {
Self {
main_dir: Direction::BottomUp,

View file

@ -111,10 +111,7 @@ fn menu_impl<'c>(
style.visuals.widgets.inactive.bg_fill = TRANSPARENT;
style.visuals.widgets.inactive.bg_stroke = Stroke::none();
ui.set_style(style);
ui.with_layout(
Layout::top_down(Align::left()).with_cross_justify(true),
add_contents,
);
ui.with_layout(Layout::top_down_justified(Align::left()), add_contents);
})
});