mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 06:10:06 -04:00
Simplify and unify queries about available space
This commit is contained in:
@@ -61,7 +61,11 @@ impl CollapsingHeader {
|
||||
let text_pos = ui.cursor() + vec2(ui.style().indent, 0.0);
|
||||
let (title, text_size) = label.layout(text_pos, ui);
|
||||
let text_max_x = text_pos.x + text_size.x;
|
||||
let desired_width = ui.available_space_min().x.max(text_max_x - ui.cursor().x);
|
||||
let desired_width = ui
|
||||
.available_finite()
|
||||
.size()
|
||||
.x
|
||||
.max(text_max_x - ui.cursor().x);
|
||||
|
||||
let interact = ui.reserve_space(
|
||||
vec2(
|
||||
@@ -115,15 +119,21 @@ impl CollapsingHeader {
|
||||
if animate {
|
||||
ui.indent(id, |child_ui| {
|
||||
let max_height = if state.open {
|
||||
let full_height = state.open_height.unwrap_or(1000.0);
|
||||
remap(time_since_toggle, 0.0..=animation_time, 0.0..=full_height)
|
||||
if let Some(full_height) = state.open_height {
|
||||
remap(time_since_toggle, 0.0..=animation_time, 0.0..=full_height)
|
||||
} else {
|
||||
// First frame of expansion.
|
||||
// We don't know full height yet, but we will next frame.
|
||||
// Just use a placehodler value that shows some movement:
|
||||
10.0
|
||||
}
|
||||
} else {
|
||||
let full_height = state.open_height.unwrap_or_default();
|
||||
remap_clamp(time_since_toggle, 0.0..=animation_time, full_height..=0.0)
|
||||
};
|
||||
|
||||
let mut clip_rect = child_ui.clip_rect();
|
||||
clip_rect.max.y = clip_rect.max.y.min(child_ui.cursor().y + max_height);
|
||||
clip_rect.max.y = clip_rect.max.y.min(child_ui.rect().top() + max_height);
|
||||
child_ui.set_clip_rect(clip_rect);
|
||||
|
||||
let top_left = child_ui.top_left();
|
||||
|
||||
@@ -58,18 +58,14 @@ impl Frame {
|
||||
outline,
|
||||
} = self;
|
||||
|
||||
let outer_pos = ui.cursor();
|
||||
let inner_rect =
|
||||
Rect::from_min_size(outer_pos + margin, ui.available_space() - 2.0 * margin);
|
||||
let outer_rect = ui.available();
|
||||
let inner_rect = outer_rect.expand2(-margin);
|
||||
let where_to_put_background = ui.paint_list_len();
|
||||
|
||||
let mut child_ui = ui.child_ui(inner_rect);
|
||||
add_contents(&mut child_ui);
|
||||
|
||||
let inner_size = child_ui.bounding_size();
|
||||
let inner_size = inner_size.ceil(); // TODO: round to pixel
|
||||
|
||||
let outer_rect = Rect::from_min_size(outer_pos, margin + inner_size + margin);
|
||||
let outer_rect = Rect::from_min_max(outer_rect.min, child_ui.child_bounds().max + margin);
|
||||
|
||||
ui.insert_paint_cmd(
|
||||
where_to_put_background,
|
||||
@@ -81,7 +77,7 @@ impl Frame {
|
||||
},
|
||||
);
|
||||
|
||||
ui.expand_to_include_child(child_ui.child_bounds().expand2(margin));
|
||||
// TODO: move up cursor?
|
||||
ui.expand_to_include_child(outer_rect);
|
||||
// TODO: move cursor in parent ui
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ pub fn bar(ui: &mut Ui, add_contents: impl FnOnce(&mut Ui)) {
|
||||
ui.set_style(style);
|
||||
|
||||
// Take full width and fixed height:
|
||||
ui.expand_to_size(vec2(ui.available_width(), ui.style().menu_bar.height));
|
||||
ui.expand_to_size(vec2(ui.available().width(), ui.style().menu_bar.height));
|
||||
add_contents(ui)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -143,9 +143,9 @@ impl Resize {
|
||||
// TODO: a common trait for Things that follow this pattern
|
||||
impl Resize {
|
||||
pub fn show(mut self, ui: &mut Ui, add_contents: impl FnOnce(&mut Ui)) {
|
||||
let id = ui.make_child_id("scroll");
|
||||
self.min_size = self.min_size.min(ui.available_space());
|
||||
self.max_size = self.max_size.min(ui.available_space());
|
||||
let id = ui.make_child_id("resize");
|
||||
self.min_size = self.min_size.min(ui.available().size());
|
||||
self.max_size = self.max_size.min(ui.available().size());
|
||||
self.max_size = self.max_size.max(self.min_size);
|
||||
|
||||
let (is_new, mut state) = match ui.memory().resize.get(&id) {
|
||||
|
||||
@@ -69,8 +69,8 @@ impl ScrollArea {
|
||||
};
|
||||
|
||||
let outer_size = vec2(
|
||||
outer_ui.available_width(),
|
||||
outer_ui.available_height().min(self.max_height),
|
||||
outer_ui.available().width(),
|
||||
outer_ui.available().height().min(self.max_height),
|
||||
);
|
||||
|
||||
let inner_size = outer_size - vec2(current_scroll_bar_width, 0.0);
|
||||
|
||||
Reference in New Issue
Block a user