diff --git a/examples/linear.rs b/examples/linear.rs index d708a0e..97aa9cc 100644 --- a/examples/linear.rs +++ b/examples/linear.rs @@ -30,7 +30,7 @@ fn main() { .child(TextView::new(text).scrollable()) .fixed_width(30), ).button("Quit", |s| s.quit()) - .h_align(HAlign::Center), + .h_align(HAlign::Center), ); siv.run(); diff --git a/examples/mines/main.rs b/examples/mines/main.rs index 3a5e152..1fc5e5d 100644 --- a/examples/mines/main.rs +++ b/examples/mines/main.rs @@ -23,8 +23,7 @@ fn main() { .child(Button::new_raw(" New game ", show_options)) .child(Button::new_raw(" Best scores ", |s| { s.add_layer(Dialog::info("Not yet!").title("Scores")) - })) - .child(Button::new_raw(" Exit ", |s| s.quit())), + })).child(Button::new_raw(" Exit ", |s| s.quit())), ), ); @@ -43,27 +42,23 @@ fn show_options(siv: &mut Cursive) { size: Vec2::new(8, 8), mines: 10, }, - ) - .item( + ).item( "Medium: 16x16, 40 mines", game::Options { size: Vec2::new(16, 16), mines: 40, }, - ) - .item( + ).item( "Difficult: 24x24, 99 mines", game::Options { size: Vec2::new(24, 24), mines: 99, }, - ) - .on_submit(|s, option| { + ).on_submit(|s, option| { s.pop_layer(); new_game(s, *option); }), - ) - .dismiss_button("Back"), + ).dismiss_button("Back"), ); } @@ -276,8 +271,7 @@ fn new_game(siv: &mut Cursive, options: game::Options) { .content( LinearLayout::horizontal() .child(Panel::new(BoardView::new(options))), - ) - .button("Quit game", |s| { + ).button("Quit game", |s| { s.pop_layer(); }), ); diff --git a/examples/mutation.rs b/examples/mutation.rs index 32cf39b..849a38d 100644 --- a/examples/mutation.rs +++ b/examples/mutation.rs @@ -39,8 +39,7 @@ fn show_popup(siv: &mut Cursive) { let content = reverse(view.get_content().source()); view.set_content(content); }); - }) - .dismiss_button("Ok"), + }).dismiss_button("Ok"), ); } diff --git a/examples/progress.rs b/examples/progress.rs index c1a202b..1963587 100644 --- a/examples/progress.rs +++ b/examples/progress.rs @@ -125,8 +125,7 @@ fn final_step(s: &mut Cursive) { "Time travel was a success!\n\ We went forward a few seconds!!", ).center(), - ) - .button("That's it?", |s| s.quit()), + ).button("That's it?", |s| s.quit()), ); } diff --git a/examples/select.rs b/examples/select.rs index 0b5a48e..f7b1a9a 100644 --- a/examples/select.rs +++ b/examples/select.rs @@ -27,8 +27,7 @@ fn main() { .on_pre_event_inner('k', |s| { s.select_up(1); Some(EventResult::Consumed(None)) - }) - .on_pre_event_inner('j', |s| { + }).on_pre_event_inner('j', |s| { s.select_down(1); Some(EventResult::Consumed(None)) }); diff --git a/examples/slider.rs b/examples/slider.rs index 8442c7f..6887991 100644 --- a/examples/slider.rs +++ b/examples/slider.rs @@ -32,7 +32,7 @@ fn main() { ); }), ).title("[ 7 ]") - .with_id("dialog"), + .with_id("dialog"), ); siv.run(); diff --git a/examples/text_area.rs b/examples/text_area.rs index 84de991..e68567d 100644 --- a/examples/text_area.rs +++ b/examples/text_area.rs @@ -33,15 +33,13 @@ fn main() { .on_submit(find) .with_id("edit") .min_width(10), - ) - .button("Ok", |s| { - let text = - s.call_on_id("edit", |view: &mut EditView| { + ).button("Ok", |s| { + let text = s + .call_on_id("edit", |view: &mut EditView| { view.get_content() }).unwrap(); find(s, &text); - }) - .dismiss_button("Cancel"), + }).dismiss_button("Cancel"), ).on_event(Event::Key(Key::Esc), |s| { s.pop_layer(); }), diff --git a/examples/theme.rs b/examples/theme.rs index 9d1051d..7115507 100644 --- a/examples/theme.rs +++ b/examples/theme.rs @@ -16,7 +16,7 @@ fn main() { "This application uses a \ custom theme!", )).title("Themed dialog") - .button("Quit", |s| s.quit()), + .button("Quit", |s| s.quit()), ); siv.run(); diff --git a/examples/theme_manual.rs b/examples/theme_manual.rs index 80e99a1..ae79470 100644 --- a/examples/theme_manual.rs +++ b/examples/theme_manual.rs @@ -29,8 +29,7 @@ fn main() { }; s.set_theme(theme); - }) - .button("Quit", Cursive::quit), + }).button("Quit", Cursive::quit), ); siv.run(); diff --git a/examples/vpv.rs b/examples/vpv.rs index d08ea25..825cd55 100644 --- a/examples/vpv.rs +++ b/examples/vpv.rs @@ -112,10 +112,8 @@ fn main() { (0, 2), &format!("Speed: {}/s", convert(speed)), ); - }) - .fixed_size((25, 3)), - ) - .with(|l| { + }).fixed_size((25, 3)), + ).with(|l| { // If we have a file length, add a progress bar if let Some(len) = len { l.add_child( diff --git a/src/backend/blt.rs b/src/backend/blt.rs index 6b8d110..7c4e3d6 100644 --- a/src/backend/blt.rs +++ b/src/backend/blt.rs @@ -107,8 +107,7 @@ impl Backend { position: self.mouse_position, offset: Vec2::zero(), } - }) - .unwrap_or(Event::Unknown(vec![])) + }).unwrap_or(Event::Unknown(vec![])) } BltEvent::ShiftReleased | BltEvent::ControlReleased => { Event::Refresh @@ -167,8 +166,7 @@ impl Backend { position: self.mouse_position, offset: Vec2::zero(), } - }) - .unwrap_or(Event::Unknown(vec![])), + }).unwrap_or(Event::Unknown(vec![])), KeyCode::A | KeyCode::B | KeyCode::C diff --git a/src/cursive.rs b/src/cursive.rs index 41378d3..94ac5cc 100644 --- a/src/cursive.rs +++ b/src/cursive.rs @@ -87,39 +87,33 @@ impl Default for Cursive { } } -#[cfg( - all( - not(feature = "termion-backend"), - feature = "pancurses-backend" - ) -)] +#[cfg(all( + not(feature = "termion-backend"), + feature = "pancurses-backend" +))] impl Default for Cursive { fn default() -> Self { Self::pancurses() } } -#[cfg( - all( - not(feature = "termion-backend"), - not(feature = "pancurses-backend"), - feature = "blt-backend" - ) -)] +#[cfg(all( + not(feature = "termion-backend"), + not(feature = "pancurses-backend"), + feature = "blt-backend" +))] impl Default for Cursive { fn default() -> Self { Self::blt() } } -#[cfg( - all( - not(feature = "termion-backend"), - not(feature = "pancurses-backend"), - not(feature = "blt-backend"), - feature = "ncurses-backend" - ) -)] +#[cfg(all( + not(feature = "termion-backend"), + not(feature = "pancurses-backend"), + not(feature = "blt-backend"), + feature = "ncurses-backend" +))] impl Default for Cursive { fn default() -> Self { Self::ncurses() diff --git a/src/utils/lines/simple/mod.rs b/src/utils/lines/simple/mod.rs index e9719ca..fed1aa4 100644 --- a/src/utils/lines/simple/mod.rs +++ b/src/utils/lines/simple/mod.rs @@ -61,8 +61,8 @@ where // `current_width` is the width of everything // before the next token, including any space. let mut current_width = 0; - let sum: usize = - iter.take_while(|token| { + let sum: usize = iter + .take_while(|token| { let width = token.width(); if current_width + width > available_width { false @@ -73,7 +73,7 @@ where true } }).map(|token| token.len() + delimiter_len) - .sum(); + .sum(); // We counted delimiter once too many times, // but only if the iterator was non empty. diff --git a/src/views/box_view.rs b/src/views/box_view.rs index c0538cd..463d7f6 100644 --- a/src/views/box_view.rs +++ b/src/views/box_view.rs @@ -1,6 +1,6 @@ -use With; use vec::Vec2; use view::{SizeConstraint, View, ViewWrapper}; +use With; use XY; /// Wrapper around another view, with a controlled size. @@ -202,7 +202,6 @@ impl BoxView { self.invalidated = true; } - inner_getters!(self.view: T); } diff --git a/src/views/dialog.rs b/src/views/dialog.rs index f66b7c3..a4b56f4 100644 --- a/src/views/dialog.rs +++ b/src/views/dialog.rs @@ -406,11 +406,10 @@ impl Dialog { if printer.size.x < overhead.horizontal() { return None; } - let mut offset = overhead.left - + self - .align - .h - .get_offset(width, printer.size.x - overhead.horizontal()); + let mut offset = overhead.left + self + .align + .h + .get_offset(width, printer.size.x - overhead.horizontal()); let overhead_bottom = self.padding.bottom + self.borders.bottom + 1; @@ -465,10 +464,9 @@ impl Dialog { return; } let spacing = 3; //minimum distance to borders - let x = spacing - + self - .title_position - .get_offset(len, printer.size.x - 2 * spacing); + let x = spacing + self + .title_position + .get_offset(len, printer.size.x - 2 * spacing); printer.with_high_border(false, |printer| { printer.print((x - 2, 0), "┤ "); printer.print((x + len, 0), " ├"); @@ -507,8 +505,7 @@ impl Dialog { } else if position.fits_in_rect( (self.padding + self.borders).top_left(), self.content.size, - ) - && self.content.take_focus(Direction::none()) + ) && self.content.take_focus(Direction::none()) { // Or did we click the content? self.focus = DialogFocus::Content; diff --git a/src/views/dummy.rs b/src/views/dummy.rs index 669a180..a162786 100644 --- a/src/views/dummy.rs +++ b/src/views/dummy.rs @@ -9,5 +9,7 @@ pub struct DummyView; impl View for DummyView { fn draw(&self, _: &Printer) {} - fn needs_relayout(&self) -> bool { false } + fn needs_relayout(&self) -> bool { + false + } } diff --git a/src/views/edit_view.rs b/src/views/edit_view.rs index e187836..0df46db 100644 --- a/src/views/edit_view.rs +++ b/src/views/edit_view.rs @@ -551,8 +551,7 @@ impl View for EditView { } else { Some(g) } - }) - .map(|g| g.len()) + }).map(|g| g.len()) .sum(); let content = &content[..display_bytes]; @@ -674,11 +673,10 @@ impl View for EditView { if position.fits_in_rect(offset, (self.last_length, 1)) => { if let Some(position) = position.checked_sub(offset) { - self.cursor = self.offset - + simple_prefix( - &self.content[self.offset..], - position.x, - ).length; + self.cursor = self.offset + simple_prefix( + &self.content[self.offset..], + position.x, + ).length; } } _ => return EventResult::Ignored, diff --git a/src/views/hideable_view.rs b/src/views/hideable_view.rs index 1286d98..f53f8ca 100644 --- a/src/views/hideable_view.rs +++ b/src/views/hideable_view.rs @@ -1,5 +1,5 @@ -use view::{Selector, View, ViewWrapper}; use vec::Vec2; +use view::{Selector, View, ViewWrapper}; use With; use std::any::Any; @@ -100,7 +100,7 @@ impl ViewWrapper for HideableView { Ok(self.view) } - fn wrap_layout(&mut self, size: Vec2) { + fn wrap_layout(&mut self, size: Vec2) { self.invalidated = false; self.with_view_mut(|v| v.layout(size)); } diff --git a/src/views/linear_layout.rs b/src/views/linear_layout.rs index b152123..ac5e192 100644 --- a/src/views/linear_layout.rs +++ b/src/views/linear_layout.rs @@ -234,11 +234,7 @@ impl LinearLayout { ) -> Box + 'a> { match source { direction::Relative::Front => { - let start = if from_focus { - self.focus - } else { - 0 - }; + let start = if from_focus { self.focus } else { 0 }; Box::new(self.children.iter_mut().enumerate().skip(start)) } @@ -556,25 +552,29 @@ impl View for LinearLayout { self.move_focus(direction::Direction::front()) } Event::Key(Key::Left) - if self.orientation == direction::Orientation::Horizontal + if self.orientation + == direction::Orientation::Horizontal && self.focus > 0 => { self.move_focus(direction::Direction::right()) } Event::Key(Key::Up) - if self.orientation == direction::Orientation::Vertical + if self.orientation + == direction::Orientation::Vertical && self.focus > 0 => { self.move_focus(direction::Direction::down()) } Event::Key(Key::Right) - if self.orientation == direction::Orientation::Horizontal + if self.orientation + == direction::Orientation::Horizontal && self.focus + 1 < self.children.len() => { self.move_focus(direction::Direction::left()) } Event::Key(Key::Down) - if self.orientation == direction::Orientation::Vertical + if self.orientation + == direction::Orientation::Vertical && self.focus + 1 < self.children.len() => { self.move_focus(direction::Direction::up()) diff --git a/src/views/list_view.rs b/src/views/list_view.rs index 8860ee0..656c1d9 100644 --- a/src/views/list_view.rs +++ b/src/views/list_view.rs @@ -150,11 +150,7 @@ impl ListView { ) -> Box + 'a> { match source { direction::Relative::Front => { - let start = if from_focus { - self.focus - } else { - 0 - }; + let start = if from_focus { self.focus } else { 0 }; Box::new(self.children.iter_mut().enumerate().skip(start)) } diff --git a/src/views/menu_popup.rs b/src/views/menu_popup.rs index 156d925..8c43ffc 100644 --- a/src/views/menu_popup.rs +++ b/src/views/menu_popup.rs @@ -317,14 +317,11 @@ impl View for MenuPopup { position, offset, } - if self.scrollbase.scrollable() - && position - .checked_sub(offset + (0, 1)) - .map(|position| { - self.scrollbase - .start_drag(position, self.last_size.x) - }) - .unwrap_or(false) => + if self.scrollbase.scrollable() && position + .checked_sub(offset + (0, 1)) + .map(|position| { + self.scrollbase.start_drag(position, self.last_size.x) + }).unwrap_or(false) => { fix_scroll = false; } diff --git a/src/views/menubar.rs b/src/views/menubar.rs index 4811f0a..f05c986 100644 --- a/src/views/menubar.rs +++ b/src/views/menubar.rs @@ -246,18 +246,17 @@ fn show_child(s: &mut Cursive, offset: Vec2, menu: Rc) { { cb(s); } - }) - .on_event(Key::Left, |s| { - s.pop_layer(); - s.select_menubar(); - // Act as if we sent "Left" then "Down" - s.menubar().on_event(Event::Key(Key::Left)).process(s); - if let EventResult::Consumed(Some(cb)) = - s.menubar().on_event(Event::Key(Key::Down)) - { - cb(s); - } - }), + }).on_event(Key::Left, |s| { + s.pop_layer(); + s.select_menubar(); + // Act as if we sent "Left" then "Down" + s.menubar().on_event(Event::Key(Key::Left)).process(s); + if let EventResult::Consumed(Some(cb)) = + s.menubar().on_event(Event::Key(Key::Down)) + { + cb(s); + } + }), ); } diff --git a/src/views/select_view.rs b/src/views/select_view.rs index f48731a..19e13d6 100644 --- a/src/views/select_view.rs +++ b/src/views/select_view.rs @@ -436,8 +436,7 @@ impl SelectView { .checked_sub(offset) .map(|position| { position < self.last_size && position.y < self.len() - }) - .unwrap_or(false) => + }).unwrap_or(false) => { self.focus.set(position.y - offset.y) } @@ -446,14 +445,11 @@ impl SelectView { position, offset, } - if self.on_submit.is_some() - && position - .checked_sub(offset) - .map(|position| { - position < self.last_size - && position.y == self.focus() - }) - .unwrap_or(false) => + if self.on_submit.is_some() && position + .checked_sub(offset) + .map(|position| { + position < self.last_size && position.y == self.focus() + }).unwrap_or(false) => { return self.submit(); } diff --git a/src/views/text_area.rs b/src/views/text_area.rs index 604f68a..1dab7c5 100644 --- a/src/views/text_area.rs +++ b/src/views/text_area.rs @@ -559,8 +559,7 @@ impl View for TextArea { .checked_sub(offset) .map(|position| { self.scrollbase.start_drag(position, self.last_size.x) - }) - .unwrap_or(false) => + }).unwrap_or(false) => { fix_scroll = false; }