diff --git a/crates/egui/src/menu.rs b/crates/egui/src/menu.rs index 7f7575ad2538..0633f1cbd05f 100644 --- a/crates/egui/src/menu.rs +++ b/crates/egui/src/menu.rs @@ -706,7 +706,7 @@ impl MenuState { self.open_submenu(sub_id, pos); } else if open - && ui.read_response().contains_pointer() + && ui.response().contains_pointer() && !button.hovered() && !self.hovering_current_submenu(&pointer) { diff --git a/crates/egui/src/ui.rs b/crates/egui/src/ui.rs index b663571eb246..405aed28dfbb 100644 --- a/crates/egui/src/ui.rs +++ b/crates/egui/src/ui.rs @@ -1002,7 +1002,7 @@ impl Ui { /// /// On the first frame, when the [`Ui`] is created, this will return a [`Response`] with a /// [`Rect`] of [`Rect::NOTHING`]. - pub fn read_response(&self) -> Response { + pub fn response(&self) -> Response { // This is the inverse of Context::read_response. We prefer a response // based on last frame's widget rect since the one from this frame is Rect::NOTHING until // Ui::interact_bg is called or the Ui is dropped. @@ -1027,7 +1027,7 @@ impl Ui { /// The rectangle of the [`Response`] (and interactive area) will be [`Self::min_rect`]. /// You can customize the [`Sense`] via [`UiBuilder::sense`]. // This is marked as deprecated for public use but still makes sense to use internally. - #[deprecated = "Use Ui::read_response instead"] + #[deprecated = "Use Uibuilder::sense with Ui::response instead"] pub fn interact_bg(&self) -> Response { // We remove the id from used_ids to prevent a duplicate id warning from showing // when the ui was created with `UiBuilder::sense`. @@ -2886,6 +2886,7 @@ impl Drop for Ui { fn drop(&mut self) { if self.should_interact_bg_on_drop { #[allow(deprecated)] + // Register our final `min_rect` self.interact_bg(); } register_rect(self, self.min_rect()); diff --git a/crates/egui/src/ui_builder.rs b/crates/egui/src/ui_builder.rs index fcb74c27e79f..c19af8c336fe 100644 --- a/crates/egui/src/ui_builder.rs +++ b/crates/egui/src/ui_builder.rs @@ -118,7 +118,9 @@ impl UiBuilder { self } - /// Sense of the Ui. Should be the same as the one passed to [`Ui::interact_bg`] + /// Set if you want sense clicks and/or drags. + /// + /// The response can be read with [`Ui::response`]. #[inline] pub fn sense(mut self, sense: Sense) -> Self { self.sense = Some(sense); diff --git a/crates/egui_demo_lib/src/demo/interactive_container.rs b/crates/egui_demo_lib/src/demo/interactive_container.rs index 083d4eb0c1ab..11d8afa48fef 100644 --- a/crates/egui_demo_lib/src/demo/interactive_container.rs +++ b/crates/egui_demo_lib/src/demo/interactive_container.rs @@ -1,6 +1,6 @@ use egui::{Frame, Label, RichText, Sense, UiBuilder, Widget}; -/// Showcase [`egui::Ui::read_response`]. +/// Showcase [`egui::Ui::response`]. #[derive(PartialEq, Eq, Default)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "serde", serde(default))] @@ -34,7 +34,7 @@ impl crate::View for InteractiveContainerDemo { ui.horizontal_wrapped(|ui| { ui.spacing_mut().item_spacing.x = 0.0; ui.label("This demo showcases how to use "); - ui.code("Ui::read_response"); + ui.code("Ui::response"); ui.label(" to create interactive container widgets that may contain other widgets."); }); @@ -44,7 +44,7 @@ impl crate::View for InteractiveContainerDemo { .id_salt("interactive_container") .sense(Sense::click()), |ui| { - let response = ui.read_response(); + let response = ui.response(); let visuals = ui.style().interact(&response); let text_color = visuals.text_color();