diff --git a/crates/egui/src/containers/scroll_area.rs b/crates/egui/src/containers/scroll_area.rs index 9ec2263f..c430b6ea 100644 --- a/crates/egui/src/containers/scroll_area.rs +++ b/crates/egui/src/containers/scroll_area.rs @@ -776,7 +776,7 @@ impl ScrollArea { let rect = Rect::from_x_y_ranges(ui.max_rect().x_range(), y_min..=y_max); - ui.allocate_new_ui(UiBuilder::new().max_rect(rect), |viewport_ui| { + ui.scope_builder(UiBuilder::new().max_rect(rect), |viewport_ui| { viewport_ui.skip_ahead_auto_ids(min_row); // Make sure we get consistent IDs. add_contents(viewport_ui, min_row..max_row) }) diff --git a/crates/egui/src/containers/window.rs b/crates/egui/src/containers/window.rs index 2f9e8fd4..52a81d37 100644 --- a/crates/egui/src/containers/window.rs +++ b/crates/egui/src/containers/window.rs @@ -1217,7 +1217,7 @@ impl TitleBar { let button_rect = Rect::from_center_size(button_center, button_size); let button_rect = button_rect.round_ui(); - ui.allocate_new_ui(UiBuilder::new().max_rect(button_rect), |ui| { + ui.scope_builder(UiBuilder::new().max_rect(button_rect), |ui| { collapsing.show_default_button_with_size(ui, button_size); }); } diff --git a/crates/egui/src/grid.rs b/crates/egui/src/grid.rs index 1e341432..9ad386cc 100644 --- a/crates/egui/src/grid.rs +++ b/crates/egui/src/grid.rs @@ -456,7 +456,7 @@ impl Grid { ui_builder = ui_builder.sizing_pass().invisible(); } - ui.allocate_new_ui(ui_builder, |ui| { + ui.scope_builder(ui_builder, |ui| { ui.horizontal(|ui| { let is_color = color_picker.is_some(); let grid = GridLayout { diff --git a/crates/egui/src/ui.rs b/crates/egui/src/ui.rs index bd4a4de8..6da01d9b 100644 --- a/crates/egui/src/ui.rs +++ b/crates/egui/src/ui.rs @@ -1498,7 +1498,7 @@ impl Ui { let item_spacing = self.spacing().item_spacing; let frame_rect = self.placer.next_space(desired_size, item_spacing); let child_rect = self.placer.justify_and_align(frame_rect, desired_size); - self.allocate_new_ui( + self.scope_dyn( UiBuilder::new().max_rect(child_rect).layout(layout), add_contents, ) @@ -1515,7 +1515,7 @@ impl Ui { max_rect: Rect, add_contents: impl FnOnce(&mut Self) -> R, ) -> InnerResponse { - self.allocate_new_ui(UiBuilder::new().max_rect(max_rect), add_contents) + self.scope_builder(UiBuilder::new().max_rect(max_rect), add_contents) } /// Allocated space (`UiBuilder::max_rect`) and then add content to it. @@ -1523,27 +1523,13 @@ impl Ui { /// If the contents overflow, more space will be allocated. /// When finished, the amount of space actually used (`min_rect`) will be allocated in the parent. /// So you can request a lot of space and then use less. + #[deprecated = "Use `scope_builder` instead"] pub fn allocate_new_ui( &mut self, ui_builder: UiBuilder, add_contents: impl FnOnce(&mut Self) -> R, ) -> InnerResponse { - self.allocate_new_ui_dyn(ui_builder, Box::new(add_contents)) - } - - fn allocate_new_ui_dyn<'c, R>( - &mut self, - ui_builder: UiBuilder, - add_contents: Box R + 'c>, - ) -> InnerResponse { - let mut child_ui = self.new_child(ui_builder); - let inner = add_contents(&mut child_ui); - let rect = child_ui.min_rect(); - let item_spacing = self.spacing().item_spacing; - self.placer.advance_after_rects(rect, rect, item_spacing); - register_rect(self, rect); - let response = self.interact(rect, child_ui.unique_id, Sense::hover()); - InnerResponse::new(inner, response) + self.scope_dyn(ui_builder, Box::new(add_contents)) } /// Convenience function to get a region to paint on. @@ -1749,7 +1735,7 @@ impl Ui { /// /// See also [`Self::add`] and [`Self::add_sized`]. pub fn put(&mut self, max_rect: Rect, widget: impl Widget) -> Response { - self.allocate_new_ui( + self.scope_builder( UiBuilder::new() .max_rect(max_rect) .layout(Layout::centered_and_justified(Direction::TopDown)), @@ -2640,7 +2626,7 @@ impl Ui { /// See also [`Self::with_layout`] for more options. #[inline] pub fn vertical(&mut self, add_contents: impl FnOnce(&mut Ui) -> R) -> InnerResponse { - self.allocate_new_ui( + self.scope_builder( UiBuilder::new().layout(Layout::top_down(Align::Min)), add_contents, ) @@ -2662,7 +2648,7 @@ impl Ui { &mut self, add_contents: impl FnOnce(&mut Ui) -> R, ) -> InnerResponse { - self.allocate_new_ui( + self.scope_builder( UiBuilder::new().layout(Layout::top_down(Align::Center)), add_contents, ) @@ -2683,7 +2669,7 @@ impl Ui { &mut self, add_contents: impl FnOnce(&mut Ui) -> R, ) -> InnerResponse { - self.allocate_new_ui( + self.scope_builder( UiBuilder::new().layout(Layout::top_down(Align::Center).with_cross_justify(true)), add_contents, ) @@ -2709,7 +2695,7 @@ impl Ui { layout: Layout, add_contents: impl FnOnce(&mut Self) -> R, ) -> InnerResponse { - self.allocate_new_ui(UiBuilder::new().layout(layout), add_contents) + self.scope_builder(UiBuilder::new().layout(layout), add_contents) } /// This will make the next added widget centered and justified in the available space. @@ -2719,7 +2705,7 @@ impl Ui { &mut self, add_contents: impl FnOnce(&mut Self) -> R, ) -> InnerResponse { - self.allocate_new_ui( + self.scope_builder( UiBuilder::new().layout(Layout::centered_and_justified(Direction::TopDown)), add_contents, ) diff --git a/examples/custom_window_frame/src/main.rs b/examples/custom_window_frame/src/main.rs index eef0db00..bf347848 100644 --- a/examples/custom_window_frame/src/main.rs +++ b/examples/custom_window_frame/src/main.rs @@ -114,7 +114,7 @@ fn title_bar_ui(ui: &mut egui::Ui, title_bar_rect: eframe::epaint::Rect, title: ui.ctx().send_viewport_cmd(ViewportCommand::StartDrag); } - ui.allocate_new_ui( + ui.scope_builder( UiBuilder::new() .max_rect(title_bar_rect) .layout(egui::Layout::right_to_left(egui::Align::Center)),