From 2db49da1fee61bcc777ac2ed0de6d78ead022c56 Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Mon, 21 May 2018 18:08:41 -0700 Subject: [PATCH] Fix linearlayout focus grab --- src/views/linear_layout.rs | 10 +++++----- src/views/scroll_view.rs | 4 +++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/views/linear_layout.rs b/src/views/linear_layout.rs index f1bbd6d..219705d 100644 --- a/src/views/linear_layout.rs +++ b/src/views/linear_layout.rs @@ -279,11 +279,11 @@ impl LinearLayout { // this will give us the allowed window for a click. let child_size = item.child.size.get(self.orientation); - if (item.offset + child_size > position) - && item.child.view.take_focus(direction::Direction::none()) - { - // eprintln!("It's a match!"); - self.focus = i; + if item.offset + child_size > position { + if item.child.view.take_focus(direction::Direction::none()) + { + self.focus = i; + } return; } } diff --git a/src/views/scroll_view.rs b/src/views/scroll_view.rs index 43e4fc9..2dcc4fb 100644 --- a/src/views/scroll_view.rs +++ b/src/views/scroll_view.rs @@ -7,6 +7,8 @@ use xy::XY; use Printer; use With; +use std::cmp::min; + /// Wraps a view in a scrollable area. pub struct ScrollView { inner_size: Vec2, @@ -190,7 +192,7 @@ where EventResult::Consumed(None) } Event::Mouse { event: MouseEvent::WheelDown, .. } if self.enabled.y && (self.offset.y + self.last_size.y < self.inner_size.y) => { - self.offset.y += 3; + self.offset.y = min(self.inner_size.y.saturating_sub(self.last_size.y), self.offset.y + 3); EventResult::Consumed(None) } Event::Ctrl(Key::Up) |