Cargo fmt

This commit is contained in:
Alexandre Bury 2018-05-21 19:21:27 -07:00
parent 2db49da1fe
commit 8edc0e20c9
3 changed files with 43 additions and 23 deletions

View File

@ -1,20 +1,28 @@
extern crate cursive;
use cursive::traits::Boxable;
use cursive::views::{Canvas, Dialog, ScrollView, LinearLayout, Button};
use cursive::views::{Button, Canvas, Dialog, LinearLayout, ScrollView};
use cursive::Printer;
fn main() {
let mut siv = cursive::Cursive::default();
siv.add_layer(Dialog::around(
siv.add_layer(
Dialog::around(
ScrollView::new(
LinearLayout::vertical()
.child(Button::new("Foo", |s| s.add_layer(Dialog::info("Ah"))))
.child(Canvas::new(()).with_draw(draw).fixed_size((120, 40)))
.child(Button::new("Bar", |s| s.add_layer(Dialog::info("Uh"))))
.child(Button::new("Foo", |s| {
s.add_layer(Dialog::info("Ah"))
}))
.child(
Canvas::new(()).with_draw(draw).fixed_size((120, 40)),
)
.child(Button::new("Bar", |s| {
s.add_layer(Dialog::info("Uh"))
})),
).scroll_x(true),
).fixed_size((60, 30)));
).fixed_size((60, 30)),
);
siv.add_global_callback('q', |s| s.quit());

View File

@ -173,7 +173,8 @@ impl View for Button {
event: MouseEvent::Release(MouseButton::Left),
position,
offset,
} if position.fits_in_rect(offset + (self_offset, 0), self.req_size()) =>
} if position
.fits_in_rect(offset + (self_offset, 0), self.req_size()) =>
{
EventResult::Consumed(Some(self.callback.clone()))
}

View File

@ -187,23 +187,34 @@ where
// If it's a mouse scroll, try to scroll as well.
// Also allow Ctrl+arrow to move the view without moving selection.
match event {
Event::Mouse { event: MouseEvent::WheelUp, .. } if self.enabled.y && self.offset.y > 0 => {
Event::Mouse {
event: MouseEvent::WheelUp,
..
} if self.enabled.y && self.offset.y > 0 =>
{
self.offset.y = self.offset.y.saturating_sub(3);
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 = min(self.inner_size.y.saturating_sub(self.last_size.y), self.offset.y + 3);
Event::Mouse {
event: MouseEvent::WheelDown,
..
} if self.enabled.y
&& (self.offset.y + self.last_size.y
< self.inner_size.y) =>
{
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) |
Event::Key(Key::Up)
Event::Ctrl(Key::Up) | Event::Key(Key::Up)
if self.enabled.y && self.offset.y > 0 =>
{
self.offset.y -= 1;
EventResult::Consumed(None)
}
Event::Ctrl(Key::Down) |
Event::Key(Key::Down)
Event::Ctrl(Key::Down) | Event::Key(Key::Down)
if self.enabled.y
&& (self.offset.y + self.last_size.y
< self.inner_size.y) =>
@ -211,15 +222,13 @@ where
self.offset.y += 1;
EventResult::Consumed(None)
}
Event::Ctrl(Key::Left) |
Event::Key(Key::Left)
Event::Ctrl(Key::Left) | Event::Key(Key::Left)
if self.enabled.x && self.offset.x > 0 =>
{
self.offset.x -= 1;
EventResult::Consumed(None)
}
Event::Ctrl(Key::Right) |
Event::Key(Key::Right)
Event::Ctrl(Key::Right) | Event::Key(Key::Right)
if self.enabled.x
&& (self.offset.x + self.last_size.x
< self.inner_size.x) =>
@ -235,7 +244,8 @@ where
let important = self.inner.important_area(self.inner_size);
// The furthest top-left we can go
let top_left = (important.bottom_right() + (1,1)).saturating_sub(self.last_size);
let top_left = (important.bottom_right() + (1, 1))
.saturating_sub(self.last_size);
// The furthest bottom-right we can go
let bottom_right = important.top_left();
@ -244,10 +254,11 @@ where
let offset_min = Vec2::min(top_left, bottom_right);
let offset_max = Vec2::max(top_left, bottom_right);
self.offset = self.offset.or_max(offset_min).or_min(offset_max);
self.offset =
self.offset.or_max(offset_min).or_min(offset_max);
other
},
}
}
}