ui.columns: Improve allocated size estimation + justified layous

Closes https://github.com/emilk/egui/issues/76
This commit is contained in:
Emil Ernerfeldt 2020-12-25 15:34:33 +01:00
parent 355934ddc1
commit 997cd4b279
2 changed files with 14 additions and 10 deletions

View file

@ -31,10 +31,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
* `Slider` and `DragValue` uses fewer decimals by default. See the full precision by hovering over the value.
* `egui::App`: added `fn name(&self)` and `fn clear_color(&self)`.
* Combo boxes has scroll bars when needed.
* `ui.columns`: Columns now defaults to justified top-to-down layouts.
### Fixed 🐛
* The background for `CentralPanel` will now cover unused space too.
* `ui.columns`: Improve allocated size estimation.
### Deprecated
* `RawInput::screen_size` - use `RawInput::screen_rect` instead.

View file

@ -1044,24 +1044,26 @@ impl Ui {
pos,
pos2(pos.x + column_width, self.max_rect().right_bottom().y),
);
self.child_ui(child_rect, self.layout)
let mut column_ui =
self.child_ui(child_rect, Layout::top_down_justified(Align::left()));
column_ui.set_width(column_width);
column_ui
})
.collect();
let result = add_contents(&mut columns[..]);
let mut sum_width = total_spacing;
for column in &columns {
sum_width += column.min_rect().width();
}
let mut max_column_width = column_width;
let mut max_height = 0.0;
for ui in columns {
let size = ui.min_size();
max_height = size.y.max(max_height);
for column in &columns {
max_column_width = max_column_width.max(column.min_rect().width());
max_height = column.min_size().y.max(max_height);
}
let size = vec2(self.available_width().max(sum_width), max_height);
// Make sure we fit everything next frame:
let total_required_width = total_spacing + max_column_width * (num_columns as f32);
let size = vec2(self.available_width().max(total_required_width), max_height);
self.allocate_space(size);
result
}