Directly use crate::Vec2

This commit is contained in:
Alexandre Bury 2020-01-06 15:51:38 -08:00
parent cd26e40fcb
commit 4c00dd3b72
48 changed files with 65 additions and 66 deletions

View File

@ -1,5 +1,5 @@
use cursive::traits::*;
use cursive::vec::Vec2;
use cursive::Vec2;
use cursive::{Cursive, Printer};
use std::collections::VecDeque;
use std::sync::mpsc;

View File

@ -1,4 +1,4 @@
use cursive::vec::Vec2;
use cursive::Vec2;
use rand::{thread_rng, Rng};
// use std::cmp::max;

View File

@ -3,10 +3,10 @@ mod game;
use cursive::direction::Direction;
use cursive::event::{Event, EventResult, MouseButton, MouseEvent};
use cursive::theme::{BaseColor, Color, ColorStyle};
use cursive::vec::Vec2;
use cursive::views::{Button, Dialog, LinearLayout, Panel, SelectView};
use cursive::Cursive;
use cursive::Printer;
use cursive::Vec2;
fn main() {
let mut siv = Cursive::default();

View File

@ -14,7 +14,7 @@ use self::bear_lib_terminal::Color as BltColor;
use crate::backend;
use crate::event::{Event, Key, MouseButton, MouseEvent};
use crate::theme::{BaseColor, Color, ColorPair, Effect};
use crate::vec::Vec2;
use crate::Vec2;
// Use AHash instead of the slower SipHash
type HashSet<K> = std::collections::HashSet<K, ahash::ABuildHasher>;

View File

@ -32,8 +32,7 @@ use crossterm::{
use crate::{
backend,
event::{Event, Key, MouseButton, MouseEvent},
theme,
vec::Vec2,
theme, Vec2,
};
#[cfg(windows)]

View File

@ -14,7 +14,7 @@ use crate::backend;
use crate::event::{Event, Key, MouseButton, MouseEvent};
use crate::theme::{Color, ColorPair, Effect};
use crate::utf8;
use crate::vec::Vec2;
use crate::Vec2;
use self::super::split_i32;
use self::ncurses::mmask_t;

View File

@ -8,7 +8,7 @@ use std::io::{stdout, Write};
use crate::backend;
use crate::event::{Event, Key, MouseButton, MouseEvent};
use crate::theme::{Color, ColorPair, Effect};
use crate::vec::Vec2;
use crate::Vec2;
use self::pancurses::mmask_t;
use super::split_i32;

View File

@ -3,7 +3,7 @@
use crate::backend;
use crate::event::Event;
use crate::theme;
use crate::vec::Vec2;
use crate::Vec2;
/// Dummy backend that does nothing and immediately exits.
///

View File

@ -9,7 +9,7 @@
use crate::event::Event;
use crate::theme;
use crate::vec::Vec2;
use crate::Vec2;
use unicode_width::UnicodeWidthStr;
#[cfg(unix)]

View File

@ -7,7 +7,7 @@ use crate::backend::puppet::observed::ObservedScreen;
use crate::backend::puppet::observed::ObservedStyle;
use crate::event::Event;
use crate::theme;
use crate::vec::Vec2;
use crate::Vec2;
use std::cell::{Cell, RefCell};
use std::rc::Rc;
use unicode_segmentation::UnicodeSegmentation;

View File

@ -3,7 +3,7 @@ use lazy_static::lazy_static;
use crate::theme::ColorPair;
use crate::theme::{Color, Effect};
use crate::vec::Vec2;
use crate::Vec2;
use crate::XY;
use enumset::EnumSet;

View File

@ -19,7 +19,7 @@ use crossbeam_channel::{self, select, Receiver};
use crate::backend;
use crate::event::{Event, Key, MouseButton, MouseEvent};
use crate::theme;
use crate::vec::Vec2;
use crate::Vec2;
use std::cell::{Cell, RefCell};
use std::fs::File;

View File

@ -11,9 +11,9 @@ use crate::direction;
use crate::event::{Callback, Event, EventResult};
use crate::printer::Printer;
use crate::theme;
use crate::vec::Vec2;
use crate::view::{self, Finder, IntoBoxedView, Position, View};
use crate::views::{self, LayerPosition};
use crate::Vec2;
static DEBUG_VIEW_NAME: &str = "_cursive_debug_view";

View File

@ -23,7 +23,7 @@
//! `Tab` key would usually cycle focus in the "front" direction, while
//! using the arrow keys would use absolute directions instead.
use crate::vec::Vec2;
use crate::Vec2;
use crate::XY;
/// Describes a vertical or horizontal orientation for a view.

View File

@ -12,8 +12,8 @@
//! [`on_event`]: crate::View::on_event
//! [global callback]: crate::Cursive::add_global_callback
use crate::vec::Vec2;
use crate::Cursive;
use crate::Vec2;
use std::any::Any;
use std::cell::RefCell;
use std::ops::Deref;

View File

@ -6,8 +6,8 @@ use crate::theme::{
BorderStyle, ColorStyle, Effect, PaletteColor, Style, Theme,
};
use crate::utils::lines::simple::{prefix, suffix};
use crate::vec::Vec2;
use crate::with::With;
use crate::Vec2;
use enumset::EnumSet;
use std::cmp::min;
use unicode_segmentation::UnicodeSegmentation;

View File

@ -1,5 +1,5 @@
//! Rectangles on the 2D character grid.
use crate::vec::Vec2;
use crate::Vec2;
use std::ops::Add;
/// A non-empty rectangle on the 2D grid.

View File

@ -38,7 +38,7 @@ impl XY<usize> {
/// # Examples
///
/// ```rust
/// # use cursive::vec::Vec2;
/// # use cursive::Vec2;
/// assert!(Vec2::new(9999, 9999) < Vec2::max_value());
/// ```
pub fn max_value() -> Self {
@ -52,7 +52,7 @@ impl XY<usize> {
/// # Examples
///
/// ```rust
/// # use cursive::vec::Vec2;
/// # use cursive::Vec2;
/// let u = Vec2::new(1, 2);
/// let v = Vec2::new(2, 1);
/// assert_eq!(u.saturating_sub(v), Vec2::new(0, 1));
@ -69,7 +69,7 @@ impl XY<usize> {
/// # Examples
///
/// ```rust
/// # use cursive::vec::Vec2;
/// # use cursive::Vec2;
/// # use cursive::XY;
/// let u = Vec2::new(1, 2);
/// let v = XY::<isize>::new(-2, 1);
@ -92,7 +92,7 @@ impl XY<usize> {
/// # Examples
///
/// ```rust
/// # use cursive::vec::Vec2;
/// # use cursive::Vec2;
/// let u = Vec2::new(1, 6);
/// let v = Vec2::new(2, 3);
/// assert_eq!(u.div_up(v), Vec2::new(1, 2));
@ -113,7 +113,7 @@ impl XY<usize> {
/// # Examples
///
/// ```rust
/// # use cursive::vec::Vec2;
/// # use cursive::Vec2;
/// let xy = Vec2::new(1, 2);
/// assert_eq!(xy.checked_sub((1, 1)), Some(Vec2::new(0, 1)));
/// assert_eq!(xy.checked_sub((2, 2)), None);
@ -132,7 +132,7 @@ impl XY<usize> {
/// # Examples
///
/// ```rust
/// # use cursive::vec::Vec2;
/// # use cursive::Vec2;
/// # use cursive::XY;
/// let v: XY<isize> = Vec2::new(1, 2).signed().map(|i| i - 5);
/// assert_eq!(v, XY::new(-4, -3));
@ -155,7 +155,7 @@ impl<T: Ord> XY<T> {
/// # Examples
///
/// ```rust
/// # use cursive::vec::Vec2;
/// # use cursive::Vec2;
/// let v = Vec2::new(1, 2);
/// assert!(v.fits_in((1, 2)));
/// assert!(v.fits_in((3, 3)));
@ -175,7 +175,7 @@ impl<T: Ord> XY<T> {
/// # Examples
///
/// ```rust
/// # use cursive::vec::Vec2;
/// # use cursive::Vec2;
/// let v = Vec2::new(1, 2);
/// assert!(v.fits((1, 2)));
/// assert!(v.fits((0, 0)));
@ -203,7 +203,7 @@ impl<T: Ord> XY<T> {
/// # Examples
///
/// ```rust
/// # use cursive::vec::Vec2;
/// # use cursive::Vec2;
/// assert_eq!(Vec2::max((1, 2), (3, 1)), Vec2::new(3, 2));
/// ```
pub fn max<A: Into<XY<T>>, B: Into<XY<T>>>(a: A, b: B) -> Self {
@ -217,7 +217,7 @@ impl<T: Ord> XY<T> {
/// # Examples
///
/// ```rust
/// # use cursive::vec::Vec2;
/// # use cursive::Vec2;
/// assert_eq!(Vec2::min((1, 2), (3, 1)), Vec2::new(1, 1));
/// ```
pub fn min<A: Into<XY<T>>, B: Into<XY<T>>>(a: A, b: B) -> Self {
@ -315,7 +315,7 @@ impl<T: Zero + Clone> XY<T> {
/// # Examples
///
/// ```rust
/// # use cursive::vec::Vec2;
/// # use cursive::Vec2;
/// assert_eq!(Vec2::zero(), Vec2::new(0, 0));
/// ```
pub fn zero() -> Self {
@ -350,7 +350,7 @@ where
///
/// ```rust
/// # use cursive::XY;
/// # use cursive::vec::Vec2;
/// # use cursive::Vec2;
/// let u = Vec2::new(1, 2);
/// let v: XY<isize> = XY::from(u);
/// assert_eq!(v, XY::new(1, 2));
@ -378,7 +378,7 @@ impl From<(u32, u32)> for XY<usize> {
/// # Examples
///
/// ```rust
/// # use cursive::vec::Vec2;
/// # use cursive::Vec2;
/// let v = Vec2::from((1u32, 2u32));
/// assert_eq!(v, Vec2::new(1, 2));
/// ```
@ -391,7 +391,7 @@ impl From<(u8, u8)> for XY<usize> {
/// # Examples
///
/// ```rust
/// # use cursive::vec::Vec2;
/// # use cursive::Vec2;
/// let v = Vec2::from((1u8, 2u8));
/// assert_eq!(v, Vec2::new(1, 2));
/// ```
@ -404,7 +404,7 @@ impl From<(u16, u16)> for XY<usize> {
/// # Examples
///
/// ```rust
/// # use cursive::vec::Vec2;
/// # use cursive::Vec2;
/// let v = Vec2::from((1u16, 2u16));
/// assert_eq!(v, Vec2::new(1, 2));
/// ```
@ -473,7 +473,7 @@ impl Mul<usize> for XY<usize> {
/// # Examples
///
/// ```rust
/// # use cursive::vec::Vec2;
/// # use cursive::Vec2;
/// let v = Vec2::new(1, 2);
/// assert_eq!(v * 2, Vec2::new(2, 4));
/// ```

View File

@ -1,4 +1,4 @@
use crate::vec::Vec2;
use crate::Vec2;
use std::ops::{Add, Div, Mul, Sub};
/// Four values representing each direction.

View File

@ -1,4 +1,4 @@
use crate::vec::Vec2;
use crate::Vec2;
use crate::XY;
use std::cmp::min;
@ -91,7 +91,7 @@ impl Offset {
mod tests {
use super::Position;
use crate::vec::Vec2;
use crate::Vec2;
#[test]
fn test_center() {

View File

@ -1,6 +1,6 @@
use crate::vec::Vec2;
use crate::view::{SizeConstraint, View};
use crate::views::ResizedView;
use crate::Vec2;
/// Makes a view wrappable in a [`ResizedView`].
pub trait Resizable: View + Sized {

View File

@ -5,9 +5,9 @@ use crate::event::{AnyCb, Event, EventResult, Key, MouseButton, MouseEvent};
use crate::printer::Printer;
use crate::rect::Rect;
use crate::theme::ColorStyle;
use crate::vec::Vec2;
use crate::view::{ScrollStrategy, Selector, SizeCache};
use crate::with::With;
use crate::Vec2;
use crate::XY;
/// Describes an item with a scroll core.

View File

@ -1,7 +1,7 @@
use crate::div::div_up;
use crate::theme::ColorStyle;
use crate::vec::Vec2;
use crate::Printer;
use crate::Vec2;
use std::cmp::{max, min};
/// Provide scrolling functionalities to a view.

View File

@ -1,4 +1,4 @@
use crate::vec::Vec2;
use crate::Vec2;
use crate::XY;
/// Cache around a one-dimensional layout result.

View File

@ -1,9 +1,9 @@
use crate::direction::Direction;
use crate::event::{AnyCb, Event, EventResult};
use crate::rect::Rect;
use crate::vec::Vec2;
use crate::view::{AnyView, Selector};
use crate::Printer;
use crate::Vec2;
use std::any::Any;
/// Main trait defining a view behaviour.

View File

@ -1,9 +1,9 @@
use crate::direction::Direction;
use crate::event::{AnyCb, Event, EventResult};
use crate::rect::Rect;
use crate::vec::Vec2;
use crate::view::{Selector, View};
use crate::Printer;
use crate::Vec2;
/// Generic wrapper around a view.
///

View File

@ -3,8 +3,8 @@ use crate::direction::Direction;
use crate::event::*;
use crate::rect::Rect;
use crate::theme::ColorStyle;
use crate::vec::Vec2;
use crate::view::View;
use crate::Vec2;
use crate::{Cursive, Printer, With};
use unicode_width::UnicodeWidthStr;

View File

@ -1,9 +1,9 @@
use crate::direction::Direction;
use crate::event::{AnyCb, Event, EventResult};
use crate::rect::Rect;
use crate::vec::Vec2;
use crate::view::{Selector, View};
use crate::Printer;
use crate::Vec2;
use crate::With;
// Define this type separately to appease the Clippy god

View File

@ -1,10 +1,10 @@
use crate::direction::Direction;
use crate::event::{Event, EventResult, Key, MouseButton, MouseEvent};
use crate::theme::ColorStyle;
use crate::vec::Vec2;
use crate::view::View;
use crate::Cursive;
use crate::Printer;
use crate::Vec2;
use crate::With;
use std::rc::Rc;

View File

@ -1,8 +1,8 @@
use crate::logger;
use crate::theme;
use crate::vec::Vec2;
use crate::view::View;
use crate::Printer;
use crate::Vec2;
use unicode_width::UnicodeWidthStr;

View File

@ -3,11 +3,11 @@ use crate::direction::{Absolute, Direction, Relative};
use crate::event::{AnyCb, Event, EventResult, Key};
use crate::rect::Rect;
use crate::theme::ColorStyle;
use crate::vec::Vec2;
use crate::view::{Margins, Selector, View};
use crate::views::{BoxedView, Button, DummyView, LastSizeView, TextView};
use crate::Cursive;
use crate::Printer;
use crate::Vec2;
use crate::With;
use std::cell::Cell;
use std::cmp::max;

View File

@ -3,8 +3,8 @@ use crate::event::{Callback, Event, EventResult, Key, MouseEvent};
use crate::rect::Rect;
use crate::theme::{ColorStyle, Effect};
use crate::utils::lines::simple::{simple_prefix, simple_suffix};
use crate::vec::Vec2;
use crate::view::View;
use crate::Vec2;
use crate::{Cursive, Printer, With};
use std::cell::RefCell;
use std::rc::Rc;

View File

@ -1,6 +1,6 @@
use crate::event::AnyCb;
use crate::vec::Vec2;
use crate::view::{Selector, View, ViewWrapper};
use crate::Vec2;
use crate::With;
/// Wrapper around another view that can be hidden at will.

View File

@ -1,6 +1,6 @@
use crate::vec::Vec2;
use crate::view::View;
use crate::view::ViewWrapper;
use crate::Vec2;
/// Wrapper around a view that remembers its size.
pub struct LastSizeView<T> {

View File

@ -1,9 +1,9 @@
use crate::direction;
use crate::event::{AnyCb, Event, EventResult, Key};
use crate::rect::Rect;
use crate::vec::Vec2;
use crate::view::{IntoBoxedView, Selector, SizeCache, View};
use crate::Printer;
use crate::Vec2;
use crate::With;
use crate::XY;
use log::debug;

View File

@ -1,10 +1,10 @@
use crate::direction;
use crate::event::{AnyCb, Callback, Event, EventResult, Key};
use crate::rect::Rect;
use crate::vec::Vec2;
use crate::view::{IntoBoxedView, Selector, View};
use crate::Cursive;
use crate::Printer;
use crate::Vec2;
use crate::With;
use log::debug;
use std::rc::Rc;

View File

@ -4,12 +4,12 @@ use crate::event::{
};
use crate::menu::{MenuItem, MenuTree};
use crate::rect::Rect;
use crate::vec::Vec2;
use crate::view::scroll;
use crate::view::{Position, View};
use crate::views::OnEventView;
use crate::Cursive;
use crate::Printer;
use crate::Vec2;
use crate::With;
use std::cmp::min;
use std::rc::Rc;

View File

@ -3,11 +3,11 @@ use crate::event::*;
use crate::menu::{MenuItem, MenuTree};
use crate::rect::Rect;
use crate::theme::ColorStyle;
use crate::vec::Vec2;
use crate::view::{Position, View};
use crate::views::{MenuPopup, OnEventView};
use crate::Cursive;
use crate::Printer;
use crate::Vec2;
use std::rc::Rc;
use unicode_width::UnicodeWidthStr;

View File

@ -1,7 +1,7 @@
use crate::event::{Event, EventResult};
use crate::vec::Vec2;
use crate::view::{Margins, View, ViewWrapper};
use crate::Printer;
use crate::Vec2;
/// Adds padding to another view.
///

View File

@ -2,9 +2,9 @@ use crate::align::*;
use crate::event::{Event, EventResult};
use crate::rect::Rect;
use crate::theme::ColorStyle;
use crate::vec::Vec2;
use crate::view::{View, ViewWrapper};
use crate::Printer;
use crate::Vec2;
use crate::With;
use unicode_width::UnicodeWidthStr;

View File

@ -1,9 +1,9 @@
use crate::direction::Direction;
use crate::event::{Event, EventResult, Key, MouseButton, MouseEvent};
use crate::theme::ColorStyle;
use crate::vec::Vec2;
use crate::view::View;
use crate::Cursive;
use crate::Vec2;
use crate::{Printer, With};
use std::cell::RefCell;
use std::rc::Rc;

View File

@ -1,6 +1,6 @@
use crate::printer::Printer;
use crate::vec::Vec2;
use crate::view::{SizeConstraint, View, ViewWrapper};
use crate::Vec2;
use crate::XY;
/// Wrapper around another view, with a controlled size.
@ -230,9 +230,9 @@ impl<T: View> ViewWrapper for ResizedView<T> {
#[cfg(test)]
mod tests {
use crate::vec::Vec2;
use crate::view::{Boxable, View};
use crate::views::DummyView;
use crate::Vec2;
// No need to test `draw()` method as it's directly forwarded.

View File

@ -7,11 +7,11 @@ use crate::menu::MenuTree;
use crate::rect::Rect;
use crate::theme::ColorStyle;
use crate::utils::markup::StyledString;
use crate::vec::Vec2;
use crate::view::{Position, View};
use crate::views::MenuPopup;
use crate::Cursive;
use crate::Printer;
use crate::Vec2;
use crate::With;
use std::borrow::Borrow;
use std::cell::Cell;

View File

@ -1,8 +1,8 @@
use crate::event::{Event, EventResult};
use crate::theme::ColorStyle;
use crate::vec::Vec2;
use crate::view::{View, ViewWrapper};
use crate::Printer;
use crate::Vec2;
/// Wrapper view that adds a shadow.
///

View File

@ -3,8 +3,8 @@ use crate::event::{
Callback, Event, EventResult, Key, MouseButton, MouseEvent,
};
use crate::theme::ColorStyle;
use crate::vec::Vec2;
use crate::view::View;
use crate::Vec2;
use crate::With;
use crate::{Cursive, Printer};
use std::rc::Rc;

View File

@ -1,12 +1,12 @@
use crate::direction::Direction;
use crate::event::{AnyCb, Event, EventResult};
use crate::theme::ColorStyle;
use crate::vec::Vec2;
use crate::view::{
IntoBoxedView, Offset, Position, Selector, View, ViewWrapper,
};
use crate::views::{BoxedView, CircularFocus, Layer, ShadowView};
use crate::Printer;
use crate::Vec2;
use crate::With;
use std::cell;
use std::ops::Deref;

View File

@ -3,8 +3,8 @@ use crate::event::{Event, EventResult, Key, MouseButton, MouseEvent};
use crate::rect::Rect;
use crate::theme::{ColorStyle, Effect};
use crate::utils::lines::simple::{prefix, simple_prefix, LinesIterator, Row};
use crate::vec::Vec2;
use crate::view::{ScrollBase, SizeCache, View};
use crate::Vec2;
use crate::{Printer, With, XY};
use log::debug;
use std::cmp::min;

View File

@ -1,7 +1,7 @@
use crate::vec::Vec2;
use crate::view::{View, ViewWrapper};
use crate::views::NamedView;
use crate::Printer;
use crate::Vec2;
use std::cell::Cell;
/// Wrapper around a view that remembers its position.