mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Apply rustfmt
This commit is contained in:
parent
8fa704bcfa
commit
3b3f403f7a
@ -1,9 +1,9 @@
|
|||||||
use backend;
|
use backend;
|
||||||
use event::{Event, Key};
|
use event::{Event, Key};
|
||||||
use theme::{BaseColor, Color, ColorStyle, Effect};
|
|
||||||
use utf8;
|
|
||||||
|
|
||||||
use ncurses;
|
use ncurses;
|
||||||
|
use theme::{BaseColor, Color, ColorStyle, Effect};
|
||||||
|
use utf8;
|
||||||
|
|
||||||
pub struct NcursesBackend;
|
pub struct NcursesBackend;
|
||||||
|
|
||||||
|
@ -13,10 +13,10 @@
|
|||||||
//! [global callback](../struct.Cursive.html#method.add_global_callback)
|
//! [global callback](../struct.Cursive.html#method.add_global_callback)
|
||||||
//! table is checked.
|
//! table is checked.
|
||||||
|
|
||||||
use std::rc::Rc;
|
|
||||||
use std::ops::Deref;
|
|
||||||
|
|
||||||
use Cursive;
|
use Cursive;
|
||||||
|
use std::ops::Deref;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
/// Callback is a function that can be triggered by an event.
|
/// Callback is a function that can be triggered by an event.
|
||||||
/// It has a mutable access to the cursive root.
|
/// It has a mutable access to the cursive root.
|
||||||
|
25
src/lib.rs
25
src/lib.rs
@ -104,22 +104,25 @@ mod utf8;
|
|||||||
|
|
||||||
mod backend;
|
mod backend;
|
||||||
|
|
||||||
pub use xy::XY;
|
|
||||||
pub use with::With;
|
|
||||||
pub use printer::Printer;
|
|
||||||
|
|
||||||
use backend::{Backend, NcursesBackend};
|
use backend::{Backend, NcursesBackend};
|
||||||
use view::Finder;
|
|
||||||
|
|
||||||
use std::sync::mpsc;
|
use event::{Callback, Event, EventResult};
|
||||||
|
|
||||||
|
pub use printer::Printer;
|
||||||
|
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use vec::Vec2;
|
use std::sync::mpsc;
|
||||||
use view::View;
|
|
||||||
|
use vec::Vec2;
|
||||||
|
use view::Finder;
|
||||||
|
use view::View;
|
||||||
|
pub use with::With;
|
||||||
|
pub use xy::XY;
|
||||||
|
|
||||||
use event::{Callback, Event, EventResult};
|
|
||||||
|
|
||||||
/// Identifies a screen in the cursive ROOT.
|
/// Identifies a screen in the cursive ROOT.
|
||||||
pub type ScreenId = usize;
|
pub type ScreenId = usize;
|
||||||
@ -467,11 +470,7 @@ impl Cursive {
|
|||||||
|
|
||||||
// Draw the currently active screen
|
// Draw the currently active screen
|
||||||
// If the menubar is active, nothing else can be.
|
// If the menubar is active, nothing else can be.
|
||||||
let offset = if self.menubar.autohide {
|
let offset = if self.menubar.autohide { 0 } else { 1 };
|
||||||
0
|
|
||||||
} else {
|
|
||||||
1
|
|
||||||
};
|
|
||||||
// Draw the menubar?
|
// Draw the menubar?
|
||||||
if self.menubar.visible() {
|
if self.menubar.visible() {
|
||||||
let printer = printer.sub_printer(Vec2::zero(),
|
let printer = printer.sub_printer(Vec2::zero(),
|
||||||
|
@ -12,10 +12,10 @@
|
|||||||
//!
|
//!
|
||||||
//! [menubar]: ../struct.Cursive.html#method.menubar
|
//! [menubar]: ../struct.Cursive.html#method.menubar
|
||||||
|
|
||||||
use With;
|
|
||||||
use Cursive;
|
use Cursive;
|
||||||
use std::rc::Rc;
|
use With;
|
||||||
use event::Callback;
|
use event::Callback;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
/// Root of a menu tree.
|
/// Root of a menu tree.
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
//! Makes drawing on ncurses windows easier.
|
//! Makes drawing on ncurses windows easier.
|
||||||
|
|
||||||
|
|
||||||
|
use B;
|
||||||
|
use backend::Backend;
|
||||||
use std::cmp::min;
|
use std::cmp::min;
|
||||||
|
|
||||||
|
use theme::{BorderStyle, ColorStyle, Effect, Theme};
|
||||||
use unicode_segmentation::UnicodeSegmentation;
|
use unicode_segmentation::UnicodeSegmentation;
|
||||||
|
|
||||||
use utils::prefix_length;
|
use utils::prefix_length;
|
||||||
use backend::Backend;
|
|
||||||
|
|
||||||
use B;
|
|
||||||
|
|
||||||
use theme::{BorderStyle, ColorStyle, Effect, Theme};
|
|
||||||
use vec::Vec2;
|
use vec::Vec2;
|
||||||
|
|
||||||
/// Convenient interface to draw on a subset of the screen.
|
/// Convenient interface to draw on a subset of the screen.
|
||||||
|
52
src/theme.rs
52
src/theme.rs
@ -114,17 +114,17 @@
|
|||||||
//! highlight_inactive = "#5555FF"
|
//! highlight_inactive = "#5555FF"
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
use std::io;
|
|
||||||
use std::io::Read;
|
|
||||||
use std::fs::File;
|
|
||||||
use std::path::Path;
|
|
||||||
|
|
||||||
use backend::Backend;
|
|
||||||
|
|
||||||
use toml;
|
|
||||||
|
|
||||||
use B;
|
use B;
|
||||||
|
|
||||||
|
use backend::Backend;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io;
|
||||||
|
use std::io::Read;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
use toml;
|
||||||
|
|
||||||
/// Text effect
|
/// Text effect
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub enum Effect {
|
pub enum Effect {
|
||||||
@ -233,32 +233,32 @@ impl Theme {
|
|||||||
pub fn activate(&self, backend: &mut B) {
|
pub fn activate(&self, backend: &mut B) {
|
||||||
// Initialize each color with the backend
|
// Initialize each color with the backend
|
||||||
backend.init_color_style(ColorStyle::Background,
|
backend.init_color_style(ColorStyle::Background,
|
||||||
&self.colors.view,
|
&self.colors.view,
|
||||||
&self.colors.background);
|
&self.colors.background);
|
||||||
backend.init_color_style(ColorStyle::Shadow,
|
backend.init_color_style(ColorStyle::Shadow,
|
||||||
&self.colors.shadow,
|
&self.colors.shadow,
|
||||||
&self.colors.shadow);
|
&self.colors.shadow);
|
||||||
backend.init_color_style(ColorStyle::Primary,
|
backend.init_color_style(ColorStyle::Primary,
|
||||||
&self.colors.primary,
|
&self.colors.primary,
|
||||||
&self.colors.view);
|
&self.colors.view);
|
||||||
backend.init_color_style(ColorStyle::Secondary,
|
backend.init_color_style(ColorStyle::Secondary,
|
||||||
&self.colors.secondary,
|
&self.colors.secondary,
|
||||||
&self.colors.view);
|
&self.colors.view);
|
||||||
backend.init_color_style(ColorStyle::Tertiary,
|
backend.init_color_style(ColorStyle::Tertiary,
|
||||||
&self.colors.tertiary,
|
&self.colors.tertiary,
|
||||||
&self.colors.view);
|
&self.colors.view);
|
||||||
backend.init_color_style(ColorStyle::TitlePrimary,
|
backend.init_color_style(ColorStyle::TitlePrimary,
|
||||||
&self.colors.title_primary,
|
&self.colors.title_primary,
|
||||||
&self.colors.view);
|
&self.colors.view);
|
||||||
backend.init_color_style(ColorStyle::TitleSecondary,
|
backend.init_color_style(ColorStyle::TitleSecondary,
|
||||||
&self.colors.title_secondary,
|
&self.colors.title_secondary,
|
||||||
&self.colors.view);
|
&self.colors.view);
|
||||||
backend.init_color_style(ColorStyle::Highlight,
|
backend.init_color_style(ColorStyle::Highlight,
|
||||||
&self.colors.view,
|
&self.colors.view,
|
||||||
&self.colors.highlight);
|
&self.colors.highlight);
|
||||||
backend.init_color_style(ColorStyle::HighlightInactive,
|
backend.init_color_style(ColorStyle::HighlightInactive,
|
||||||
&self.colors.view,
|
&self.colors.view,
|
||||||
&self.colors.highlight_inactive);
|
&self.colors.highlight_inactive);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
use unicode_width::UnicodeWidthStr;
|
|
||||||
use unicode_segmentation::UnicodeSegmentation;
|
|
||||||
|
|
||||||
use With;
|
use With;
|
||||||
|
use unicode_segmentation::UnicodeSegmentation;
|
||||||
|
use unicode_width::UnicodeWidthStr;
|
||||||
use utils::prefix_length;
|
use utils::prefix_length;
|
||||||
|
|
||||||
/// Generates rows of text in constrained width.
|
/// Generates rows of text in constrained width.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//! Toolbox to make text layout easier.
|
//! Toolbox to make text layout easier.
|
||||||
|
|
||||||
use unicode_width::UnicodeWidthStr;
|
|
||||||
use unicode_segmentation::UnicodeSegmentation;
|
use unicode_segmentation::UnicodeSegmentation;
|
||||||
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
|
||||||
mod lines_iterator;
|
mod lines_iterator;
|
||||||
mod reader;
|
mod reader;
|
||||||
@ -55,11 +55,7 @@ pub fn prefix_length<'a, I>(iter: I, width: usize, delimiter: &str) -> usize
|
|||||||
|
|
||||||
// We counted delimiter once too many times,
|
// We counted delimiter once too many times,
|
||||||
// but only if the iterator was non empty.
|
// but only if the iterator was non empty.
|
||||||
if sum == 0 {
|
if sum == 0 { sum } else { sum - delimiter_len }
|
||||||
sum
|
|
||||||
} else {
|
|
||||||
sum - delimiter_len
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Computes the length of a suffix that fits in the given `width`.
|
/// Computes the length of a suffix that fits in the given `width`.
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
//! Points on the 2D character grid.
|
//! Points on the 2D character grid.
|
||||||
|
|
||||||
use XY;
|
use XY;
|
||||||
use direction::Orientation;
|
use direction::Orientation;
|
||||||
|
use std::cmp::{Ordering, max, min};
|
||||||
|
|
||||||
use std::ops::{Add, Div, Mul, Sub};
|
use std::ops::{Add, Div, Mul, Sub};
|
||||||
use std::cmp::{Ordering, max, min};
|
|
||||||
|
|
||||||
/// Simple 2D size, in cells.
|
/// Simple 2D size, in cells.
|
||||||
///
|
///
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
|
use vec::Vec2;
|
||||||
use view::{SizeConstraint, View};
|
use view::{SizeConstraint, View};
|
||||||
use views::BoxView;
|
use views::BoxView;
|
||||||
use vec::Vec2;
|
|
||||||
|
|
||||||
/// Makes a view wrappable in a [`BoxView`].
|
/// Makes a view wrappable in a [`BoxView`].
|
||||||
///
|
///
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use views::IdView;
|
|
||||||
use view::View;
|
use view::View;
|
||||||
|
use views::IdView;
|
||||||
|
|
||||||
/// Makes a view wrappable in an [`IdView`].
|
/// Makes a view wrappable in an [`IdView`].
|
||||||
///
|
///
|
||||||
|
@ -50,12 +50,12 @@ mod identifiable;
|
|||||||
mod boxable;
|
mod boxable;
|
||||||
|
|
||||||
|
|
||||||
use std::any::Any;
|
use Printer;
|
||||||
|
|
||||||
use direction::Direction;
|
use direction::Direction;
|
||||||
use event::{Event, EventResult};
|
use event::{Event, EventResult};
|
||||||
use vec::Vec2;
|
pub use self::boxable::Boxable;
|
||||||
use Printer;
|
pub use self::identifiable::Identifiable;
|
||||||
|
|
||||||
pub use self::position::{Offset, Position};
|
pub use self::position::{Offset, Position};
|
||||||
|
|
||||||
@ -65,8 +65,8 @@ pub use self::size_cache::SizeCache;
|
|||||||
pub use self::size_constraint::SizeConstraint;
|
pub use self::size_constraint::SizeConstraint;
|
||||||
pub use self::view_path::ViewPath;
|
pub use self::view_path::ViewPath;
|
||||||
pub use self::view_wrapper::ViewWrapper;
|
pub use self::view_wrapper::ViewWrapper;
|
||||||
pub use self::identifiable::Identifiable;
|
use std::any::Any;
|
||||||
pub use self::boxable::Boxable;
|
use vec::Vec2;
|
||||||
|
|
||||||
|
|
||||||
/// Main trait defining a view behaviour.
|
/// Main trait defining a view behaviour.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use std::cmp::min;
|
|
||||||
use XY;
|
use XY;
|
||||||
|
use std::cmp::min;
|
||||||
use vec::Vec2;
|
use vec::Vec2;
|
||||||
|
|
||||||
/// Location of the view on screen
|
/// Location of the view on screen
|
||||||
@ -60,7 +60,8 @@ pub enum Offset {
|
|||||||
|
|
||||||
impl Offset {
|
impl Offset {
|
||||||
/// Computes a single-dimension offset requred to draw a view.
|
/// Computes a single-dimension offset requred to draw a view.
|
||||||
pub fn compute_offset(&self, size: usize, available: usize, parent: usize)
|
pub fn compute_offset(&self, size: usize, available: usize,
|
||||||
|
parent: usize)
|
||||||
-> usize {
|
-> usize {
|
||||||
if size > available {
|
if size > available {
|
||||||
0
|
0
|
||||||
@ -79,17 +80,17 @@ impl Offset {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use vec::Vec2;
|
|
||||||
use super::Position;
|
use super::Position;
|
||||||
|
use vec::Vec2;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_center() {
|
fn test_center() {
|
||||||
let center = Position::center();
|
let c = Position::center();
|
||||||
assert_eq!(Vec2::new(2, 1), center.compute_offset((1,1), (5,3), (0,0)));
|
assert_eq!(Vec2::new(2, 1), c.compute_offset((1, 1), (5, 3), (0, 0)));
|
||||||
assert_eq!(Vec2::new(2, 0), center.compute_offset((1,3), (5,3), (0,0)));
|
assert_eq!(Vec2::new(2, 0), c.compute_offset((1, 3), (5, 3), (0, 0)));
|
||||||
assert_eq!(Vec2::new(1, 1), center.compute_offset((3,1), (5,3), (0,0)));
|
assert_eq!(Vec2::new(1, 1), c.compute_offset((3, 1), (5, 3), (0, 0)));
|
||||||
assert_eq!(Vec2::new(0, 1), center.compute_offset((5,1), (5,3), (0,0)));
|
assert_eq!(Vec2::new(0, 1), c.compute_offset((5, 1), (5, 3), (0, 0)));
|
||||||
assert_eq!(Vec2::new(0, 0), center.compute_offset((5,3), (5,3), (0,0)));
|
assert_eq!(Vec2::new(0, 0), c.compute_offset((5, 3), (5, 3), (0, 0)));
|
||||||
assert_eq!(Vec2::new(0, 0), center.compute_offset((5,3), (3,1), (0,0)));
|
assert_eq!(Vec2::new(0, 0), c.compute_offset((5, 3), (3, 1), (0, 0)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
|
use Printer;
|
||||||
use std::cmp::{max, min};
|
use std::cmp::{max, min};
|
||||||
|
|
||||||
use theme::ColorStyle;
|
use theme::ColorStyle;
|
||||||
use vec::Vec2;
|
use vec::Vec2;
|
||||||
use Printer;
|
|
||||||
|
|
||||||
/// Provide scrolling functionalities to a view.
|
/// Provide scrolling functionalities to a view.
|
||||||
///
|
///
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
use std::any::Any;
|
use Printer;
|
||||||
|
|
||||||
use direction::Direction;
|
use direction::Direction;
|
||||||
|
use event::{Event, EventResult};
|
||||||
|
use std::any::Any;
|
||||||
use vec::Vec2;
|
use vec::Vec2;
|
||||||
use view::{Selector, View};
|
use view::{Selector, View};
|
||||||
use Printer;
|
|
||||||
use event::{Event, EventResult};
|
|
||||||
|
|
||||||
/// Generic wrapper around a view.
|
/// Generic wrapper around a view.
|
||||||
///
|
///
|
||||||
|
@ -38,7 +38,8 @@ impl<T: View> BoxView<T> {
|
|||||||
/// Creates a new `BoxView` with the given width and height requirements.
|
/// Creates a new `BoxView` with the given width and height requirements.
|
||||||
///
|
///
|
||||||
/// `None` values will use the wrapped view's preferences.
|
/// `None` values will use the wrapped view's preferences.
|
||||||
pub fn new(width: SizeConstraint, height: SizeConstraint, view: T) -> Self {
|
pub fn new(width: SizeConstraint, height: SizeConstraint, view: T)
|
||||||
|
-> Self {
|
||||||
BoxView {
|
BoxView {
|
||||||
size: (width, height).into(),
|
size: (width, height).into(),
|
||||||
squishable: false,
|
squishable: false,
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
use unicode_width::UnicodeWidthStr;
|
|
||||||
|
|
||||||
use {Cursive, Printer, With};
|
use {Cursive, Printer, With};
|
||||||
use align::HAlign;
|
use align::HAlign;
|
||||||
use event::*;
|
|
||||||
use direction::Direction;
|
use direction::Direction;
|
||||||
|
use event::*;
|
||||||
use theme::ColorStyle;
|
use theme::ColorStyle;
|
||||||
|
use unicode_width::UnicodeWidthStr;
|
||||||
use vec::Vec2;
|
use vec::Vec2;
|
||||||
use view::View;
|
use view::View;
|
||||||
|
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
use With;
|
|
||||||
use Cursive;
|
use Cursive;
|
||||||
use Printer;
|
use Printer;
|
||||||
use vec::Vec2;
|
use With;
|
||||||
use theme::ColorStyle;
|
|
||||||
use view::View;
|
|
||||||
use event::{Event, EventResult, Key};
|
|
||||||
use direction::Direction;
|
use direction::Direction;
|
||||||
|
use event::{Event, EventResult, Key};
|
||||||
|
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
use theme::ColorStyle;
|
||||||
|
use vec::Vec2;
|
||||||
|
use view::View;
|
||||||
|
|
||||||
|
|
||||||
/// Checkable box.
|
/// Checkable box.
|
||||||
|
@ -1,18 +1,19 @@
|
|||||||
use std::cmp::max;
|
|
||||||
use std::any::Any;
|
|
||||||
|
|
||||||
use Cursive;
|
use Cursive;
|
||||||
use With;
|
|
||||||
use direction::Direction;
|
|
||||||
use align::*;
|
|
||||||
use event::*;
|
|
||||||
use theme::ColorStyle;
|
|
||||||
use view::{Selector, View};
|
|
||||||
use views::{Button, DummyView, SizedView, TextView};
|
|
||||||
use vec::{Vec2, Vec4};
|
|
||||||
use Printer;
|
use Printer;
|
||||||
|
use With;
|
||||||
|
use align::*;
|
||||||
|
use direction::Direction;
|
||||||
|
use event::*;
|
||||||
|
use std::any::Any;
|
||||||
|
use std::cmp::max;
|
||||||
|
use theme::ColorStyle;
|
||||||
|
|
||||||
use unicode_width::UnicodeWidthStr;
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
use vec::{Vec2, Vec4};
|
||||||
|
use view::{Selector, View};
|
||||||
|
use views::{Button, DummyView, SizedView, TextView};
|
||||||
|
|
||||||
#[derive(PartialEq)]
|
#[derive(PartialEq)]
|
||||||
enum Focus {
|
enum Focus {
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
use unicode_segmentation::UnicodeSegmentation;
|
|
||||||
use unicode_width::UnicodeWidthStr;
|
|
||||||
|
|
||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
use {Cursive, Printer, With};
|
use {Cursive, Printer, With};
|
||||||
use direction::Direction;
|
use direction::Direction;
|
||||||
|
use event::{Callback, Event, EventResult, Key};
|
||||||
|
|
||||||
|
use std::rc::Rc;
|
||||||
use theme::{ColorStyle, Effect};
|
use theme::{ColorStyle, Effect};
|
||||||
|
use unicode_segmentation::UnicodeSegmentation;
|
||||||
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
use utils::simple_suffix_length;
|
||||||
use vec::Vec2;
|
use vec::Vec2;
|
||||||
use view::View;
|
use view::View;
|
||||||
use event::{Callback, Event, EventResult, Key};
|
|
||||||
use utils::simple_suffix_length;
|
|
||||||
|
|
||||||
|
|
||||||
/// Input box where the user can enter and edit text.
|
/// Input box where the user can enter and edit text.
|
||||||
@ -289,11 +290,7 @@ impl View for EditView {
|
|||||||
let display_bytes = content.graphemes(true)
|
let display_bytes = content.graphemes(true)
|
||||||
.scan(0, |w, g| {
|
.scan(0, |w, g| {
|
||||||
*w += g.width();
|
*w += g.width();
|
||||||
if *w > self.last_length {
|
if *w > self.last_length { None } else { Some(g) }
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(g)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.map(|g| g.len())
|
.map(|g| g.len())
|
||||||
.fold(0, |a, b| a + b);
|
.fold(0, |a, b| a + b);
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use Cursive;
|
use Cursive;
|
||||||
use event::{Callback, Event, EventResult};
|
use event::{Callback, Event, EventResult};
|
||||||
|
use std::collections::HashMap;
|
||||||
use view::{View, ViewWrapper};
|
use view::{View, ViewWrapper};
|
||||||
|
|
||||||
/// A simple wrapper view that catches some ignored event from its child.
|
/// A simple wrapper view that catches some ignored event from its child.
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
use XY;
|
|
||||||
use With;
|
|
||||||
use direction;
|
|
||||||
use view::View;
|
|
||||||
use view::{Selector, SizeCache};
|
|
||||||
use vec::Vec2;
|
|
||||||
use Printer;
|
use Printer;
|
||||||
|
use With;
|
||||||
|
use XY;
|
||||||
|
use direction;
|
||||||
use event::{Event, EventResult, Key};
|
use event::{Event, EventResult, Key};
|
||||||
|
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::cmp::min;
|
use std::cmp::min;
|
||||||
|
use vec::Vec2;
|
||||||
|
use view::{Selector, SizeCache};
|
||||||
|
use view::View;
|
||||||
|
|
||||||
/// Arranges its children linearly according to its orientation.
|
/// Arranges its children linearly according to its orientation.
|
||||||
pub struct LinearLayout {
|
pub struct LinearLayout {
|
||||||
@ -120,11 +120,7 @@ impl LinearLayout {
|
|||||||
|
|
||||||
match source {
|
match source {
|
||||||
direction::Relative::Front => {
|
direction::Relative::Front => {
|
||||||
let start = if from_focus {
|
let start = if from_focus { self.focus } else { 0 };
|
||||||
self.focus
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
};
|
|
||||||
|
|
||||||
Box::new(self.children.iter_mut().enumerate().skip(start))
|
Box::new(self.children.iter_mut().enumerate().skip(start))
|
||||||
}
|
}
|
||||||
@ -263,11 +259,7 @@ impl View for LinearLayout {
|
|||||||
let mut overweight: Vec<(usize, usize)> = sizes.iter()
|
let mut overweight: Vec<(usize, usize)> = sizes.iter()
|
||||||
.map(|v| self.orientation.get(v))
|
.map(|v| self.orientation.get(v))
|
||||||
.zip(min_sizes.iter().map(|v| self.orientation.get(v)))
|
.zip(min_sizes.iter().map(|v| self.orientation.get(v)))
|
||||||
.map(|(a, b)| if a > b {
|
.map(|(a, b)| if a > b { a - b } else { 0 })
|
||||||
a - b
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
})
|
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.collect();
|
.collect();
|
||||||
// println_stderr!("Overweight: {:?}", overweight);
|
// println_stderr!("Overweight: {:?}", overweight);
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
use Printer;
|
use Printer;
|
||||||
use With;
|
use With;
|
||||||
use vec::Vec2;
|
|
||||||
use view::View;
|
|
||||||
use view::Selector;
|
|
||||||
use direction;
|
use direction;
|
||||||
use view::ScrollBase;
|
|
||||||
use event::{Event, EventResult, Key};
|
use event::{Event, EventResult, Key};
|
||||||
|
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
|
use vec::Vec2;
|
||||||
|
use view::ScrollBase;
|
||||||
|
use view::Selector;
|
||||||
|
use view::View;
|
||||||
|
|
||||||
enum Child {
|
enum Child {
|
||||||
Row(String, Box<View>),
|
Row(String, Box<View>),
|
||||||
@ -84,11 +84,7 @@ impl ListView {
|
|||||||
|
|
||||||
match source {
|
match source {
|
||||||
direction::Relative::Front => {
|
direction::Relative::Front => {
|
||||||
let start = if from_focus {
|
let start = if from_focus { self.focus } else { 0 };
|
||||||
self.focus
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
};
|
|
||||||
|
|
||||||
Box::new(self.children.iter_mut().enumerate().skip(start))
|
Box::new(self.children.iter_mut().enumerate().skip(start))
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,18 @@
|
|||||||
use std::rc::Rc;
|
|
||||||
use std::cmp::min;
|
|
||||||
|
|
||||||
use unicode_width::UnicodeWidthStr;
|
|
||||||
|
|
||||||
use Cursive;
|
use Cursive;
|
||||||
use With;
|
|
||||||
use menu::{MenuItem, MenuTree};
|
|
||||||
use Printer;
|
use Printer;
|
||||||
|
use With;
|
||||||
|
use align::Align;
|
||||||
|
use event::{Callback, Event, EventResult, Key};
|
||||||
|
use menu::{MenuItem, MenuTree};
|
||||||
|
use std::cmp::min;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
use vec::Vec2;
|
||||||
use view::{Position, ScrollBase, View};
|
use view::{Position, ScrollBase, View};
|
||||||
use views::KeyEventView;
|
use views::KeyEventView;
|
||||||
use align::Align;
|
|
||||||
use vec::Vec2;
|
|
||||||
use event::{Callback, Event, EventResult, Key};
|
|
||||||
|
|
||||||
/// Popup that shows a list of items.
|
/// Popup that shows a list of items.
|
||||||
pub struct MenuPopup {
|
pub struct MenuPopup {
|
||||||
@ -205,11 +206,7 @@ impl View for MenuPopup {
|
|||||||
|
|
||||||
let scrolling = req.y < h;
|
let scrolling = req.y < h;
|
||||||
|
|
||||||
let w = if scrolling {
|
let w = if scrolling { w + 1 } else { w };
|
||||||
w + 1
|
|
||||||
} else {
|
|
||||||
w
|
|
||||||
};
|
|
||||||
|
|
||||||
Vec2::new(w, h)
|
Vec2::new(w, h)
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
use Cursive;
|
use Cursive;
|
||||||
use view::{Position, View};
|
|
||||||
use vec::Vec2;
|
|
||||||
use direction;
|
|
||||||
use menu::MenuTree;
|
|
||||||
use backend::Backend;
|
|
||||||
use views::{KeyEventView, MenuPopup};
|
|
||||||
use theme::ColorStyle;
|
|
||||||
use Printer;
|
use Printer;
|
||||||
|
use backend::Backend;
|
||||||
|
use direction;
|
||||||
use event::*;
|
use event::*;
|
||||||
|
use menu::MenuTree;
|
||||||
|
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
use theme::ColorStyle;
|
||||||
|
|
||||||
use unicode_width::UnicodeWidthStr;
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
use vec::Vec2;
|
||||||
|
use view::{Position, View};
|
||||||
|
use views::{KeyEventView, MenuPopup};
|
||||||
|
|
||||||
/// Current state of the menubar
|
/// Current state of the menubar
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Debug)]
|
||||||
@ -169,11 +169,7 @@ impl View for Menubar {
|
|||||||
.iter()
|
.iter()
|
||||||
.map(|&(ref title, _)| title.width() + 2)
|
.map(|&(ref title, _)| title.width() + 2)
|
||||||
.fold(0, |a, b| a + b),
|
.fold(0, |a, b| a + b),
|
||||||
if self.autohide {
|
if self.autohide { 1 } else { 0 });
|
||||||
1
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
});
|
|
||||||
// Since the closure will be called multiple times,
|
// Since the closure will be called multiple times,
|
||||||
// we also need a new Rc on every call.
|
// we also need a new Rc on every call.
|
||||||
return EventResult::with_cb(move |s| {
|
return EventResult::with_cb(move |s| {
|
||||||
|
@ -58,25 +58,25 @@ mod text_area;
|
|||||||
mod text_view;
|
mod text_view;
|
||||||
mod tracked_view;
|
mod tracked_view;
|
||||||
|
|
||||||
pub use self::id_view::IdView;
|
|
||||||
pub use self::box_view::BoxView;
|
pub use self::box_view::BoxView;
|
||||||
pub use self::button::Button;
|
pub use self::button::Button;
|
||||||
pub use self::checkbox::Checkbox;
|
pub use self::checkbox::Checkbox;
|
||||||
pub use self::dialog::Dialog;
|
pub use self::dialog::Dialog;
|
||||||
pub use self::dummy::DummyView;
|
pub use self::dummy::DummyView;
|
||||||
pub use self::edit_view::EditView;
|
pub use self::edit_view::EditView;
|
||||||
|
pub use self::id_view::IdView;
|
||||||
pub use self::key_event_view::KeyEventView;
|
pub use self::key_event_view::KeyEventView;
|
||||||
pub use self::linear_layout::LinearLayout;
|
pub use self::linear_layout::LinearLayout;
|
||||||
pub use self::list_view::ListView;
|
pub use self::list_view::ListView;
|
||||||
pub use self::menubar::Menubar;
|
|
||||||
pub use self::menu_popup::MenuPopup;
|
pub use self::menu_popup::MenuPopup;
|
||||||
|
pub use self::menubar::Menubar;
|
||||||
pub use self::panel::Panel;
|
pub use self::panel::Panel;
|
||||||
pub use self::progress_bar::{Counter, ProgressBar};
|
pub use self::progress_bar::{Counter, ProgressBar};
|
||||||
pub use self::radio::{RadioGroup, RadioButton};
|
pub use self::radio::{RadioGroup, RadioButton};
|
||||||
pub use self::select_view::SelectView;
|
pub use self::select_view::SelectView;
|
||||||
pub use self::slider_view::SliderView;
|
|
||||||
pub use self::shadow_view::ShadowView;
|
pub use self::shadow_view::ShadowView;
|
||||||
pub use self::sized_view::SizedView;
|
pub use self::sized_view::SizedView;
|
||||||
|
pub use self::slider_view::SliderView;
|
||||||
pub use self::stack_view::StackView;
|
pub use self::stack_view::StackView;
|
||||||
pub use self::text_area::TextArea;
|
pub use self::text_area::TextArea;
|
||||||
pub use self::text_view::TextView;
|
pub use self::text_view::TextView;
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use std::thread;
|
|
||||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
|
||||||
use std::cmp;
|
|
||||||
|
|
||||||
use {Cursive, Printer};
|
use {Cursive, Printer};
|
||||||
use align::HAlign;
|
use align::HAlign;
|
||||||
|
use std::cmp;
|
||||||
|
use std::sync::Arc;
|
||||||
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
|
|
||||||
|
use std::thread;
|
||||||
use theme::{ColorStyle, Effect};
|
use theme::{ColorStyle, Effect};
|
||||||
use view::View;
|
use view::View;
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
use {Printer, With};
|
use {Printer, With};
|
||||||
use vec::Vec2;
|
|
||||||
use view::View;
|
|
||||||
use theme::ColorStyle;
|
|
||||||
use event::{Event, EventResult, Key};
|
|
||||||
use direction::Direction;
|
use direction::Direction;
|
||||||
|
use event::{Event, EventResult, Key};
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
use theme::ColorStyle;
|
||||||
|
use vec::Vec2;
|
||||||
|
use view::View;
|
||||||
|
|
||||||
struct SharedState<T> {
|
struct SharedState<T> {
|
||||||
selection: usize,
|
selection: usize,
|
||||||
@ -98,7 +98,8 @@ pub struct RadioButton<T> {
|
|||||||
impl<T> RadioButton<T> {
|
impl<T> RadioButton<T> {
|
||||||
impl_enabled!(self.enabled);
|
impl_enabled!(self.enabled);
|
||||||
|
|
||||||
fn new(state: Rc<RefCell<SharedState<T>>>, id: usize, label: String) -> Self {
|
fn new(state: Rc<RefCell<SharedState<T>>>, id: usize, label: String)
|
||||||
|
-> Self {
|
||||||
RadioButton {
|
RadioButton {
|
||||||
state: state,
|
state: state,
|
||||||
id: id,
|
id: id,
|
||||||
|
@ -1,21 +1,22 @@
|
|||||||
use std::cmp::min;
|
|
||||||
use std::rc::Rc;
|
|
||||||
use std::cell::Cell;
|
|
||||||
use std::borrow::Borrow;
|
|
||||||
|
|
||||||
use Cursive;
|
use Cursive;
|
||||||
use With;
|
|
||||||
use menu::MenuTree;
|
|
||||||
use direction::Direction;
|
|
||||||
use view::{Position, ScrollBase, View};
|
|
||||||
use views::MenuPopup;
|
|
||||||
use align::{Align, HAlign, VAlign};
|
|
||||||
use event::{Callback, Event, EventResult, Key};
|
|
||||||
use theme::ColorStyle;
|
|
||||||
use vec::Vec2;
|
|
||||||
use Printer;
|
use Printer;
|
||||||
|
use With;
|
||||||
|
use align::{Align, HAlign, VAlign};
|
||||||
|
use direction::Direction;
|
||||||
|
use event::{Callback, Event, EventResult, Key};
|
||||||
|
use menu::MenuTree;
|
||||||
|
use std::borrow::Borrow;
|
||||||
|
use std::cell::Cell;
|
||||||
|
use std::cmp::min;
|
||||||
|
use std::rc::Rc;
|
||||||
|
use theme::ColorStyle;
|
||||||
|
|
||||||
use unicode_width::UnicodeWidthStr;
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
use vec::Vec2;
|
||||||
|
use view::{Position, ScrollBase, View};
|
||||||
|
use views::MenuPopup;
|
||||||
|
|
||||||
/// View to select an item among a list.
|
/// View to select an item among a list.
|
||||||
///
|
///
|
||||||
@ -394,11 +395,7 @@ impl<T: 'static> View for SelectView<T> {
|
|||||||
let scrolling = req.y < h;
|
let scrolling = req.y < h;
|
||||||
|
|
||||||
// Add 2 spaces for the scrollbar if we need
|
// Add 2 spaces for the scrollbar if we need
|
||||||
let w = if scrolling {
|
let w = if scrolling { w + 2 } else { w };
|
||||||
w + 2
|
|
||||||
} else {
|
|
||||||
w
|
|
||||||
};
|
|
||||||
|
|
||||||
Vec2::new(w, h)
|
Vec2::new(w, h)
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use view::{View, ViewWrapper};
|
|
||||||
use Printer;
|
use Printer;
|
||||||
use vec::Vec2;
|
|
||||||
use theme::ColorStyle;
|
use theme::ColorStyle;
|
||||||
|
use vec::Vec2;
|
||||||
|
use view::{View, ViewWrapper};
|
||||||
|
|
||||||
/// Wrapper view that adds a shadow.
|
/// Wrapper view that adds a shadow.
|
||||||
///
|
///
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use view::View;
|
|
||||||
use vec::Vec2;
|
use vec::Vec2;
|
||||||
|
use view::View;
|
||||||
use view::ViewWrapper;
|
use view::ViewWrapper;
|
||||||
|
|
||||||
/// Wrapper around a view that remembers its size.
|
/// Wrapper around a view that remembers its size.
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
use std::rc::Rc;
|
use {Cursive, Printer};
|
||||||
|
|
||||||
use With;
|
use With;
|
||||||
use {Cursive, Printer};
|
use direction::{Direction, Orientation};
|
||||||
use theme::ColorStyle;
|
|
||||||
use event::{Callback, Event, EventResult, Key};
|
use event::{Callback, Event, EventResult, Key};
|
||||||
|
use std::rc::Rc;
|
||||||
|
use theme::ColorStyle;
|
||||||
use vec::Vec2;
|
use vec::Vec2;
|
||||||
use view::View;
|
use view::View;
|
||||||
use direction::{Direction, Orientation};
|
|
||||||
|
|
||||||
/// A horizontal or vertical slider.
|
/// A horizontal or vertical slider.
|
||||||
pub struct SliderView {
|
pub struct SliderView {
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
use std::any::Any;
|
use Printer;
|
||||||
|
use backend::Backend;
|
||||||
|
|
||||||
use direction::Direction;
|
use direction::Direction;
|
||||||
use backend::Backend;
|
use event::{Event, EventResult};
|
||||||
|
use std::any::Any;
|
||||||
|
use theme::ColorStyle;
|
||||||
use vec::Vec2;
|
use vec::Vec2;
|
||||||
use view::{Offset, Position, Selector, View};
|
use view::{Offset, Position, Selector, View};
|
||||||
use views::ShadowView;
|
use views::ShadowView;
|
||||||
use event::{Event, EventResult};
|
|
||||||
use Printer;
|
|
||||||
use theme::ColorStyle;
|
|
||||||
|
|
||||||
/// Simple stack of views.
|
/// Simple stack of views.
|
||||||
/// Only the top-most view is active and can receive input.
|
/// Only the top-most view is active and can receive input.
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
use unicode_segmentation::UnicodeSegmentation;
|
|
||||||
use unicode_width::UnicodeWidthStr;
|
|
||||||
use odds::vec::VecExt;
|
|
||||||
|
|
||||||
use {Printer, With, XY};
|
use {Printer, With, XY};
|
||||||
use direction::Direction;
|
use direction::Direction;
|
||||||
use vec::Vec2;
|
|
||||||
use event::{Event, EventResult, Key};
|
use event::{Event, EventResult, Key};
|
||||||
use utils::{LinesIterator, Row, prefix_length};
|
use odds::vec::VecExt;
|
||||||
use view::{ScrollBase, SizeCache, View};
|
|
||||||
use theme::{ColorStyle, Effect};
|
use theme::{ColorStyle, Effect};
|
||||||
|
use unicode_segmentation::UnicodeSegmentation;
|
||||||
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
use utils::{LinesIterator, Row, prefix_length};
|
||||||
|
use vec::Vec2;
|
||||||
|
use view::{ScrollBase, SizeCache, View};
|
||||||
|
|
||||||
/// Multi-lines text editor.
|
/// Multi-lines text editor.
|
||||||
///
|
///
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
use XY;
|
|
||||||
use With;
|
|
||||||
use direction::Direction;
|
|
||||||
use vec::Vec2;
|
|
||||||
use view::{SizeCache, View};
|
|
||||||
use Printer;
|
use Printer;
|
||||||
|
use With;
|
||||||
|
use XY;
|
||||||
use align::*;
|
use align::*;
|
||||||
|
use direction::Direction;
|
||||||
use event::*;
|
use event::*;
|
||||||
use view::ScrollBase;
|
|
||||||
|
|
||||||
use utils::{LinesIterator, Row};
|
|
||||||
|
|
||||||
use unicode_width::UnicodeWidthStr;
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
|
||||||
|
use utils::{LinesIterator, Row};
|
||||||
|
use vec::Vec2;
|
||||||
|
use view::{SizeCache, View};
|
||||||
|
use view::ScrollBase;
|
||||||
|
|
||||||
|
|
||||||
/// A simple view showing a fixed text
|
/// A simple view showing a fixed text
|
||||||
pub struct TextView {
|
pub struct TextView {
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
|
use Printer;
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
use vec::Vec2;
|
||||||
|
|
||||||
use view::{View, ViewWrapper};
|
use view::{View, ViewWrapper};
|
||||||
use views::IdView;
|
use views::IdView;
|
||||||
use Printer;
|
|
||||||
use vec::Vec2;
|
|
||||||
|
|
||||||
/// Wrapper around a view that remembers its position.
|
/// Wrapper around a view that remembers its position.
|
||||||
pub struct TrackedView<T: View> {
|
pub struct TrackedView<T: View> {
|
||||||
|
Loading…
Reference in New Issue
Block a user