From 3ed68274b09243f425f898ac4ae7a8b0206a81ff Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sat, 19 Feb 2022 11:12:09 +0100 Subject: [PATCH] Make `Slider` report gained_focus,has_focus,lost_focus from DragValue Closes https://github.com/emilk/egui/issues/1268 --- egui/src/widgets/slider.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/egui/src/widgets/slider.rs b/egui/src/widgets/slider.rs index a5fac31d..f9285fe2 100644 --- a/egui/src/widgets/slider.rs +++ b/egui/src/widgets/slider.rs @@ -500,7 +500,18 @@ impl<'a> Slider<'a> { if self.show_value { let position_range = self.position_range(&response.rect); - response |= self.value_ui(ui, position_range); + let value_response = self.value_ui(ui, position_range); + if value_response.gained_focus() + || value_response.has_focus() + || value_response.lost_focus() + { + // Use the `DragValue` id as the id of the whole widget, + // so that the focus events work as expected. + response = value_response | response; + } else { + // Use the slider id as the id for the whole widget + response = response | value_response; + } } if !self.text.is_empty() {