Add helpers ui.set_width and ui.set_width_range

This commit is contained in:
Emil Ernerfeldt 2020-12-25 15:29:00 +01:00
parent 38e36fd806
commit 355934ddc1
2 changed files with 13 additions and 3 deletions

View file

@ -63,9 +63,7 @@ pub fn combo_box(
let frame_margin = frame.margin;
frame.show(ui, |ui| {
ui.with_layout(Layout::top_down_justified(Align::left()), |ui| {
let width = button_response.rect.width() - 2.0 * frame_margin.x;
ui.set_min_width(width);
ui.set_max_width(width);
ui.set_width(button_response.rect.width() - 2.0 * frame_margin.x);
ScrollArea::from_max_height(MAX_COMBO_HEIGHT).show(ui, menu_contents);
});
});

View file

@ -301,6 +301,18 @@ impl Ui {
self.region.expand_to_include_rect(rect);
}
/// `ui.set_width_range(min..=max);` is equivalent to `ui.set_min_width(min); ui.set_max_width(max);`.
pub fn set_width_range(&mut self, width: std::ops::RangeInclusive<f32>) {
self.set_min_width(*width.start());
self.set_max_width(*width.end());
}
/// `ui.set_width_range(width);` is equivalent to `ui.set_min_width(width); ui.set_max_width(width);`.
pub fn set_width(&mut self, width: f32) {
self.set_min_width(width);
self.set_max_width(width);
}
// ------------------------------------------------------------------------
// Layout related measures: