Moves to "Tall" fn_args_layout
This commit is contained in:
Alexandre Bury 2019-07-30 16:08:05 -07:00
parent 4a1fc3e49d
commit b7d71e8381
36 changed files with 256 additions and 119 deletions

View File

@ -11,17 +11,19 @@ fn main() {
pub mod tests { pub mod tests {
extern crate cursive; extern crate cursive;
use self::cursive::backend::puppet::observed::{
ObservedCell, ObservedPieceInterface,
};
use cursive::align::HAlign; use cursive::align::HAlign;
use cursive::backend::puppet::observed::ObservedScreen;
use cursive::event::Event;
use cursive::event::EventResult; use cursive::event::EventResult;
use cursive::event::Key;
use cursive::traits::*; use cursive::traits::*;
use cursive::views::*; use cursive::views::*;
use cursive::*; use cursive::*;
use cursive::backend::puppet::observed::ObservedScreen;
use cursive::event::Event;
use std::cell::RefCell; use std::cell::RefCell;
use std::time::Duration; use std::time::Duration;
use cursive::event::Key;
use self::cursive::backend::puppet::observed::{ObservedCell, ObservedPieceInterface};
pub struct BasicSetup { pub struct BasicSetup {
siv: Cursive, siv: Cursive,
@ -77,7 +79,7 @@ pub mod tests {
siv, siv,
screen_stream: sink, screen_stream: sink,
input, input,
last_screen : RefCell::new(None) last_screen: RefCell::new(None),
} }
} }
@ -90,9 +92,7 @@ pub mod tests {
} }
pub fn dump_debug(&self) { pub fn dump_debug(&self) {
self.last_screen().as_ref().map(|s| { self.last_screen().as_ref().map(|s| s.print_stdout());
s.print_stdout()
});
} }
pub fn hit_keystroke(&mut self, key: Key) { pub fn hit_keystroke(&mut self, key: Key) {
@ -111,7 +111,6 @@ pub mod tests {
); );
} }
#[test] #[test]
fn displays() { fn displays() {
let mut s = BasicSetup::new(); let mut s = BasicSetup::new();
@ -129,7 +128,10 @@ pub mod tests {
let mut screen = s.last_screen().unwrap(); let mut screen = s.last_screen().unwrap();
s.dump_debug(); 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); assert_eq!(screen.find_occurences("Abidjan").len(), 0);
} }
} }

View File

@ -1,5 +1,5 @@
unstable_features = true unstable_features = true
max_width = 79 max_width = 79
reorder_imports = true reorder_imports = true
fn_args_density = "Compressed" fn_args_layout = "Tall"

View File

@ -112,7 +112,10 @@ impl Backend {
} }
fn blt_keycode_to_ev( fn blt_keycode_to_ev(
&mut self, kc: KeyCode, shift: bool, ctrl: bool, &mut self,
kc: KeyCode,
shift: bool,
ctrl: bool,
) -> Event { ) -> Event {
match kc { match kc {
KeyCode::F1 KeyCode::F1

View File

@ -251,7 +251,9 @@ impl backend::Backend for Backend {
theme::Effect::Reverse => self.set_attr(Attribute::Reverse), theme::Effect::Reverse => self.set_attr(Attribute::Reverse),
theme::Effect::Bold => self.set_attr(Attribute::Bold), theme::Effect::Bold => self.set_attr(Attribute::Bold),
theme::Effect::Italic => self.set_attr(Attribute::Italic), 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), 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::Reverse => self.set_attr(Attribute::Reverse),
theme::Effect::Bold => self.set_attr(Attribute::NoBold), theme::Effect::Bold => self.set_attr(Attribute::NoBold),
theme::Effect::Italic => self.set_attr(Attribute::NoItalic), 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), theme::Effect::Underline => self.set_attr(Attribute::Underlined),
} }
} }

View File

@ -128,7 +128,9 @@ impl Backend {
/// Save a new color pair. /// Save a new color pair.
fn insert_color( 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 { ) -> i16 {
let n = 1 + pairs.len() as i16; let n = 1 + pairs.len() as i16;

View File

@ -87,7 +87,9 @@ impl Backend {
/// Save a new color pair. /// Save a new color pair.
fn insert_color( 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 { ) -> i32 {
let n = 1 + pairs.len() as i32; let n = 1 + pairs.len() as i32;

View File

@ -20,8 +20,8 @@ pub mod dummy;
pub mod blt; pub mod blt;
pub mod crossterm; pub mod crossterm;
pub mod curses; pub mod curses;
pub mod termion;
pub mod puppet; pub mod puppet;
pub mod termion;
/// Trait defining the required methods to be a backend. /// Trait defining the required methods to be a backend.
/// ///

View File

@ -6,12 +6,12 @@ use crate::backend::puppet::observed::ObservedCell;
use crate::backend::puppet::observed::ObservedScreen; use crate::backend::puppet::observed::ObservedScreen;
use crate::backend::puppet::observed::ObservedStyle; use crate::backend::puppet::observed::ObservedStyle;
use crate::event::Event; use crate::event::Event;
use crate::theme;
use crate::vec::Vec2;
use std::cell::RefCell; use std::cell::RefCell;
use std::rc::Rc; use std::rc::Rc;
use crate::theme;
use unicode_segmentation::UnicodeSegmentation; use unicode_segmentation::UnicodeSegmentation;
use unicode_width::UnicodeWidthStr; use unicode_width::UnicodeWidthStr;
use crate::vec::Vec2;
pub mod observed; pub mod observed;
pub mod observed_screen_view; pub mod observed_screen_view;
@ -45,7 +45,9 @@ impl Backend {
prev_frame: RefCell::new(None), prev_frame: RefCell::new(None),
current_frame: RefCell::new(ObservedScreen::new(size)), current_frame: RefCell::new(ObservedScreen::new(size)),
size: RefCell::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(), screen_channel: crossbeam_channel::unbounded(),
}; };
@ -74,12 +76,11 @@ impl Backend {
} }
impl backend::Backend for Backend { impl backend::Backend for Backend {
fn poll_event(&mut self) -> Option<Event> { fn poll_event(&mut self) -> Option<Event> {
match self.inner_receiver.try_recv() { match self.inner_receiver.try_recv() {
Ok(event) => event, Ok(event) => event,
Err(TryRecvError::Empty) => None, 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 { for _ in 0..grapheme.width() - 1 {
offset += 1; offset += 1;
let spos = pos + Vec2::new(idx + offset, 0); 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));
} }
} }
} }

View File

@ -1,14 +1,14 @@
//! Structs representing output of puppet backend //! Structs representing output of puppet backend
use crate::theme::ColorPair;
use crate::theme::Effect;
use crate::Vec2;
use enumset::EnumSet; use enumset::EnumSet;
use std::ops::Index; use std::ops::Index;
use std::ops::IndexMut; use std::ops::IndexMut;
use std::rc::Rc; use std::rc::Rc;
use std::string::ToString; use std::string::ToString;
use crate::theme::ColorPair;
use crate::theme::Effect;
use unicode_segmentation::UnicodeSegmentation; use unicode_segmentation::UnicodeSegmentation;
use unicode_width::UnicodeWidthStr; use unicode_width::UnicodeWidthStr;
use crate::Vec2;
/// Style of observed cell /// Style of observed cell
#[derive(Debug, Clone, Eq, PartialEq)] #[derive(Debug, Clone, Eq, PartialEq)]
@ -180,10 +180,7 @@ impl ObservedScreen {
} }
/// Returns occurences of given string pattern /// Returns occurences of given string pattern
pub fn find_occurences( pub fn find_occurences(&self, pattern: &str) -> Vec<ObservedLine> {
&self,
pattern: &str,
) -> Vec<ObservedLine> {
// TODO(njskalski): test for two-cell letters. // TODO(njskalski): test for two-cell letters.
// TODO(njskalski): fails with whitespaces like "\t". // TODO(njskalski): fails with whitespaces like "\t".
@ -259,7 +256,6 @@ impl ObservedScreen {
/// Represents rectangular piece of observed screen (Puppet backend output) /// Represents rectangular piece of observed screen (Puppet backend output)
pub trait ObservedPieceInterface { pub trait ObservedPieceInterface {
/// Minimums of coordinates /// Minimums of coordinates
fn min(&self) -> Vec2; fn min(&self) -> Vec2;
/// Maximums of coordinates /// Maximums of coordinates
@ -393,7 +389,7 @@ impl<'a> ObservedPieceInterface for ObservedLine<'a> {
} }
fn max(&self) -> Vec2 { fn max(&self) -> Vec2 {
self.line_start + Vec2::new(self.line_len, 1) self.line_start + (self.line_len, 1)
} }
fn parent(&self) -> &ObservedScreen { fn parent(&self) -> &ObservedScreen {
@ -407,12 +403,11 @@ impl<'a> ToString for ObservedLine<'a> {
} }
} }
impl Index<Vec2> for ObservedPieceInterface { impl Index<Vec2> for dyn ObservedPieceInterface {
type Output = Option<ObservedCell>; type Output = Option<ObservedCell>;
fn index(&self, index: Vec2) -> &Self::Output { fn index(&self, index: Vec2) -> &Self::Output {
assert!(self.max().x - self.min().x > index.x); assert!(self.max() - self.min() > index);
assert!(self.max().y - self.min().y > index.y);
let parent_index = self.min() + index; let parent_index = self.min() + index;

View File

@ -1,10 +1,8 @@
/// Some default values to Puppet backend. /// Some default values to Puppet backend.
#[allow(missing_docs)]
use lazy_static::lazy_static; use lazy_static::lazy_static;
use crate::theme::{Color, Effect};
use crate::theme::ColorPair; use crate::theme::ColorPair;
use crate::theme::{Color, Effect};
use crate::vec::Vec2; use crate::vec::Vec2;
use crate::XY; use crate::XY;
use enumset::EnumSet; use enumset::EnumSet;
@ -12,7 +10,10 @@ use enumset::EnumSet;
use crate::backend::puppet::observed::*; use crate::backend::puppet::observed::*;
lazy_static! { lazy_static! {
/// Default size for the puppet terminal.
pub static ref DEFAULT_SIZE: Vec2 = XY::<usize> { x: 120, y: 80 }; pub static ref DEFAULT_SIZE: Vec2 = XY::<usize> { x: 120, y: 80 };
/// Default style for the puppet terminal.
pub static ref DEFAULT_OBSERVED_STYLE: ObservedStyle = ObservedStyle { pub static ref DEFAULT_OBSERVED_STYLE: ObservedStyle = ObservedStyle {
colors: ColorPair { colors: ColorPair {
front: Color::TerminalDefault, front: Color::TerminalDefault,

View File

@ -8,7 +8,8 @@ use signal_hook::iterator::Signals;
/// This starts a new thread to listen for SIGWINCH signals /// This starts a new thread to listen for SIGWINCH signals
#[allow(unused)] #[allow(unused)]
pub fn start_resize_thread( pub fn start_resize_thread(
resize_sender: Sender<()>, resize_running: Arc<AtomicBool>, resize_sender: Sender<()>,
resize_running: Arc<AtomicBool>,
) { ) {
let signals = Signals::new(&[libc::SIGWINCH]).unwrap(); let signals = Signals::new(&[libc::SIGWINCH]).unwrap();
thread::spawn(move || { thread::spawn(move || {

View File

@ -407,7 +407,8 @@ impl Cursive {
/// ///
/// `filename` must point to a valid toml file. /// `filename` must point to a valid toml file.
pub fn load_theme_file<P: AsRef<Path>>( pub fn load_theme_file<P: AsRef<Path>>(
&mut self, filename: P, &mut self,
filename: P,
) -> Result<(), theme::Error> { ) -> Result<(), theme::Error> {
theme::load_theme_file(filename).map(|theme| self.set_theme(theme)) theme::load_theme_file(filename).map(|theme| self.set_theme(theme))
} }
@ -512,7 +513,9 @@ impl Cursive {
/// # } /// # }
/// ``` /// ```
pub fn call_on<V, F, R>( pub fn call_on<V, F, R>(
&mut self, sel: &view::Selector<'_>, callback: F, &mut self,
sel: &view::Selector<'_>,
callback: F,
) -> Option<R> ) -> Option<R>
where where
V: View + Any, V: View + Any,
@ -696,7 +699,9 @@ impl Cursive {
/// Convenient stub forwarding layer repositioning. /// Convenient stub forwarding layer repositioning.
pub fn reposition_layer( pub fn reposition_layer(
&mut self, layer: LayerPosition, position: Position, &mut self,
layer: LayerPosition,
position: Position,
) { ) {
self.screen_mut().reposition_layer(layer, position); self.screen_mut().reposition_layer(layer, position);
} }

View File

@ -89,7 +89,6 @@ pub mod theme;
pub mod vec; pub mod vec;
pub mod views; pub mod views;
// This probably doesn't need to be public? // This probably doesn't need to be public?
mod cursive; mod cursive;
mod printer; mod printer;

View File

@ -67,7 +67,9 @@ impl<'a, 'b> Printer<'a, 'b> {
/// But nobody needs to know that. /// But nobody needs to know that.
#[doc(hidden)] #[doc(hidden)]
pub fn new<T: Into<Vec2>>( pub fn new<T: Into<Vec2>>(
size: T, theme: &'a Theme, backend: &'b dyn Backend, size: T,
theme: &'a Theme,
backend: &'b dyn Backend,
) -> Self { ) -> Self {
let size = size.into(); let size = size.into();
Printer { Printer {
@ -94,7 +96,9 @@ impl<'a, 'b> Printer<'a, 'b> {
/// Prints some styled text at the given position. /// Prints some styled text at the given position.
pub fn print_styled<S>( pub fn print_styled<S>(
&self, start: S, text: crate::utils::span::SpannedStr<'_, Style>, &self,
start: S,
text: crate::utils::span::SpannedStr<'_, Style>,
) where ) where
S: Into<Vec2>, S: Into<Vec2>,
{ {
@ -197,7 +201,10 @@ impl<'a, 'b> Printer<'a, 'b> {
/// Prints a vertical line using the given character. /// Prints a vertical line using the given character.
pub fn print_vline<T: Into<Vec2>>( pub fn print_vline<T: Into<Vec2>>(
&self, start: T, height: usize, c: &str, &self,
start: T,
height: usize,
c: &str,
) { ) {
let start = start.into(); let start = start.into();
@ -234,7 +241,11 @@ impl<'a, 'b> Printer<'a, 'b> {
/// Prints a line using the given character. /// Prints a line using the given character.
pub fn print_line<T: Into<Vec2>>( pub fn print_line<T: Into<Vec2>>(
&self, orientation: Orientation, start: T, length: usize, c: &str, &self,
orientation: Orientation,
start: T,
length: usize,
c: &str,
) { ) {
match orientation { match orientation {
Orientation::Vertical => self.print_vline(start, length, c), 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); /// printer.print_box((0,0), (6,4), false);
/// ``` /// ```
pub fn print_box<T: Into<Vec2>, S: Into<Vec2>>( pub fn print_box<T: Into<Vec2>, S: Into<Vec2>>(
&self, start: T, size: S, invert: bool, &self,
start: T,
size: S,
invert: bool,
) { ) {
let start = start.into(); let start = start.into();
let size = size.into(); let size = size.into();
@ -455,7 +469,9 @@ impl<'a, 'b> Printer<'a, 'b> {
/// uses `ColorStyle::highlight()`. /// uses `ColorStyle::highlight()`.
/// * Otherwise, uses `ColorStyle::highlight_inactive()`. /// * Otherwise, uses `ColorStyle::highlight_inactive()`.
pub fn with_selection<F: FnOnce(&Printer<'_, '_>)>( pub fn with_selection<F: FnOnce(&Printer<'_, '_>)>(
&self, selection: bool, f: F, &self,
selection: bool,
f: F,
) { ) {
self.with_color( self.with_color(
if selection { if selection {

View File

@ -125,7 +125,9 @@ impl Palette {
/// Adds a color namespace to this palette. /// Adds a color namespace to this palette.
pub fn add_namespace( pub fn add_namespace(
&mut self, key: &str, namespace: HashMap<String, PaletteNode>, &mut self,
key: &str,
namespace: HashMap<String, PaletteNode>,
) { ) {
self.custom self.custom
.insert(key.to_string(), PaletteNode::Namespace(namespace)); .insert(key.to_string(), PaletteNode::Namespace(namespace));

View File

@ -164,10 +164,7 @@ where
// Concatenate all segments // Concatenate all segments
let segments = SegmentMergeIterator::new( let segments = SegmentMergeIterator::new(
chunks chunks.into_iter().flat_map(|chunk| chunk.segments), //.filter(|segment| segment.start != segment.end),
.into_iter()
.flat_map(|chunk| chunk.segments)
//.filter(|segment| segment.start != segment.end),
) )
.collect(); .collect();

View File

@ -3,7 +3,9 @@ use std::iter::Peekable;
/// Concatenates chunks as long as they fit in the given width. /// Concatenates chunks as long as they fit in the given width.
pub fn prefix<I>( pub fn prefix<I>(
tokens: &mut Peekable<I>, width: usize, offset: &mut ChunkPart, tokens: &mut Peekable<I>,
width: usize,
offset: &mut ChunkPart,
) -> Vec<Chunk> ) -> Vec<Chunk>
where where
I: Iterator<Item = Chunk>, I: Iterator<Item = Chunk>,

View File

@ -8,7 +8,9 @@ use crate::views::BoxView;
pub trait Boxable: View + Sized { pub trait Boxable: View + Sized {
/// Wraps `self` in a `BoxView` with the given size constraints. /// Wraps `self` in a `BoxView` with the given size constraints.
fn boxed( fn boxed(
self, width: SizeConstraint, height: SizeConstraint, self,
width: SizeConstraint,
height: SizeConstraint,
) -> BoxView<Self> { ) -> BoxView<Self> {
BoxView::new(width, height, self) BoxView::new(width, height, self)
} }

View File

@ -17,7 +17,9 @@ pub trait Finder {
/// If the view is not found, or if it is not of the asked type, /// If the view is not found, or if it is not of the asked type,
/// it returns `None`. /// it returns `None`.
fn call_on<V, F, R>( fn call_on<V, F, R>(
&mut self, sel: &Selector<'_>, callback: F, &mut self,
sel: &Selector<'_>,
callback: F,
) -> Option<R> ) -> Option<R>
where where
V: View + Any, V: View + Any,
@ -45,7 +47,9 @@ pub trait Finder {
impl<T: View> Finder for T { impl<T: View> Finder for T {
fn call_on<V, F, R>( fn call_on<V, F, R>(
&mut self, sel: &Selector<'_>, callback: F, &mut self,
sel: &Selector<'_>,
callback: F,
) -> Option<R> ) -> Option<R>
where where
V: View + Any, V: View + Any,

View File

@ -30,7 +30,10 @@ impl Position {
/// child with its top-left corner at the returned coordinates will /// child with its top-left corner at the returned coordinates will
/// position him appropriately. /// position him appropriately.
pub fn compute_offset<S, A, P>( pub fn compute_offset<S, A, P>(
&self, size: S, available: A, parent: P, &self,
size: S,
available: A,
parent: P,
) -> Vec2 ) -> Vec2
where where
S: Into<Vec2>, S: Into<Vec2>,
@ -65,7 +68,10 @@ pub enum Offset {
impl Offset { impl Offset {
/// Computes a single-dimension offset requred to draw a view. /// Computes a single-dimension offset requred to draw a view.
pub fn compute_offset( pub fn compute_offset(
&self, size: usize, available: usize, parent: usize, &self,
size: usize,
available: usize,
parent: usize,
) -> usize { ) -> usize {
if size > available { if size > available {
0 0

View File

@ -97,7 +97,8 @@ impl Core {
/// Returns a sub-printer ready to draw the content. /// Returns a sub-printer ready to draw the content.
pub fn sub_printer<'a, 'b>( pub fn sub_printer<'a, 'b>(
&self, printer: &Printer<'a, 'b>, &self,
printer: &Printer<'a, 'b>,
) -> Printer<'a, 'b> { ) -> Printer<'a, 'b> {
// Draw scrollbar? // Draw scrollbar?
let scrolling = self.is_scrolling(); let scrolling = self.is_scrolling();
@ -184,7 +185,9 @@ impl Core {
/// Handle an event after processing by the content. /// Handle an event after processing by the content.
pub fn on_inner_event( pub fn on_inner_event(
&mut self, event: Event, inner_result: EventResult, &mut self,
event: Event,
inner_result: EventResult,
important_area: Rect, important_area: Rect,
) -> EventResult { ) -> EventResult {
match inner_result { match inner_result {
@ -362,7 +365,9 @@ impl Core {
/// Performs `View::call_on_any()` /// Performs `View::call_on_any()`
pub fn call_on_any<'a, F>( 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, inner_call_on_any: F,
) where ) where
F: FnOnce(&Selector, AnyCb), F: FnOnce(&Selector, AnyCb),
@ -372,7 +377,9 @@ impl Core {
/// Performs `View::focus_view()` /// Performs `View::focus_view()`
pub fn focus_view<F>( pub fn focus_view<F>(
&mut self, selector: &Selector<'_>, inner_focus_view: F, &mut self,
selector: &Selector<'_>,
inner_focus_view: F,
) -> Result<(), ()> ) -> Result<(), ()>
where where
F: FnOnce(&Selector) -> Result<(), ()>, F: FnOnce(&Selector) -> Result<(), ()>,
@ -406,7 +413,8 @@ impl Core {
/// Sets the padding between content and scrollbar. /// Sets the padding between content and scrollbar.
pub fn set_scrollbar_padding<V: Into<Vec2>>( pub fn set_scrollbar_padding<V: Into<Vec2>>(
&mut self, scrollbar_padding: V, &mut self,
scrollbar_padding: V,
) { ) {
self.scrollbar_padding = scrollbar_padding.into(); self.scrollbar_padding = scrollbar_padding.into();
} }
@ -415,7 +423,8 @@ impl Core {
/// ///
/// Chainable variant. /// Chainable variant.
pub fn scrollbar_padding<V: Into<Vec2>>( pub fn scrollbar_padding<V: Into<Vec2>>(
self, scrollbar_padding: V, self,
scrollbar_padding: V,
) -> Self { ) -> Self {
self.with(|s| s.set_scrollbar_padding(scrollbar_padding)) self.with(|s| s.set_scrollbar_padding(scrollbar_padding))
} }

View File

@ -54,7 +54,9 @@ impl Default for ScrollStrategy {
/// } /// }
/// ``` /// ```
pub fn on_event<T, OnEvent, ImportantArea>( pub fn on_event<T, OnEvent, ImportantArea>(
scroller: &mut T, event: Event, on_event: OnEvent, scroller: &mut T,
event: Event,
on_event: OnEvent,
important_area: ImportantArea, important_area: ImportantArea,
) -> EventResult ) -> EventResult
where where
@ -73,7 +75,9 @@ where
/// Performs `View::important_area` on a `scroll::Scroller`. /// Performs `View::important_area` on a `scroll::Scroller`.
pub fn important_area<T, ImportantArea>( pub fn important_area<T, ImportantArea>(
scroller: &T, size: Vec2, mut important_area: ImportantArea, scroller: &T,
size: Vec2,
mut important_area: ImportantArea,
) -> Rect ) -> Rect
where where
T: Scroller, T: Scroller,
@ -92,7 +96,10 @@ where
/// Performs `View::layout` on a `scroll::Scroller`. /// Performs `View::layout` on a `scroll::Scroller`.
pub fn layout<T, Layout, RequiredSize>( pub fn layout<T, Layout, RequiredSize>(
scroller: &mut T, size: Vec2, needs_relayout: bool, layout: Layout, scroller: &mut T,
size: Vec2,
needs_relayout: bool,
layout: Layout,
required_size: RequiredSize, required_size: RequiredSize,
) where ) where
T: Scroller, T: Scroller,
@ -111,7 +118,9 @@ pub fn layout<T, Layout, RequiredSize>(
/// Performs `View::required_size` on a `scroll::Scroller`. /// Performs `View::required_size` on a `scroll::Scroller`.
pub fn required_size<T, RequiredSize>( pub fn required_size<T, RequiredSize>(
scroller: &mut T, size: Vec2, needs_relayout: bool, scroller: &mut T,
size: Vec2,
needs_relayout: bool,
required_size: RequiredSize, required_size: RequiredSize,
) -> Vec2 ) -> Vec2
where where
@ -140,7 +149,9 @@ where
/// ///
/// This is an alternative to `scroll::draw()` when you just need to print individual lines. /// This is an alternative to `scroll::draw()` when you just need to print individual lines.
pub fn draw_lines<T, LineDrawer>( pub fn draw_lines<T, LineDrawer>(
scroller: &T, printer: &Printer, mut line_drawer: LineDrawer, scroller: &T,
printer: &Printer,
mut line_drawer: LineDrawer,
) where ) where
T: Scroller, T: Scroller,
LineDrawer: FnMut(&T, &Printer, usize), LineDrawer: FnMut(&T, &Printer, usize),
@ -159,8 +170,11 @@ pub fn draw_lines<T, LineDrawer>(
/// ///
/// `left_border` will be called for each row to draw the left border for the given line number. /// `left_border` will be called for each row to draw the left border for the given line number.
pub fn draw_frame<T, LeftBorder, TopBorder, RightBorder, BottomBorder>( pub fn draw_frame<T, LeftBorder, TopBorder, RightBorder, BottomBorder>(
scroller: &T, printer: &Printer, mut left_border: LeftBorder, scroller: &T,
mut top_border: TopBorder, mut right_border: RightBorder, printer: &Printer,
mut left_border: LeftBorder,
mut top_border: TopBorder,
mut right_border: RightBorder,
mut bottom_border: BottomBorder, mut bottom_border: BottomBorder,
) where ) where
T: Scroller, T: Scroller,
@ -180,11 +194,7 @@ pub fn draw_frame<T, LeftBorder, TopBorder, RightBorder, BottomBorder>(
// Also draw padding // Also draw padding
let scrollbar_size = scroller.get_scroller().scrollbar_size(); let scrollbar_size = scroller.get_scroller().scrollbar_size();
printer.print_hline((viewport.right() + 2, 0), scrollbar_size.x, ""); printer.print_hline((viewport.right() + 2, 0), scrollbar_size.x, "");
printer.print_hline( printer.print_hline((viewport.right() + 2, size.y), scrollbar_size.x, "");
(viewport.right() + 2, size.y),
scrollbar_size.x,
"",
);
printer.print_vline((0, viewport.bottom() + 2), scrollbar_size.y, ""); printer.print_vline((0, viewport.bottom() + 2), scrollbar_size.y, "");
printer.print_vline( printer.print_vline(
(size.x, viewport.bottom() + 2), (size.x, viewport.bottom() + 2),
@ -210,7 +220,9 @@ pub fn draw_frame<T, LeftBorder, TopBorder, RightBorder, BottomBorder>(
/// ///
/// It will print a box with the appropriate `├`, `┤` and so on. /// It will print a box with the appropriate `├`, `┤` and so on.
pub fn draw_box_frame<T, IsHDelim, IsVDelim>( pub fn draw_box_frame<T, IsHDelim, IsVDelim>(
scroller: &T, printer: &Printer, is_h_delim: IsHDelim, scroller: &T,
printer: &Printer,
is_h_delim: IsHDelim,
is_v_delim: IsVDelim, is_v_delim: IsVDelim,
) where ) where
T: Scroller, T: Scroller,

View File

@ -11,7 +11,9 @@ use crate::Vec2;
/// Implements `View::draw` over the `model`. /// Implements `View::draw` over the `model`.
pub fn draw<Model, GetScroller, Draw>( pub fn draw<Model, GetScroller, Draw>(
printer: &Printer, model: &Model, mut get_scroller: GetScroller, printer: &Printer,
model: &Model,
mut get_scroller: GetScroller,
inner_draw: Draw, inner_draw: Draw,
) where ) where
Model: ?Sized, Model: ?Sized,
@ -30,8 +32,12 @@ pub fn draw<Model, GetScroller, Draw>(
/// ///
/// Returns (Inner size, Outer size, New scrolling) /// Returns (Inner size, Outer size, New scrolling)
fn sizes_when_scrolling<Model, GetScroller, RequiredSize>( fn sizes_when_scrolling<Model, GetScroller, RequiredSize>(
constraint: Vec2, scrolling: XY<bool>, strict: bool, model: &mut Model, constraint: Vec2,
get_scroller: &mut GetScroller, required_size: &mut RequiredSize, scrolling: XY<bool>,
strict: bool,
model: &mut Model,
get_scroller: &mut GetScroller,
required_size: &mut RequiredSize,
) -> (Vec2, Vec2, XY<bool>) ) -> (Vec2, Vec2, XY<bool>)
where where
Model: ?Sized, Model: ?Sized,
@ -77,8 +83,12 @@ where
/// ///
/// Returns (Inner size, Outer size) /// Returns (Inner size, Outer size)
fn sizes<Model, GetScroller, RequiredSize>( fn sizes<Model, GetScroller, RequiredSize>(
constraint: Vec2, strict: bool, needs_relayout: bool, model: &mut Model, constraint: Vec2,
get_scroller: &mut GetScroller, required_size: &mut RequiredSize, strict: bool,
needs_relayout: bool,
model: &mut Model,
get_scroller: &mut GetScroller,
required_size: &mut RequiredSize,
) -> (Vec2, Vec2) ) -> (Vec2, Vec2)
where where
Model: ?Sized, Model: ?Sized,
@ -141,8 +151,11 @@ where
/// Implements `View::layout` on the given model. /// Implements `View::layout` on the given model.
pub fn layout<Model, GetScroller, RequiredSize, Layout>( pub fn layout<Model, GetScroller, RequiredSize, Layout>(
size: Vec2, needs_relayout: bool, model: &mut Model, size: Vec2,
mut get_scroller: GetScroller, mut required_size: RequiredSize, needs_relayout: bool,
model: &mut Model,
mut get_scroller: GetScroller,
mut required_size: RequiredSize,
mut layout: Layout, mut layout: Layout,
) where ) where
Model: ?Sized, Model: ?Sized,
@ -172,8 +185,11 @@ pub fn layout<Model, GetScroller, RequiredSize, Layout>(
/// Implements `View::required_size` on the given model. /// Implements `View::required_size` on the given model.
pub fn required_size<Model, GetScroller, RequiredSize>( pub fn required_size<Model, GetScroller, RequiredSize>(
constraint: Vec2, needs_relayout: bool, model: &mut Model, constraint: Vec2,
mut get_scroller: GetScroller, mut required_size: RequiredSize, needs_relayout: bool,
model: &mut Model,
mut get_scroller: GetScroller,
mut required_size: RequiredSize,
) -> Vec2 ) -> Vec2
where where
Model: ?Sized, Model: ?Sized,
@ -194,8 +210,11 @@ where
/// Implements `View::on_event` on the given model. /// Implements `View::on_event` on the given model.
pub fn on_event<Model, GetScroller, OnEvent, ImportantArea>( pub fn on_event<Model, GetScroller, OnEvent, ImportantArea>(
event: Event, model: &mut Model, mut get_scroller: GetScroller, event: Event,
mut on_event: OnEvent, mut important_area: ImportantArea, model: &mut Model,
mut get_scroller: GetScroller,
mut on_event: OnEvent,
mut important_area: ImportantArea,
) -> EventResult ) -> EventResult
where where
Model: ?Sized, Model: ?Sized,

View File

@ -79,7 +79,9 @@ pub trait ViewWrapper: 'static {
/// Wraps the `find` method. /// Wraps the `find` method.
fn wrap_call_on_any<'a>( 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)); self.with_view_mut(|v| v.call_on_any(selector, callback));
} }
@ -125,7 +127,8 @@ impl<T: ViewWrapper> View for T {
} }
fn call_on_any<'a>( fn call_on_any<'a>(
&mut self, selector: &Selector<'_>, &mut self,
selector: &Selector<'_>,
callback: Box<dyn FnMut(&mut dyn Any) + 'a>, callback: Box<dyn FnMut(&mut dyn Any) + 'a>,
) { ) {
self.wrap_call_on_any(selector, callback) self.wrap_call_on_any(selector, callback)

View File

@ -43,7 +43,9 @@ impl<T: View> BoxView<T> {
/// ///
/// `None` values will use the wrapped view's preferences. /// `None` values will use the wrapped view's preferences.
pub fn new( pub fn new(
width: SizeConstraint, height: SizeConstraint, view: T, width: SizeConstraint,
height: SizeConstraint,
view: T,
) -> Self { ) -> Self {
BoxView { BoxView {
size: (width, height).into(), size: (width, height).into(),
@ -55,7 +57,9 @@ impl<T: View> BoxView<T> {
/// Sets the size constraints for this view. /// Sets the size constraints for this view.
pub fn set_constraints( pub fn set_constraints(
&mut self, width: SizeConstraint, height: SizeConstraint, &mut self,
width: SizeConstraint,
height: SizeConstraint,
) { ) {
self.set_width(width); self.set_width(width);
self.set_height(height); self.set_height(height);

View File

@ -32,7 +32,8 @@ impl Checkbox {
/// Sets a callback to be used when the state changes. /// Sets a callback to be used when the state changes.
pub fn set_on_change<F: 'static + Fn(&mut Cursive, bool)>( pub fn set_on_change<F: 'static + Fn(&mut Cursive, bool)>(
&mut self, on_change: F, &mut self,
on_change: F,
) { ) {
self.on_change = Some(Rc::new(on_change)); self.on_change = Some(Rc::new(on_change));
} }
@ -41,7 +42,8 @@ impl Checkbox {
/// ///
/// Chainable variant. /// Chainable variant.
pub fn on_change<F: 'static + Fn(&mut Cursive, bool)>( pub fn on_change<F: 'static + Fn(&mut Cursive, bool)>(
self, on_change: F, self,
on_change: F,
) -> Self { ) -> Self {
self.with(|s| s.set_on_change(on_change)) self.with(|s| s.set_on_change(on_change))
} }

View File

@ -317,7 +317,9 @@ impl Dialog {
// An event is received while a button is in focus // An event is received while a button is in focus
fn on_event_button( fn on_event_button(
&mut self, event: Event, button_id: usize, &mut self,
event: Event,
button_id: usize,
) -> EventResult { ) -> EventResult {
let result = { let result = {
let button = &mut self.buttons[button_id]; let button = &mut self.buttons[button_id];
@ -655,7 +657,9 @@ impl View for Dialog {
} }
fn call_on_any<'a>( 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); self.content.call_on_any(selector, callback);
} }

View File

@ -91,7 +91,8 @@ impl<V: View> ViewWrapper for HideableView<V> {
} }
fn wrap_call_on_any<'a>( fn wrap_call_on_any<'a>(
&mut self, selector: &Selector<'_>, &mut self,
selector: &Selector<'_>,
callback: Box<dyn FnMut(&mut dyn Any) + 'a>, callback: Box<dyn FnMut(&mut dyn Any) + 'a>,
) { ) {
// We always run callbacks, even when invisible. // We always run callbacks, even when invisible.

View File

@ -77,7 +77,9 @@ impl<T: View + 'static> ViewWrapper for IdView<T> {
// Some for<'b> weirdness here to please the borrow checker gods... // 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 callback: BoxedCallback<'a>, &mut self,
selector: &Selector<'_>,
mut callback: BoxedCallback<'a>,
) { ) {
match selector { match selector {
&Selector::Id(id) if id == self.id => callback(self), &Selector::Id(id) if id == self.id => callback(self),

View File

@ -58,7 +58,9 @@ struct ChildItem<T> {
impl<T> ChildIterator<T> { impl<T> ChildIterator<T> {
fn new( fn new(
inner: T, orientation: direction::Orientation, available: usize, inner: T,
orientation: direction::Orientation,
available: usize,
) -> Self { ) -> Self {
ChildIterator { ChildIterator {
inner, inner,
@ -272,7 +274,9 @@ impl LinearLayout {
/// Returns a cyclic mutable iterator starting with the child in focus /// Returns a cyclic mutable iterator starting with the child in focus
fn iter_mut<'a>( fn iter_mut<'a>(
&'a mut self, from_focus: bool, source: direction::Relative, &'a mut self,
from_focus: bool,
source: direction::Relative,
) -> Box<dyn Iterator<Item = (usize, &mut Child)> + 'a> { ) -> Box<dyn Iterator<Item = (usize, &mut Child)> + 'a> {
match source { match source {
direction::Relative::Front => { direction::Relative::Front => {
@ -358,7 +362,8 @@ impl LinearLayout {
} }
fn try_focus( fn try_focus(
(i, child): (usize, &mut Child), source: direction::Direction, (i, child): (usize, &mut Child),
source: direction::Direction,
) -> Option<usize> { ) -> Option<usize> {
if child.view.take_focus(source) { if child.view.take_focus(source) {
Some(i) Some(i)
@ -632,7 +637,9 @@ impl View for LinearLayout {
} }
fn call_on_any<'a>( 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 { for child in &mut self.children {
child child

View File

@ -107,7 +107,10 @@ impl Menubar {
/// Insert a new item at the given position. /// Insert a new item at the given position.
pub fn insert_subtree<S>( pub fn insert_subtree<S>(
&mut self, i: usize, title: S, menu: MenuTree, &mut self,
i: usize,
title: S,
menu: MenuTree,
) -> &mut Self ) -> &mut Self
where where
S: Into<String>, S: Into<String>,

View File

@ -121,7 +121,8 @@ impl ProgressBar {
/// ///
/// Chainable variant. /// Chainable variant.
pub fn with_task<F: FnOnce(Counter) + Send + 'static>( pub fn with_task<F: FnOnce(Counter) + Send + 'static>(
mut self, task: F, mut self,
task: F,
) -> Self { ) -> Self {
self.start(task); self.start(task);
self self
@ -141,7 +142,8 @@ impl ProgressBar {
/// } /// }
/// ``` /// ```
pub fn with_label<F: Fn(usize, (usize, usize)) -> String + 'static>( pub fn with_label<F: Fn(usize, (usize, usize)) -> String + 'static>(
mut self, label_maker: F, mut self,
label_maker: F,
) -> Self { ) -> Self {
self.label_maker = Box::new(label_maker); self.label_maker = Box::new(label_maker);
self self

View File

@ -56,7 +56,9 @@ impl<T: 'static> RadioGroup<T> {
/// ///
/// The button will display `label` next to it, and will embed `value`. /// The button will display `label` next to it, and will embed `value`.
pub fn button<S: Into<String>>( pub fn button<S: Into<String>>(
&mut self, value: T, label: S, &mut self,
value: T,
label: S,
) -> 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));
@ -77,7 +79,8 @@ impl<T: 'static> RadioGroup<T> {
/// Sets a callback to be used when the selection changes. /// Sets a callback to be used when the selection changes.
pub fn set_on_change<F: 'static + Fn(&mut Cursive, &T)>( pub fn set_on_change<F: 'static + Fn(&mut Cursive, &T)>(
&mut self, on_change: F, &mut self,
on_change: F,
) { ) {
self.state.borrow_mut().on_change = Some(Rc::new(on_change)); self.state.borrow_mut().on_change = Some(Rc::new(on_change));
} }
@ -86,7 +89,8 @@ impl<T: 'static> RadioGroup<T> {
/// ///
/// Chainable variant. /// Chainable variant.
pub fn on_change<F: 'static + Fn(&mut Cursive, &T)>( pub fn on_change<F: 'static + Fn(&mut Cursive, &T)>(
self, on_change: F, self,
on_change: F,
) -> Self { ) -> Self {
self.with(|s| s.set_on_change(on_change)) self.with(|s| s.set_on_change(on_change))
} }
@ -95,7 +99,8 @@ impl<T: 'static> RadioGroup<T> {
impl RadioGroup<String> { impl RadioGroup<String> {
/// Adds a button, using the label itself as value. /// Adds a button, using the label itself as value.
pub fn button_str<S: Into<String>>( pub fn button_str<S: Into<String>>(
&mut self, text: S, &mut self,
text: S,
) -> RadioButton<String> { ) -> RadioButton<String> {
let text = text.into(); let text = text.into();
self.button(text.clone(), text) self.button(text.clone(), text)
@ -124,7 +129,9 @@ impl<T: 'static> RadioButton<T> {
impl_enabled!(self.enabled); impl_enabled!(self.enabled);
fn new( fn new(
state: Rc<RefCell<SharedState<T>>>, id: usize, label: String, state: Rc<RefCell<SharedState<T>>>,
id: usize,
label: String,
) -> Self { ) -> Self {
RadioButton { RadioButton {
state, state,

View File

@ -273,7 +273,8 @@ impl<T: 'static> SelectView<T> {
/// Gets a mut item at given idx or None. /// Gets a mut item at given idx or None.
pub fn get_item_mut( pub fn get_item_mut(
&mut self, i: usize, &mut self,
i: usize,
) -> Option<(&mut StyledString, &mut T)> { ) -> Option<(&mut StyledString, &mut T)> {
if i >= self.items.len() { if i >= self.items.len() {
None None

View File

@ -42,7 +42,10 @@ pub enum LayerPosition {
impl Placement { impl Placement {
pub fn compute_offset<S, A, P>( pub fn compute_offset<S, A, P>(
&self, size: S, available: A, parent: P, &self,
size: S,
available: A,
parent: P,
) -> Vec2 ) -> Vec2
where where
S: Into<Vec2>, S: Into<Vec2>,
@ -169,7 +172,9 @@ impl<T: View> View for ChildWrapper<T> {
} }
fn call_on_any<'a>( fn call_on_any<'a>(
&mut self, selector: &Selector<'_>, callback: AnyCb<'a>, &mut self,
selector: &Selector<'_>,
callback: AnyCb<'a>,
) { ) {
match *self { match *self {
ChildWrapper::Shadow(ref mut v) => { ChildWrapper::Shadow(ref mut v) => {
@ -490,7 +495,9 @@ impl StackView {
/// ///
/// If `layer` is out of bounds. /// If `layer` is out of bounds.
pub fn reposition_layer( pub fn reposition_layer(
&mut self, layer: LayerPosition, position: Position, &mut self,
layer: LayerPosition,
position: Position,
) { ) {
let i = self.get_index(layer).unwrap(); let i = self.get_index(layer).unwrap();
let child = &mut self.layers[i]; let child = &mut self.layers[i];
@ -659,7 +666,9 @@ impl View for StackView {
} }
fn call_on_any<'a>( 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 { for layer in &mut self.layers {
layer layer

View File

@ -280,7 +280,10 @@ impl<T> XY<T> {
/// ); /// );
/// ``` /// ```
pub fn zip4<U, V, W>( pub fn zip4<U, V, W>(
self, a: XY<U>, b: XY<V>, c: XY<W>, self,
a: XY<U>,
b: XY<V>,
c: XY<W>,
) -> XY<(T, U, V, W)> { ) -> XY<(T, U, V, W)> {
XY::new((self.x, a.x, b.x, c.x), (self.y, a.y, b.y, c.y)) XY::new((self.x, a.x, b.x, c.x), (self.y, a.y, b.y, c.y))
} }
@ -308,7 +311,11 @@ impl<T> XY<T> {
/// assert_eq!(xy, XY::new(Some('a'), Some('y'))); /// assert_eq!(xy, XY::new(Some('a'), Some('y')));
/// ``` /// ```
pub fn zip5<U, V, W, Z>( pub fn zip5<U, V, W, Z>(
self, a: XY<U>, b: XY<V>, c: XY<W>, d: XY<Z>, self,
a: XY<U>,
b: XY<V>,
c: XY<W>,
d: XY<Z>,
) -> XY<(T, U, V, W, Z)> { ) -> 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)) XY::new((self.x, a.x, b.x, c.x, d.x), (self.y, a.y, b.y, c.y, d.y))
} }