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 { .with(|list| for i in 0..50 {
list.add_child( list.add_child(
&format!("Item {}", i), &format!("Item {}", i),
EditView::new(), EditView::new(),
); );
}), }),
), ),
); );

View File

@ -346,9 +346,8 @@ impl View for ListView {
offset, offset,
} if self.scrollbase.is_dragging() => } if self.scrollbase.is_dragging() =>
{ {
position let position = position.saturating_sub(offset);
.checked_sub(offset) self.scrollbase.drag(position);
.map(|position| self.scrollbase.drag(position));
return EventResult::Consumed(None); return EventResult::Consumed(None);
} }
Event::Mouse { Event::Mouse {
@ -397,12 +396,10 @@ impl View for ListView {
direction::Direction::back(), direction::Direction::back(),
) )
} }
Event::Key(Key::End) | Event::Ctrl(Key::End) => { Event::Key(Key::End) | Event::Ctrl(Key::End) => self.move_focus(
self.move_focus( usize::max_value(),
usize::max_value(), direction::Direction::front(),
direction::Direction::front(), ),
)
}
Event::Key(Key::Tab) => { Event::Key(Key::Tab) => {
self.move_focus(1, direction::Direction::front()) 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_hline((1, 0), printer.size.x - 2, " ");
printer.print((2, 0), label); 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, _) => { MenuItem::Leaf(ref label, _) => {
if printer.size.x < 2 { if printer.size.x < 2 {
@ -333,9 +333,8 @@ impl View for MenuPopup {
} => { } => {
// If the mouse is dragged, we always consume the event. // If the mouse is dragged, we always consume the event.
fix_scroll = false; fix_scroll = false;
position let position = position.saturating_sub(offset);
.checked_sub(offset + (0, 1)) self.scrollbase.drag(position);
.map(|position| self.scrollbase.drag(position));
} }
Event::Mouse { Event::Mouse {
event: MouseEvent::Press(_), event: MouseEvent::Press(_),

View File

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

View File

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

View File

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