Fix clippy warnings

This commit is contained in:
Alexandre Bury 2017-10-13 11:22:02 -07:00
parent 111d593f55
commit 93982517ae
18 changed files with 62 additions and 88 deletions

View File

@ -6,9 +6,9 @@ use self::bear_lib_terminal::terminal::{self, state, Event as BltEvent,
KeyCode};
use backend;
use event::{Event, Key, MouseButton, MouseEvent};
use std::collections::HashSet;
use theme::{BaseColor, Color, ColorPair, Effect};
use vec::Vec2;
use std::collections::HashSet;
enum ColorRole {
Foreground,
@ -235,7 +235,7 @@ impl backend::Backend for Concrete {
event: MouseEvent::Hold(*btn),
position: self.mouse_position,
offset: Vec2::zero(),
}
},
}
}
BltEvent::MouseScroll { delta } => Event::Mouse {

View File

@ -104,9 +104,9 @@ impl Concrete {
// The event is either a mouse drag event,
// or a weird double-release event. :S
self.last_mouse_button
.map(|b| MouseEvent::Hold(b))
.map(MouseEvent::Hold)
.map(&make_event)
.unwrap_or(Event::Unknown(vec![]))
.unwrap_or_else(|| Event::Unknown(vec![]))
} else {
// Identify the button
let mut bare_event = mevent.bstate & ((1 << 25) - 1);

View File

@ -149,16 +149,14 @@ impl backend::Backend for Concrete {
}
});
let backend = Concrete {
Concrete {
terminal: terminal,
current_style: Cell::new(theme::ColorPair::from_256colors(0, 0)),
input: receiver,
resize: resize,
timeout: None,
last_button: None,
};
backend
}
}
fn finish(&mut self) {

View File

@ -313,12 +313,7 @@ pub enum Event {
impl Event {
/// Returns the position of the mouse, if `self` is a mouse event.
pub fn mouse_position(&self) -> Option<Vec2> {
if let Event::Mouse {
offset: _,
position,
event: _,
} = *self
{
if let Event::Mouse { position, .. } = *self {
Some(position)
} else {
None
@ -333,12 +328,7 @@ impl Event {
where
V: Into<Vec2>,
{
if let Event::Mouse {
ref mut offset,
position: _,
event: _,
} = *self
{
if let Event::Mouse { ref mut offset, .. } = *self {
*offset = *offset + top_left;
}
}

View File

@ -275,7 +275,7 @@ impl<'a> Printer<'a> {
focused: self.focused && focused,
theme: self.theme,
backend: self.backend,
new: self.new.clone(),
new: Rc::clone(&self.new),
}
}

View File

@ -90,7 +90,7 @@ impl Checkbox {
pub fn set_checked(&mut self, checked: bool) -> EventResult {
self.checked = checked;
if let Some(ref on_change) = self.on_change {
let on_change = on_change.clone();
let on_change = Rc::clone(on_change);
EventResult::with_cb(move |s| on_change(s, checked))
} else {
EventResult::Consumed(None)

View File

@ -362,11 +362,11 @@ impl Dialog {
}
fn check_focus_grab(&mut self, event: &Event) {
if let &Event::Mouse {
if let Event::Mouse {
offset,
position,
event,
} = event
} = *event
{
if !event.grabs_focus() {
return;

View File

@ -335,7 +335,7 @@ impl EditView {
/// Get the current text.
pub fn get_content(&self) -> Rc<String> {
self.content.clone()
Rc::clone(&self.content)
}
/// Sets the current content to the given value.
@ -573,7 +573,7 @@ impl View for EditView {
}
Event::Key(Key::Enter) if self.on_submit.is_some() => {
let cb = self.on_submit.clone().unwrap();
let content = self.content.clone();
let content = Rc::clone(&self.content);
return EventResult::with_cb(move |s| {
cb(s, &content);
});
@ -599,7 +599,7 @@ impl View for EditView {
let cb = self.on_edit.clone().map(|cb| {
// Get a new Rc on the content
let content = self.content.clone();
let content = Rc::clone(&self.content);
let cursor = self.cursor;
Callback::from_fn(move |s| {

View File

@ -34,7 +34,7 @@ impl<V: View> IdView<V> {
///
/// Panics if another reference for this view already exists.
pub fn get_mut(&mut self) -> ViewRef<V> {
let cell_ref = RcRef::new(self.view.clone());
let cell_ref = RcRef::new(Rc::clone(&self.view));
OwningHandle::new_mut(cell_ref)
}
@ -57,6 +57,7 @@ impl<T: View + 'static> ViewWrapper for IdView<T> {
self.view.try_borrow_mut().ok().map(|mut v| f(&mut *v))
}
// Some for<'b> weirdness here to please the borrow checker gods...
fn wrap_call_on_any<'a>(
&mut self, selector: &Selector,
mut callback: Box<for<'b> FnMut(&'b mut Any) + 'a>,

View File

@ -43,7 +43,8 @@ struct ChildIterator<I> {
orientation: direction::Orientation,
}
impl <'a,T: Deref<Target=Child>, I: Iterator<Item=T>> Iterator for ChildIterator<I> {
impl<'a, T: Deref<Target = Child>, I: Iterator<Item = T>> Iterator
for ChildIterator<I> {
type Item = (usize, T);
fn next(&mut self) -> Option<Self::Item> {
@ -184,11 +185,11 @@ impl LinearLayout {
}
fn check_focus_grab(&mut self, event: &Event) {
if let &Event::Mouse {
if let Event::Mouse {
offset,
position,
event,
} = event
} = *event
{
if !event.grabs_focus() {
return;
@ -208,13 +209,13 @@ impl LinearLayout {
};
for (i, (offset, child)) in iterator.enumerate() {
let child_size = child.size.get(self.orientation);
// eprintln!("Offset {:?}, size {:?}, position: {:?}", offset, child_size, position);
if offset + child_size > position {
if child.view.take_focus(direction::Direction::none()) {
// eprintln!("It's a match!");
self.focus = i;
return;
}
// eprintln!("Offset {:?}, size {:?}, position: {:?}", offset, child_size, position);
if (offset + child_size > position)
&& child.view.take_focus(direction::Direction::none())
{
// eprintln!("It's a match!");
self.focus = i;
return;
}
}
}

View File

@ -206,11 +206,11 @@ impl ListView {
}
fn check_focus_grab(&mut self, event: &Event) {
if let &Event::Mouse {
if let Event::Mouse {
offset,
position,
event,
} = event
} = *event
{
if !event.grabs_focus() {
return;
@ -229,9 +229,7 @@ impl ListView {
// Now that we have a relative position, checks for buttons?
let focus = position.y + self.scrollbase.start_line;
if let &mut ListChild::Row(_, ref mut view) =
&mut self.children[focus]
{
if let ListChild::Row(_, ref mut view) = self.children[focus] {
if view.take_focus(direction::Direction::none()) {
self.focus = focus;
}

View File

@ -139,7 +139,7 @@ impl MenuPopup {
}
fn make_subtree_cb(&self, tree: &Rc<MenuTree>) -> EventResult {
let tree = tree.clone();
let tree = Rc::clone(tree);
let max_width = 4
+ self.menu
.children
@ -155,7 +155,7 @@ impl MenuPopup {
s.screen_mut().add_layer_at(
Position::parent(offset),
OnEventView::new(
MenuPopup::new(tree.clone()).on_action(move |s| {
MenuPopup::new(Rc::clone(&tree)).on_action(move |s| {
// This will happen when the subtree popup
// activates something;
// First, remove ourselve.
@ -271,9 +271,6 @@ impl View for MenuPopup {
fn on_event(&mut self, event: Event) -> EventResult {
let mut fix_scroll = true;
match event {
Event::Key(Key::Esc) => {
return self.dismiss();
}
Event::Key(Key::Up) => self.scroll_up(1, true),
Event::Key(Key::PageUp) => self.scroll_up(5, false),
Event::Key(Key::Down) => self.scroll_down(1, true),
@ -301,8 +298,7 @@ impl View for MenuPopup {
}
Event::Mouse {
event: MouseEvent::WheelUp,
position: _,
offset: _,
..
} if self.scrollbase.can_scroll_up() =>
{
fix_scroll = false;
@ -310,8 +306,7 @@ impl View for MenuPopup {
}
Event::Mouse {
event: MouseEvent::WheelDown,
position: _,
offset: _,
..
} if self.scrollbase.can_scroll_down() =>
{
fix_scroll = false;
@ -373,20 +368,19 @@ impl View for MenuPopup {
if let Some(position) =
position.checked_sub(offset + (1, 1))
{
if position < self.last_size.saturating_sub((2, 2)) {
if position.y + self.scrollbase.start_line
== self.focus
{
return self.submit();
}
if position < self.last_size.saturating_sub((2, 2))
&& (position.y + self.scrollbase.start_line
== self.focus)
{
return self.submit();
}
}
}
}
Event::Key(Key::Esc) |
Event::Mouse {
event: MouseEvent::Press(_),
position: _,
offset: _,
..
} => {
return self.dismiss();
}

View File

@ -156,7 +156,7 @@ impl Menubar {
fn select_child(&mut self) -> EventResult {
// First, we need a new Rc to send the callback,
// since we don't know when it will be called.
let menu = self.menus[self.focus].1.clone();
let menu = Rc::clone(&self.menus[self.focus].1);
self.state = State::Submenu;
let offset = (
self.menus[..self.focus]
@ -167,7 +167,7 @@ impl Menubar {
);
// Since the closure will be called multiple times,
// we also need a new Rc on every call.
EventResult::with_cb(move |s| show_child(s, offset, menu.clone()))
EventResult::with_cb(move |s| show_child(s, offset, Rc::clone(&menu)))
}
}
@ -264,8 +264,7 @@ impl View for Menubar {
}
Event::Mouse {
event: MouseEvent::Press(_),
position: _,
offset: _,
..
} => {
self.hide();
return EventResult::with_cb(|s| s.clear());

View File

@ -34,7 +34,7 @@ impl<T> Clone for Action<T> {
fn clone(&self) -> Self {
Action {
phase: self.phase.clone(),
callback: self.callback.clone(),
callback: Rc::clone(&self.callback),
}
}
}

View File

@ -14,7 +14,7 @@ struct SharedState<T> {
impl<T> SharedState<T> {
pub fn selection(&self) -> Rc<T> {
self.values[self.selection].clone()
Rc::clone(&self.values[self.selection])
}
}
@ -56,7 +56,7 @@ impl<T> RadioGroup<T> {
) -> RadioButton<T> {
let count = self.state.borrow().values.len();
self.state.borrow_mut().values.push(Rc::new(value));
RadioButton::new(self.state.clone(), count, label.into())
RadioButton::new(Rc::clone(&self.state), count, label.into())
}
/// Returns the id of the selected button.

View File

@ -200,7 +200,7 @@ impl<T: 'static> SelectView<T> {
///
/// Panics if the list is empty.
pub fn selection(&self) -> Rc<T> {
self.items[self.focus()].value.clone()
Rc::clone(&self.items[self.focus()].value)
}
/// Removes all items from this view.
@ -341,8 +341,7 @@ impl<T: 'static> SelectView<T> {
}
Event::Mouse {
event: MouseEvent::WheelDown,
position: _,
offset: _,
..
} if self.scrollbase.can_scroll_down() =>
{
fix_scroll = false;
@ -350,8 +349,7 @@ impl<T: 'static> SelectView<T> {
}
Event::Mouse {
event: MouseEvent::WheelUp,
position: _,
offset: _,
..
} if self.scrollbase.can_scroll_up() =>
{
fix_scroll = false;
@ -400,12 +398,11 @@ impl<T: 'static> SelectView<T> {
self.scrollbase.release_grab();
if self.on_submit.is_some() {
if let Some(position) = position.checked_sub(offset) {
if position < self.last_size {
if position.y + self.scrollbase.start_line
if position < self.last_size
&& (position.y + self.scrollbase.start_line)
== self.focus()
{
return self.submit();
}
{
return self.submit();
}
}
}
@ -447,9 +444,9 @@ impl<T: 'static> SelectView<T> {
// TODO: cache it?
let mut tree = MenuTree::new();
for (i, item) in self.items.iter().enumerate() {
let focus = self.focus.clone();
let focus = Rc::clone(&self.focus);
let on_submit = self.on_submit.as_ref().cloned();
let value = item.value.clone();
let value = Rc::clone(&item.value);
tree.add_leaf(item.label.clone(), move |s| {
focus.set(i);
if let Some(ref on_submit) = on_submit {
@ -480,7 +477,7 @@ impl<T: 'static> SelectView<T> {
// And now, we can return the callback that will create the popup.
EventResult::with_cb(move |s| {
// The callback will want to work with a fresh Rc
let tree = tree.clone();
let tree = Rc::clone(&tree);
// We'll relativise the absolute position,
// So that we are locked to the parent view.
// A nice effect is that window resizes will keep both

View File

@ -194,8 +194,7 @@ impl View for SliderView {
}
Event::Mouse {
event: MouseEvent::Release(MouseButton::Left),
position: _,
offset: _,
..
} => {
self.dragging = false;
EventResult::Ignored

View File

@ -270,16 +270,14 @@ impl View for TextView {
}
Event::Mouse {
event: MouseEvent::WheelDown,
position: _,
offset: _,
..
} if self.scrollbase.can_scroll_down() =>
{
self.scrollbase.scroll_down(5)
}
Event::Mouse {
event: MouseEvent::WheelUp,
position: _,
offset: _,
..
} if self.scrollbase.can_scroll_up() =>
{
self.scrollbase.scroll_up(5)
@ -312,8 +310,7 @@ impl View for TextView {
}
Event::Mouse {
event: MouseEvent::Release(MouseButton::Left),
position: _,
offset: _,
..
} => {
self.scrollbase.release_grab();
}