Better mouse scroll drag

Now saturates when to the top or left.
This commit is contained in:
Alexandre Bury 2017-10-14 21:34:37 -07:00
parent f90621811c
commit 420454cc0f
6 changed files with 19 additions and 26 deletions

View File

@ -57,9 +57,9 @@ fn main() {
)
.with(|list| for i in 0..50 {
list.add_child(
&format!("Item {}", i),
EditView::new(),
);
&format!("Item {}", i),
EditView::new(),
);
}),
),
);

View File

@ -346,9 +346,8 @@ impl View for ListView {
offset,
} if self.scrollbase.is_dragging() =>
{
position
.checked_sub(offset)
.map(|position| self.scrollbase.drag(position));
let position = position.saturating_sub(offset);
self.scrollbase.drag(position);
return EventResult::Consumed(None);
}
Event::Mouse {
@ -397,12 +396,10 @@ impl View for ListView {
direction::Direction::back(),
)
}
Event::Key(Key::End) | Event::Ctrl(Key::End) => {
self.move_focus(
usize::max_value(),
direction::Direction::front(),
)
}
Event::Key(Key::End) | Event::Ctrl(Key::End) => self.move_focus(
usize::max_value(),
direction::Direction::front(),
),
Event::Key(Key::Tab) => {
self.move_focus(1, direction::Direction::front())
}

View File

@ -234,8 +234,8 @@ impl View for MenuPopup {
}
printer.print_hline((1, 0), printer.size.x - 2, " ");
printer.print((2, 0), label);
printer.print((printer.size.x.saturating_sub(4), 0),
">>");
let x = printer.size.x.saturating_sub(4);
printer.print((x, 0), ">>");
}
MenuItem::Leaf(ref label, _) => {
if printer.size.x < 2 {
@ -333,9 +333,8 @@ impl View for MenuPopup {
} => {
// If the mouse is dragged, we always consume the event.
fix_scroll = false;
position
.checked_sub(offset + (0, 1))
.map(|position| self.scrollbase.drag(position));
let position = position.saturating_sub(offset);
self.scrollbase.drag(position);
}
Event::Mouse {
event: MouseEvent::Press(_),

View File

@ -375,9 +375,8 @@ impl<T: 'static> SelectView<T> {
} => {
// If the mouse is dragged, we always consume the event.
fix_scroll = false;
position
.checked_sub(offset)
.map(|position| self.scrollbase.drag(position));
let position = position.saturating_sub(offset);
self.scrollbase.drag(position);
}
Event::Mouse {
event: MouseEvent::Press(_),

View File

@ -502,9 +502,8 @@ impl View for TextArea {
offset,
} => {
fix_scroll = false;
position
.checked_sub(offset)
.map(|position| self.scrollbase.drag(position));
let position = position.saturating_sub(offset);
self.scrollbase.drag(position);
}
Event::Mouse {
event: MouseEvent::Press(_),

View File

@ -303,9 +303,8 @@ impl View for TextView {
offset,
} => {
// If the mouse is dragged, we always consume the event.
position
.checked_sub(offset)
.map(|position| self.scrollbase.drag(position));
let position = position.saturating_sub(offset);
self.scrollbase.drag(position);
}
Event::Mouse {
event: MouseEvent::Release(MouseButton::Left),