mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 09:25:01 +00:00
Run cargo fix --edition-idioms
This commit is contained in:
parent
e51be07e5d
commit
e096dc9740
@ -3,7 +3,7 @@
|
||||
//! Requires the `blt-backend` feature.
|
||||
#![cfg(feature = "bear-lib-terminal")]
|
||||
|
||||
extern crate bear_lib_terminal;
|
||||
use bear_lib_terminal;
|
||||
|
||||
use std::collections::HashSet;
|
||||
|
||||
@ -31,7 +31,7 @@ pub struct Backend {
|
||||
|
||||
impl Backend {
|
||||
/// Creates a new BearLibTerminal-based backend.
|
||||
pub fn init() -> Box<backend::Backend> {
|
||||
pub fn init() -> Box<dyn backend::Backend> {
|
||||
terminal::open("Cursive", 80, 24);
|
||||
terminal::set(terminal::config::Window::empty().resizeable(true));
|
||||
terminal::set(vec![
|
||||
|
@ -1,5 +1,5 @@
|
||||
//! Ncurses-specific backend.
|
||||
extern crate ncurses;
|
||||
use ncurses;
|
||||
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::collections::HashMap;
|
||||
@ -56,7 +56,7 @@ fn write_to_tty(bytes: &[u8]) -> io::Result<()> {
|
||||
|
||||
impl Backend {
|
||||
/// Creates a new ncurses-based backend.
|
||||
pub fn init() -> Box<backend::Backend> {
|
||||
pub fn init() -> Box<dyn backend::Backend> {
|
||||
// Change the locale.
|
||||
// For some reasons it's mandatory to get some UTF-8 support.
|
||||
ncurses::setlocale(ncurses::LcCategory::all, "");
|
||||
|
@ -1,5 +1,5 @@
|
||||
//! Pancuses-specific backend.
|
||||
extern crate pancurses;
|
||||
use pancurses;
|
||||
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::collections::HashMap;
|
||||
@ -33,7 +33,7 @@ fn find_closest_pair(pair: ColorPair) -> (i16, i16) {
|
||||
|
||||
impl Backend {
|
||||
/// Creates a new pancurses-based backend.
|
||||
pub fn init() -> Box<backend::Backend> {
|
||||
pub fn init() -> Box<dyn backend::Backend> {
|
||||
::std::env::set_var("ESCDELAY", "25");
|
||||
|
||||
let window = pancurses::initscr();
|
||||
|
@ -12,7 +12,7 @@ pub struct Backend;
|
||||
|
||||
impl Backend {
|
||||
/// Creates a new dummy backend.
|
||||
pub fn init() -> Box<backend::Backend>
|
||||
pub fn init() -> Box<dyn backend::Backend>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
|
@ -3,7 +3,7 @@
|
||||
//! Requires the `termion-backend` feature.
|
||||
#![cfg(feature = "termion")]
|
||||
|
||||
extern crate termion;
|
||||
use termion;
|
||||
|
||||
use self::termion::color as tcolor;
|
||||
use self::termion::event::Event as TEvent;
|
||||
@ -43,7 +43,7 @@ pub struct Backend {
|
||||
|
||||
impl Backend {
|
||||
/// Creates a new termion-based backend.
|
||||
pub fn init() -> Box<backend::Backend> {
|
||||
pub fn init() -> Box<dyn backend::Backend> {
|
||||
// Use a ~8MB buffer
|
||||
// Should be enough for a single screen most of the time.
|
||||
let terminal =
|
||||
@ -284,7 +284,7 @@ impl backend::Backend for Backend {
|
||||
|
||||
fn with_color<F, R>(clr: &theme::Color, f: F) -> R
|
||||
where
|
||||
F: FnOnce(&tcolor::Color) -> R,
|
||||
F: FnOnce(&dyn tcolor::Color) -> R,
|
||||
{
|
||||
match *clr {
|
||||
theme::Color::TerminalDefault => f(&tcolor::Reset),
|
||||
|
@ -39,17 +39,17 @@ pub struct Cursive {
|
||||
|
||||
running: bool,
|
||||
|
||||
backend: Box<backend::Backend>,
|
||||
backend: Box<dyn backend::Backend>,
|
||||
|
||||
cb_source: Receiver<Box<CbFunc>>,
|
||||
cb_sink: Sender<Box<CbFunc>>,
|
||||
cb_source: Receiver<Box<dyn CbFunc>>,
|
||||
cb_sink: Sender<Box<dyn CbFunc>>,
|
||||
}
|
||||
|
||||
/// Identifies a screen in the cursive root.
|
||||
pub type ScreenId = usize;
|
||||
|
||||
/// Convenient alias to the result of `Cursive::cb_sink`.
|
||||
pub type CbSink = Sender<Box<CbFunc>>;
|
||||
pub type CbSink = Sender<Box<dyn CbFunc>>;
|
||||
|
||||
/// Asynchronous callback function trait.
|
||||
///
|
||||
@ -127,7 +127,7 @@ impl Cursive {
|
||||
/// ```
|
||||
pub fn new<F>(backend_init: F) -> Self
|
||||
where
|
||||
F: FnOnce() -> Box<backend::Backend>,
|
||||
F: FnOnce() -> Box<dyn backend::Backend>,
|
||||
{
|
||||
let theme = theme::load_default();
|
||||
|
||||
@ -422,7 +422,7 @@ 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,
|
||||
@ -522,7 +522,7 @@ impl Cursive {
|
||||
}
|
||||
|
||||
/// Moves the focus to the view identified by `sel`.
|
||||
pub fn focus(&mut self, sel: &view::Selector) -> Result<(), ()> {
|
||||
pub fn focus(&mut self, sel: &view::Selector<'_>) -> Result<(), ()> {
|
||||
self.screen_mut().focus_view(sel)
|
||||
}
|
||||
|
||||
@ -604,7 +604,7 @@ impl Cursive {
|
||||
}
|
||||
|
||||
/// Convenient method to remove a layer from the current screen.
|
||||
pub fn pop_layer(&mut self) -> Option<Box<View>> {
|
||||
pub fn pop_layer(&mut self) -> Option<Box<dyn View>> {
|
||||
self.screen_mut().pop_layer()
|
||||
}
|
||||
|
||||
|
22
src/event.rs
22
src/event.rs
@ -23,14 +23,14 @@ use crate::Cursive;
|
||||
/// Callback is a function that can be triggered by an event.
|
||||
/// It has a mutable access to the cursive root.
|
||||
#[derive(Clone)]
|
||||
pub struct Callback(Rc<Box<Fn(&mut Cursive)>>);
|
||||
pub struct Callback(Rc<Box<dyn Fn(&mut Cursive)>>);
|
||||
// TODO: remove the Box when Box<T: Sized> -> Rc<T> is possible
|
||||
|
||||
/// A boxed callback that can be run on `&mut Any`.
|
||||
pub type AnyCb<'a> = Box<FnMut(&mut Any) + 'a>;
|
||||
pub type AnyCb<'a> = Box<FnMut(&mut dyn Any) + 'a>;
|
||||
|
||||
/// A trigger that only selects some types of events.
|
||||
pub struct EventTrigger(Box<Fn(&Event) -> bool>);
|
||||
pub struct EventTrigger(Box<dyn Fn(&Event) -> bool>);
|
||||
|
||||
impl EventTrigger {
|
||||
/// Create a new `EventTrigger` using the given function as filter.
|
||||
@ -148,26 +148,26 @@ impl Callback {
|
||||
}
|
||||
|
||||
impl Deref for Callback {
|
||||
type Target = Box<Fn(&mut Cursive)>;
|
||||
fn deref<'a>(&'a self) -> &'a Box<Fn(&mut Cursive)> {
|
||||
type Target = Box<dyn Fn(&mut Cursive)>;
|
||||
fn deref<'a>(&'a self) -> &'a Box<dyn Fn(&mut Cursive)> {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Rc<Box<Fn(&mut Cursive)>>> for Callback {
|
||||
fn from(f: Rc<Box<Fn(&mut Cursive)>>) -> Self {
|
||||
impl From<Rc<Box<dyn Fn(&mut Cursive)>>> for Callback {
|
||||
fn from(f: Rc<Box<dyn Fn(&mut Cursive)>>) -> Self {
|
||||
Callback(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Box<Fn(&mut Cursive) + Send>> for Callback {
|
||||
fn from(f: Box<Fn(&mut Cursive) + Send>) -> Self {
|
||||
impl From<Box<dyn Fn(&mut Cursive) + Send>> for Callback {
|
||||
fn from(f: Box<dyn Fn(&mut Cursive) + Send>) -> Self {
|
||||
Callback(Rc::new(f))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Box<Fn(&mut Cursive)>> for Callback {
|
||||
fn from(f: Box<Fn(&mut Cursive)>) -> Self {
|
||||
impl From<Box<dyn Fn(&mut Cursive)>> for Callback {
|
||||
fn from(f: Box<dyn Fn(&mut Cursive)>) -> Self {
|
||||
Callback(Rc::new(f))
|
||||
}
|
||||
}
|
||||
|
19
src/lib.rs
19
src/lib.rs
@ -78,17 +78,16 @@ extern crate maplit;
|
||||
|
||||
// We use chan_signal to detect SIGWINCH.
|
||||
// It's not how windows work, so no need to use that.
|
||||
#[cfg(unix)]
|
||||
extern crate signal_hook;
|
||||
|
||||
extern crate chrono;
|
||||
extern crate libc;
|
||||
extern crate num;
|
||||
extern crate owning_ref;
|
||||
extern crate toml;
|
||||
extern crate unicode_segmentation;
|
||||
extern crate unicode_width;
|
||||
extern crate xi_unicode;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
macro_rules! new_default(
|
||||
($c:ty) => {
|
||||
|
@ -27,11 +27,11 @@ lazy_static! {
|
||||
}
|
||||
|
||||
impl log::Log for CursiveLogger {
|
||||
fn enabled(&self, _metadata: &log::Metadata) -> bool {
|
||||
fn enabled(&self, _metadata: &log::Metadata<'_>) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn log(&self, record: &log::Record) {
|
||||
fn log(&self, record: &log::Record<'_>) {
|
||||
let mut logs = LOGS.lock().unwrap();
|
||||
// TODO: customize the format? Use colors? Save more info?
|
||||
if logs.len() == logs.capacity() {
|
||||
|
@ -50,7 +50,7 @@ pub struct Printer<'a, 'b> {
|
||||
pub theme: &'a Theme,
|
||||
|
||||
/// Backend used to actually draw things
|
||||
backend: &'b Backend,
|
||||
backend: &'b dyn Backend,
|
||||
}
|
||||
|
||||
impl<'a, 'b> Printer<'a, 'b> {
|
||||
@ -59,7 +59,7 @@ 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 Backend,
|
||||
size: T, theme: &'a Theme, backend: &'b dyn Backend,
|
||||
) -> Self {
|
||||
let size = size.into();
|
||||
Printer {
|
||||
@ -265,7 +265,7 @@ impl<'a, 'b> Printer<'a, 'b> {
|
||||
/// ```
|
||||
pub fn with_color<F>(&self, c: ColorStyle, f: F)
|
||||
where
|
||||
F: FnOnce(&Printer),
|
||||
F: FnOnce(&Printer<'_, '_>),
|
||||
{
|
||||
let old = self.backend.set_color(c.resolve(&self.theme.palette));
|
||||
f(self);
|
||||
@ -276,7 +276,7 @@ impl<'a, 'b> Printer<'a, 'b> {
|
||||
/// that will apply the given style on prints.
|
||||
pub fn with_style<F, T>(&self, style: T, f: F)
|
||||
where
|
||||
F: FnOnce(&Printer),
|
||||
F: FnOnce(&Printer<'_, '_>),
|
||||
T: Into<Style>,
|
||||
{
|
||||
let style = style.into();
|
||||
@ -297,7 +297,7 @@ impl<'a, 'b> Printer<'a, 'b> {
|
||||
/// that will apply the given effect on prints.
|
||||
pub fn with_effect<F>(&self, effect: Effect, f: F)
|
||||
where
|
||||
F: FnOnce(&Printer),
|
||||
F: FnOnce(&Printer<'_, '_>),
|
||||
{
|
||||
self.backend.set_effect(effect);
|
||||
f(self);
|
||||
@ -308,7 +308,7 @@ impl<'a, 'b> Printer<'a, 'b> {
|
||||
/// that will apply the given theme on prints.
|
||||
pub fn with_theme<F>(&self, theme: &Theme, f: F)
|
||||
where
|
||||
F: FnOnce(&Printer),
|
||||
F: FnOnce(&Printer<'_, '_>),
|
||||
{
|
||||
f(&self.theme(theme));
|
||||
}
|
||||
@ -328,7 +328,7 @@ impl<'a, 'b> Printer<'a, 'b> {
|
||||
/// that will apply each given effect on prints.
|
||||
pub fn with_effects<F>(&self, effects: EnumSet<Effect>, f: F)
|
||||
where
|
||||
F: FnOnce(&Printer),
|
||||
F: FnOnce(&Printer<'_, '_>),
|
||||
{
|
||||
match effects.iter().next() {
|
||||
None => f(self),
|
||||
@ -391,7 +391,7 @@ impl<'a, 'b> Printer<'a, 'b> {
|
||||
/// * Otherwise, use `ColorStyle::Primary`.
|
||||
pub fn with_high_border<F>(&self, invert: bool, f: F)
|
||||
where
|
||||
F: FnOnce(&Printer),
|
||||
F: FnOnce(&Printer<'_, '_>),
|
||||
{
|
||||
let color = match self.theme.borders {
|
||||
BorderStyle::None => return,
|
||||
@ -410,7 +410,7 @@ impl<'a, 'b> Printer<'a, 'b> {
|
||||
/// * Otherwise, use `ColorStyle::primary()`.
|
||||
pub fn with_low_border<F>(&self, invert: bool, f: F)
|
||||
where
|
||||
F: FnOnce(&Printer),
|
||||
F: FnOnce(&Printer<'_, '_>),
|
||||
{
|
||||
let color = match self.theme.borders {
|
||||
BorderStyle::None => return,
|
||||
@ -428,7 +428,7 @@ impl<'a, 'b> Printer<'a, 'b> {
|
||||
/// * If the printer currently has the focus,
|
||||
/// uses `ColorStyle::highlight()`.
|
||||
/// * Otherwise, uses `ColorStyle::highlight_inactive()`.
|
||||
pub fn with_selection<F: FnOnce(&Printer)>(&self, selection: bool, f: F) {
|
||||
pub fn with_selection<F: FnOnce(&Printer<'_, '_>)>(&self, selection: bool, f: F) {
|
||||
self.with_color(
|
||||
if selection {
|
||||
if self.focused {
|
||||
@ -457,7 +457,7 @@ impl<'a, 'b> Printer<'a, 'b> {
|
||||
/// Returns a sub-printer with the given offset.
|
||||
///
|
||||
/// It will print in an area slightly to the bottom/right.
|
||||
pub fn offset<S>(&self, offset: S) -> Printer
|
||||
pub fn offset<S>(&self, offset: S) -> Printer<'_, '_>
|
||||
where
|
||||
S: Into<Vec2>,
|
||||
{
|
||||
|
@ -198,9 +198,9 @@ fn load_hex(s: &str) -> u16 {
|
||||
for c in s.chars() {
|
||||
sum *= 16;
|
||||
sum += match c {
|
||||
n @ '0'...'9' => n as i16 - '0' as i16,
|
||||
n @ 'a'...'f' => n as i16 - 'a' as i16 + 10,
|
||||
n @ 'A'...'F' => n as i16 - 'A' as i16 + 10,
|
||||
n @ '0'..='9' => n as i16 - '0' as i16,
|
||||
n @ 'a'..='f' => n as i16 - 'a' as i16 + 10,
|
||||
n @ 'A'..='F' => n as i16 - 'A' as i16 + 10,
|
||||
_ => 0,
|
||||
};
|
||||
}
|
||||
|
@ -17,9 +17,9 @@ where
|
||||
|
||||
// Number of leading 1s determines the number of bytes we'll have to read
|
||||
let n_bytes = match (!first).leading_zeros() {
|
||||
n @ 2...6 => n as usize,
|
||||
n @ 2..=6 => n as usize,
|
||||
1 => return Err("First byte is continuation byte.".to_string()),
|
||||
7...8 => return Err("WTF is this byte??".to_string()),
|
||||
7..=8 => return Err("WTF is this byte??".to_string()),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
//!
|
||||
//! Needs the `markdown` feature to be enabled.
|
||||
|
||||
extern crate pulldown_cmark;
|
||||
use pulldown_cmark;
|
||||
|
||||
use self::pulldown_cmark::{Event, Tag};
|
||||
use crate::theme::{Effect, Style};
|
||||
|
@ -16,10 +16,7 @@ pub struct SpannedString<T> {
|
||||
|
||||
/// The immutable, borrowed equivalent of `SpannedString`.
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct SpannedStr<'a, T>
|
||||
where
|
||||
T: 'a,
|
||||
{
|
||||
pub struct SpannedStr<'a, T> {
|
||||
source: &'a str,
|
||||
spans: &'a [IndexedSpan<T>],
|
||||
}
|
||||
@ -45,7 +42,7 @@ pub trait SpannedText {
|
||||
/// A reference to another `SpannedText`.
|
||||
pub struct SpannedTextRef<'a, C>
|
||||
where
|
||||
C: 'a + SpannedText + ?Sized,
|
||||
C: SpannedText + ?Sized,
|
||||
{
|
||||
r: &'a C,
|
||||
}
|
||||
@ -288,7 +285,7 @@ impl<T> AsRef<IndexedCow> for IndexedSpan<T> {
|
||||
|
||||
/// A resolved span borrowing its source string.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Span<'a, T: 'a> {
|
||||
pub struct Span<'a, T> {
|
||||
/// Content of this span.
|
||||
pub content: &'a str,
|
||||
|
||||
@ -353,7 +350,7 @@ impl IndexedCow {
|
||||
/// Returns an indexed view of the given item.
|
||||
///
|
||||
/// **Note**: it is assumed `cow`, if borrowed, is a substring of `source`.
|
||||
pub fn from_cow(cow: Cow<str>, source: &str) -> Self {
|
||||
pub fn from_cow(cow: Cow<'_, str>, source: &str) -> Self {
|
||||
match cow {
|
||||
Cow::Owned(value) => IndexedCow::Owned(value),
|
||||
Cow::Borrowed(value) => {
|
||||
|
@ -6,10 +6,10 @@ use crate::view::View;
|
||||
/// This trait is automatically implemented for any `T: View`.
|
||||
pub trait AnyView {
|
||||
/// Downcast self to a `Any`.
|
||||
fn as_any(&self) -> &Any;
|
||||
fn as_any(&self) -> &dyn Any;
|
||||
|
||||
/// Downcast self to a mutable `Any`.
|
||||
fn as_any_mut(&mut self) -> &mut Any;
|
||||
fn as_any_mut(&mut self) -> &mut dyn Any;
|
||||
|
||||
/// Returns a boxed any from a boxed self.
|
||||
///
|
||||
@ -25,21 +25,21 @@ pub trait AnyView {
|
||||
/// let text: Box<TextView> = boxed.as_boxed_any().downcast().unwrap();
|
||||
/// # }
|
||||
/// ```
|
||||
fn as_boxed_any(self: Box<Self>) -> Box<Any>;
|
||||
fn as_boxed_any(self: Box<Self>) -> Box<dyn Any>;
|
||||
}
|
||||
|
||||
impl<T: View> AnyView for T {
|
||||
/// Downcast self to a `Any`.
|
||||
fn as_any(&self) -> &Any {
|
||||
fn as_any(&self) -> &dyn Any {
|
||||
self
|
||||
}
|
||||
|
||||
/// Downcast self to a mutable `Any`.
|
||||
fn as_any_mut(&mut self) -> &mut Any {
|
||||
fn as_any_mut(&mut self) -> &mut dyn Any {
|
||||
self
|
||||
}
|
||||
|
||||
fn as_boxed_any(self: Box<Self>) -> Box<Any> {
|
||||
fn as_boxed_any(self: Box<Self>) -> Box<dyn Any> {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ 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) -> Option<R>
|
||||
fn call_on<V, F, R>(&mut self, sel: &Selector<'_>, callback: F) -> Option<R>
|
||||
where
|
||||
V: View + Any,
|
||||
F: FnOnce(&mut V) -> R;
|
||||
@ -42,7 +42,7 @@ pub trait Finder {
|
||||
}
|
||||
|
||||
impl<T: View> Finder for T {
|
||||
fn call_on<V, F, R>(&mut self, sel: &Selector, callback: F) -> Option<R>
|
||||
fn call_on<V, F, R>(&mut self, sel: &Selector<'_>, callback: F) -> Option<R>
|
||||
where
|
||||
V: View + Any,
|
||||
F: FnOnce(&mut V) -> R,
|
||||
@ -52,7 +52,7 @@ impl<T: View> Finder for T {
|
||||
let result_ref = &mut result;
|
||||
|
||||
let mut callback = Some(callback);
|
||||
let callback = |v: &mut Any| {
|
||||
let callback = |v: &mut dyn Any| {
|
||||
if let Some(callback) = callback.take() {
|
||||
if v.is::<V>() {
|
||||
*result_ref =
|
||||
|
@ -3,20 +3,20 @@ use crate::view::View;
|
||||
/// Represents a type that can be made into a `Box<View>`.
|
||||
pub trait IntoBoxedView {
|
||||
/// Returns a `Box<View>`.
|
||||
fn as_boxed_view(self) -> Box<View>;
|
||||
fn as_boxed_view(self) -> Box<dyn View>;
|
||||
}
|
||||
|
||||
impl<T> IntoBoxedView for T
|
||||
where
|
||||
T: View,
|
||||
{
|
||||
fn as_boxed_view(self) -> Box<View> {
|
||||
fn as_boxed_view(self) -> Box<dyn View> {
|
||||
Box::new(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoBoxedView for Box<View> {
|
||||
fn as_boxed_view(self) -> Box<View> {
|
||||
impl IntoBoxedView for Box<dyn View> {
|
||||
fn as_boxed_view(self) -> Box<dyn View> {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
@ -241,9 +241,9 @@ impl ScrollBase {
|
||||
/// printer.print((0,0), lines[i]);
|
||||
/// });
|
||||
/// ```
|
||||
pub fn draw<F>(&self, printer: &Printer, line_drawer: F)
|
||||
pub fn draw<F>(&self, printer: &Printer<'_, '_>, line_drawer: F)
|
||||
where
|
||||
F: Fn(&Printer, usize),
|
||||
F: Fn(&Printer<'_, '_>, usize),
|
||||
{
|
||||
if self.view_height == 0 {
|
||||
return;
|
||||
|
@ -13,7 +13,7 @@ pub trait View: Any + AnyView {
|
||||
/// Draws the view with the given printer (includes bounds) and focus.
|
||||
///
|
||||
/// This is the only *required* method to implement.
|
||||
fn draw(&self, printer: &Printer);
|
||||
fn draw(&self, printer: &Printer<'_, '_>);
|
||||
|
||||
/// Called once the size for this view has been decided.
|
||||
///
|
||||
@ -83,7 +83,7 @@ pub trait View: Any + AnyView {
|
||||
/// View groups should implement this to forward the call to each children.
|
||||
///
|
||||
/// Default implementation is a no-op.
|
||||
fn call_on_any<'a>(&mut self, _: &Selector, _: AnyCb<'a>) {
|
||||
fn call_on_any<'a>(&mut self, _: &Selector<'_>, _: AnyCb<'a>) {
|
||||
// TODO: FnMut -> FnOnce once it works
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ pub trait View: Any + AnyView {
|
||||
/// Returns `Ok(())` if the view was found and selected.
|
||||
///
|
||||
/// Default implementation simply returns `Err(())`.
|
||||
fn focus_view(&mut self, _: &Selector) -> Result<(), ()> {
|
||||
fn focus_view(&mut self, _: &Selector<'_>) -> Result<(), ()> {
|
||||
Err(())
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ pub trait ViewWrapper: 'static {
|
||||
}
|
||||
|
||||
/// Wraps the `draw` method.
|
||||
fn wrap_draw(&self, printer: &Printer) {
|
||||
fn wrap_draw(&self, printer: &Printer<'_, '_>) {
|
||||
self.with_view(|v| v.draw(printer));
|
||||
}
|
||||
|
||||
@ -79,13 +79,13 @@ 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));
|
||||
}
|
||||
|
||||
/// Wraps the `focus_view` method.
|
||||
fn wrap_focus_view(&mut self, selector: &Selector) -> Result<(), ()> {
|
||||
fn wrap_focus_view(&mut self, selector: &Selector<'_>) -> Result<(), ()> {
|
||||
self.with_view_mut(|v| v.focus_view(selector))
|
||||
.unwrap_or(Err(()))
|
||||
}
|
||||
@ -104,7 +104,7 @@ pub trait ViewWrapper: 'static {
|
||||
|
||||
// The main point of implementing ViewWrapper is to have View for free.
|
||||
impl<T: ViewWrapper> View for T {
|
||||
fn draw(&self, printer: &Printer) {
|
||||
fn draw(&self, printer: &Printer<'_, '_>) {
|
||||
self.wrap_draw(printer);
|
||||
}
|
||||
|
||||
@ -125,7 +125,7 @@ impl<T: ViewWrapper> View for T {
|
||||
}
|
||||
|
||||
fn call_on_any<'a>(
|
||||
&mut self, selector: &Selector, callback: Box<FnMut(&mut Any) + 'a>,
|
||||
&mut self, selector: &Selector<'_>, callback: Box<FnMut(&mut dyn Any) + 'a>,
|
||||
) {
|
||||
self.wrap_call_on_any(selector, callback)
|
||||
}
|
||||
@ -134,7 +134,7 @@ impl<T: ViewWrapper> View for T {
|
||||
self.wrap_needs_relayout()
|
||||
}
|
||||
|
||||
fn focus_view(&mut self, selector: &Selector) -> Result<(), ()> {
|
||||
fn focus_view(&mut self, selector: &Selector<'_>) -> Result<(), ()> {
|
||||
self.wrap_focus_view(selector)
|
||||
}
|
||||
|
||||
|
@ -137,7 +137,7 @@ impl Button {
|
||||
}
|
||||
|
||||
impl View for Button {
|
||||
fn draw(&self, printer: &Printer) {
|
||||
fn draw(&self, printer: &Printer<'_, '_>) {
|
||||
if printer.size.x == 0 {
|
||||
return;
|
||||
}
|
||||
|
@ -12,15 +12,15 @@ use crate::With;
|
||||
pub struct Canvas<T> {
|
||||
state: T,
|
||||
|
||||
draw: Box<Fn(&T, &Printer)>,
|
||||
on_event: Box<FnMut(&mut T, Event) -> EventResult>,
|
||||
required_size: Box<FnMut(&mut T, Vec2) -> Vec2>,
|
||||
layout: Box<FnMut(&mut T, Vec2)>,
|
||||
take_focus: Box<FnMut(&mut T, Direction) -> bool>,
|
||||
needs_relayout: Box<Fn(&T) -> bool>,
|
||||
focus_view: Box<FnMut(&mut T, &Selector) -> Result<(), ()>>,
|
||||
call_on_any: Box<for<'a> FnMut(&mut T, &Selector, AnyCb<'a>)>,
|
||||
important_area: Box<Fn(&T, Vec2) -> Rect>,
|
||||
draw: Box<dyn Fn(&T, &Printer)>,
|
||||
on_event: Box<dyn FnMut(&mut T, Event) -> EventResult>,
|
||||
required_size: Box<dyn FnMut(&mut T, Vec2) -> Vec2>,
|
||||
layout: Box<dyn FnMut(&mut T, Vec2)>,
|
||||
take_focus: Box<dyn FnMut(&mut T, Direction) -> bool>,
|
||||
needs_relayout: Box<dyn Fn(&T) -> bool>,
|
||||
focus_view: Box<dyn FnMut(&mut T, &Selector) -> Result<(), ()>>,
|
||||
call_on_any: Box<dyn for<'a> FnMut(&mut T, &Selector, AnyCb<'a>)>,
|
||||
important_area: Box<dyn Fn(&T, Vec2) -> Rect>,
|
||||
}
|
||||
|
||||
impl<T: 'static + View> Canvas<T> {
|
||||
@ -78,7 +78,7 @@ impl<T> Canvas<T> {
|
||||
/// Sets the closure for `draw(&Printer)`.
|
||||
pub fn set_draw<F>(&mut self, f: F)
|
||||
where
|
||||
F: 'static + Fn(&T, &Printer),
|
||||
F: 'static + Fn(&T, &Printer<'_, '_>),
|
||||
{
|
||||
self.draw = Box::new(f);
|
||||
}
|
||||
@ -88,7 +88,7 @@ impl<T> Canvas<T> {
|
||||
/// Chainable variant.
|
||||
pub fn with_draw<F>(self, f: F) -> Self
|
||||
where
|
||||
F: 'static + Fn(&T, &Printer),
|
||||
F: 'static + Fn(&T, &Printer<'_, '_>),
|
||||
{
|
||||
self.with(|s| s.set_draw(f))
|
||||
}
|
||||
@ -186,7 +186,7 @@ impl<T> Canvas<T> {
|
||||
/// Sets the closure for `call_on_any()`.
|
||||
pub fn set_call_on_any<F>(&mut self, f: F)
|
||||
where
|
||||
F: 'static + for<'a> FnMut(&mut T, &Selector, AnyCb<'a>),
|
||||
F: 'static + for<'a> FnMut(&mut T, &Selector<'_>, AnyCb<'a>),
|
||||
{
|
||||
self.call_on_any = Box::new(f);
|
||||
}
|
||||
@ -196,7 +196,7 @@ impl<T> Canvas<T> {
|
||||
/// Chainable variant.
|
||||
pub fn with_call_on_any<F>(self, f: F) -> Self
|
||||
where
|
||||
F: 'static + for<'a> FnMut(&mut T, &Selector, AnyCb<'a>),
|
||||
F: 'static + for<'a> FnMut(&mut T, &Selector<'_>, AnyCb<'a>),
|
||||
{
|
||||
self.with(|s| s.set_call_on_any(f))
|
||||
}
|
||||
@ -222,7 +222,7 @@ impl<T> Canvas<T> {
|
||||
/// Sets the closure for `focus_view()`.
|
||||
pub fn set_focus_view<F>(&mut self, f: F)
|
||||
where
|
||||
F: 'static + FnMut(&mut T, &Selector) -> Result<(), ()>,
|
||||
F: 'static + FnMut(&mut T, &Selector<'_>) -> Result<(), ()>,
|
||||
{
|
||||
self.focus_view = Box::new(f);
|
||||
}
|
||||
@ -232,14 +232,14 @@ impl<T> Canvas<T> {
|
||||
/// Chainable variant.
|
||||
pub fn with_focus_view<F>(self, f: F) -> Self
|
||||
where
|
||||
F: 'static + FnMut(&mut T, &Selector) -> Result<(), ()>,
|
||||
F: 'static + FnMut(&mut T, &Selector<'_>) -> Result<(), ()>,
|
||||
{
|
||||
self.with(|s| s.set_focus_view(f))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: 'static> View for Canvas<T> {
|
||||
fn draw(&self, printer: &Printer) {
|
||||
fn draw(&self, printer: &Printer<'_, '_>) {
|
||||
(self.draw)(&self.state, printer);
|
||||
}
|
||||
|
||||
@ -263,7 +263,7 @@ impl<T: 'static> View for Canvas<T> {
|
||||
(self.needs_relayout)(&self.state)
|
||||
}
|
||||
|
||||
fn focus_view(&mut self, selector: &Selector) -> Result<(), ()> {
|
||||
fn focus_view(&mut self, selector: &Selector<'_>) -> Result<(), ()> {
|
||||
(self.focus_view)(&mut self.state, selector)
|
||||
}
|
||||
|
||||
@ -271,7 +271,7 @@ impl<T: 'static> View for Canvas<T> {
|
||||
(self.important_area)(&self.state, view_size)
|
||||
}
|
||||
|
||||
fn call_on_any<'a>(&mut self, selector: &Selector, cb: AnyCb<'a>) {
|
||||
fn call_on_any<'a>(&mut self, selector: &Selector<'_>, cb: AnyCb<'a>) {
|
||||
(self.call_on_any)(&mut self.state, selector, cb);
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ pub struct Checkbox {
|
||||
checked: bool,
|
||||
enabled: bool,
|
||||
|
||||
on_change: Option<Rc<Fn(&mut Cursive, bool)>>,
|
||||
on_change: Option<Rc<dyn Fn(&mut Cursive, bool)>>,
|
||||
}
|
||||
|
||||
new_default!(Checkbox);
|
||||
@ -96,7 +96,7 @@ impl Checkbox {
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_internal(&self, printer: &Printer) {
|
||||
fn draw_internal(&self, printer: &Printer<'_, '_>) {
|
||||
printer.print((0, 0), "[ ]");
|
||||
if self.checked {
|
||||
printer.print((1, 0), "X");
|
||||
@ -113,7 +113,7 @@ impl View for Checkbox {
|
||||
self.enabled
|
||||
}
|
||||
|
||||
fn draw(&self, printer: &Printer) {
|
||||
fn draw(&self, printer: &Printer<'_, '_>) {
|
||||
if self.enabled && printer.enabled {
|
||||
printer.with_selection(printer.focused, |printer| {
|
||||
self.draw_internal(printer)
|
||||
|
@ -19,7 +19,7 @@ impl DebugView {
|
||||
}
|
||||
|
||||
impl View for DebugView {
|
||||
fn draw(&self, printer: &Printer) {
|
||||
fn draw(&self, printer: &Printer<'_, '_>) {
|
||||
let logs = logger::LOGS.lock().unwrap();
|
||||
// Only print the last logs, so skip what doesn't fit
|
||||
let skipped = logs.len().saturating_sub(printer.size.y);
|
||||
|
@ -124,12 +124,12 @@ impl Dialog {
|
||||
/// .unwrap();
|
||||
/// assert_eq!(text_view.get_content().source(), "Hello!");
|
||||
/// ```
|
||||
pub fn get_content(&self) -> &View {
|
||||
pub fn get_content(&self) -> &dyn View {
|
||||
&*self.content.view
|
||||
}
|
||||
|
||||
/// Gets mutable access to the content.
|
||||
pub fn get_content_mut(&mut self) -> &mut View {
|
||||
pub fn get_content_mut(&mut self) -> &mut dyn View {
|
||||
self.invalidate();
|
||||
&mut *self.content.view
|
||||
}
|
||||
@ -391,7 +391,7 @@ impl Dialog {
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_buttons(&self, printer: &Printer) -> Option<usize> {
|
||||
fn draw_buttons(&self, printer: &Printer<'_, '_>) -> Option<usize> {
|
||||
let mut buttons_height = 0;
|
||||
// Current horizontal position of the next button we'll draw.
|
||||
|
||||
@ -439,7 +439,7 @@ impl Dialog {
|
||||
Some(buttons_height)
|
||||
}
|
||||
|
||||
fn draw_content(&self, printer: &Printer, buttons_height: usize) {
|
||||
fn draw_content(&self, printer: &Printer<'_, '_>, buttons_height: usize) {
|
||||
// What do we have left?
|
||||
let taken = Vec2::new(0, buttons_height)
|
||||
+ self.borders.combined()
|
||||
@ -458,7 +458,7 @@ impl Dialog {
|
||||
);
|
||||
}
|
||||
|
||||
fn draw_title(&self, printer: &Printer) {
|
||||
fn draw_title(&self, printer: &Printer<'_, '_>) {
|
||||
if !self.title.is_empty() {
|
||||
let len = self.title.width();
|
||||
if len + 4 > printer.size.x {
|
||||
@ -521,7 +521,7 @@ impl Dialog {
|
||||
}
|
||||
|
||||
impl View for Dialog {
|
||||
fn draw(&self, printer: &Printer) {
|
||||
fn draw(&self, printer: &Printer<'_, '_>) {
|
||||
// This will be the buttons_height used by the buttons.
|
||||
let buttons_height = match self.draw_buttons(printer) {
|
||||
Some(height) => height,
|
||||
@ -653,11 +653,11 @@ impl View for Dialog {
|
||||
}
|
||||
}
|
||||
|
||||
fn call_on_any<'a>(&mut self, selector: &Selector, callback: AnyCb<'a>) {
|
||||
fn call_on_any<'a>(&mut self, selector: &Selector<'_>, callback: AnyCb<'a>) {
|
||||
self.content.call_on_any(selector, callback);
|
||||
}
|
||||
|
||||
fn focus_view(&mut self, selector: &Selector) -> Result<(), ()> {
|
||||
fn focus_view(&mut self, selector: &Selector<'_>) -> Result<(), ()> {
|
||||
self.content.focus_view(selector)
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ use crate::Printer;
|
||||
pub struct DummyView;
|
||||
|
||||
impl View for DummyView {
|
||||
fn draw(&self, _: &Printer) {}
|
||||
fn draw(&self, _: &Printer<'_, '_>) {}
|
||||
|
||||
fn needs_relayout(&self) -> bool {
|
||||
false
|
||||
|
@ -15,12 +15,12 @@ use crate::{Cursive, Printer, With};
|
||||
///
|
||||
/// Arguments are the `Cursive`, current content of the input and cursor
|
||||
/// position
|
||||
pub type OnEdit = Fn(&mut Cursive, &str, usize);
|
||||
pub type OnEdit = dyn Fn(&mut Cursive, &str, usize);
|
||||
|
||||
/// Closure type for callbacks when Enter is pressed.
|
||||
///
|
||||
/// Arguments are the `Cursive` and the content of the input.
|
||||
pub type OnSubmit = Fn(&mut Cursive, &str);
|
||||
pub type OnSubmit = dyn Fn(&mut Cursive, &str);
|
||||
|
||||
/// Input box where the user can enter and edit text.
|
||||
///
|
||||
@ -502,7 +502,7 @@ fn make_small_stars(length: usize) -> &'static str {
|
||||
}
|
||||
|
||||
impl View for EditView {
|
||||
fn draw(&self, printer: &Printer) {
|
||||
fn draw(&self, printer: &Printer<'_, '_>) {
|
||||
assert_eq!(
|
||||
printer.size.x, self.last_length,
|
||||
"Was promised {}, received {}",
|
||||
|
@ -35,7 +35,7 @@ impl<V: View> ViewWrapper for EnableableView<V> {
|
||||
}
|
||||
}
|
||||
|
||||
fn wrap_draw(&self, printer: &Printer) {
|
||||
fn wrap_draw(&self, printer: &Printer<'_, '_>) {
|
||||
self.view.draw(&printer.enabled(self.enabled));
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ impl<V: View> ViewWrapper for HideableView<V> {
|
||||
}
|
||||
|
||||
fn wrap_call_on_any<'a>(
|
||||
&mut self, selector: &Selector, callback: Box<FnMut(&mut Any) + 'a>,
|
||||
&mut self, selector: &Selector<'_>, callback: Box<FnMut(&mut dyn Any) + 'a>,
|
||||
) {
|
||||
// We always run callbacks, even when invisible.
|
||||
self.view.call_on_any(selector, callback)
|
||||
|
@ -42,7 +42,7 @@ impl<V: View> IdView<V> {
|
||||
}
|
||||
|
||||
// Shortcut for a boxed callback (for the wrap_call_on_any method).
|
||||
type BoxedCallback<'a> = Box<for<'b> FnMut(&'b mut Any) + 'a>;
|
||||
type BoxedCallback<'a> = Box<for<'b> FnMut(&'b mut dyn Any) + 'a>;
|
||||
|
||||
impl<T: View + 'static> ViewWrapper for IdView<T> {
|
||||
type V = T;
|
||||
@ -77,7 +77,7 @@ 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),
|
||||
@ -89,7 +89,7 @@ impl<T: View + 'static> ViewWrapper for IdView<T> {
|
||||
}
|
||||
}
|
||||
|
||||
fn wrap_focus_view(&mut self, selector: &Selector) -> Result<(), ()> {
|
||||
fn wrap_focus_view(&mut self, selector: &Selector<'_>) -> Result<(), ()> {
|
||||
match selector {
|
||||
&Selector::Id(id) if id == self.id => Ok(()),
|
||||
s => self
|
||||
|
@ -23,7 +23,7 @@ impl<T: View> Layer<T> {
|
||||
impl<T: View> ViewWrapper for Layer<T> {
|
||||
wrap_impl!(self.view: T);
|
||||
|
||||
fn wrap_draw(&self, printer: &Printer) {
|
||||
fn wrap_draw(&self, printer: &Printer<'_, '_>) {
|
||||
for y in 0..printer.size.y {
|
||||
printer.print_hline((0, y), printer.size.x, " ");
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ pub struct LinearLayout {
|
||||
}
|
||||
|
||||
struct Child {
|
||||
view: Box<View>,
|
||||
view: Box<dyn View>,
|
||||
// The last result from the child's required_size
|
||||
// Doesn't have to be what the child actually gets.
|
||||
size: Vec2,
|
||||
@ -33,7 +33,7 @@ impl Child {
|
||||
self.size
|
||||
}
|
||||
|
||||
fn as_view(&self) -> &View {
|
||||
fn as_view(&self) -> &dyn View {
|
||||
&*self.view
|
||||
}
|
||||
}
|
||||
@ -176,12 +176,12 @@ impl LinearLayout {
|
||||
}
|
||||
|
||||
/// Returns a reference to a child.
|
||||
pub fn get_child(&self, i: usize) -> Option<&View> {
|
||||
pub fn get_child(&self, i: usize) -> Option<&dyn View> {
|
||||
self.children.get(i).map(|child| &*child.view)
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to a child.
|
||||
pub fn get_child_mut(&mut self, i: usize) -> Option<&mut View> {
|
||||
pub fn get_child_mut(&mut self, i: usize) -> Option<&mut dyn View> {
|
||||
// Anything could happen to the child view, so bust the cache.
|
||||
self.invalidate();
|
||||
self.children.get_mut(i).map(|child| &mut *child.view)
|
||||
@ -190,7 +190,7 @@ impl LinearLayout {
|
||||
/// Removes a child.
|
||||
///
|
||||
/// If `i` is within bounds, the removed child will be returned.
|
||||
pub fn remove_child(&mut self, i: usize) -> Option<Box<View>> {
|
||||
pub fn remove_child(&mut self, i: usize) -> Option<Box<dyn View>> {
|
||||
if i < self.children.len() {
|
||||
// Any alteration means we should invalidate the cache.
|
||||
self.invalidate();
|
||||
@ -240,7 +240,7 @@ 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,
|
||||
) -> Box<Iterator<Item = (usize, &mut Child)> + 'a> {
|
||||
) -> Box<dyn Iterator<Item = (usize, &mut Child)> + 'a> {
|
||||
match source {
|
||||
direction::Relative::Front => {
|
||||
let start = if from_focus { self.focus } else { 0 };
|
||||
@ -334,7 +334,7 @@ fn try_focus(
|
||||
}
|
||||
|
||||
impl View for LinearLayout {
|
||||
fn draw(&self, printer: &Printer) {
|
||||
fn draw(&self, printer: &Printer<'_, '_>) {
|
||||
// Use pre-computed sizes
|
||||
// debug!("Pre loop!");
|
||||
for (i, item) in ChildIterator::new(
|
||||
@ -597,7 +597,7 @@ 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
|
||||
@ -606,7 +606,7 @@ impl View for LinearLayout {
|
||||
}
|
||||
}
|
||||
|
||||
fn focus_view(&mut self, selector: &Selector) -> Result<(), ()> {
|
||||
fn focus_view(&mut self, selector: &Selector<'_>) -> Result<(), ()> {
|
||||
for (i, child) in self.children.iter_mut().enumerate() {
|
||||
if child.view.focus_view(selector).is_ok() {
|
||||
self.focus = i;
|
||||
|
@ -14,7 +14,7 @@ use crate::With;
|
||||
/// [`ListView`]: struct.ListView.html
|
||||
pub enum ListChild {
|
||||
/// A single row, with a label and a view.
|
||||
Row(String, Box<View>),
|
||||
Row(String, Box<dyn View>),
|
||||
/// A delimiter between groups.
|
||||
Delimiter,
|
||||
}
|
||||
@ -27,7 +27,7 @@ impl ListChild {
|
||||
}
|
||||
}
|
||||
|
||||
fn view(&mut self) -> Option<&mut View> {
|
||||
fn view(&mut self) -> Option<&mut dyn View> {
|
||||
match *self {
|
||||
ListChild::Row(_, ref mut view) => Some(view.as_mut()),
|
||||
_ => None,
|
||||
@ -40,7 +40,7 @@ pub struct ListView {
|
||||
children: Vec<ListChild>,
|
||||
focus: usize,
|
||||
// This callback is called when the selection is changed.
|
||||
on_select: Option<Rc<Fn(&mut Cursive, &String)>>,
|
||||
on_select: Option<Rc<dyn Fn(&mut Cursive, &String)>>,
|
||||
last_size: Vec2,
|
||||
}
|
||||
|
||||
@ -147,7 +147,7 @@ impl ListView {
|
||||
|
||||
fn iter_mut<'a>(
|
||||
&'a mut self, from_focus: bool, source: direction::Relative,
|
||||
) -> Box<Iterator<Item = (usize, &mut ListChild)> + 'a> {
|
||||
) -> Box<dyn Iterator<Item = (usize, &mut ListChild)> + 'a> {
|
||||
match source {
|
||||
direction::Relative::Front => {
|
||||
let start = if from_focus { self.focus } else { 0 };
|
||||
@ -250,7 +250,7 @@ fn try_focus(
|
||||
}
|
||||
|
||||
impl View for ListView {
|
||||
fn draw(&self, printer: &Printer) {
|
||||
fn draw(&self, printer: &Printer<'_, '_>) {
|
||||
if self.children.is_empty() {
|
||||
return;
|
||||
}
|
||||
@ -379,14 +379,14 @@ impl View for ListView {
|
||||
}
|
||||
|
||||
fn call_on_any<'a>(
|
||||
&mut self, selector: &Selector, mut callback: AnyCb<'a>,
|
||||
&mut self, selector: &Selector<'_>, mut callback: AnyCb<'a>,
|
||||
) {
|
||||
for view in self.children.iter_mut().filter_map(ListChild::view) {
|
||||
view.call_on_any(selector, Box::new(|any| callback(any)));
|
||||
}
|
||||
}
|
||||
|
||||
fn focus_view(&mut self, selector: &Selector) -> Result<(), ()> {
|
||||
fn focus_view(&mut self, selector: &Selector<'_>) -> Result<(), ()> {
|
||||
if let Some(i) = self
|
||||
.children
|
||||
.iter_mut()
|
||||
|
@ -202,7 +202,7 @@ impl MenuPopup {
|
||||
}
|
||||
|
||||
impl View for MenuPopup {
|
||||
fn draw(&self, printer: &Printer) {
|
||||
fn draw(&self, printer: &Printer<'_, '_>) {
|
||||
if !printer.size.fits((2, 2)) {
|
||||
return;
|
||||
}
|
||||
|
@ -261,7 +261,7 @@ fn show_child(s: &mut Cursive, offset: Vec2, menu: Rc<MenuTree>) {
|
||||
}
|
||||
|
||||
impl View for Menubar {
|
||||
fn draw(&self, printer: &Printer) {
|
||||
fn draw(&self, printer: &Printer<'_, '_>) {
|
||||
// Draw the bar at the top
|
||||
printer.with_color(ColorStyle::primary(), |printer| {
|
||||
printer.print_hline((0, 0), printer.size.x, " ");
|
||||
|
@ -43,7 +43,7 @@ pub struct OnEventView<T: View> {
|
||||
callbacks: Vec<(EventTrigger, Action<T>)>,
|
||||
}
|
||||
|
||||
type InnerCallback<T> = Rc<Box<Fn(&mut T, &Event) -> Option<EventResult>>>;
|
||||
type InnerCallback<T> = Rc<Box<dyn Fn(&mut T, &Event) -> Option<EventResult>>>;
|
||||
|
||||
struct Action<T> {
|
||||
phase: TriggerPhase,
|
||||
|
@ -56,7 +56,7 @@ impl<V: View> ViewWrapper for PaddedView<V> {
|
||||
self.view.on_event(event.relativized(padding))
|
||||
}
|
||||
|
||||
fn wrap_draw(&self, printer: &Printer) {
|
||||
fn wrap_draw(&self, printer: &Printer<'_, '_>) {
|
||||
let top_left = self.margins.top_left();
|
||||
let bot_right = self.margins.bot_right();
|
||||
let printer = &printer.offset(top_left).shrinked(bot_right);
|
||||
|
@ -62,7 +62,7 @@ impl<V: View> Panel<V> {
|
||||
self.title_position = align;
|
||||
}
|
||||
|
||||
fn draw_title(&self, printer: &Printer) {
|
||||
fn draw_title(&self, printer: &Printer<'_, '_>) {
|
||||
if !self.title.is_empty() {
|
||||
let len = self.title.width();
|
||||
if len + 4 > printer.size.x {
|
||||
@ -102,7 +102,7 @@ impl<V: View> ViewWrapper for Panel<V> {
|
||||
self.view.required_size(req) + (2, 2)
|
||||
}
|
||||
|
||||
fn wrap_draw(&self, printer: &Printer) {
|
||||
fn wrap_draw(&self, printer: &Printer<'_, '_>) {
|
||||
printer.print_box((0, 0), printer.size, true);
|
||||
self.draw_title(&printer);
|
||||
|
||||
|
@ -40,7 +40,7 @@ pub struct ProgressBar {
|
||||
value: Counter,
|
||||
color: ColorType,
|
||||
// TODO: use a Promise instead?
|
||||
label_maker: Box<Fn(usize, (usize, usize)) -> String>,
|
||||
label_maker: Box<dyn Fn(usize, (usize, usize)) -> String>,
|
||||
}
|
||||
|
||||
fn make_percentage(value: usize, (min, max): (usize, usize)) -> String {
|
||||
@ -225,7 +225,7 @@ fn sub_block(extra: usize) -> &'static str {
|
||||
}
|
||||
|
||||
impl View for ProgressBar {
|
||||
fn draw(&self, printer: &Printer) {
|
||||
fn draw(&self, printer: &Printer<'_, '_>) {
|
||||
// Now, the bar itself...
|
||||
let available = printer.size.x;
|
||||
|
||||
|
@ -12,7 +12,7 @@ struct SharedState<T> {
|
||||
selection: usize,
|
||||
values: Vec<Rc<T>>,
|
||||
|
||||
on_change: Option<Rc<Fn(&mut Cursive, &T)>>,
|
||||
on_change: Option<Rc<dyn Fn(&mut Cursive, &T)>>,
|
||||
}
|
||||
|
||||
impl<T> SharedState<T> {
|
||||
@ -162,7 +162,7 @@ impl<T: 'static> RadioButton<T> {
|
||||
})
|
||||
}
|
||||
|
||||
fn draw_internal(&self, printer: &Printer) {
|
||||
fn draw_internal(&self, printer: &Printer<'_, '_>) {
|
||||
printer.print((0, 0), "( )");
|
||||
if self.is_selected() {
|
||||
printer.print((1, 0), "X");
|
||||
@ -193,7 +193,7 @@ impl<T: 'static> View for RadioButton<T> {
|
||||
self.enabled
|
||||
}
|
||||
|
||||
fn draw(&self, printer: &Printer) {
|
||||
fn draw(&self, printer: &Printer<'_, '_>) {
|
||||
if self.enabled && printer.enabled {
|
||||
printer.with_selection(printer.focused, |printer| {
|
||||
self.draw_internal(printer)
|
||||
|
@ -431,7 +431,7 @@ impl<V> View for ScrollView<V>
|
||||
where
|
||||
V: View,
|
||||
{
|
||||
fn draw(&self, printer: &Printer) {
|
||||
fn draw(&self, printer: &Printer<'_, '_>) {
|
||||
// Draw scrollbar?
|
||||
let scrolling = self.is_scrolling();
|
||||
|
||||
@ -692,11 +692,11 @@ where
|
||||
size
|
||||
}
|
||||
|
||||
fn call_on_any<'a>(&mut self, selector: &Selector, cb: AnyCb<'a>) {
|
||||
fn call_on_any<'a>(&mut self, selector: &Selector<'_>, cb: AnyCb<'a>) {
|
||||
self.inner.call_on_any(selector, cb)
|
||||
}
|
||||
|
||||
fn focus_view(&mut self, selector: &Selector) -> Result<(), ()> {
|
||||
fn focus_view(&mut self, selector: &Selector<'_>) -> Result<(), ()> {
|
||||
self.inner.focus_view(selector)
|
||||
}
|
||||
|
||||
|
@ -59,11 +59,11 @@ pub struct SelectView<T = String> {
|
||||
|
||||
// This is a custom callback to include a &T.
|
||||
// It will be called whenever "Enter" is pressed or when an item is clicked.
|
||||
on_submit: Option<Rc<Fn(&mut Cursive, &T)>>,
|
||||
on_submit: Option<Rc<dyn Fn(&mut Cursive, &T)>>,
|
||||
|
||||
// This callback is called when the selection is changed.
|
||||
// TODO: add the previous selection? Indices?
|
||||
on_select: Option<Rc<Fn(&mut Cursive, &T)>>,
|
||||
on_select: Option<Rc<dyn Fn(&mut Cursive, &T)>>,
|
||||
|
||||
// If `true`, when a character is pressed, jump to the next item starting
|
||||
// with this character.
|
||||
@ -347,7 +347,7 @@ impl<T: 'static> SelectView<T> {
|
||||
self.with(|s| s.add_all(iter))
|
||||
}
|
||||
|
||||
fn draw_item(&self, printer: &Printer, i: usize) {
|
||||
fn draw_item(&self, printer: &Printer<'_, '_>, i: usize) {
|
||||
let l = self.items[i].label.width();
|
||||
let x = self.align.h.get_offset(l, printer.size.x);
|
||||
printer.print_hline((0, 0), x, " ");
|
||||
@ -670,7 +670,7 @@ impl SelectView<String> {
|
||||
}
|
||||
|
||||
impl<T: 'static> View for SelectView<T> {
|
||||
fn draw(&self, printer: &Printer) {
|
||||
fn draw(&self, printer: &Printer<'_, '_>) {
|
||||
self.last_offset.set(printer.offset);
|
||||
|
||||
if self.popup {
|
||||
|
@ -70,7 +70,7 @@ impl<T: View> ViewWrapper for ShadowView<T> {
|
||||
self.view.on_event(event.relativized(padding))
|
||||
}
|
||||
|
||||
fn wrap_draw(&self, printer: &Printer) {
|
||||
fn wrap_draw(&self, printer: &Printer<'_, '_>) {
|
||||
if printer.size.y <= self.top_padding as usize
|
||||
|| printer.size.x <= self.left_padding as usize
|
||||
{
|
||||
|
@ -10,8 +10,8 @@ use crate::{Cursive, Printer};
|
||||
/// A horizontal or vertical slider.
|
||||
pub struct SliderView {
|
||||
orientation: Orientation,
|
||||
on_change: Option<Rc<Fn(&mut Cursive, usize)>>,
|
||||
on_enter: Option<Rc<Fn(&mut Cursive, usize)>>,
|
||||
on_change: Option<Rc<dyn Fn(&mut Cursive, usize)>>,
|
||||
on_enter: Option<Rc<dyn Fn(&mut Cursive, usize)>>,
|
||||
value: usize,
|
||||
max_value: usize,
|
||||
dragging: bool,
|
||||
@ -112,7 +112,7 @@ impl SliderView {
|
||||
}
|
||||
|
||||
impl View for SliderView {
|
||||
fn draw(&self, printer: &Printer) {
|
||||
fn draw(&self, printer: &Printer<'_, '_>) {
|
||||
match self.orientation {
|
||||
Orientation::Vertical => {
|
||||
printer.print_vline((0, 0), self.max_value, "|")
|
||||
|
@ -126,7 +126,7 @@ impl<T: View> ChildWrapper<T> {
|
||||
|
||||
// TODO: use macros to make this less ugly?
|
||||
impl<T: View> View for ChildWrapper<T> {
|
||||
fn draw(&self, printer: &Printer) {
|
||||
fn draw(&self, printer: &Printer<'_, '_>) {
|
||||
match *self {
|
||||
ChildWrapper::Shadow(ref v) => v.draw(printer),
|
||||
ChildWrapper::Backfilled(ref v) => v.draw(printer),
|
||||
@ -166,7 +166,7 @@ impl<T: View> View for ChildWrapper<T> {
|
||||
}
|
||||
}
|
||||
|
||||
fn call_on_any<'a>(&mut self, selector: &Selector, callback: AnyCb<'a>) {
|
||||
fn call_on_any<'a>(&mut self, selector: &Selector<'_>, callback: AnyCb<'a>) {
|
||||
match *self {
|
||||
ChildWrapper::Shadow(ref mut v) => {
|
||||
v.call_on_any(selector, callback)
|
||||
@ -180,7 +180,7 @@ impl<T: View> View for ChildWrapper<T> {
|
||||
}
|
||||
}
|
||||
|
||||
fn focus_view(&mut self, selector: &Selector) -> Result<(), ()> {
|
||||
fn focus_view(&mut self, selector: &Selector<'_>) -> Result<(), ()> {
|
||||
match *self {
|
||||
ChildWrapper::Shadow(ref mut v) => v.focus_view(selector),
|
||||
ChildWrapper::Backfilled(ref mut v) => v.focus_view(selector),
|
||||
@ -266,14 +266,14 @@ impl StackView {
|
||||
}
|
||||
|
||||
/// Returns a reference to the layer at the given position.
|
||||
pub fn get(&self, pos: LayerPosition) -> Option<&View> {
|
||||
pub fn get(&self, pos: LayerPosition) -> Option<&dyn View> {
|
||||
self.get_index(pos).and_then(|i| {
|
||||
self.layers.get(i).map(|child| &**child.view.get_inner())
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to the layer at the given position.
|
||||
pub fn get_mut(&mut self, pos: LayerPosition) -> Option<&mut View> {
|
||||
pub fn get_mut(&mut self, pos: LayerPosition) -> Option<&mut dyn View> {
|
||||
self.get_index(pos).and_then(move |i| {
|
||||
self.layers
|
||||
.get_mut(i)
|
||||
@ -397,13 +397,13 @@ impl StackView {
|
||||
/// # Panics
|
||||
///
|
||||
/// If the given position is out of bounds.
|
||||
pub fn remove_layer(&mut self, position: LayerPosition) -> Box<View> {
|
||||
pub fn remove_layer(&mut self, position: LayerPosition) -> Box<dyn View> {
|
||||
let i = self.get_index(position).unwrap();
|
||||
self.layers.remove(i).view.unwrap().unwrap()
|
||||
}
|
||||
|
||||
/// Remove the top-most layer.
|
||||
pub fn pop_layer(&mut self) -> Option<Box<View>> {
|
||||
pub fn pop_layer(&mut self) -> Option<Box<dyn View>> {
|
||||
self.bg_dirty.set(true);
|
||||
self.layers
|
||||
.pop()
|
||||
@ -500,7 +500,7 @@ impl StackView {
|
||||
/// ease inserting layers under the stackview but above its background.
|
||||
///
|
||||
/// you probably just want to call draw()
|
||||
pub fn draw_bg(&self, printer: &Printer) {
|
||||
pub fn draw_bg(&self, printer: &Printer<'_, '_>) {
|
||||
// If the background is dirty draw a new background
|
||||
if self.bg_dirty.get() {
|
||||
for y in 0..printer.size.y {
|
||||
@ -520,7 +520,7 @@ impl StackView {
|
||||
/// ease inserting layers under the stackview but above its background.
|
||||
///
|
||||
/// You probably just want to call draw()
|
||||
pub fn draw_fg(&self, printer: &Printer) {
|
||||
pub fn draw_fg(&self, printer: &Printer<'_, '_>) {
|
||||
let last = self.layers.len();
|
||||
printer.with_color(ColorStyle::primary(), |printer| {
|
||||
for (i, (v, offset)) in
|
||||
@ -585,7 +585,7 @@ where
|
||||
}
|
||||
|
||||
impl View for StackView {
|
||||
fn draw(&self, printer: &Printer) {
|
||||
fn draw(&self, printer: &Printer<'_, '_>) {
|
||||
// This function is included for compat with the view trait,
|
||||
// it should behave the same as calling them seperately, but does
|
||||
// not pause to let you insert in between the layers.
|
||||
@ -650,7 +650,7 @@ 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
|
||||
@ -659,7 +659,7 @@ impl View for StackView {
|
||||
}
|
||||
}
|
||||
|
||||
fn focus_view(&mut self, selector: &Selector) -> Result<(), ()> {
|
||||
fn focus_view(&mut self, selector: &Selector<'_>) -> Result<(), ()> {
|
||||
for layer in &mut self.layers {
|
||||
if layer.view.focus_view(selector).is_ok() {
|
||||
return Ok(());
|
||||
|
@ -459,7 +459,7 @@ impl View for TextArea {
|
||||
)
|
||||
}
|
||||
|
||||
fn draw(&self, printer: &Printer) {
|
||||
fn draw(&self, printer: &Printer<'_, '_>) {
|
||||
printer.with_color(ColorStyle::secondary(), |printer| {
|
||||
let effect = if self.enabled && printer.enabled {
|
||||
Effect::Reverse
|
||||
|
@ -346,7 +346,7 @@ impl TextView {
|
||||
}
|
||||
|
||||
impl View for TextView {
|
||||
fn draw(&self, printer: &Printer) {
|
||||
fn draw(&self, printer: &Printer<'_, '_>) {
|
||||
let h = self.rows.len();
|
||||
// If the content is smaller than the view, align it somewhere.
|
||||
let offset = self.align.v.get_offset(h, printer.size.y);
|
||||
|
@ -37,7 +37,7 @@ impl<T: View> TrackedView<T> {
|
||||
impl<T: View> ViewWrapper for TrackedView<T> {
|
||||
wrap_impl!(self.view: T);
|
||||
|
||||
fn wrap_draw(&self, printer: &Printer) {
|
||||
fn wrap_draw(&self, printer: &Printer<'_, '_>) {
|
||||
self.offset.set(printer.offset);
|
||||
self.view.draw(printer);
|
||||
}
|
||||
|
@ -5,12 +5,12 @@ use crate::view::{IntoBoxedView, View, ViewWrapper};
|
||||
///
|
||||
/// It derefs to the wrapped view.
|
||||
pub struct ViewBox {
|
||||
view: Box<View>,
|
||||
view: Box<dyn View>,
|
||||
}
|
||||
|
||||
impl ViewBox {
|
||||
/// Creates a new `ViewBox` around the given boxed view.
|
||||
pub fn new(view: Box<View>) -> Self {
|
||||
pub fn new(view: Box<dyn View>) -> Self {
|
||||
ViewBox { view }
|
||||
}
|
||||
|
||||
@ -23,27 +23,27 @@ impl ViewBox {
|
||||
}
|
||||
|
||||
/// Returns the inner boxed view.
|
||||
pub fn unwrap(self) -> Box<View> {
|
||||
pub fn unwrap(self) -> Box<dyn View> {
|
||||
self.view
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for ViewBox {
|
||||
type Target = View;
|
||||
type Target = dyn View;
|
||||
|
||||
fn deref(&self) -> &View {
|
||||
fn deref(&self) -> &dyn View {
|
||||
&*self.view
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for ViewBox {
|
||||
fn deref_mut(&mut self) -> &mut View {
|
||||
fn deref_mut(&mut self) -> &mut dyn View {
|
||||
&mut *self.view
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewWrapper for ViewBox {
|
||||
type V = View;
|
||||
type V = dyn View;
|
||||
|
||||
fn with_view<F, R>(&self, f: F) -> Option<R>
|
||||
where
|
||||
|
Loading…
Reference in New Issue
Block a user