From 13a63684f222fad8b299e9880509f8a399745b6d Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Tue, 14 Jan 2020 09:56:03 -0800 Subject: [PATCH] Fix ScrollView offset after change of focus --- src/views/scroll_view.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/views/scroll_view.rs b/src/views/scroll_view.rs index 06cdb75..5528ae3 100644 --- a/src/views/scroll_view.rs +++ b/src/views/scroll_view.rs @@ -210,15 +210,25 @@ where } fn call_on_any<'a>(&mut self, selector: &Selector<'_>, cb: AnyCb<'a>) { + // TODO: should we scroll_to_important_area here? + // The callback may change the focus or some other thing. self.inner.call_on_any(selector, cb) } fn focus_view(&mut self, selector: &Selector<'_>) -> Result<(), ()> { - self.inner.focus_view(selector) + self.inner.focus_view(selector).map(|()| { + self.scroll_to_important_area(); + }) } fn take_focus(&mut self, source: Direction) -> bool { - self.inner.take_focus(source) || self.core.is_scrolling().any() + // If the inner view takes focus, re-align the important area. + if self.inner.take_focus(source) { + self.scroll_to_important_area(); + true + } else { + self.core.is_scrolling().any() + } } fn important_area(&self, size: Vec2) -> Rect {