diff --git a/src/theme.rs b/src/theme.rs index 89bfbb4..177d329 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -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 { diff --git a/src/view/dialog.rs b/src/view/dialog.rs index 267c34b..32d1ecd 100644 --- a/src/view/dialog.rs +++ b/src/view/dialog.rs @@ -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) { diff --git a/src/view/linear_layout.rs b/src/view/linear_layout.rs index 1028760..2c23fe7 100644 --- a/src/view/linear_layout.rs +++ b/src/view/linear_layout.rs @@ -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 + 'a> { + -> Box + '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)