diff --git a/examples/select_test.rs b/examples/select_test.rs index 9084fe6..62198df 100644 --- a/examples/select_test.rs +++ b/examples/select_test.rs @@ -11,17 +11,19 @@ fn main() { pub mod tests { extern crate cursive; + use self::cursive::backend::puppet::observed::{ + ObservedCell, ObservedPieceInterface, + }; use cursive::align::HAlign; + use cursive::backend::puppet::observed::ObservedScreen; + use cursive::event::Event; use cursive::event::EventResult; + use cursive::event::Key; use cursive::traits::*; use cursive::views::*; use cursive::*; - use cursive::backend::puppet::observed::ObservedScreen; - use cursive::event::Event; use std::cell::RefCell; use std::time::Duration; - use cursive::event::Key; - use self::cursive::backend::puppet::observed::{ObservedCell, ObservedPieceInterface}; pub struct BasicSetup { siv: Cursive, @@ -77,7 +79,7 @@ pub mod tests { siv, screen_stream: sink, input, - last_screen : RefCell::new(None) + last_screen: RefCell::new(None), } } @@ -90,9 +92,7 @@ pub mod tests { } pub fn dump_debug(&self) { - self.last_screen().as_ref().map(|s| { - s.print_stdout() - }); + self.last_screen().as_ref().map(|s| s.print_stdout()); } pub fn hit_keystroke(&mut self, key: Key) { @@ -111,7 +111,6 @@ pub mod tests { ); } - #[test] fn displays() { let mut s = BasicSetup::new(); @@ -129,7 +128,10 @@ pub mod tests { let mut screen = s.last_screen().unwrap(); s.dump_debug(); - assert_eq!(screen.find_occurences("Abu Dhabi is a great city!").len(), 1); + assert_eq!( + screen.find_occurences("Abu Dhabi is a great city!").len(), + 1 + ); assert_eq!(screen.find_occurences("Abidjan").len(), 0); } } diff --git a/rustfmt.toml b/rustfmt.toml index 7355152..6724669 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,5 +1,5 @@ unstable_features = true max_width = 79 reorder_imports = true -fn_args_density = "Compressed" +fn_args_layout = "Tall" diff --git a/src/backend/blt.rs b/src/backend/blt.rs index d4e3f3c..ce1005f 100644 --- a/src/backend/blt.rs +++ b/src/backend/blt.rs @@ -112,7 +112,10 @@ impl Backend { } fn blt_keycode_to_ev( - &mut self, kc: KeyCode, shift: bool, ctrl: bool, + &mut self, + kc: KeyCode, + shift: bool, + ctrl: bool, ) -> Event { match kc { KeyCode::F1 diff --git a/src/backend/crossterm.rs b/src/backend/crossterm.rs index cfd52e2..08916e3 100644 --- a/src/backend/crossterm.rs +++ b/src/backend/crossterm.rs @@ -251,7 +251,9 @@ impl backend::Backend for Backend { theme::Effect::Reverse => self.set_attr(Attribute::Reverse), theme::Effect::Bold => self.set_attr(Attribute::Bold), theme::Effect::Italic => self.set_attr(Attribute::Italic), - theme::Effect::Strikethrough => self.set_attr(Attribute::CrossedOut), + theme::Effect::Strikethrough => { + self.set_attr(Attribute::CrossedOut) + } theme::Effect::Underline => self.set_attr(Attribute::Underlined), } } @@ -262,7 +264,9 @@ impl backend::Backend for Backend { theme::Effect::Reverse => self.set_attr(Attribute::Reverse), theme::Effect::Bold => self.set_attr(Attribute::NoBold), theme::Effect::Italic => self.set_attr(Attribute::NoItalic), - theme::Effect::Strikethrough => self.set_attr(Attribute::NotCrossedOut), + theme::Effect::Strikethrough => { + self.set_attr(Attribute::NotCrossedOut) + } theme::Effect::Underline => self.set_attr(Attribute::Underlined), } } diff --git a/src/backend/curses/n.rs b/src/backend/curses/n.rs index 9b7f9f6..23140d1 100644 --- a/src/backend/curses/n.rs +++ b/src/backend/curses/n.rs @@ -128,7 +128,9 @@ impl Backend { /// Save a new color pair. fn insert_color( - &self, pairs: &mut HashMap<(i16, i16), i16>, (front, back): (i16, i16), + &self, + pairs: &mut HashMap<(i16, i16), i16>, + (front, back): (i16, i16), ) -> i16 { let n = 1 + pairs.len() as i16; diff --git a/src/backend/curses/pan.rs b/src/backend/curses/pan.rs index 48a75e5..fd4db59 100644 --- a/src/backend/curses/pan.rs +++ b/src/backend/curses/pan.rs @@ -87,7 +87,9 @@ impl Backend { /// Save a new color pair. fn insert_color( - &self, pairs: &mut HashMap<(i16, i16), i32>, (front, back): (i16, i16), + &self, + pairs: &mut HashMap<(i16, i16), i32>, + (front, back): (i16, i16), ) -> i32 { let n = 1 + pairs.len() as i32; diff --git a/src/backend/mod.rs b/src/backend/mod.rs index 9583124..a950298 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -20,8 +20,8 @@ pub mod dummy; pub mod blt; pub mod crossterm; pub mod curses; -pub mod termion; pub mod puppet; +pub mod termion; /// Trait defining the required methods to be a backend. /// diff --git a/src/backend/puppet/mod.rs b/src/backend/puppet/mod.rs index 207784a..7decc37 100644 --- a/src/backend/puppet/mod.rs +++ b/src/backend/puppet/mod.rs @@ -6,12 +6,12 @@ use crate::backend::puppet::observed::ObservedCell; use crate::backend::puppet::observed::ObservedScreen; use crate::backend::puppet::observed::ObservedStyle; use crate::event::Event; +use crate::theme; +use crate::vec::Vec2; use std::cell::RefCell; use std::rc::Rc; -use crate::theme; use unicode_segmentation::UnicodeSegmentation; use unicode_width::UnicodeWidthStr; -use crate::vec::Vec2; pub mod observed; pub mod observed_screen_view; @@ -45,7 +45,9 @@ impl Backend { prev_frame: RefCell::new(None), current_frame: RefCell::new(ObservedScreen::new(size)), size: RefCell::new(size), - current_style: RefCell::new(Rc::new(DEFAULT_OBSERVED_STYLE.clone())), + current_style: RefCell::new(Rc::new( + DEFAULT_OBSERVED_STYLE.clone(), + )), screen_channel: crossbeam_channel::unbounded(), }; @@ -74,12 +76,11 @@ impl Backend { } impl backend::Backend for Backend { - fn poll_event(&mut self) -> Option { match self.inner_receiver.try_recv() { Ok(event) => event, Err(TryRecvError::Empty) => None, - Err(e) => panic!(e) + Err(e) => panic!(e), } } @@ -117,7 +118,8 @@ impl backend::Backend for Backend { for _ in 0..grapheme.width() - 1 { offset += 1; let spos = pos + Vec2::new(idx + offset, 0); - screen[spos] = Some(ObservedCell::new(spos, style.clone(), None)); + screen[spos] = + Some(ObservedCell::new(spos, style.clone(), None)); } } } diff --git a/src/backend/puppet/observed.rs b/src/backend/puppet/observed.rs index f8852fc..849c443 100644 --- a/src/backend/puppet/observed.rs +++ b/src/backend/puppet/observed.rs @@ -1,14 +1,14 @@ //! Structs representing output of puppet backend +use crate::theme::ColorPair; +use crate::theme::Effect; +use crate::Vec2; use enumset::EnumSet; use std::ops::Index; use std::ops::IndexMut; use std::rc::Rc; use std::string::ToString; -use crate::theme::ColorPair; -use crate::theme::Effect; use unicode_segmentation::UnicodeSegmentation; use unicode_width::UnicodeWidthStr; -use crate::Vec2; /// Style of observed cell #[derive(Debug, Clone, Eq, PartialEq)] @@ -180,10 +180,7 @@ impl ObservedScreen { } /// Returns occurences of given string pattern - pub fn find_occurences( - &self, - pattern: &str, - ) -> Vec { + pub fn find_occurences(&self, pattern: &str) -> Vec { // TODO(njskalski): test for two-cell letters. // TODO(njskalski): fails with whitespaces like "\t". @@ -259,7 +256,6 @@ impl ObservedScreen { /// Represents rectangular piece of observed screen (Puppet backend output) pub trait ObservedPieceInterface { - /// Minimums of coordinates fn min(&self) -> Vec2; /// Maximums of coordinates @@ -393,7 +389,7 @@ impl<'a> ObservedPieceInterface for ObservedLine<'a> { } fn max(&self) -> Vec2 { - self.line_start + Vec2::new(self.line_len, 1) + self.line_start + (self.line_len, 1) } fn parent(&self) -> &ObservedScreen { @@ -407,12 +403,11 @@ impl<'a> ToString for ObservedLine<'a> { } } -impl Index for ObservedPieceInterface { +impl Index for dyn ObservedPieceInterface { type Output = Option; fn index(&self, index: Vec2) -> &Self::Output { - assert!(self.max().x - self.min().x > index.x); - assert!(self.max().y - self.min().y > index.y); + assert!(self.max() - self.min() > index); let parent_index = self.min() + index; diff --git a/src/backend/puppet/static_values.rs b/src/backend/puppet/static_values.rs index 3bbea17..6dcaef8 100644 --- a/src/backend/puppet/static_values.rs +++ b/src/backend/puppet/static_values.rs @@ -1,10 +1,8 @@ /// Some default values to Puppet backend. -#[allow(missing_docs)] - use lazy_static::lazy_static; -use crate::theme::{Color, Effect}; use crate::theme::ColorPair; +use crate::theme::{Color, Effect}; use crate::vec::Vec2; use crate::XY; use enumset::EnumSet; @@ -12,7 +10,10 @@ use enumset::EnumSet; use crate::backend::puppet::observed::*; lazy_static! { + /// Default size for the puppet terminal. pub static ref DEFAULT_SIZE: Vec2 = XY:: { x: 120, y: 80 }; + + /// Default style for the puppet terminal. pub static ref DEFAULT_OBSERVED_STYLE: ObservedStyle = ObservedStyle { colors: ColorPair { front: Color::TerminalDefault, diff --git a/src/backend/resize.rs b/src/backend/resize.rs index 9efe4bb..6dc9972 100644 --- a/src/backend/resize.rs +++ b/src/backend/resize.rs @@ -8,7 +8,8 @@ use signal_hook::iterator::Signals; /// This starts a new thread to listen for SIGWINCH signals #[allow(unused)] pub fn start_resize_thread( - resize_sender: Sender<()>, resize_running: Arc, + resize_sender: Sender<()>, + resize_running: Arc, ) { let signals = Signals::new(&[libc::SIGWINCH]).unwrap(); thread::spawn(move || { diff --git a/src/cursive.rs b/src/cursive.rs index e82ed63..c98c8a3 100644 --- a/src/cursive.rs +++ b/src/cursive.rs @@ -407,7 +407,8 @@ impl Cursive { /// /// `filename` must point to a valid toml file. pub fn load_theme_file>( - &mut self, filename: P, + &mut self, + filename: P, ) -> Result<(), theme::Error> { theme::load_theme_file(filename).map(|theme| self.set_theme(theme)) } @@ -512,7 +513,9 @@ impl Cursive { /// # } /// ``` pub fn call_on( - &mut self, sel: &view::Selector<'_>, callback: F, + &mut self, + sel: &view::Selector<'_>, + callback: F, ) -> Option where V: View + Any, @@ -696,7 +699,9 @@ impl Cursive { /// Convenient stub forwarding layer repositioning. pub fn reposition_layer( - &mut self, layer: LayerPosition, position: Position, + &mut self, + layer: LayerPosition, + position: Position, ) { self.screen_mut().reposition_layer(layer, position); } diff --git a/src/lib.rs b/src/lib.rs index 7496d30..700ab1e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -89,7 +89,6 @@ pub mod theme; pub mod vec; pub mod views; - // This probably doesn't need to be public? mod cursive; mod printer; diff --git a/src/printer.rs b/src/printer.rs index 6075be7..f822540 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -67,7 +67,9 @@ impl<'a, 'b> Printer<'a, 'b> { /// But nobody needs to know that. #[doc(hidden)] pub fn new>( - size: T, theme: &'a Theme, backend: &'b dyn Backend, + size: T, + theme: &'a Theme, + backend: &'b dyn Backend, ) -> Self { let size = size.into(); Printer { @@ -94,7 +96,9 @@ impl<'a, 'b> Printer<'a, 'b> { /// Prints some styled text at the given position. pub fn print_styled( - &self, start: S, text: crate::utils::span::SpannedStr<'_, Style>, + &self, + start: S, + text: crate::utils::span::SpannedStr<'_, Style>, ) where S: Into, { @@ -197,7 +201,10 @@ impl<'a, 'b> Printer<'a, 'b> { /// Prints a vertical line using the given character. pub fn print_vline>( - &self, start: T, height: usize, c: &str, + &self, + start: T, + height: usize, + c: &str, ) { let start = start.into(); @@ -234,7 +241,11 @@ impl<'a, 'b> Printer<'a, 'b> { /// Prints a line using the given character. pub fn print_line>( - &self, orientation: Orientation, start: T, length: usize, c: &str, + &self, + orientation: Orientation, + start: T, + length: usize, + c: &str, ) { match orientation { Orientation::Vertical => self.print_vline(start, length, c), @@ -384,7 +395,10 @@ impl<'a, 'b> Printer<'a, 'b> { /// printer.print_box((0,0), (6,4), false); /// ``` pub fn print_box, S: Into>( - &self, start: T, size: S, invert: bool, + &self, + start: T, + size: S, + invert: bool, ) { let start = start.into(); let size = size.into(); @@ -455,7 +469,9 @@ impl<'a, 'b> Printer<'a, 'b> { /// uses `ColorStyle::highlight()`. /// * Otherwise, uses `ColorStyle::highlight_inactive()`. pub fn with_selection)>( - &self, selection: bool, f: F, + &self, + selection: bool, + f: F, ) { self.with_color( if selection { diff --git a/src/theme/palette.rs b/src/theme/palette.rs index 62d4fac..61cfc5d 100644 --- a/src/theme/palette.rs +++ b/src/theme/palette.rs @@ -125,7 +125,9 @@ impl Palette { /// Adds a color namespace to this palette. pub fn add_namespace( - &mut self, key: &str, namespace: HashMap, + &mut self, + key: &str, + namespace: HashMap, ) { self.custom .insert(key.to_string(), PaletteNode::Namespace(namespace)); diff --git a/src/utils/lines/spans/lines_iterator.rs b/src/utils/lines/spans/lines_iterator.rs index fa6b653..a063e70 100644 --- a/src/utils/lines/spans/lines_iterator.rs +++ b/src/utils/lines/spans/lines_iterator.rs @@ -164,10 +164,7 @@ where // Concatenate all segments let segments = SegmentMergeIterator::new( - chunks - .into_iter() - .flat_map(|chunk| chunk.segments) - //.filter(|segment| segment.start != segment.end), + chunks.into_iter().flat_map(|chunk| chunk.segments), //.filter(|segment| segment.start != segment.end), ) .collect(); diff --git a/src/utils/lines/spans/prefix.rs b/src/utils/lines/spans/prefix.rs index 7c7d5fa..d18e799 100644 --- a/src/utils/lines/spans/prefix.rs +++ b/src/utils/lines/spans/prefix.rs @@ -3,7 +3,9 @@ use std::iter::Peekable; /// Concatenates chunks as long as they fit in the given width. pub fn prefix( - tokens: &mut Peekable, width: usize, offset: &mut ChunkPart, + tokens: &mut Peekable, + width: usize, + offset: &mut ChunkPart, ) -> Vec where I: Iterator, diff --git a/src/view/boxable.rs b/src/view/boxable.rs index de6d26d..97a0296 100644 --- a/src/view/boxable.rs +++ b/src/view/boxable.rs @@ -8,7 +8,9 @@ use crate::views::BoxView; pub trait Boxable: View + Sized { /// Wraps `self` in a `BoxView` with the given size constraints. fn boxed( - self, width: SizeConstraint, height: SizeConstraint, + self, + width: SizeConstraint, + height: SizeConstraint, ) -> BoxView { BoxView::new(width, height, self) } diff --git a/src/view/finder.rs b/src/view/finder.rs index f5c0c81..ad7f570 100644 --- a/src/view/finder.rs +++ b/src/view/finder.rs @@ -17,7 +17,9 @@ pub trait Finder { /// If the view is not found, or if it is not of the asked type, /// it returns `None`. fn call_on( - &mut self, sel: &Selector<'_>, callback: F, + &mut self, + sel: &Selector<'_>, + callback: F, ) -> Option where V: View + Any, @@ -45,7 +47,9 @@ pub trait Finder { impl Finder for T { fn call_on( - &mut self, sel: &Selector<'_>, callback: F, + &mut self, + sel: &Selector<'_>, + callback: F, ) -> Option where V: View + Any, diff --git a/src/view/position.rs b/src/view/position.rs index 20c631d..9c61fed 100644 --- a/src/view/position.rs +++ b/src/view/position.rs @@ -30,7 +30,10 @@ impl Position { /// child with its top-left corner at the returned coordinates will /// position him appropriately. pub fn compute_offset( - &self, size: S, available: A, parent: P, + &self, + size: S, + available: A, + parent: P, ) -> Vec2 where S: Into, @@ -65,7 +68,10 @@ pub enum Offset { impl Offset { /// Computes a single-dimension offset requred to draw a view. pub fn compute_offset( - &self, size: usize, available: usize, parent: usize, + &self, + size: usize, + available: usize, + parent: usize, ) -> usize { if size > available { 0 diff --git a/src/view/scroll/core.rs b/src/view/scroll/core.rs index 532d112..d80b820 100644 --- a/src/view/scroll/core.rs +++ b/src/view/scroll/core.rs @@ -97,7 +97,8 @@ impl Core { /// Returns a sub-printer ready to draw the content. pub fn sub_printer<'a, 'b>( - &self, printer: &Printer<'a, 'b>, + &self, + printer: &Printer<'a, 'b>, ) -> Printer<'a, 'b> { // Draw scrollbar? let scrolling = self.is_scrolling(); @@ -184,7 +185,9 @@ impl Core { /// Handle an event after processing by the content. pub fn on_inner_event( - &mut self, event: Event, inner_result: EventResult, + &mut self, + event: Event, + inner_result: EventResult, important_area: Rect, ) -> EventResult { match inner_result { @@ -362,7 +365,9 @@ impl Core { /// Performs `View::call_on_any()` pub fn call_on_any<'a, F>( - &mut self, selector: &Selector<'_>, cb: AnyCb<'a>, + &mut self, + selector: &Selector<'_>, + cb: AnyCb<'a>, inner_call_on_any: F, ) where F: FnOnce(&Selector, AnyCb), @@ -372,7 +377,9 @@ impl Core { /// Performs `View::focus_view()` pub fn focus_view( - &mut self, selector: &Selector<'_>, inner_focus_view: F, + &mut self, + selector: &Selector<'_>, + inner_focus_view: F, ) -> Result<(), ()> where F: FnOnce(&Selector) -> Result<(), ()>, @@ -406,7 +413,8 @@ impl Core { /// Sets the padding between content and scrollbar. pub fn set_scrollbar_padding>( - &mut self, scrollbar_padding: V, + &mut self, + scrollbar_padding: V, ) { self.scrollbar_padding = scrollbar_padding.into(); } @@ -415,7 +423,8 @@ impl Core { /// /// Chainable variant. pub fn scrollbar_padding>( - self, scrollbar_padding: V, + self, + scrollbar_padding: V, ) -> Self { self.with(|s| s.set_scrollbar_padding(scrollbar_padding)) } diff --git a/src/view/scroll/mod.rs b/src/view/scroll/mod.rs index 187fff2..8d4300e 100644 --- a/src/view/scroll/mod.rs +++ b/src/view/scroll/mod.rs @@ -54,7 +54,9 @@ impl Default for ScrollStrategy { /// } /// ``` pub fn on_event( - scroller: &mut T, event: Event, on_event: OnEvent, + scroller: &mut T, + event: Event, + on_event: OnEvent, important_area: ImportantArea, ) -> EventResult where @@ -73,7 +75,9 @@ where /// Performs `View::important_area` on a `scroll::Scroller`. pub fn important_area( - scroller: &T, size: Vec2, mut important_area: ImportantArea, + scroller: &T, + size: Vec2, + mut important_area: ImportantArea, ) -> Rect where T: Scroller, @@ -92,7 +96,10 @@ where /// Performs `View::layout` on a `scroll::Scroller`. pub fn layout( - scroller: &mut T, size: Vec2, needs_relayout: bool, layout: Layout, + scroller: &mut T, + size: Vec2, + needs_relayout: bool, + layout: Layout, required_size: RequiredSize, ) where T: Scroller, @@ -111,7 +118,9 @@ pub fn layout( /// Performs `View::required_size` on a `scroll::Scroller`. pub fn required_size( - scroller: &mut T, size: Vec2, needs_relayout: bool, + scroller: &mut T, + size: Vec2, + needs_relayout: bool, required_size: RequiredSize, ) -> Vec2 where @@ -140,7 +149,9 @@ where /// /// This is an alternative to `scroll::draw()` when you just need to print individual lines. pub fn draw_lines( - scroller: &T, printer: &Printer, mut line_drawer: LineDrawer, + scroller: &T, + printer: &Printer, + mut line_drawer: LineDrawer, ) where T: Scroller, LineDrawer: FnMut(&T, &Printer, usize), @@ -159,8 +170,11 @@ pub fn draw_lines( /// /// `left_border` will be called for each row to draw the left border for the given line number. pub fn draw_frame( - scroller: &T, printer: &Printer, mut left_border: LeftBorder, - mut top_border: TopBorder, mut right_border: RightBorder, + scroller: &T, + printer: &Printer, + mut left_border: LeftBorder, + mut top_border: TopBorder, + mut right_border: RightBorder, mut bottom_border: BottomBorder, ) where T: Scroller, @@ -180,11 +194,7 @@ pub fn draw_frame( // Also draw padding let scrollbar_size = scroller.get_scroller().scrollbar_size(); printer.print_hline((viewport.right() + 2, 0), scrollbar_size.x, "─"); - printer.print_hline( - (viewport.right() + 2, size.y), - scrollbar_size.x, - "─", - ); + printer.print_hline((viewport.right() + 2, size.y), scrollbar_size.x, "─"); printer.print_vline((0, viewport.bottom() + 2), scrollbar_size.y, "│"); printer.print_vline( (size.x, viewport.bottom() + 2), @@ -210,7 +220,9 @@ pub fn draw_frame( /// /// It will print a box with the appropriate `├`, `┤` and so on. pub fn draw_box_frame( - scroller: &T, printer: &Printer, is_h_delim: IsHDelim, + scroller: &T, + printer: &Printer, + is_h_delim: IsHDelim, is_v_delim: IsVDelim, ) where T: Scroller, diff --git a/src/view/scroll/raw.rs b/src/view/scroll/raw.rs index 3da714c..1ed0aba 100644 --- a/src/view/scroll/raw.rs +++ b/src/view/scroll/raw.rs @@ -11,7 +11,9 @@ use crate::Vec2; /// Implements `View::draw` over the `model`. pub fn draw( - printer: &Printer, model: &Model, mut get_scroller: GetScroller, + printer: &Printer, + model: &Model, + mut get_scroller: GetScroller, inner_draw: Draw, ) where Model: ?Sized, @@ -30,8 +32,12 @@ pub fn draw( /// /// Returns (Inner size, Outer size, New scrolling) fn sizes_when_scrolling( - constraint: Vec2, scrolling: XY, strict: bool, model: &mut Model, - get_scroller: &mut GetScroller, required_size: &mut RequiredSize, + constraint: Vec2, + scrolling: XY, + strict: bool, + model: &mut Model, + get_scroller: &mut GetScroller, + required_size: &mut RequiredSize, ) -> (Vec2, Vec2, XY) where Model: ?Sized, @@ -77,8 +83,12 @@ where /// /// Returns (Inner size, Outer size) fn sizes( - constraint: Vec2, strict: bool, needs_relayout: bool, model: &mut Model, - get_scroller: &mut GetScroller, required_size: &mut RequiredSize, + constraint: Vec2, + strict: bool, + needs_relayout: bool, + model: &mut Model, + get_scroller: &mut GetScroller, + required_size: &mut RequiredSize, ) -> (Vec2, Vec2) where Model: ?Sized, @@ -141,8 +151,11 @@ where /// Implements `View::layout` on the given model. pub fn layout( - size: Vec2, needs_relayout: bool, model: &mut Model, - mut get_scroller: GetScroller, mut required_size: RequiredSize, + size: Vec2, + needs_relayout: bool, + model: &mut Model, + mut get_scroller: GetScroller, + mut required_size: RequiredSize, mut layout: Layout, ) where Model: ?Sized, @@ -172,8 +185,11 @@ pub fn layout( /// Implements `View::required_size` on the given model. pub fn required_size( - constraint: Vec2, needs_relayout: bool, model: &mut Model, - mut get_scroller: GetScroller, mut required_size: RequiredSize, + constraint: Vec2, + needs_relayout: bool, + model: &mut Model, + mut get_scroller: GetScroller, + mut required_size: RequiredSize, ) -> Vec2 where Model: ?Sized, @@ -194,8 +210,11 @@ where /// Implements `View::on_event` on the given model. pub fn on_event( - event: Event, model: &mut Model, mut get_scroller: GetScroller, - mut on_event: OnEvent, mut important_area: ImportantArea, + event: Event, + model: &mut Model, + mut get_scroller: GetScroller, + mut on_event: OnEvent, + mut important_area: ImportantArea, ) -> EventResult where Model: ?Sized, diff --git a/src/view/view_wrapper.rs b/src/view/view_wrapper.rs index 7a46a3f..ad49278 100644 --- a/src/view/view_wrapper.rs +++ b/src/view/view_wrapper.rs @@ -79,7 +79,9 @@ pub trait ViewWrapper: 'static { /// Wraps the `find` method. fn wrap_call_on_any<'a>( - &mut self, selector: &Selector<'_>, callback: AnyCb<'a>, + &mut self, + selector: &Selector<'_>, + callback: AnyCb<'a>, ) { self.with_view_mut(|v| v.call_on_any(selector, callback)); } @@ -125,7 +127,8 @@ impl View for T { } fn call_on_any<'a>( - &mut self, selector: &Selector<'_>, + &mut self, + selector: &Selector<'_>, callback: Box, ) { self.wrap_call_on_any(selector, callback) diff --git a/src/views/box_view.rs b/src/views/box_view.rs index 1bfdfff..bd2a73d 100644 --- a/src/views/box_view.rs +++ b/src/views/box_view.rs @@ -43,7 +43,9 @@ impl BoxView { /// /// `None` values will use the wrapped view's preferences. pub fn new( - width: SizeConstraint, height: SizeConstraint, view: T, + width: SizeConstraint, + height: SizeConstraint, + view: T, ) -> Self { BoxView { size: (width, height).into(), @@ -55,7 +57,9 @@ impl BoxView { /// Sets the size constraints for this view. pub fn set_constraints( - &mut self, width: SizeConstraint, height: SizeConstraint, + &mut self, + width: SizeConstraint, + height: SizeConstraint, ) { self.set_width(width); self.set_height(height); diff --git a/src/views/checkbox.rs b/src/views/checkbox.rs index 9e90c6a..b66848b 100644 --- a/src/views/checkbox.rs +++ b/src/views/checkbox.rs @@ -32,7 +32,8 @@ impl Checkbox { /// Sets a callback to be used when the state changes. pub fn set_on_change( - &mut self, on_change: F, + &mut self, + on_change: F, ) { self.on_change = Some(Rc::new(on_change)); } @@ -41,7 +42,8 @@ impl Checkbox { /// /// Chainable variant. pub fn on_change( - self, on_change: F, + self, + on_change: F, ) -> Self { self.with(|s| s.set_on_change(on_change)) } diff --git a/src/views/dialog.rs b/src/views/dialog.rs index ee8388d..8c74d16 100644 --- a/src/views/dialog.rs +++ b/src/views/dialog.rs @@ -317,7 +317,9 @@ impl Dialog { // An event is received while a button is in focus fn on_event_button( - &mut self, event: Event, button_id: usize, + &mut self, + event: Event, + button_id: usize, ) -> EventResult { let result = { let button = &mut self.buttons[button_id]; @@ -655,7 +657,9 @@ impl View for Dialog { } fn call_on_any<'a>( - &mut self, selector: &Selector<'_>, callback: AnyCb<'a>, + &mut self, + selector: &Selector<'_>, + callback: AnyCb<'a>, ) { self.content.call_on_any(selector, callback); } diff --git a/src/views/hideable_view.rs b/src/views/hideable_view.rs index 9458742..bba943f 100644 --- a/src/views/hideable_view.rs +++ b/src/views/hideable_view.rs @@ -91,7 +91,8 @@ impl ViewWrapper for HideableView { } fn wrap_call_on_any<'a>( - &mut self, selector: &Selector<'_>, + &mut self, + selector: &Selector<'_>, callback: Box, ) { // We always run callbacks, even when invisible. diff --git a/src/views/id_view.rs b/src/views/id_view.rs index 7800615..0548dd1 100644 --- a/src/views/id_view.rs +++ b/src/views/id_view.rs @@ -77,7 +77,9 @@ impl ViewWrapper for IdView { // Some for<'b> weirdness here to please the borrow checker gods... fn wrap_call_on_any<'a>( - &mut self, selector: &Selector<'_>, mut callback: BoxedCallback<'a>, + &mut self, + selector: &Selector<'_>, + mut callback: BoxedCallback<'a>, ) { match selector { &Selector::Id(id) if id == self.id => callback(self), diff --git a/src/views/linear_layout.rs b/src/views/linear_layout.rs index 4d15314..619fb61 100644 --- a/src/views/linear_layout.rs +++ b/src/views/linear_layout.rs @@ -58,7 +58,9 @@ struct ChildItem { impl ChildIterator { fn new( - inner: T, orientation: direction::Orientation, available: usize, + inner: T, + orientation: direction::Orientation, + available: usize, ) -> Self { ChildIterator { inner, @@ -272,7 +274,9 @@ impl LinearLayout { /// Returns a cyclic mutable iterator starting with the child in focus fn iter_mut<'a>( - &'a mut self, from_focus: bool, source: direction::Relative, + &'a mut self, + from_focus: bool, + source: direction::Relative, ) -> Box + 'a> { match source { direction::Relative::Front => { @@ -358,7 +362,8 @@ impl LinearLayout { } fn try_focus( - (i, child): (usize, &mut Child), source: direction::Direction, + (i, child): (usize, &mut Child), + source: direction::Direction, ) -> Option { if child.view.take_focus(source) { Some(i) @@ -632,7 +637,9 @@ impl View for LinearLayout { } fn call_on_any<'a>( - &mut self, selector: &Selector<'_>, mut callback: AnyCb<'a>, + &mut self, + selector: &Selector<'_>, + mut callback: AnyCb<'a>, ) { for child in &mut self.children { child diff --git a/src/views/menubar.rs b/src/views/menubar.rs index 74817d9..1786f13 100644 --- a/src/views/menubar.rs +++ b/src/views/menubar.rs @@ -107,7 +107,10 @@ impl Menubar { /// Insert a new item at the given position. pub fn insert_subtree( - &mut self, i: usize, title: S, menu: MenuTree, + &mut self, + i: usize, + title: S, + menu: MenuTree, ) -> &mut Self where S: Into, diff --git a/src/views/progress_bar.rs b/src/views/progress_bar.rs index 5eb8647..1a6a015 100644 --- a/src/views/progress_bar.rs +++ b/src/views/progress_bar.rs @@ -121,7 +121,8 @@ impl ProgressBar { /// /// Chainable variant. pub fn with_task( - mut self, task: F, + mut self, + task: F, ) -> Self { self.start(task); self @@ -141,7 +142,8 @@ impl ProgressBar { /// } /// ``` pub fn with_label String + 'static>( - mut self, label_maker: F, + mut self, + label_maker: F, ) -> Self { self.label_maker = Box::new(label_maker); self diff --git a/src/views/radio.rs b/src/views/radio.rs index a0fc8ea..2e72dfe 100644 --- a/src/views/radio.rs +++ b/src/views/radio.rs @@ -56,7 +56,9 @@ impl RadioGroup { /// /// The button will display `label` next to it, and will embed `value`. pub fn button>( - &mut self, value: T, label: S, + &mut self, + value: T, + label: S, ) -> RadioButton { let count = self.state.borrow().values.len(); self.state.borrow_mut().values.push(Rc::new(value)); @@ -77,7 +79,8 @@ impl RadioGroup { /// Sets a callback to be used when the selection changes. pub fn set_on_change( - &mut self, on_change: F, + &mut self, + on_change: F, ) { self.state.borrow_mut().on_change = Some(Rc::new(on_change)); } @@ -86,7 +89,8 @@ impl RadioGroup { /// /// Chainable variant. pub fn on_change( - self, on_change: F, + self, + on_change: F, ) -> Self { self.with(|s| s.set_on_change(on_change)) } @@ -95,7 +99,8 @@ impl RadioGroup { impl RadioGroup { /// Adds a button, using the label itself as value. pub fn button_str>( - &mut self, text: S, + &mut self, + text: S, ) -> RadioButton { let text = text.into(); self.button(text.clone(), text) @@ -124,7 +129,9 @@ impl RadioButton { impl_enabled!(self.enabled); fn new( - state: Rc>>, id: usize, label: String, + state: Rc>>, + id: usize, + label: String, ) -> Self { RadioButton { state, diff --git a/src/views/select_view.rs b/src/views/select_view.rs index 254976b..f12e11c 100644 --- a/src/views/select_view.rs +++ b/src/views/select_view.rs @@ -273,7 +273,8 @@ impl SelectView { /// Gets a mut item at given idx or None. pub fn get_item_mut( - &mut self, i: usize, + &mut self, + i: usize, ) -> Option<(&mut StyledString, &mut T)> { if i >= self.items.len() { None diff --git a/src/views/stack_view.rs b/src/views/stack_view.rs index f391f9e..1770107 100644 --- a/src/views/stack_view.rs +++ b/src/views/stack_view.rs @@ -42,7 +42,10 @@ pub enum LayerPosition { impl Placement { pub fn compute_offset( - &self, size: S, available: A, parent: P, + &self, + size: S, + available: A, + parent: P, ) -> Vec2 where S: Into, @@ -169,7 +172,9 @@ impl View for ChildWrapper { } fn call_on_any<'a>( - &mut self, selector: &Selector<'_>, callback: AnyCb<'a>, + &mut self, + selector: &Selector<'_>, + callback: AnyCb<'a>, ) { match *self { ChildWrapper::Shadow(ref mut v) => { @@ -490,7 +495,9 @@ impl StackView { /// /// If `layer` is out of bounds. pub fn reposition_layer( - &mut self, layer: LayerPosition, position: Position, + &mut self, + layer: LayerPosition, + position: Position, ) { let i = self.get_index(layer).unwrap(); let child = &mut self.layers[i]; @@ -659,7 +666,9 @@ impl View for StackView { } fn call_on_any<'a>( - &mut self, selector: &Selector<'_>, mut callback: AnyCb<'a>, + &mut self, + selector: &Selector<'_>, + mut callback: AnyCb<'a>, ) { for layer in &mut self.layers { layer diff --git a/src/xy.rs b/src/xy.rs index 5a75544..5fbd58a 100644 --- a/src/xy.rs +++ b/src/xy.rs @@ -280,7 +280,10 @@ impl XY { /// ); /// ``` pub fn zip4( - self, a: XY, b: XY, c: XY, + self, + a: XY, + b: XY, + c: XY, ) -> XY<(T, U, V, W)> { XY::new((self.x, a.x, b.x, c.x), (self.y, a.y, b.y, c.y)) } @@ -308,7 +311,11 @@ impl XY { /// assert_eq!(xy, XY::new(Some('a'), Some('y'))); /// ``` pub fn zip5( - self, a: XY, b: XY, c: XY, d: XY, + self, + a: XY, + b: XY, + c: XY, + d: XY, ) -> XY<(T, U, V, W, Z)> { XY::new((self.x, a.x, b.x, c.x, d.x), (self.y, a.y, b.y, c.y, d.y)) }