Fix clippy warnings

This commit is contained in:
Alexandre Bury 2016-07-14 22:32:43 -07:00
parent 91fdf96066
commit bd5c45ac0e
3 changed files with 10 additions and 44 deletions

View File

@ -323,8 +323,8 @@ impl Color {
3 => (1, 17),
_ => panic!("Cannot parse color: {}", value),
};
let r = load_hex(&value[0 * l..1 * l]) * multiplier;
let g = load_hex(&value[1 * l..2 * l]) * multiplier;
let r = load_hex(&value[0..l]) * multiplier;
let g = load_hex(&value[l..2 * l]) * multiplier;
let b = load_hex(&value[2 * l..3 * l]) * multiplier;
Some(Color::Rgb(r as u8, g as u8, b as u8))
} else if value.len() == 3 {

View File

@ -2,7 +2,7 @@ use std::cmp::max;
use std::any::Any;
use Cursive;
use direction;
use direction::Direction;
use align::*;
use event::*;
use theme::ColorStyle;
@ -249,7 +249,7 @@ impl View for Dialog {
// Up goes back to the content
Event::Key(Key::Up) => {
if self.content
.take_focus(direction::Direction::down()) {
.take_focus(Direction::down()) {
self.focus = Focus::Content;
EventResult::Consumed(None)
} else {
@ -258,7 +258,7 @@ impl View for Dialog {
}
Event::Shift(Key::Tab) => {
if self.content
.take_focus(direction::Direction::back()) {
.take_focus(Direction::back()) {
self.focus = Focus::Content;
EventResult::Consumed(None)
} else {
@ -267,13 +267,12 @@ impl View for Dialog {
}
Event::Key(Key::Tab) => {
if self.content
.take_focus(direction::Direction::front()) {
.take_focus(Direction::front()) {
self.focus = Focus::Content;
EventResult::Consumed(None)
} else {
EventResult::Ignored
}
}
// Left and Right move to other buttons
Event::Key(Key::Right) if i + 1 <
@ -295,7 +294,7 @@ impl View for Dialog {
}
}
fn take_focus(&mut self, source: direction::Direction) -> bool {
fn take_focus(&mut self, source: Direction) -> bool {
// Dialogs aren't meant to be used in layouts, so...
// Let's be super lazy and not even care about the focus source.
if self.content.take_focus(source) {

View File

@ -29,13 +29,9 @@ impl Child {
self.size
}
fn as_ref(&self) -> &View {
fn as_view(&self) -> &View {
&*self.view
}
fn as_mut(&mut self) -> &mut View {
&mut *self.view
}
}
impl LinearLayout {
@ -106,14 +102,14 @@ impl LinearLayout {
fn children_are_sleeping(&self) -> bool {
!self.children
.iter()
.map(Child::as_ref)
.map(Child::as_view)
.any(View::needs_relayout)
}
/// Returns a cyclic mutable iterator starting with the child in focus
fn iter_mut<'a>(&'a mut self, from_focus: bool,
direction: direction::Relative)
-> Box<Iterator<Item = (usize, &'a mut Child)> + 'a> {
-> Box<Iterator<Item = (usize, &mut Child)> + 'a> {
match direction {
direction::Relative::Front => {
@ -154,35 +150,6 @@ impl LinearLayout {
self.focus = i;
EventResult::Consumed(None)
}
fn focus_prev(&mut self) -> EventResult {
if let Some(i) = self.children[..self.focus]
.iter_mut()
.rev()
.map(Child::as_mut)
.position(|v| v.take_focus(direction::Direction::back())) {
// We're looking at the list in reverse
self.focus -= i + 1;
EventResult::Consumed(None)
} else {
EventResult::Ignored
}
}
fn focus_next(&mut self) -> EventResult {
if let Some(i) = self.children[(self.focus + 1)..]
.iter_mut()
.rev()
.map(Child::as_mut)
.position(|v| v.take_focus(direction::Direction::front())) {
// Our slice doesn't start at 0
self.focus += i + 1;
EventResult::Consumed(None)
} else {
EventResult::Ignored
}
}
}
fn try_focus((i, child): (usize, &mut Child), source: direction::Direction)