mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-10 03:10:41 +00:00
Better mouse scroll drag
Now saturates when to the top or left.
This commit is contained in:
parent
f90621811c
commit
420454cc0f
@ -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(),
|
||||
);
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
@ -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())
|
||||
}
|
||||
|
@ -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(_),
|
||||
|
@ -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(_),
|
||||
|
@ -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(_),
|
||||
|
@ -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),
|
||||
|
Loading…
Reference in New Issue
Block a user