diff --git a/crates/egui/src/containers/collapsing_header.rs b/crates/egui/src/containers/collapsing_header.rs index c8803fc7..7980f4be 100644 --- a/crates/egui/src/containers/collapsing_header.rs +++ b/crates/egui/src/containers/collapsing_header.rs @@ -112,10 +112,7 @@ impl CollapsingState { response.rect.center().y, )); let openness = self.openness(ui.ctx()); - let small_icon_response = Response { - rect: icon_rect, - ..response.clone() - }; + let small_icon_response = response.clone().with_new_rect(icon_rect); icon_fn(ui, openness, &small_icon_response); response } @@ -576,10 +573,7 @@ impl CollapsingHeader { header_response.rect.left() + ui.spacing().indent / 2.0, header_response.rect.center().y, )); - let icon_response = Response { - rect: icon_rect, - ..header_response.clone() - }; + let icon_response = header_response.clone().with_new_rect(icon_rect); if let Some(icon) = icon { icon(ui, openness, &icon_response); } else { diff --git a/crates/egui/src/response.rs b/crates/egui/src/response.rs index b3d79906..161707fd 100644 --- a/crates/egui/src/response.rs +++ b/crates/egui/src/response.rs @@ -57,7 +57,7 @@ pub struct Response { pub double_clicked: [bool; NUM_POINTER_BUTTONS], /// The thing was triple-clicked. - pub(crate) triple_clicked: [bool; NUM_POINTER_BUTTONS], + pub triple_clicked: [bool; NUM_POINTER_BUTTONS], /// The widgets is being dragged #[doc(hidden)] @@ -744,6 +744,13 @@ impl Response { } } +impl Response { + /// Returns a response with a modified [`Self::rect`]. + pub fn with_new_rect(self, rect: Rect) -> Self { + Self { rect, ..self } + } +} + /// To summarize the response from many widgets you can use this pattern: /// /// ```