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

View File

@ -104,9 +104,9 @@ impl Concrete {
// The event is either a mouse drag event, // The event is either a mouse drag event,
// or a weird double-release event. :S // or a weird double-release event. :S
self.last_mouse_button self.last_mouse_button
.map(|b| MouseEvent::Hold(b)) .map(MouseEvent::Hold)
.map(&make_event) .map(&make_event)
.unwrap_or(Event::Unknown(vec![])) .unwrap_or_else(|| Event::Unknown(vec![]))
} else { } else {
// Identify the button // Identify the button
let mut bare_event = mevent.bstate & ((1 << 25) - 1); 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, terminal: terminal,
current_style: Cell::new(theme::ColorPair::from_256colors(0, 0)), current_style: Cell::new(theme::ColorPair::from_256colors(0, 0)),
input: receiver, input: receiver,
resize: resize, resize: resize,
timeout: None, timeout: None,
last_button: None, last_button: None,
}; }
backend
} }
fn finish(&mut self) { fn finish(&mut self) {

View File

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

View File

@ -275,7 +275,7 @@ impl<'a> Printer<'a> {
focused: self.focused && focused, focused: self.focused && focused,
theme: self.theme, theme: self.theme,
backend: self.backend, 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 { pub fn set_checked(&mut self, checked: bool) -> EventResult {
self.checked = checked; self.checked = checked;
if let Some(ref on_change) = self.on_change { 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)) EventResult::with_cb(move |s| on_change(s, checked))
} else { } else {
EventResult::Consumed(None) EventResult::Consumed(None)

View File

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

View File

@ -335,7 +335,7 @@ impl EditView {
/// Get the current text. /// Get the current text.
pub fn get_content(&self) -> Rc<String> { pub fn get_content(&self) -> Rc<String> {
self.content.clone() Rc::clone(&self.content)
} }
/// Sets the current content to the given value. /// 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() => { Event::Key(Key::Enter) if self.on_submit.is_some() => {
let cb = self.on_submit.clone().unwrap(); let cb = self.on_submit.clone().unwrap();
let content = self.content.clone(); let content = Rc::clone(&self.content);
return EventResult::with_cb(move |s| { return EventResult::with_cb(move |s| {
cb(s, &content); cb(s, &content);
}); });
@ -599,7 +599,7 @@ impl View for EditView {
let cb = self.on_edit.clone().map(|cb| { let cb = self.on_edit.clone().map(|cb| {
// Get a new Rc on the content // Get a new Rc on the content
let content = self.content.clone(); let content = Rc::clone(&self.content);
let cursor = self.cursor; let cursor = self.cursor;
Callback::from_fn(move |s| { 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. /// Panics if another reference for this view already exists.
pub fn get_mut(&mut self) -> ViewRef<V> { 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) 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)) 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>( fn wrap_call_on_any<'a>(
&mut self, selector: &Selector, &mut self, selector: &Selector,
mut callback: Box<for<'b> FnMut(&'b mut Any) + 'a>, mut callback: Box<for<'b> FnMut(&'b mut Any) + 'a>,

View File

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

View File

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

View File

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

View File

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

View File

@ -34,7 +34,7 @@ impl<T> Clone for Action<T> {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Action { Action {
phase: self.phase.clone(), 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> { impl<T> SharedState<T> {
pub fn selection(&self) -> Rc<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> { ) -> RadioButton<T> {
let count = self.state.borrow().values.len(); let count = self.state.borrow().values.len();
self.state.borrow_mut().values.push(Rc::new(value)); 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. /// Returns the id of the selected button.

View File

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

View File

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

View File

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