mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-08 18:30:40 +00:00
Rustfmt
Moves to "Tall" fn_args_layout
This commit is contained in:
parent
4a1fc3e49d
commit
b7d71e8381
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
unstable_features = true
|
||||
max_width = 79
|
||||
reorder_imports = true
|
||||
fn_args_density = "Compressed"
|
||||
fn_args_layout = "Tall"
|
||||
|
||||
|
@ -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
|
||||
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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.
|
||||
///
|
||||
|
@ -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<Event> {
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<ObservedLine> {
|
||||
pub fn find_occurences(&self, pattern: &str) -> Vec<ObservedLine> {
|
||||
// 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<Vec2> for ObservedPieceInterface {
|
||||
impl Index<Vec2> for dyn ObservedPieceInterface {
|
||||
type Output = Option<ObservedCell>;
|
||||
|
||||
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;
|
||||
|
||||
|
@ -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::<usize> { x: 120, y: 80 };
|
||||
|
||||
/// Default style for the puppet terminal.
|
||||
pub static ref DEFAULT_OBSERVED_STYLE: ObservedStyle = ObservedStyle {
|
||||
colors: ColorPair {
|
||||
front: Color::TerminalDefault,
|
||||
|
@ -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<AtomicBool>,
|
||||
resize_sender: Sender<()>,
|
||||
resize_running: Arc<AtomicBool>,
|
||||
) {
|
||||
let signals = Signals::new(&[libc::SIGWINCH]).unwrap();
|
||||
thread::spawn(move || {
|
||||
|
@ -407,7 +407,8 @@ impl Cursive {
|
||||
///
|
||||
/// `filename` must point to a valid toml file.
|
||||
pub fn load_theme_file<P: AsRef<Path>>(
|
||||
&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<V, F, R>(
|
||||
&mut self, sel: &view::Selector<'_>, callback: F,
|
||||
&mut self,
|
||||
sel: &view::Selector<'_>,
|
||||
callback: F,
|
||||
) -> Option<R>
|
||||
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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -67,7 +67,9 @@ impl<'a, 'b> Printer<'a, 'b> {
|
||||
/// But nobody needs to know that.
|
||||
#[doc(hidden)]
|
||||
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 {
|
||||
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<S>(
|
||||
&self, start: S, text: crate::utils::span::SpannedStr<'_, Style>,
|
||||
&self,
|
||||
start: S,
|
||||
text: crate::utils::span::SpannedStr<'_, Style>,
|
||||
) where
|
||||
S: Into<Vec2>,
|
||||
{
|
||||
@ -197,7 +201,10 @@ impl<'a, 'b> Printer<'a, 'b> {
|
||||
|
||||
/// Prints a vertical line using the given character.
|
||||
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();
|
||||
|
||||
@ -234,7 +241,11 @@ impl<'a, 'b> Printer<'a, 'b> {
|
||||
|
||||
/// Prints a line using the given character.
|
||||
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 {
|
||||
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<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 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<F: FnOnce(&Printer<'_, '_>)>(
|
||||
&self, selection: bool, f: F,
|
||||
&self,
|
||||
selection: bool,
|
||||
f: F,
|
||||
) {
|
||||
self.with_color(
|
||||
if selection {
|
||||
|
@ -125,7 +125,9 @@ impl Palette {
|
||||
|
||||
/// Adds a color namespace to this palette.
|
||||
pub fn add_namespace(
|
||||
&mut self, key: &str, namespace: HashMap<String, PaletteNode>,
|
||||
&mut self,
|
||||
key: &str,
|
||||
namespace: HashMap<String, PaletteNode>,
|
||||
) {
|
||||
self.custom
|
||||
.insert(key.to_string(), PaletteNode::Namespace(namespace));
|
||||
|
@ -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();
|
||||
|
||||
|
@ -3,7 +3,9 @@ use std::iter::Peekable;
|
||||
|
||||
/// Concatenates chunks as long as they fit in the given width.
|
||||
pub fn prefix<I>(
|
||||
tokens: &mut Peekable<I>, width: usize, offset: &mut ChunkPart,
|
||||
tokens: &mut Peekable<I>,
|
||||
width: usize,
|
||||
offset: &mut ChunkPart,
|
||||
) -> Vec<Chunk>
|
||||
where
|
||||
I: Iterator<Item = Chunk>,
|
||||
|
@ -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<Self> {
|
||||
BoxView::new(width, height, self)
|
||||
}
|
||||
|
@ -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<V, F, R>(
|
||||
&mut self, sel: &Selector<'_>, callback: F,
|
||||
&mut self,
|
||||
sel: &Selector<'_>,
|
||||
callback: F,
|
||||
) -> Option<R>
|
||||
where
|
||||
V: View + Any,
|
||||
@ -45,7 +47,9 @@ pub trait Finder {
|
||||
|
||||
impl<T: View> Finder for T {
|
||||
fn call_on<V, F, R>(
|
||||
&mut self, sel: &Selector<'_>, callback: F,
|
||||
&mut self,
|
||||
sel: &Selector<'_>,
|
||||
callback: F,
|
||||
) -> Option<R>
|
||||
where
|
||||
V: View + Any,
|
||||
|
@ -30,7 +30,10 @@ impl Position {
|
||||
/// child with its top-left corner at the returned coordinates will
|
||||
/// position him appropriately.
|
||||
pub fn compute_offset<S, A, P>(
|
||||
&self, size: S, available: A, parent: P,
|
||||
&self,
|
||||
size: S,
|
||||
available: A,
|
||||
parent: P,
|
||||
) -> Vec2
|
||||
where
|
||||
S: Into<Vec2>,
|
||||
@ -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
|
||||
|
@ -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<F>(
|
||||
&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<V: Into<Vec2>>(
|
||||
&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<V: Into<Vec2>>(
|
||||
self, scrollbar_padding: V,
|
||||
self,
|
||||
scrollbar_padding: V,
|
||||
) -> Self {
|
||||
self.with(|s| s.set_scrollbar_padding(scrollbar_padding))
|
||||
}
|
||||
|
@ -54,7 +54,9 @@ impl Default for ScrollStrategy {
|
||||
/// }
|
||||
/// ```
|
||||
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,
|
||||
) -> EventResult
|
||||
where
|
||||
@ -73,7 +75,9 @@ where
|
||||
|
||||
/// Performs `View::important_area` on a `scroll::Scroller`.
|
||||
pub fn important_area<T, ImportantArea>(
|
||||
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<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,
|
||||
) where
|
||||
T: Scroller,
|
||||
@ -111,7 +118,9 @@ pub fn layout<T, Layout, RequiredSize>(
|
||||
|
||||
/// Performs `View::required_size` on a `scroll::Scroller`.
|
||||
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,
|
||||
) -> 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<T, LineDrawer>(
|
||||
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<T, LineDrawer>(
|
||||
///
|
||||
/// `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>(
|
||||
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<T, LeftBorder, TopBorder, RightBorder, BottomBorder>(
|
||||
// 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<T, LeftBorder, TopBorder, RightBorder, BottomBorder>(
|
||||
///
|
||||
/// It will print a box with the appropriate `├`, `┤` and so on.
|
||||
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,
|
||||
) where
|
||||
T: Scroller,
|
||||
|
@ -11,7 +11,9 @@ use crate::Vec2;
|
||||
|
||||
/// Implements `View::draw` over the `model`.
|
||||
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,
|
||||
) where
|
||||
Model: ?Sized,
|
||||
@ -30,8 +32,12 @@ pub fn draw<Model, GetScroller, Draw>(
|
||||
///
|
||||
/// Returns (Inner size, Outer size, New scrolling)
|
||||
fn sizes_when_scrolling<Model, GetScroller, RequiredSize>(
|
||||
constraint: Vec2, scrolling: XY<bool>, strict: bool, model: &mut Model,
|
||||
get_scroller: &mut GetScroller, required_size: &mut RequiredSize,
|
||||
constraint: Vec2,
|
||||
scrolling: XY<bool>,
|
||||
strict: bool,
|
||||
model: &mut Model,
|
||||
get_scroller: &mut GetScroller,
|
||||
required_size: &mut RequiredSize,
|
||||
) -> (Vec2, Vec2, XY<bool>)
|
||||
where
|
||||
Model: ?Sized,
|
||||
@ -77,8 +83,12 @@ where
|
||||
///
|
||||
/// Returns (Inner size, Outer size)
|
||||
fn sizes<Model, GetScroller, RequiredSize>(
|
||||
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<Model, GetScroller, RequiredSize, 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<Model, GetScroller, RequiredSize, Layout>(
|
||||
|
||||
/// Implements `View::required_size` on the given model.
|
||||
pub fn required_size<Model, GetScroller, RequiredSize>(
|
||||
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<Model, GetScroller, OnEvent, ImportantArea>(
|
||||
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,
|
||||
|
@ -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<T: ViewWrapper> View for T {
|
||||
}
|
||||
|
||||
fn call_on_any<'a>(
|
||||
&mut self, selector: &Selector<'_>,
|
||||
&mut self,
|
||||
selector: &Selector<'_>,
|
||||
callback: Box<dyn FnMut(&mut dyn Any) + 'a>,
|
||||
) {
|
||||
self.wrap_call_on_any(selector, callback)
|
||||
|
@ -43,7 +43,9 @@ impl<T: View> BoxView<T> {
|
||||
///
|
||||
/// `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<T: View> BoxView<T> {
|
||||
|
||||
/// 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);
|
||||
|
@ -32,7 +32,8 @@ impl Checkbox {
|
||||
|
||||
/// Sets a callback to be used when the state changes.
|
||||
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));
|
||||
}
|
||||
@ -41,7 +42,8 @@ impl Checkbox {
|
||||
///
|
||||
/// Chainable variant.
|
||||
pub fn on_change<F: 'static + Fn(&mut Cursive, bool)>(
|
||||
self, on_change: F,
|
||||
self,
|
||||
on_change: F,
|
||||
) -> Self {
|
||||
self.with(|s| s.set_on_change(on_change))
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -91,7 +91,8 @@ impl<V: View> ViewWrapper for HideableView<V> {
|
||||
}
|
||||
|
||||
fn wrap_call_on_any<'a>(
|
||||
&mut self, selector: &Selector<'_>,
|
||||
&mut self,
|
||||
selector: &Selector<'_>,
|
||||
callback: Box<dyn FnMut(&mut dyn Any) + 'a>,
|
||||
) {
|
||||
// We always run callbacks, even when invisible.
|
||||
|
@ -77,7 +77,9 @@ impl<T: View + 'static> ViewWrapper for IdView<T> {
|
||||
|
||||
// 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),
|
||||
|
@ -58,7 +58,9 @@ struct ChildItem<T> {
|
||||
|
||||
impl<T> ChildIterator<T> {
|
||||
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<dyn Iterator<Item = (usize, &mut Child)> + '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<usize> {
|
||||
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
|
||||
|
@ -107,7 +107,10 @@ impl Menubar {
|
||||
|
||||
/// Insert a new item at the given position.
|
||||
pub fn insert_subtree<S>(
|
||||
&mut self, i: usize, title: S, menu: MenuTree,
|
||||
&mut self,
|
||||
i: usize,
|
||||
title: S,
|
||||
menu: MenuTree,
|
||||
) -> &mut Self
|
||||
where
|
||||
S: Into<String>,
|
||||
|
@ -121,7 +121,8 @@ impl ProgressBar {
|
||||
///
|
||||
/// Chainable variant.
|
||||
pub fn with_task<F: FnOnce(Counter) + Send + 'static>(
|
||||
mut self, task: F,
|
||||
mut self,
|
||||
task: F,
|
||||
) -> Self {
|
||||
self.start(task);
|
||||
self
|
||||
@ -141,7 +142,8 @@ impl ProgressBar {
|
||||
/// }
|
||||
/// ```
|
||||
pub fn with_label<F: Fn(usize, (usize, usize)) -> String + 'static>(
|
||||
mut self, label_maker: F,
|
||||
mut self,
|
||||
label_maker: F,
|
||||
) -> Self {
|
||||
self.label_maker = Box::new(label_maker);
|
||||
self
|
||||
|
@ -56,7 +56,9 @@ impl<T: 'static> RadioGroup<T> {
|
||||
///
|
||||
/// The button will display `label` next to it, and will embed `value`.
|
||||
pub fn button<S: Into<String>>(
|
||||
&mut self, value: T, label: S,
|
||||
&mut self,
|
||||
value: T,
|
||||
label: S,
|
||||
) -> RadioButton<T> {
|
||||
let count = self.state.borrow().values.len();
|
||||
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.
|
||||
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));
|
||||
}
|
||||
@ -86,7 +89,8 @@ impl<T: 'static> RadioGroup<T> {
|
||||
///
|
||||
/// Chainable variant.
|
||||
pub fn on_change<F: 'static + Fn(&mut Cursive, &T)>(
|
||||
self, on_change: F,
|
||||
self,
|
||||
on_change: F,
|
||||
) -> Self {
|
||||
self.with(|s| s.set_on_change(on_change))
|
||||
}
|
||||
@ -95,7 +99,8 @@ impl<T: 'static> RadioGroup<T> {
|
||||
impl RadioGroup<String> {
|
||||
/// Adds a button, using the label itself as value.
|
||||
pub fn button_str<S: Into<String>>(
|
||||
&mut self, text: S,
|
||||
&mut self,
|
||||
text: S,
|
||||
) -> RadioButton<String> {
|
||||
let text = text.into();
|
||||
self.button(text.clone(), text)
|
||||
@ -124,7 +129,9 @@ impl<T: 'static> RadioButton<T> {
|
||||
impl_enabled!(self.enabled);
|
||||
|
||||
fn new(
|
||||
state: Rc<RefCell<SharedState<T>>>, id: usize, label: String,
|
||||
state: Rc<RefCell<SharedState<T>>>,
|
||||
id: usize,
|
||||
label: String,
|
||||
) -> Self {
|
||||
RadioButton {
|
||||
state,
|
||||
|
@ -273,7 +273,8 @@ impl<T: 'static> SelectView<T> {
|
||||
|
||||
/// 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
|
||||
|
@ -42,7 +42,10 @@ pub enum LayerPosition {
|
||||
|
||||
impl Placement {
|
||||
pub fn compute_offset<S, A, P>(
|
||||
&self, size: S, available: A, parent: P,
|
||||
&self,
|
||||
size: S,
|
||||
available: A,
|
||||
parent: P,
|
||||
) -> Vec2
|
||||
where
|
||||
S: Into<Vec2>,
|
||||
@ -169,7 +172,9 @@ impl<T: View> View for ChildWrapper<T> {
|
||||
}
|
||||
|
||||
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
|
||||
|
11
src/xy.rs
11
src/xy.rs
@ -280,7 +280,10 @@ impl<T> XY<T> {
|
||||
/// );
|
||||
/// ```
|
||||
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::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')));
|
||||
/// ```
|
||||
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::new((self.x, a.x, b.x, c.x, d.x), (self.y, a.y, b.y, c.y, d.y))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user