Skip to content

Commit

Permalink
Apply suggestions from emil
Browse files Browse the repository at this point in the history
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
  • Loading branch information
lucasmerlin and emilk committed Sep 10, 2024
1 parent 22466f9 commit 6cf1906
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion crates/egui/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
5 changes: 3 additions & 2 deletions crates/egui/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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`.
Expand Down Expand Up @@ -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());
Expand Down
4 changes: 3 additions & 1 deletion crates/egui/src/ui_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions crates/egui_demo_lib/src/demo/interactive_container.rs
Original file line number Diff line number Diff line change
@@ -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))]
Expand Down Expand Up @@ -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.");
});

Expand All @@ -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();

Expand Down

0 comments on commit 6cf1906

Please sign in to comment.