Bug fix: ui.scope(…) is now equivalent to ui.allocate_space(…) WRT IDs

Before a disabled and enabled button would leave the parent ui
in different states, which lead to a bug where a slider drag could be
aborted if it caused a button before it to switch between enabled
and disabled.

Repro: dragging slider in "Manual Layout Test"
This commit is contained in:
Emil Ernerfeldt 2021-06-24 15:08:16 +02:00
parent 9007890440
commit 6e3604ee4b

View file

@ -1280,7 +1280,9 @@ impl Ui {
/// ``` /// ```
pub fn scope<R>(&mut self, add_contents: impl FnOnce(&mut Ui) -> R) -> InnerResponse<R> { pub fn scope<R>(&mut self, add_contents: impl FnOnce(&mut Ui) -> R) -> InnerResponse<R> {
let child_rect = self.available_rect_before_wrap(); let child_rect = self.available_rect_before_wrap();
let next_auto_id_source = self.next_auto_id_source;
let mut child_ui = self.child_ui(child_rect, *self.layout()); let mut child_ui = self.child_ui(child_rect, *self.layout());
self.next_auto_id_source = next_auto_id_source; // HACK: we want `scope` to only increment this once, so that `ui.scope` is equivalent to `ui.allocate_space`.
let ret = add_contents(&mut child_ui); let ret = add_contents(&mut child_ui);
let response = self.allocate_rect(child_ui.min_rect(), Sense::hover()); let response = self.allocate_rect(child_ui.min_rect(), Sense::hover());
InnerResponse::new(ret, response) InnerResponse::new(ret, response)