mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Rustfmt
This commit is contained in:
parent
017e100b1b
commit
8acc08f340
@ -1,9 +1,9 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::{Cursive, Printer};
|
||||
use cursive::theme::{Color, ColorStyle};
|
||||
use cursive::view::Boxable;
|
||||
use cursive::views::Canvas;
|
||||
use cursive::{Cursive, Printer};
|
||||
|
||||
// This example will draw a colored square with a gradient.
|
||||
//
|
||||
|
@ -1,7 +1,7 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::Cursive;
|
||||
use cursive::views::{Dialog, TextView};
|
||||
use cursive::Cursive;
|
||||
|
||||
fn main() {
|
||||
// Creates the cursive root - required for every application.
|
||||
|
@ -1,8 +1,8 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::Cursive;
|
||||
use cursive::traits::*;
|
||||
use cursive::views::{Dialog, EditView, TextView};
|
||||
use cursive::Cursive;
|
||||
|
||||
fn main() {
|
||||
let mut siv = Cursive::default();
|
||||
|
@ -1,7 +1,7 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::Cursive;
|
||||
use cursive::views::TextView;
|
||||
use cursive::Cursive;
|
||||
|
||||
fn main() {
|
||||
let mut siv = Cursive::default();
|
||||
|
@ -1,8 +1,8 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::{Cursive, Printer};
|
||||
use cursive::event::{Event, EventResult};
|
||||
use cursive::traits::*;
|
||||
use cursive::{Cursive, Printer};
|
||||
|
||||
// This example define a custom view that prints any event it receives.
|
||||
// This is a handy way to check the input received by cursive.
|
||||
|
@ -1,9 +1,9 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::Cursive;
|
||||
use cursive::align::HAlign;
|
||||
use cursive::traits::*;
|
||||
use cursive::views::{Dialog, DummyView, LinearLayout, TextView};
|
||||
use cursive::Cursive;
|
||||
|
||||
// This example uses a LinearLayout to stick multiple views next to each other.
|
||||
|
||||
|
@ -1,9 +1,10 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::Cursive;
|
||||
use cursive::traits::*;
|
||||
use cursive::views::{Checkbox, Dialog, EditView, LinearLayout, ListView,
|
||||
SelectView, TextView};
|
||||
use cursive::views::{
|
||||
Checkbox, Dialog, EditView, LinearLayout, ListView, SelectView, TextView,
|
||||
};
|
||||
use cursive::Cursive;
|
||||
|
||||
// This example uses a ListView.
|
||||
//
|
||||
|
@ -1,8 +1,8 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::{Cursive, Printer};
|
||||
use cursive::traits::*;
|
||||
use cursive::vec::Vec2;
|
||||
use cursive::{Cursive, Printer};
|
||||
use std::collections::VecDeque;
|
||||
use std::sync::mpsc;
|
||||
use std::thread;
|
||||
|
@ -1,12 +1,12 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::Cursive;
|
||||
use cursive::theme::BaseColor;
|
||||
use cursive::theme::Color;
|
||||
use cursive::theme::Effect;
|
||||
use cursive::theme::Style;
|
||||
use cursive::utils::markup::StyledString;
|
||||
use cursive::views::{Dialog, TextView};
|
||||
use cursive::Cursive;
|
||||
|
||||
fn main() {
|
||||
let mut siv = Cursive::default();
|
||||
|
@ -1,10 +1,10 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::Cursive;
|
||||
use cursive::event::Key;
|
||||
use cursive::menu::MenuTree;
|
||||
use cursive::traits::*;
|
||||
use cursive::views::Dialog;
|
||||
use cursive::Cursive;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
// This examples shows how to configure and use a menubar at the top of the
|
||||
|
@ -3,13 +3,13 @@ extern crate rand;
|
||||
|
||||
mod game;
|
||||
|
||||
use cursive::Cursive;
|
||||
use cursive::Printer;
|
||||
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;
|
||||
|
||||
fn main() {
|
||||
let mut siv = Cursive::default();
|
||||
|
@ -1,9 +1,9 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::Cursive;
|
||||
use cursive::traits::*;
|
||||
use cursive::view::{Offset, Position};
|
||||
use cursive::views::{Dialog, OnEventView, TextView};
|
||||
use cursive::Cursive;
|
||||
|
||||
// This example modifies a view after creation.
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::Cursive;
|
||||
use cursive::view::Position;
|
||||
use cursive::views::LayerPosition;
|
||||
use cursive::views::TextView;
|
||||
use cursive::Cursive;
|
||||
|
||||
/// Moves top layer by the specified amount
|
||||
fn move_top(c: &mut Cursive, x_in: isize, y_in: isize) {
|
||||
|
@ -1,10 +1,10 @@
|
||||
extern crate cursive;
|
||||
extern crate rand;
|
||||
|
||||
use cursive::Cursive;
|
||||
use cursive::traits::*;
|
||||
use cursive::views::{Button, Dialog, LinearLayout, ProgressBar, TextView};
|
||||
use cursive::utils::Counter;
|
||||
use cursive::views::{Button, Dialog, LinearLayout, ProgressBar, TextView};
|
||||
use cursive::Cursive;
|
||||
use rand::Rng;
|
||||
use std::cmp::min;
|
||||
use std::thread;
|
||||
|
@ -1,7 +1,7 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::Cursive;
|
||||
use cursive::views::{Dialog, DummyView, LinearLayout, RadioGroup};
|
||||
use cursive::Cursive;
|
||||
|
||||
// This example uses radio buttons.
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::Cursive;
|
||||
use cursive::view::{Boxable, Identifiable};
|
||||
use cursive::views::{Dialog, EditView, LinearLayout, TextView};
|
||||
use cursive::Cursive;
|
||||
|
||||
// This example shows a way to access multiple views at the same time.
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::Cursive;
|
||||
use cursive::align::HAlign;
|
||||
use cursive::event::EventResult;
|
||||
use cursive::traits::*;
|
||||
use cursive::views::{Dialog, OnEventView, SelectView, TextView};
|
||||
use cursive::Cursive;
|
||||
|
||||
// We'll use a SelectView here.
|
||||
//
|
||||
|
@ -1,8 +1,8 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::Cursive;
|
||||
use cursive::traits::*;
|
||||
use cursive::views::{Dialog, SliderView};
|
||||
use cursive::Cursive;
|
||||
|
||||
fn main() {
|
||||
let mut siv = Cursive::default();
|
||||
|
@ -1,8 +1,8 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::Cursive;
|
||||
use cursive::theme::{Color, PaletteColor, Theme};
|
||||
use cursive::views::TextView;
|
||||
use cursive::Cursive;
|
||||
|
||||
// This example sets the background color to the terminal default.
|
||||
//
|
||||
|
@ -1,9 +1,9 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::Cursive;
|
||||
use cursive::event::{Event, Key};
|
||||
use cursive::traits::*;
|
||||
use cursive::views::{Dialog, EditView, OnEventView, TextArea};
|
||||
use cursive::Cursive;
|
||||
|
||||
fn main() {
|
||||
let mut siv = Cursive::default();
|
||||
@ -35,10 +35,10 @@ fn main() {
|
||||
.min_width(10),
|
||||
)
|
||||
.button("Ok", |s| {
|
||||
let text = s.call_on_id(
|
||||
"edit",
|
||||
|view: &mut EditView| view.get_content(),
|
||||
).unwrap();
|
||||
let text =
|
||||
s.call_on_id("edit", |view: &mut EditView| {
|
||||
view.get_content()
|
||||
}).unwrap();
|
||||
find(s, &text);
|
||||
})
|
||||
.dismiss_button("Cancel"),
|
||||
|
@ -1,7 +1,7 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::Cursive;
|
||||
use cursive::views::{Dialog, TextView};
|
||||
use cursive::Cursive;
|
||||
|
||||
fn main() {
|
||||
let mut siv = Cursive::default();
|
||||
|
@ -1,8 +1,8 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::Cursive;
|
||||
use cursive::theme::{BaseColor, BorderStyle, Color, ColorStyle};
|
||||
use cursive::views::{Dialog, EditView, LinearLayout, TextView};
|
||||
use cursive::Cursive;
|
||||
|
||||
fn main() {
|
||||
let mut siv = Cursive::default();
|
||||
|
@ -3,10 +3,10 @@ extern crate pretty_bytes;
|
||||
|
||||
use std::io;
|
||||
|
||||
use cursive::Cursive;
|
||||
use cursive::traits::{Boxable, With};
|
||||
use cursive::utils;
|
||||
use cursive::views::{Canvas, Dialog, LinearLayout, ProgressBar};
|
||||
use cursive::Cursive;
|
||||
use pretty_bytes::converter::convert;
|
||||
use std::thread;
|
||||
use std::time;
|
||||
@ -31,10 +31,7 @@ fn main() {
|
||||
let meta = std::fs::metadata(&source).unwrap();
|
||||
// If possible, read the file size to have a progress bar.
|
||||
let len = meta.len();
|
||||
(
|
||||
Some(source),
|
||||
if len > 0 { Some(len) } else { None },
|
||||
)
|
||||
(Some(source), if len > 0 { Some(len) } else { None })
|
||||
}
|
||||
None => (None, None),
|
||||
};
|
||||
@ -68,9 +65,7 @@ fn main() {
|
||||
}
|
||||
|
||||
// When we're done, shut down the application
|
||||
cb_sink
|
||||
.send(Box::new(|s: &mut Cursive| s.quit()))
|
||||
.unwrap();
|
||||
cb_sink.send(Box::new(|s: &mut Cursive| s.quit())).unwrap();
|
||||
});
|
||||
|
||||
// Add a single view: progress status
|
||||
|
@ -5,10 +5,11 @@
|
||||
|
||||
extern crate bear_lib_terminal;
|
||||
|
||||
use self::bear_lib_terminal::Color as BltColor;
|
||||
use self::bear_lib_terminal::geometry::Size;
|
||||
use self::bear_lib_terminal::terminal::{self, state, Event as BltEvent,
|
||||
KeyCode};
|
||||
use self::bear_lib_terminal::terminal::{
|
||||
self, state, Event as BltEvent, KeyCode,
|
||||
};
|
||||
use self::bear_lib_terminal::Color as BltColor;
|
||||
use backend;
|
||||
use event::{Event, Key, MouseButton, MouseEvent};
|
||||
use std::collections::HashSet;
|
||||
@ -49,7 +50,7 @@ impl Backend {
|
||||
}
|
||||
|
||||
fn blt_keycode_to_ev(
|
||||
&mut self, kc: KeyCode, shift: bool, ctrl: bool
|
||||
&mut self, kc: KeyCode, shift: bool, ctrl: bool,
|
||||
) -> Event {
|
||||
match kc {
|
||||
KeyCode::F1
|
||||
@ -179,12 +180,12 @@ impl backend::Backend for Backend {
|
||||
fn set_color(&self, color: ColorPair) -> ColorPair {
|
||||
let current = ColorPair {
|
||||
front: blt_colour_to_colour(state::foreground()),
|
||||
back: blt_colour_to_colour(state::background())
|
||||
back: blt_colour_to_colour(state::background()),
|
||||
};
|
||||
|
||||
|
||||
let fg = colour_to_blt_colour(color.front, ColorRole::Foreground);
|
||||
let bg = colour_to_blt_colour(color.back, ColorRole::Background);
|
||||
|
||||
|
||||
terminal::set_colors(fg, bg);
|
||||
|
||||
current
|
||||
@ -196,14 +197,14 @@ impl backend::Backend for Backend {
|
||||
Effect::Bold
|
||||
| Effect::Italic
|
||||
| Effect::Underline
|
||||
| Effect::Simple => {},
|
||||
| Effect::Simple => {}
|
||||
// TODO: how to do this correctly?`
|
||||
// BLT itself doesn't do this kind of thing,
|
||||
// we'd need the colours in our position,
|
||||
// but `f()` can do whatever
|
||||
Effect::Reverse => terminal::set_colors(
|
||||
state::background(), state::foreground()
|
||||
),
|
||||
Effect::Reverse => {
|
||||
terminal::set_colors(state::background(), state::foreground())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -213,11 +214,11 @@ impl backend::Backend for Backend {
|
||||
Effect::Bold
|
||||
| Effect::Italic
|
||||
| Effect::Underline
|
||||
| Effect::Simple => {},
|
||||
| Effect::Simple => {}
|
||||
// The process of reversing is the same as unreversing
|
||||
Effect::Reverse => terminal::set_colors(
|
||||
state::background(), state::foreground()
|
||||
),
|
||||
Effect::Reverse => {
|
||||
terminal::set_colors(state::background(), state::foreground())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ where
|
||||
|
||||
fn find_closest_pair(pair: &ColorPair, max_colors: i16) -> (i16, i16) {
|
||||
(
|
||||
find_closest(&pair.front,max_colors),
|
||||
find_closest(&pair.front, max_colors),
|
||||
find_closest(&pair.back, max_colors),
|
||||
)
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
extern crate ncurses;
|
||||
|
||||
use self::ncurses::mmask_t;
|
||||
use self::super::split_i32;
|
||||
use self::ncurses::mmask_t;
|
||||
use backend;
|
||||
use event::{Event, Key, MouseButton, MouseEvent};
|
||||
use libc;
|
||||
@ -10,7 +10,7 @@ use std::collections::HashMap;
|
||||
use std::ffi::CString;
|
||||
use std::fs::File;
|
||||
use std::io;
|
||||
use std::io::{Write};
|
||||
use std::io::Write;
|
||||
use theme::{Color, ColorPair, Effect};
|
||||
use utf8;
|
||||
use vec::Vec2;
|
||||
@ -95,10 +95,9 @@ impl Backend {
|
||||
Box::new(c)
|
||||
}
|
||||
|
||||
|
||||
/// Save a new color pair.
|
||||
fn insert_color(
|
||||
&self, pairs: &mut HashMap<(i16, i16), i16>, (front, back): (i16, i16)
|
||||
&self, pairs: &mut HashMap<(i16, i16), i16>, (front, back): (i16, i16),
|
||||
) -> i16 {
|
||||
let n = 1 + pairs.len() as i16;
|
||||
|
||||
@ -157,7 +156,8 @@ impl Backend {
|
||||
let _alt = (mevent.bstate & ncurses::BUTTON_ALT as mmask_t) != 0;
|
||||
let _ctrl = (mevent.bstate & ncurses::BUTTON_CTRL as mmask_t) != 0;
|
||||
|
||||
mevent.bstate &= !(ncurses::BUTTON_SHIFT | ncurses::BUTTON_ALT
|
||||
mevent.bstate &= !(ncurses::BUTTON_SHIFT
|
||||
| ncurses::BUTTON_ALT
|
||||
| ncurses::BUTTON_CTRL)
|
||||
as mmask_t;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
extern crate pancurses;
|
||||
|
||||
use self::pancurses::mmask_t;
|
||||
use self::super::split_i32;
|
||||
use self::pancurses::mmask_t;
|
||||
use backend;
|
||||
use event::{Event, Key, MouseButton, MouseEvent};
|
||||
use std::cell::{Cell, RefCell};
|
||||
@ -65,9 +65,7 @@ impl Backend {
|
||||
|
||||
/// Save a new color pair.
|
||||
fn insert_color(
|
||||
&self,
|
||||
pairs: &mut HashMap<(i16,i16), i32>,
|
||||
(front, back): (i16, i16),
|
||||
&self, pairs: &mut HashMap<(i16, i16), i32>, (front, back): (i16, i16),
|
||||
) -> i32 {
|
||||
let n = 1 + pairs.len() as i32;
|
||||
|
||||
@ -119,7 +117,8 @@ impl Backend {
|
||||
let _alt = (mevent.bstate & pancurses::BUTTON_ALT as mmask_t) != 0;
|
||||
let _ctrl = (mevent.bstate & pancurses::BUTTON_CTRL as mmask_t) != 0;
|
||||
|
||||
mevent.bstate &= !(pancurses::BUTTON_SHIFT | pancurses::BUTTON_ALT
|
||||
mevent.bstate &= !(pancurses::BUTTON_SHIFT
|
||||
| pancurses::BUTTON_ALT
|
||||
| pancurses::BUTTON_CTRL) as mmask_t;
|
||||
|
||||
let make_event = |event| Event::Mouse {
|
||||
|
@ -1,7 +1,7 @@
|
||||
//! Dummy backend
|
||||
use backend;
|
||||
use theme;
|
||||
use event;
|
||||
use theme;
|
||||
use vec::Vec2;
|
||||
|
||||
pub struct Backend;
|
||||
|
@ -4,7 +4,7 @@
|
||||
//! backend library, which handles all actual input and output.
|
||||
//!
|
||||
//! This module defines the `Backend` trait, as well as a few implementations
|
||||
//! using some common libraries. Each of those included backends needs a
|
||||
//! using some common libraries. Each of those included backends needs a
|
||||
//! corresonding feature to be enabled.
|
||||
|
||||
use event;
|
||||
@ -14,9 +14,9 @@ use vec::Vec2;
|
||||
|
||||
pub mod dummy;
|
||||
|
||||
pub mod termion;
|
||||
pub mod blt;
|
||||
pub mod curses;
|
||||
pub mod termion;
|
||||
|
||||
/// Trait defining the required methods to be a backend.
|
||||
pub trait Backend {
|
||||
@ -58,7 +58,6 @@ pub trait Backend {
|
||||
/// Enables the given effect.
|
||||
fn set_effect(&self, effect: theme::Effect);
|
||||
|
||||
|
||||
/// Disables the given effect.
|
||||
fn unset_effect(&self, effect: theme::Effect);
|
||||
}
|
||||
|
@ -46,14 +46,27 @@ impl Default for Cursive {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(not(feature = "termion"), not(feature = "pancurses"), feature = "bear-lib-terminal"))]
|
||||
#[cfg(
|
||||
all(
|
||||
not(feature = "termion"),
|
||||
not(feature = "pancurses"),
|
||||
feature = "bear-lib-terminal"
|
||||
)
|
||||
)]
|
||||
impl Default for Cursive {
|
||||
fn default() -> Self {
|
||||
Self::blt()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(not(feature = "termion"), not(feature = "pancurses"), not(feature = "bear-lib-terminal"), feature = "ncurses"))]
|
||||
#[cfg(
|
||||
all(
|
||||
not(feature = "termion"),
|
||||
not(feature = "pancurses"),
|
||||
not(feature = "bear-lib-terminal"),
|
||||
feature = "ncurses"
|
||||
)
|
||||
)]
|
||||
impl Default for Cursive {
|
||||
fn default() -> Self {
|
||||
Self::ncurses()
|
||||
@ -261,7 +274,7 @@ impl Cursive {
|
||||
///
|
||||
/// `filename` must point to a valid toml file.
|
||||
pub fn load_theme_file<P: AsRef<Path>>(
|
||||
&mut self, filename: P
|
||||
&mut self, filename: P,
|
||||
) -> Result<(), theme::Error> {
|
||||
self.set_theme(try!(theme::load_theme_file(filename)));
|
||||
Ok(())
|
||||
@ -366,7 +379,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,
|
||||
@ -532,7 +545,7 @@ impl Cursive {
|
||||
|
||||
/// Convenient stub forwarding layer repositioning.
|
||||
pub fn reposition_layer(
|
||||
&mut self, layer: LayerPosition, position: Position
|
||||
&mut self, layer: LayerPosition, position: Position,
|
||||
) {
|
||||
self.screen_mut().reposition_layer(layer, position);
|
||||
}
|
||||
@ -661,7 +674,8 @@ impl Cursive {
|
||||
event, position, ..
|
||||
} = event
|
||||
{
|
||||
if event.grabs_focus() && !self.menubar.autohide
|
||||
if event.grabs_focus()
|
||||
&& !self.menubar.autohide
|
||||
&& !self.menubar.has_submenu()
|
||||
&& position.y == 0
|
||||
{
|
||||
|
@ -15,8 +15,8 @@
|
||||
//! * Relative direction: front or back.
|
||||
//! Its actual direction depends on the orientation.
|
||||
|
||||
use XY;
|
||||
use vec::Vec2;
|
||||
use XY;
|
||||
|
||||
/// Describes a vertical or horizontal orientation for a view.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
|
@ -13,10 +13,10 @@
|
||||
//! [global callback](../struct.Cursive.html#method.add_global_callback)
|
||||
//! table is checked.
|
||||
|
||||
use Cursive;
|
||||
use std::ops::Deref;
|
||||
use std::rc::Rc;
|
||||
use vec::Vec2;
|
||||
use Cursive;
|
||||
|
||||
/// Callback is a function that can be triggered by an event.
|
||||
/// It has a mutable access to the cursive root.
|
||||
|
14
src/lib.rs
14
src/lib.rs
@ -72,8 +72,8 @@ extern crate log;
|
||||
#[macro_use]
|
||||
extern crate maplit;
|
||||
|
||||
extern crate num;
|
||||
extern crate libc;
|
||||
extern crate num;
|
||||
extern crate owning_ref;
|
||||
extern crate toml;
|
||||
extern crate unicode_segmentation;
|
||||
@ -100,20 +100,20 @@ pub mod event;
|
||||
#[macro_use]
|
||||
pub mod view;
|
||||
|
||||
pub mod views;
|
||||
pub mod vec;
|
||||
pub mod align;
|
||||
pub mod direction;
|
||||
pub mod menu;
|
||||
pub mod rect;
|
||||
pub mod theme;
|
||||
pub mod align;
|
||||
pub mod menu;
|
||||
pub mod direction;
|
||||
pub mod utils;
|
||||
pub mod vec;
|
||||
pub mod views;
|
||||
|
||||
// This probably doesn't need to be public?
|
||||
mod cursive;
|
||||
mod printer;
|
||||
mod xy;
|
||||
mod with;
|
||||
mod xy;
|
||||
|
||||
mod div;
|
||||
mod utf8;
|
||||
|
@ -12,10 +12,10 @@
|
||||
//!
|
||||
//! [menubar]: ../struct.Cursive.html#method.menubar
|
||||
|
||||
use Cursive;
|
||||
use With;
|
||||
use event::Callback;
|
||||
use std::rc::Rc;
|
||||
use Cursive;
|
||||
use With;
|
||||
|
||||
/// Root of a menu tree.
|
||||
#[derive(Default, Clone)]
|
||||
|
@ -33,7 +33,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 Backend,
|
||||
) -> Self {
|
||||
Printer {
|
||||
offset: Vec2::zero(),
|
||||
@ -93,7 +93,7 @@ impl<'a, 'b> Printer<'a, 'b> {
|
||||
|
||||
let p = p + self.offset;
|
||||
for y in 0..len {
|
||||
self.backend.print_at(p + (0,y), c);
|
||||
self.backend.print_at(p + (0, y), c);
|
||||
}
|
||||
}
|
||||
|
||||
@ -178,12 +178,12 @@ impl<'a, 'b> Printer<'a, 'b> {
|
||||
F: FnOnce(&Printer),
|
||||
{
|
||||
let new_printer = Printer {
|
||||
offset: self.offset,
|
||||
size: self.size,
|
||||
focused: self.focused,
|
||||
theme : theme,
|
||||
new: self.new.clone(),
|
||||
backend : self.backend
|
||||
offset: self.offset,
|
||||
size: self.size,
|
||||
focused: self.focused,
|
||||
theme: theme,
|
||||
new: self.new.clone(),
|
||||
backend: self.backend,
|
||||
};
|
||||
f(&new_printer);
|
||||
}
|
||||
@ -222,7 +222,7 @@ impl<'a, 'b> Printer<'a, 'b> {
|
||||
/// printer.print_box((0,0), (6,4), false);
|
||||
/// ```
|
||||
pub fn print_box<T: Into<Vec2>, S: Into<Vec2>>(
|
||||
&self, start: T, size: S, invert: bool
|
||||
&self, start: T, size: S, invert: bool,
|
||||
) {
|
||||
self.new.set(false);
|
||||
|
||||
@ -319,7 +319,7 @@ impl<'a, 'b> Printer<'a, 'b> {
|
||||
|
||||
/// Returns a printer on a subset of this one's area.
|
||||
pub fn sub_printer<S: Into<Vec2>, T: Into<Vec2>>(
|
||||
&self, offset: S, size: T, focused: bool
|
||||
&self, offset: S, size: T, focused: bool,
|
||||
) -> Printer<'a, 'b> {
|
||||
let size = size.into();
|
||||
let offset = offset.into().or_min(self.size);
|
||||
|
@ -80,7 +80,10 @@ impl Rect {
|
||||
}
|
||||
|
||||
/// Adds the given offset to this rectangle.
|
||||
pub fn offset<V>(&mut self, offset: V) where V: Into<Vec2> {
|
||||
pub fn offset<V>(&mut self, offset: V)
|
||||
where
|
||||
V: Into<Vec2>,
|
||||
{
|
||||
let offset = offset.into();
|
||||
self.top_left = self.top_left + offset;
|
||||
self.bottom_right = self.bottom_right + offset;
|
||||
|
@ -156,13 +156,13 @@
|
||||
//! highlight = "#F00"
|
||||
//! highlight_inactive = "#5555FF"
|
||||
//! ```
|
||||
mod style;
|
||||
mod effect;
|
||||
mod border_style;
|
||||
mod color;
|
||||
mod color_pair;
|
||||
mod color_style;
|
||||
mod border_style;
|
||||
mod effect;
|
||||
mod palette;
|
||||
mod style;
|
||||
|
||||
pub use self::border_style::BorderStyle;
|
||||
pub use self::color::{BaseColor, Color};
|
||||
|
@ -82,8 +82,9 @@ impl Palette {
|
||||
for (key, value) in palette.iter() {
|
||||
match *value {
|
||||
PaletteNode::Color(color) => result.set_color(key, color),
|
||||
PaletteNode::Namespace(ref map) =>
|
||||
result.add_namespace(key, map.clone()),
|
||||
PaletteNode::Namespace(ref map) => {
|
||||
result.add_namespace(key, map.clone())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -116,8 +117,11 @@ impl Palette {
|
||||
}
|
||||
|
||||
/// Adds a color namespace to this palette.
|
||||
fn add_namespace(&mut self, key: &str, namespace: HashMap<String, PaletteNode>) {
|
||||
self.custom.insert(key.to_string(), PaletteNode::Namespace(namespace));
|
||||
fn add_namespace(
|
||||
&mut self, key: &str, namespace: HashMap<String, PaletteNode>,
|
||||
) {
|
||||
self.custom
|
||||
.insert(key.to_string(), PaletteNode::Namespace(namespace));
|
||||
}
|
||||
}
|
||||
|
||||
@ -158,14 +162,18 @@ impl Default for Palette {
|
||||
}
|
||||
|
||||
// Iterate over a toml
|
||||
fn iterate_toml<'a>(table: &'a toml::value::Table) -> impl Iterator<Item=(&'a str, PaletteNode)> + 'a {
|
||||
fn iterate_toml<'a>(
|
||||
table: &'a toml::value::Table,
|
||||
) -> impl Iterator<Item = (&'a str, PaletteNode)> + 'a {
|
||||
table.iter().flat_map(|(key, value)| {
|
||||
let node = match value {
|
||||
toml::Value::Table(table) => {
|
||||
// This should define a new namespace
|
||||
// Treat basic colors as simple string.
|
||||
// We'll convert them back in the merge method.
|
||||
let map = iterate_toml(table).map(|(key, value)| (key.to_string(), value)).collect();
|
||||
let map = iterate_toml(table)
|
||||
.map(|(key, value)| (key.to_string(), value))
|
||||
.collect();
|
||||
// Should we only return something if it's non-empty?
|
||||
Some(PaletteNode::Namespace(map))
|
||||
}
|
||||
@ -184,7 +192,10 @@ fn iterate_toml<'a>(table: &'a toml::value::Table) -> impl Iterator<Item=(&'a st
|
||||
}
|
||||
other => {
|
||||
// Other - error?
|
||||
debug!("Found unexpected value in theme: {} = {:?}", key, other);
|
||||
debug!(
|
||||
"Found unexpected value in theme: {} = {:?}",
|
||||
key, other
|
||||
);
|
||||
None
|
||||
}
|
||||
};
|
||||
|
@ -8,7 +8,7 @@
|
||||
//! use cursive::traits::*;
|
||||
//! ```
|
||||
|
||||
#[doc(no_inline)]
|
||||
pub use With;
|
||||
#[doc(no_inline)]
|
||||
pub use view::{Boxable, Finder, Identifiable, View};
|
||||
#[doc(no_inline)]
|
||||
pub use With;
|
||||
|
@ -1,5 +1,5 @@
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::sync::Arc;
|
||||
|
||||
/// Atomic counter used by [`ProgressBar`].
|
||||
///
|
||||
|
@ -70,10 +70,6 @@ impl<'a> Iterator for LinesIterator<'a> {
|
||||
|
||||
let width = row.width;
|
||||
|
||||
Some(Row {
|
||||
start,
|
||||
end,
|
||||
width,
|
||||
})
|
||||
Some(Row { start, end, width })
|
||||
}
|
||||
}
|
||||
|
@ -61,18 +61,19 @@ where
|
||||
// `current_width` is the width of everything
|
||||
// before the next token, including any space.
|
||||
let mut current_width = 0;
|
||||
let sum: usize = iter.take_while(|token| {
|
||||
let width = token.width();
|
||||
if current_width + width > available_width {
|
||||
false
|
||||
} else {
|
||||
// Include the delimiter after this token.
|
||||
current_width += width;
|
||||
current_width += delimiter_width;
|
||||
true
|
||||
}
|
||||
}).map(|token| token.len() + delimiter_len)
|
||||
.sum();
|
||||
let sum: usize =
|
||||
iter.take_while(|token| {
|
||||
let width = token.width();
|
||||
if current_width + width > available_width {
|
||||
false
|
||||
} else {
|
||||
// Include the delimiter after this token.
|
||||
current_width += width;
|
||||
current_width += delimiter_width;
|
||||
true
|
||||
}
|
||||
}).map(|token| token.len() + delimiter_len)
|
||||
.sum();
|
||||
|
||||
// We counted delimiter once too many times,
|
||||
// but only if the iterator was non empty.
|
||||
|
@ -47,10 +47,7 @@ where
|
||||
}
|
||||
|
||||
// Skip empty spans
|
||||
if self.source.spans()[self.current_span]
|
||||
.as_ref()
|
||||
.is_empty()
|
||||
{
|
||||
if self.source.spans()[self.current_span].as_ref().is_empty() {
|
||||
self.current_span += 1;
|
||||
return self.next();
|
||||
}
|
||||
@ -123,13 +120,9 @@ where
|
||||
self.current_span += 1;
|
||||
|
||||
// Skip empty spans
|
||||
while let Some(true) = self.source
|
||||
.spans()
|
||||
.get(self.current_span)
|
||||
.map(|span| {
|
||||
span.as_ref()
|
||||
.resolve(self.source.source())
|
||||
.is_empty()
|
||||
while let Some(true) =
|
||||
self.source.spans().get(self.current_span).map(|span| {
|
||||
span.as_ref().resolve(self.source.source()).is_empty()
|
||||
}) {
|
||||
self.current_span += 1;
|
||||
}
|
||||
|
@ -76,11 +76,8 @@ where
|
||||
self.width
|
||||
};
|
||||
|
||||
let mut chunks = prefix(
|
||||
&mut self.iter,
|
||||
allowed_width,
|
||||
&mut self.chunk_offset,
|
||||
);
|
||||
let mut chunks =
|
||||
prefix(&mut self.iter, allowed_width, &mut self.chunk_offset);
|
||||
|
||||
// println!("Chunks..: {:?}", chunks);
|
||||
|
||||
@ -152,10 +149,7 @@ where
|
||||
|
||||
// We can know text was wrapped if the stop was optional,
|
||||
// and there's more coming.
|
||||
let text_wrap = !chunks
|
||||
.last()
|
||||
.map(|c| c.hard_stop)
|
||||
.unwrap_or(true)
|
||||
let text_wrap = !chunks.last().map(|c| c.hard_stop).unwrap_or(true)
|
||||
&& self.iter.peek().is_some();
|
||||
|
||||
// If we had to break a line in two, then at least pretent we're
|
||||
@ -178,9 +172,6 @@ where
|
||||
|
||||
// TODO: merge consecutive segments of the same span
|
||||
|
||||
Some(Row {
|
||||
segments,
|
||||
width,
|
||||
})
|
||||
Some(Row { segments, width })
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ use std::iter::Peekable;
|
||||
|
||||
/// Concatenates chunks as long as they fit in the given width.
|
||||
pub fn prefix<I>(
|
||||
tokens: &mut Peekable<I>, width: usize, offset: &mut ChunkPart
|
||||
tokens: &mut Peekable<I>, width: usize, offset: &mut ChunkPart,
|
||||
) -> Vec<Chunk>
|
||||
where
|
||||
I: Iterator<Item = Chunk>,
|
||||
|
@ -8,9 +8,7 @@ fn input() -> StyledString {
|
||||
text.append(StyledString::styled("didn't", Effect::Bold));
|
||||
text.append(StyledString::plain(" say "));
|
||||
text.append(StyledString::styled("half", Effect::Italic));
|
||||
text.append(StyledString::plain(
|
||||
" the things people say I did.",
|
||||
));
|
||||
text.append(StyledString::plain(" the things people say I did."));
|
||||
text.append(StyledString::plain("\n"));
|
||||
text.append(StyledString::plain("\n"));
|
||||
text.append(StyledString::plain(" - A. Einstein"));
|
||||
@ -49,25 +47,19 @@ fn test_line_breaks() {
|
||||
attr: &Style::from(Effect::Italic),
|
||||
},
|
||||
],
|
||||
vec![
|
||||
Span {
|
||||
content: "the things people",
|
||||
attr: &Style::none(),
|
||||
},
|
||||
],
|
||||
vec![
|
||||
Span {
|
||||
content: "say I did.",
|
||||
attr: &Style::none(),
|
||||
},
|
||||
],
|
||||
vec![Span {
|
||||
content: "the things people",
|
||||
attr: &Style::none(),
|
||||
}],
|
||||
vec![Span {
|
||||
content: "say I did.",
|
||||
attr: &Style::none(),
|
||||
}],
|
||||
vec![],
|
||||
vec![
|
||||
Span {
|
||||
content: " - A. Einstein",
|
||||
attr: &Style::none(),
|
||||
},
|
||||
],
|
||||
vec![Span {
|
||||
content: " - A. Einstein",
|
||||
attr: &Style::none(),
|
||||
}],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
@ -73,10 +73,12 @@ impl<'a> Iterator for Parser<'a> {
|
||||
self.stack.push(Style::from(Effect::Italic))
|
||||
}
|
||||
Tag::Header(level) => {
|
||||
return Some(self.literal(format!(
|
||||
"{} ",
|
||||
header(level as usize)
|
||||
)))
|
||||
return Some(
|
||||
self.literal(format!(
|
||||
"{} ",
|
||||
header(level as usize)
|
||||
)),
|
||||
)
|
||||
}
|
||||
Tag::Rule => return Some(self.literal("---")),
|
||||
Tag::BlockQuote => return Some(self.literal("> ")),
|
||||
@ -139,10 +141,8 @@ Attention
|
||||
====
|
||||
I *really* love __Cursive__!";
|
||||
let spans = parse_spans(input);
|
||||
let spans: Vec<_> = spans
|
||||
.iter()
|
||||
.map(|span| span.resolve(input))
|
||||
.collect();
|
||||
let spans: Vec<_> =
|
||||
spans.iter().map(|span| span.resolve(input)).collect();
|
||||
|
||||
// println!("{:?}", spans);
|
||||
assert_eq!(
|
||||
|
@ -195,15 +195,13 @@ impl<T> SpannedString<T> {
|
||||
{
|
||||
let source = source.into();
|
||||
|
||||
let spans = vec![
|
||||
IndexedSpan {
|
||||
content: IndexedCow::Borrowed {
|
||||
start: 0,
|
||||
end: source.len(),
|
||||
},
|
||||
attr,
|
||||
let spans = vec![IndexedSpan {
|
||||
content: IndexedCow::Borrowed {
|
||||
start: 0,
|
||||
end: source.len(),
|
||||
},
|
||||
];
|
||||
attr,
|
||||
}];
|
||||
|
||||
Self::with_spans(source, spans)
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
//! Points on the 2D character grid.
|
||||
|
||||
use XY;
|
||||
use num::traits::Zero;
|
||||
use std::cmp::{max, min, Ordering};
|
||||
use std::ops::{Add, Div, Mul, Sub};
|
||||
use XY;
|
||||
|
||||
/// Simple 2D size, in cells.
|
||||
///
|
||||
|
@ -8,7 +8,7 @@ use views::BoxView;
|
||||
pub trait Boxable: View + Sized {
|
||||
/// Wraps `self` in a `BoxView` with the given size constraints.
|
||||
fn boxed(
|
||||
self, width: SizeConstraint, height: SizeConstraint
|
||||
self, width: SizeConstraint, height: SizeConstraint,
|
||||
) -> BoxView<Self> {
|
||||
BoxView::new(width, height, self)
|
||||
}
|
||||
|
@ -46,7 +46,8 @@ impl<T: View> Finder for T {
|
||||
*result_ref =
|
||||
v.downcast_mut::<V>().map(|v| callback(v));
|
||||
} else if v.is::<IdView<V>>() {
|
||||
*result_ref = v.downcast_mut::<IdView<V>>()
|
||||
*result_ref = v
|
||||
.downcast_mut::<IdView<V>>()
|
||||
.and_then(|v| v.with_view_mut(callback));
|
||||
}
|
||||
}
|
||||
|
@ -61,12 +61,7 @@ impl From<(usize, usize, usize, usize)> for Margins {
|
||||
|
||||
impl From<(i32, i32, i32, i32)> for Margins {
|
||||
fn from((left, right, top, bottom): (i32, i32, i32, i32)) -> Margins {
|
||||
(
|
||||
left as usize,
|
||||
right as usize,
|
||||
top as usize,
|
||||
bottom as usize,
|
||||
).into()
|
||||
(left as usize, right as usize, top as usize, bottom as usize).into()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,17 +41,17 @@ mod view_wrapper;
|
||||
// Essentials components
|
||||
mod any;
|
||||
mod finder;
|
||||
mod position;
|
||||
mod margins;
|
||||
mod position;
|
||||
mod size_cache;
|
||||
mod size_constraint;
|
||||
mod view_path;
|
||||
mod view;
|
||||
mod view_path;
|
||||
|
||||
// Helper bases
|
||||
mod scroll;
|
||||
mod identifiable;
|
||||
mod boxable;
|
||||
mod identifiable;
|
||||
mod scroll;
|
||||
|
||||
mod into_boxed_view;
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
use XY;
|
||||
use std::cmp::min;
|
||||
use vec::Vec2;
|
||||
use XY;
|
||||
|
||||
/// Location of the view on screen
|
||||
pub type Position = XY<Offset>;
|
||||
@ -30,7 +30,7 @@ impl Position {
|
||||
/// child with its top-left corner at the returned coordinates will
|
||||
/// position him appropriately.
|
||||
pub fn compute_offset<S, A, P>(
|
||||
&self, size: S, available: A, parent: P
|
||||
&self, size: S, available: A, parent: P,
|
||||
) -> Vec2
|
||||
where
|
||||
S: Into<Vec2>,
|
||||
@ -65,7 +65,7 @@ pub enum Offset {
|
||||
impl Offset {
|
||||
/// Computes a single-dimension offset requred to draw a view.
|
||||
pub fn compute_offset(
|
||||
&self, size: usize, available: usize, parent: usize
|
||||
&self, size: usize, available: usize, parent: usize,
|
||||
) -> usize {
|
||||
if size > available {
|
||||
0
|
||||
|
@ -1,8 +1,8 @@
|
||||
use Printer;
|
||||
use div::div_up;
|
||||
use std::cmp::{max, min};
|
||||
use theme::ColorStyle;
|
||||
use vec::Vec2;
|
||||
use Printer;
|
||||
|
||||
/// Provide scrolling functionalities to a view.
|
||||
///
|
||||
|
@ -18,10 +18,7 @@ pub struct SizeCache {
|
||||
impl SizeCache {
|
||||
/// Creates a new sized cache
|
||||
pub fn new(value: usize, constrained: bool) -> Self {
|
||||
SizeCache {
|
||||
value,
|
||||
constrained,
|
||||
}
|
||||
SizeCache { value, constrained }
|
||||
}
|
||||
|
||||
/// Returns `true` if `self` is still valid for the given `request`.
|
||||
|
@ -1,15 +1,14 @@
|
||||
use Printer;
|
||||
use direction::Direction;
|
||||
use event::{Event, EventResult};
|
||||
use std::any::Any;
|
||||
use vec::Vec2;
|
||||
use view::{AnyView, Selector};
|
||||
use Printer;
|
||||
|
||||
/// Main trait defining a view behaviour.
|
||||
///
|
||||
/// This is what you should implement to define a custom View.
|
||||
pub trait View: Any + AnyView {
|
||||
|
||||
/// Draws the view with the given printer (includes bounds) and focus.
|
||||
///
|
||||
/// This is the only *required* method to implement.
|
||||
@ -63,7 +62,6 @@ pub trait View: Any + AnyView {
|
||||
EventResult::Ignored
|
||||
}
|
||||
|
||||
|
||||
/// Runs a closure on the view identified by the given selector.
|
||||
///
|
||||
/// See [`Finder::call_on`] for a nicer interface, implemented for all
|
||||
|
@ -1,9 +1,9 @@
|
||||
use Printer;
|
||||
use direction::Direction;
|
||||
use event::{Event, EventResult};
|
||||
use std::any::Any;
|
||||
use vec::Vec2;
|
||||
use view::{Selector, View};
|
||||
use Printer;
|
||||
|
||||
/// Generic wrapper around a view.
|
||||
///
|
||||
@ -78,7 +78,7 @@ pub trait ViewWrapper: 'static {
|
||||
|
||||
/// Wraps the `find` method.
|
||||
fn wrap_call_on_any<'a>(
|
||||
&mut self, selector: &Selector, callback: Box<FnMut(&mut Any) + 'a>
|
||||
&mut self, selector: &Selector, callback: Box<FnMut(&mut Any) + 'a>,
|
||||
) {
|
||||
self.with_view_mut(|v| v.call_on_any(selector, callback));
|
||||
}
|
||||
@ -118,7 +118,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 Any) + 'a>,
|
||||
) {
|
||||
self.wrap_call_on_any(selector, callback)
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
use XY;
|
||||
use vec::Vec2;
|
||||
use view::{SizeConstraint, View, ViewWrapper};
|
||||
use XY;
|
||||
|
||||
/// Wrapper around another view, with a controlled size.
|
||||
///
|
||||
@ -39,7 +39,7 @@ impl<T: View> BoxView<T> {
|
||||
///
|
||||
/// `None` values will use the wrapped view's preferences.
|
||||
pub fn new(
|
||||
width: SizeConstraint, height: SizeConstraint, view: T
|
||||
width: SizeConstraint, height: SizeConstraint, view: T,
|
||||
) -> Self {
|
||||
BoxView {
|
||||
size: (width, height).into(),
|
||||
@ -50,7 +50,7 @@ impl<T: View> BoxView<T> {
|
||||
|
||||
/// Sets the size constraints for this view.
|
||||
pub fn set_constraints(
|
||||
&mut self, width: SizeConstraint, height: SizeConstraint
|
||||
&mut self, width: SizeConstraint, height: SizeConstraint,
|
||||
) {
|
||||
self.set_width(width);
|
||||
self.set_height(height);
|
||||
@ -195,7 +195,8 @@ impl<T: View> ViewWrapper for BoxView<T> {
|
||||
let req = self.size.zip_map(req, SizeConstraint::available);
|
||||
let child_size = self.view.required_size(req);
|
||||
|
||||
let result = self.size
|
||||
let result = self
|
||||
.size
|
||||
.zip_map(child_size.zip(req), SizeConstraint::result);
|
||||
|
||||
debug!("{:?}", result);
|
||||
|
@ -1,4 +1,3 @@
|
||||
use {Cursive, Printer, With};
|
||||
use align::HAlign;
|
||||
use direction::Direction;
|
||||
use event::*;
|
||||
@ -6,6 +5,7 @@ use theme::ColorStyle;
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
use vec::Vec2;
|
||||
use view::View;
|
||||
use {Cursive, Printer, With};
|
||||
|
||||
/// Simple text label with a callback when <Enter> is pressed.
|
||||
///
|
||||
|
@ -1,9 +1,9 @@
|
||||
use Printer;
|
||||
use With;
|
||||
use direction::Direction;
|
||||
use event::{Event, EventResult};
|
||||
use vec::Vec2;
|
||||
use view::View;
|
||||
use Printer;
|
||||
use With;
|
||||
|
||||
/// A blank view that forwards calls to closures.
|
||||
///
|
||||
|
@ -1,12 +1,12 @@
|
||||
use Cursive;
|
||||
use Printer;
|
||||
use With;
|
||||
use direction::Direction;
|
||||
use event::{Event, EventResult, Key, MouseButton, MouseEvent};
|
||||
use std::rc::Rc;
|
||||
use theme::ColorStyle;
|
||||
use vec::Vec2;
|
||||
use view::View;
|
||||
use Cursive;
|
||||
use Printer;
|
||||
use With;
|
||||
|
||||
/// Checkable box.
|
||||
pub struct Checkbox {
|
||||
@ -32,7 +32,7 @@ impl Checkbox {
|
||||
|
||||
/// Sets a callback to be used when the state changes.
|
||||
pub fn set_on_change<F: 'static + Fn(&mut Cursive, bool)>(
|
||||
&mut self, on_change: F
|
||||
&mut self, on_change: F,
|
||||
) {
|
||||
self.on_change = Some(Rc::new(on_change));
|
||||
}
|
||||
@ -41,7 +41,7 @@ impl Checkbox {
|
||||
///
|
||||
/// Chainable variant.
|
||||
pub fn on_change<F: 'static + Fn(&mut Cursive, bool)>(
|
||||
self, on_change: F
|
||||
self, on_change: F,
|
||||
) -> Self {
|
||||
self.with(|s| s.set_on_change(on_change))
|
||||
}
|
||||
|
@ -1,6 +1,3 @@
|
||||
use Cursive;
|
||||
use Printer;
|
||||
use With;
|
||||
use align::*;
|
||||
use direction::Direction;
|
||||
use event::*;
|
||||
@ -12,6 +9,9 @@ use unicode_width::UnicodeWidthStr;
|
||||
use vec::Vec2;
|
||||
use view::{Margins, Selector, View};
|
||||
use views::{Button, DummyView, SizedView, TextView, ViewBox};
|
||||
use Cursive;
|
||||
use Printer;
|
||||
use With;
|
||||
|
||||
/// Identifies currently focused element in [`Dialog`].
|
||||
///
|
||||
@ -246,7 +246,7 @@ impl Dialog {
|
||||
|
||||
/// Returns an iterator on this buttons for this dialog.
|
||||
pub fn buttons_mut<'a>(
|
||||
&'a mut self
|
||||
&'a mut self,
|
||||
) -> Box<'a + Iterator<Item = &'a mut Button>> {
|
||||
Box::new(self.buttons.iter_mut().map(|b| &mut b.button.view))
|
||||
}
|
||||
@ -281,7 +281,7 @@ impl Dialog {
|
||||
|
||||
// An event is received while a button is in focus
|
||||
fn on_event_button(
|
||||
&mut self, event: Event, button_id: usize
|
||||
&mut self, event: Event, button_id: usize,
|
||||
) -> EventResult {
|
||||
let result = {
|
||||
let button = &mut self.buttons[button_id];
|
||||
@ -340,7 +340,8 @@ impl Dialog {
|
||||
// Current horizontal position of the next button we'll draw.
|
||||
|
||||
// Sum of the sizes + len-1 for margins
|
||||
let width = self.buttons
|
||||
let width = self
|
||||
.buttons
|
||||
.iter()
|
||||
.map(|button| button.button.size.x)
|
||||
.sum::<usize>()
|
||||
@ -350,7 +351,8 @@ impl Dialog {
|
||||
return None;
|
||||
}
|
||||
let mut offset = overhead.left
|
||||
+ self.align
|
||||
+ self
|
||||
.align
|
||||
.h
|
||||
.get_offset(width, printer.size.x - overhead.horizontal());
|
||||
|
||||
@ -382,7 +384,8 @@ impl Dialog {
|
||||
|
||||
fn draw_content(&self, printer: &Printer, buttons_height: usize) {
|
||||
// What do we have left?
|
||||
let taken = Vec2::new(0, buttons_height) + self.borders.combined()
|
||||
let taken = Vec2::new(0, buttons_height)
|
||||
+ self.borders.combined()
|
||||
+ self.padding.combined();
|
||||
|
||||
let inner_size = match printer.size.checked_sub(taken) {
|
||||
@ -405,7 +408,8 @@ impl Dialog {
|
||||
}
|
||||
let spacing = 3; //minimum distance to borders
|
||||
let x = spacing
|
||||
+ self.title_position
|
||||
+ self
|
||||
.title_position
|
||||
.get_offset(len, printer.size.x - 2 * spacing);
|
||||
printer.with_high_border(false, |printer| {
|
||||
printer.print((x - 2, 0), "┤ ");
|
||||
@ -564,7 +568,7 @@ impl View for Dialog {
|
||||
}
|
||||
|
||||
fn call_on_any<'a>(
|
||||
&mut self, selector: &Selector, callback: Box<FnMut(&mut Any) + 'a>
|
||||
&mut self, selector: &Selector, callback: Box<FnMut(&mut Any) + 'a>,
|
||||
) {
|
||||
self.content.call_on_any(selector, callback);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
use Printer;
|
||||
use view::View;
|
||||
use Printer;
|
||||
|
||||
/// Dummy view.
|
||||
///
|
||||
|
@ -367,8 +367,7 @@ impl EditView {
|
||||
self.offset = 0;
|
||||
self.set_cursor(len);
|
||||
|
||||
self.make_edit_cb()
|
||||
.unwrap_or_else(Callback::dummy)
|
||||
self.make_edit_cb().unwrap_or_else(Callback::dummy)
|
||||
}
|
||||
|
||||
/// Get the current text.
|
||||
@ -420,8 +419,7 @@ impl EditView {
|
||||
|
||||
self.keep_cursor_in_view();
|
||||
|
||||
self.make_edit_cb()
|
||||
.unwrap_or_else(Callback::dummy)
|
||||
self.make_edit_cb().unwrap_or_else(Callback::dummy)
|
||||
}
|
||||
|
||||
/// Remove the character at the current cursor position.
|
||||
@ -436,8 +434,7 @@ impl EditView {
|
||||
|
||||
self.keep_cursor_in_view();
|
||||
|
||||
self.make_edit_cb()
|
||||
.unwrap_or_else(Callback::dummy)
|
||||
self.make_edit_cb().unwrap_or_else(Callback::dummy)
|
||||
}
|
||||
|
||||
fn make_edit_cb(&self) -> Option<Callback> {
|
||||
|
@ -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),
|
||||
@ -93,7 +93,8 @@ impl<T: View + 'static> ViewWrapper for IdView<T> {
|
||||
fn wrap_focus_view(&mut self, selector: &Selector) -> Result<(), ()> {
|
||||
match selector {
|
||||
&Selector::Id(id) if id == self.id => Ok(()),
|
||||
s => self.view
|
||||
s => self
|
||||
.view
|
||||
.try_borrow_mut()
|
||||
.map_err(|_| ())
|
||||
.and_then(|mut v| v.deref_mut().focus_view(s)),
|
||||
|
@ -1,5 +1,5 @@
|
||||
use Printer;
|
||||
use view::{View, ViewWrapper};
|
||||
use Printer;
|
||||
|
||||
/// Wrapper view that fills the background.
|
||||
///
|
||||
|
@ -1,6 +1,3 @@
|
||||
use Printer;
|
||||
use With;
|
||||
use XY;
|
||||
use direction;
|
||||
use event::{Event, EventResult, Key};
|
||||
use std::any::Any;
|
||||
@ -8,6 +5,9 @@ use std::cmp::min;
|
||||
use std::ops::Deref;
|
||||
use vec::Vec2;
|
||||
use view::{Selector, SizeCache, View};
|
||||
use Printer;
|
||||
use With;
|
||||
use XY;
|
||||
|
||||
/// Arranges its children linearly according to its orientation.
|
||||
pub struct LinearLayout {
|
||||
@ -57,7 +57,7 @@ struct ChildItem<T> {
|
||||
|
||||
impl<T> ChildIterator<T> {
|
||||
fn new(
|
||||
inner: T, orientation: direction::Orientation, available: usize
|
||||
inner: T, orientation: direction::Orientation, available: usize,
|
||||
) -> Self {
|
||||
ChildIterator {
|
||||
inner,
|
||||
@ -195,7 +195,8 @@ impl LinearLayout {
|
||||
}
|
||||
|
||||
fn children_are_sleeping(&self) -> bool {
|
||||
!self.children
|
||||
!self
|
||||
.children
|
||||
.iter()
|
||||
.map(Child::as_view)
|
||||
.any(View::needs_relayout)
|
||||
@ -203,7 +204,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
|
||||
&'a mut self, from_focus: bool, source: direction::Relative,
|
||||
) -> Box<Iterator<Item = (usize, &mut Child)> + 'a> {
|
||||
match source {
|
||||
direction::Relative::Front => {
|
||||
@ -292,7 +293,7 @@ impl LinearLayout {
|
||||
}
|
||||
|
||||
fn try_focus(
|
||||
(i, child): (usize, &mut Child), source: direction::Direction
|
||||
(i, child): (usize, &mut Child), source: direction::Direction,
|
||||
) -> Option<usize> {
|
||||
if child.view.take_focus(source) {
|
||||
Some(i)
|
||||
@ -358,7 +359,8 @@ impl View for LinearLayout {
|
||||
}
|
||||
|
||||
// First, make a naive scenario: everything will work fine.
|
||||
let ideal_sizes: Vec<Vec2> = self.children
|
||||
let ideal_sizes: Vec<Vec2> = self
|
||||
.children
|
||||
.iter_mut()
|
||||
.map(|c| c.required_size(req))
|
||||
.collect();
|
||||
@ -382,7 +384,8 @@ impl View for LinearLayout {
|
||||
|
||||
// See how they like it that way.
|
||||
// This is, hopefully, the absolute minimum these views will accept.
|
||||
let min_sizes: Vec<Vec2> = self.children
|
||||
let min_sizes: Vec<Vec2> = self
|
||||
.children
|
||||
.iter_mut()
|
||||
.map(|c| c.required_size(budget_req))
|
||||
.collect();
|
||||
@ -462,7 +465,8 @@ impl View for LinearLayout {
|
||||
|
||||
// Let's ask everyone one last time. Everyone should be happy.
|
||||
// (But they may ask more on the other axis.)
|
||||
let final_sizes: Vec<Vec2> = self.children
|
||||
let final_sizes: Vec<Vec2> = self
|
||||
.children
|
||||
.iter_mut()
|
||||
.enumerate()
|
||||
.map(|(i, c)| c.required_size(final_lengths[i]))
|
||||
@ -482,10 +486,9 @@ impl View for LinearLayout {
|
||||
// In what order will we iterate on the children?
|
||||
let rel = source.relative(self.orientation);
|
||||
// We activate from_focus only if coming from the "sides".
|
||||
let i = if let Some(i) = self.iter_mut(
|
||||
rel.is_none(),
|
||||
rel.unwrap_or(direction::Relative::Front),
|
||||
).filter_map(|p| try_focus(p, source))
|
||||
let i = if let Some(i) = self
|
||||
.iter_mut(rel.is_none(), rel.unwrap_or(direction::Relative::Front))
|
||||
.filter_map(|p| try_focus(p, source))
|
||||
.next()
|
||||
{
|
||||
// ... we can't update `self.focus` here,
|
||||
|
@ -1,6 +1,3 @@
|
||||
use Cursive;
|
||||
use Printer;
|
||||
use With;
|
||||
use direction;
|
||||
use event::{Callback, Event, EventResult, Key, MouseButton, MouseEvent};
|
||||
use std::any::Any;
|
||||
@ -8,6 +5,9 @@ use std::rc::Rc;
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
use vec::Vec2;
|
||||
use view::{ScrollBase, Selector, View};
|
||||
use Cursive;
|
||||
use Printer;
|
||||
use With;
|
||||
|
||||
/// Represents a child from a [`ListView`].
|
||||
///
|
||||
@ -148,7 +148,7 @@ impl ListView {
|
||||
}
|
||||
|
||||
fn iter_mut<'a>(
|
||||
&'a mut self, from_focus: bool, source: direction::Relative
|
||||
&'a mut self, from_focus: bool, source: direction::Relative,
|
||||
) -> Box<Iterator<Item = (usize, &mut ListChild)> + 'a> {
|
||||
match source {
|
||||
direction::Relative::Front => {
|
||||
@ -172,7 +172,7 @@ impl ListView {
|
||||
}
|
||||
|
||||
fn move_focus(
|
||||
&mut self, n: usize, source: direction::Direction
|
||||
&mut self, n: usize, source: direction::Direction,
|
||||
) -> EventResult {
|
||||
let i = if let Some(i) = source
|
||||
.relative(direction::Orientation::Vertical)
|
||||
@ -246,7 +246,7 @@ impl ListView {
|
||||
}
|
||||
|
||||
fn try_focus(
|
||||
(i, child): (usize, &mut ListChild), source: direction::Direction
|
||||
(i, child): (usize, &mut ListChild), source: direction::Direction,
|
||||
) -> Option<usize> {
|
||||
match *child {
|
||||
ListChild::Delimiter => None,
|
||||
@ -279,14 +279,16 @@ impl View for ListView {
|
||||
|
||||
fn required_size(&mut self, req: Vec2) -> Vec2 {
|
||||
// We'll show 2 columns: the labels, and the views.
|
||||
let label_width = self.children
|
||||
let label_width = self
|
||||
.children
|
||||
.iter()
|
||||
.map(ListChild::label)
|
||||
.map(UnicodeWidthStr::width)
|
||||
.max()
|
||||
.unwrap_or(0);
|
||||
|
||||
let view_size = self.children
|
||||
let view_size = self
|
||||
.children
|
||||
.iter_mut()
|
||||
.filter_map(ListChild::view)
|
||||
.map(|v| v.required_size(req).x)
|
||||
@ -306,7 +308,8 @@ impl View for ListView {
|
||||
self.scrollbase.set_heights(size.y, self.children.len());
|
||||
|
||||
// We'll show 2 columns: the labels, and the views.
|
||||
let label_width = self.children
|
||||
let label_width = self
|
||||
.children
|
||||
.iter()
|
||||
.map(ListChild::label)
|
||||
.map(UnicodeWidthStr::width)
|
||||
@ -316,7 +319,8 @@ impl View for ListView {
|
||||
let spacing = 1;
|
||||
let scrollbar_width = if self.children.len() > size.y { 2 } else { 0 };
|
||||
|
||||
let available = size.x
|
||||
let available = size
|
||||
.x
|
||||
.saturating_sub(label_width + spacing + scrollbar_width);
|
||||
|
||||
debug!("Available: {}", available);
|
||||
@ -399,16 +403,10 @@ impl View for ListView {
|
||||
Event::Key(Key::PageDown) => {
|
||||
self.move_focus(10, direction::Direction::up())
|
||||
}
|
||||
Event::Key(Key::Home) | Event::Ctrl(Key::Home) => {
|
||||
self.move_focus(
|
||||
usize::max_value(),
|
||||
direction::Direction::back(),
|
||||
)
|
||||
}
|
||||
Event::Key(Key::End) | Event::Ctrl(Key::End) => self.move_focus(
|
||||
usize::max_value(),
|
||||
direction::Direction::front(),
|
||||
),
|
||||
Event::Key(Key::Home) | Event::Ctrl(Key::Home) => self
|
||||
.move_focus(usize::max_value(), direction::Direction::back()),
|
||||
Event::Key(Key::End) | Event::Ctrl(Key::End) => self
|
||||
.move_focus(usize::max_value(), direction::Direction::front()),
|
||||
Event::Key(Key::Tab) => {
|
||||
self.move_focus(1, direction::Direction::front())
|
||||
}
|
||||
@ -437,10 +435,9 @@ impl View for ListView {
|
||||
|
||||
fn take_focus(&mut self, source: direction::Direction) -> bool {
|
||||
let rel = source.relative(direction::Orientation::Vertical);
|
||||
let i = if let Some(i) = self.iter_mut(
|
||||
rel.is_none(),
|
||||
rel.unwrap_or(direction::Relative::Front),
|
||||
).filter_map(|p| try_focus(p, source))
|
||||
let i = if let Some(i) = self
|
||||
.iter_mut(rel.is_none(), rel.unwrap_or(direction::Relative::Front))
|
||||
.filter_map(|p| try_focus(p, source))
|
||||
.next()
|
||||
{
|
||||
i
|
||||
@ -463,7 +460,8 @@ impl View for ListView {
|
||||
}
|
||||
|
||||
fn focus_view(&mut self, selector: &Selector) -> Result<(), ()> {
|
||||
if let Some(i) = self.children
|
||||
if let Some(i) = self
|
||||
.children
|
||||
.iter_mut()
|
||||
.enumerate()
|
||||
.filter_map(|(i, v)| v.view().map(|v| (i, v)))
|
||||
|
@ -1,6 +1,3 @@
|
||||
use Cursive;
|
||||
use Printer;
|
||||
use With;
|
||||
use align::Align;
|
||||
use event::{Callback, Event, EventResult, Key, MouseButton, MouseEvent};
|
||||
use menu::{MenuItem, MenuTree};
|
||||
@ -10,6 +7,9 @@ use unicode_width::UnicodeWidthStr;
|
||||
use vec::Vec2;
|
||||
use view::{Position, ScrollBase, View};
|
||||
use views::OnEventView;
|
||||
use Cursive;
|
||||
use Printer;
|
||||
use With;
|
||||
|
||||
/// Popup that shows a list of items.
|
||||
pub struct MenuPopup {
|
||||
@ -137,13 +137,13 @@ impl MenuPopup {
|
||||
|
||||
fn make_subtree_cb(&self, tree: &Rc<MenuTree>) -> EventResult {
|
||||
let tree = Rc::clone(tree);
|
||||
let max_width = 4
|
||||
+ self.menu
|
||||
.children
|
||||
.iter()
|
||||
.map(Self::item_width)
|
||||
.max()
|
||||
.unwrap_or(1);
|
||||
let max_width = 4 + self
|
||||
.menu
|
||||
.children
|
||||
.iter()
|
||||
.map(Self::item_width)
|
||||
.max()
|
||||
.unwrap_or(1);
|
||||
let offset = Vec2::new(max_width, self.focus);
|
||||
let action_cb = self.on_action.clone();
|
||||
|
||||
@ -250,13 +250,13 @@ impl View for MenuPopup {
|
||||
|
||||
fn required_size(&mut self, req: Vec2) -> Vec2 {
|
||||
// We can't really shrink our items here, so it's not flexible.
|
||||
let w = 4
|
||||
+ self.menu
|
||||
.children
|
||||
.iter()
|
||||
.map(Self::item_width)
|
||||
.max()
|
||||
.unwrap_or(1);
|
||||
let w = 4 + self
|
||||
.menu
|
||||
.children
|
||||
.iter()
|
||||
.map(Self::item_width)
|
||||
.max()
|
||||
.unwrap_or(1);
|
||||
let h = 2 + self.menu.children.len();
|
||||
|
||||
let scrolling = req.y < h;
|
||||
|
@ -1,5 +1,3 @@
|
||||
use Cursive;
|
||||
use Printer;
|
||||
use direction;
|
||||
use event::*;
|
||||
use menu::{MenuItem, MenuTree};
|
||||
@ -9,6 +7,8 @@ use unicode_width::UnicodeWidthStr;
|
||||
use vec::Vec2;
|
||||
use view::{Position, View};
|
||||
use views::{MenuPopup, OnEventView};
|
||||
use Cursive;
|
||||
use Printer;
|
||||
|
||||
/// Current state of the menubar
|
||||
#[derive(PartialEq, Debug)]
|
||||
@ -106,7 +106,7 @@ impl Menubar {
|
||||
|
||||
/// Insert a new item at the given position.
|
||||
pub fn insert_subtree<S>(
|
||||
&mut self, i: usize, title: S, menu: MenuTree
|
||||
&mut self, i: usize, title: S, menu: MenuTree,
|
||||
) -> &mut Self
|
||||
where
|
||||
S: Into<String>,
|
||||
@ -341,7 +341,8 @@ impl View for Menubar {
|
||||
.checked_sub(offset)
|
||||
.and_then(|pos| self.child_at(pos.x))
|
||||
{
|
||||
if self.focus == child && btn == MouseButton::Left
|
||||
if self.focus == child
|
||||
&& btn == MouseButton::Left
|
||||
&& self.root.children[child].is_leaf()
|
||||
{
|
||||
return self.select_child(false);
|
||||
@ -371,7 +372,8 @@ impl View for Menubar {
|
||||
// We add 2 to the length of every label for marin.
|
||||
// Also, we add 1 at the beginning.
|
||||
// (See the `draw()` method)
|
||||
let width = self.root
|
||||
let width = self
|
||||
.root
|
||||
.children
|
||||
.iter()
|
||||
.map(|item| item.label().len() + 2)
|
||||
|
@ -35,7 +35,6 @@ macro_rules! impl_enabled {
|
||||
}
|
||||
}
|
||||
|
||||
mod view_box;
|
||||
mod box_view;
|
||||
mod button;
|
||||
mod canvas;
|
||||
@ -44,23 +43,24 @@ mod dialog;
|
||||
mod dummy;
|
||||
mod edit_view;
|
||||
mod id_view;
|
||||
mod on_event_view;
|
||||
mod layer;
|
||||
mod linear_layout;
|
||||
mod list_view;
|
||||
mod menubar;
|
||||
mod menu_popup;
|
||||
mod menubar;
|
||||
mod on_event_view;
|
||||
mod panel;
|
||||
mod progress_bar;
|
||||
mod radio;
|
||||
mod select_view;
|
||||
mod slider_view;
|
||||
mod shadow_view;
|
||||
mod sized_view;
|
||||
mod slider_view;
|
||||
mod stack_view;
|
||||
mod text_area;
|
||||
mod text_view;
|
||||
mod tracked_view;
|
||||
mod view_box;
|
||||
|
||||
pub use self::box_view::BoxView;
|
||||
pub use self::button::Button;
|
||||
|
@ -1,9 +1,9 @@
|
||||
use Cursive;
|
||||
use With;
|
||||
use event::{Callback, Event, EventResult};
|
||||
use std::collections::HashMap;
|
||||
use std::rc::Rc;
|
||||
use view::{View, ViewWrapper};
|
||||
use Cursive;
|
||||
use With;
|
||||
|
||||
/// A wrapper view that can react to events.
|
||||
///
|
||||
|
@ -1,7 +1,7 @@
|
||||
use Printer;
|
||||
use event::{Event, EventResult};
|
||||
use vec::Vec2;
|
||||
use view::{View, ViewWrapper};
|
||||
use Printer;
|
||||
|
||||
/// Draws a border around a wrapped view.
|
||||
#[derive(Debug)]
|
||||
|
@ -1,10 +1,10 @@
|
||||
use Printer;
|
||||
use align::HAlign;
|
||||
use std::cmp;
|
||||
use std::thread;
|
||||
use theme::{ColorStyle, Effect};
|
||||
use utils::Counter;
|
||||
use view::View;
|
||||
use Printer;
|
||||
|
||||
// pub type CbPromise = Option<Box<Fn(&mut Cursive) + Send>>;
|
||||
|
||||
@ -96,7 +96,7 @@ impl ProgressBar {
|
||||
///
|
||||
/// Chainable variant.
|
||||
pub fn with_task<F: FnOnce(Counter) + Send + 'static>(
|
||||
mut self, task: F
|
||||
mut self, task: F,
|
||||
) -> Self {
|
||||
self.start(task);
|
||||
self
|
||||
@ -116,7 +116,7 @@ impl ProgressBar {
|
||||
/// }
|
||||
/// ```
|
||||
pub fn with_label<F: Fn(usize, (usize, usize)) -> String + 'static>(
|
||||
mut self, label_maker: F
|
||||
mut self, label_maker: F,
|
||||
) -> Self {
|
||||
self.label_maker = Box::new(label_maker);
|
||||
self
|
||||
|
@ -1,4 +1,3 @@
|
||||
use {Printer, With};
|
||||
use direction::Direction;
|
||||
use event::{Event, EventResult, Key, MouseButton, MouseEvent};
|
||||
use std::cell::RefCell;
|
||||
@ -6,6 +5,7 @@ use std::rc::Rc;
|
||||
use theme::ColorStyle;
|
||||
use vec::Vec2;
|
||||
use view::View;
|
||||
use {Printer, With};
|
||||
|
||||
struct SharedState<T> {
|
||||
selection: usize,
|
||||
@ -52,7 +52,7 @@ impl<T> RadioGroup<T> {
|
||||
///
|
||||
/// The button will display `label` next to it, and will embed `value`.
|
||||
pub fn button<S: Into<String>>(
|
||||
&mut self, value: T, label: S
|
||||
&mut self, value: T, label: S,
|
||||
) -> RadioButton<T> {
|
||||
let count = self.state.borrow().values.len();
|
||||
self.state.borrow_mut().values.push(Rc::new(value));
|
||||
@ -75,7 +75,7 @@ impl<T> RadioGroup<T> {
|
||||
impl RadioGroup<String> {
|
||||
/// Adds a button, using the label itself as value.
|
||||
pub fn button_str<S: Into<String>>(
|
||||
&mut self, text: S
|
||||
&mut self, text: S,
|
||||
) -> RadioButton<String> {
|
||||
let text = text.into();
|
||||
self.button(text.clone(), text)
|
||||
@ -104,7 +104,7 @@ impl<T> RadioButton<T> {
|
||||
impl_enabled!(self.enabled);
|
||||
|
||||
fn new(
|
||||
state: Rc<RefCell<SharedState<T>>>, id: usize, label: String
|
||||
state: Rc<RefCell<SharedState<T>>>, id: usize, label: String,
|
||||
) -> Self {
|
||||
RadioButton {
|
||||
state,
|
||||
|
@ -1,6 +1,3 @@
|
||||
use Cursive;
|
||||
use Printer;
|
||||
use With;
|
||||
use align::{Align, HAlign, VAlign};
|
||||
use direction::Direction;
|
||||
use event::{Callback, Event, EventResult, Key, MouseButton, MouseEvent};
|
||||
@ -14,6 +11,9 @@ use unicode_width::UnicodeWidthStr;
|
||||
use vec::Vec2;
|
||||
use view::{Position, ScrollBase, View};
|
||||
use views::MenuPopup;
|
||||
use Cursive;
|
||||
use Printer;
|
||||
use With;
|
||||
|
||||
/// View to select an item among a list.
|
||||
///
|
||||
@ -526,7 +526,8 @@ impl<T: 'static> SelectView<T> {
|
||||
// the list when we reach the end.
|
||||
// This is achieved by chaining twice the iterator
|
||||
let iter = self.items.iter().chain(self.items.iter());
|
||||
if let Some((i, _)) = iter.enumerate()
|
||||
if let Some((i, _)) = iter
|
||||
.enumerate()
|
||||
.skip(self.focus() + 1)
|
||||
.find(|&(_, item)| item.label.starts_with(c))
|
||||
{
|
||||
@ -640,7 +641,10 @@ impl SelectView<String> {
|
||||
}
|
||||
|
||||
/// Convenient method to use the label as value.
|
||||
pub fn insert_item_str<S>(&mut self, index: usize, label: S) where S: Into<String> {
|
||||
pub fn insert_item_str<S>(&mut self, index: usize, label: S)
|
||||
where
|
||||
S: Into<String>,
|
||||
{
|
||||
let label = label.into();
|
||||
self.insert_item(index, label.clone(), label);
|
||||
}
|
||||
@ -732,7 +736,8 @@ impl<T: 'static> View for SelectView<T> {
|
||||
// Items here are not compressible.
|
||||
// So no matter what the horizontal requirements are,
|
||||
// we'll still return our longest item.
|
||||
let w = self.items
|
||||
let w = self
|
||||
.items
|
||||
.iter()
|
||||
.map(|item| item.label.width())
|
||||
.max()
|
||||
|
@ -1,8 +1,8 @@
|
||||
use Printer;
|
||||
use event::{Event, EventResult};
|
||||
use theme::ColorStyle;
|
||||
use vec::Vec2;
|
||||
use view::{View, ViewWrapper};
|
||||
use Printer;
|
||||
|
||||
/// Wrapper view that adds a shadow.
|
||||
///
|
||||
|
@ -1,11 +1,11 @@
|
||||
use {Cursive, Printer};
|
||||
use With;
|
||||
use direction::{Direction, Orientation};
|
||||
use event::{Callback, Event, EventResult, Key, MouseButton, MouseEvent};
|
||||
use std::rc::Rc;
|
||||
use theme::ColorStyle;
|
||||
use vec::Vec2;
|
||||
use view::View;
|
||||
use With;
|
||||
use {Cursive, Printer};
|
||||
|
||||
/// A horizontal or vertical slider.
|
||||
pub struct SliderView {
|
||||
|
@ -1,5 +1,3 @@
|
||||
use Printer;
|
||||
use With;
|
||||
use direction::Direction;
|
||||
use event::{Event, EventResult};
|
||||
use std::any::Any;
|
||||
@ -9,6 +7,8 @@ use theme::ColorStyle;
|
||||
use vec::Vec2;
|
||||
use view::{IntoBoxedView, Offset, Position, Selector, View, ViewWrapper};
|
||||
use views::{Layer, ShadowView, ViewBox};
|
||||
use Printer;
|
||||
use With;
|
||||
|
||||
/// Simple stack of views.
|
||||
/// Only the top-most view is active and can receive input.
|
||||
@ -37,7 +37,7 @@ pub enum LayerPosition {
|
||||
|
||||
impl Placement {
|
||||
pub fn compute_offset<S, A, P>(
|
||||
&self, size: S, available: A, parent: P
|
||||
&self, size: S, available: A, parent: P,
|
||||
) -> Vec2
|
||||
where
|
||||
S: Into<Vec2>,
|
||||
@ -146,7 +146,7 @@ impl<T: View> View for ChildWrapper<T> {
|
||||
}
|
||||
|
||||
fn call_on_any<'a>(
|
||||
&mut self, selector: &Selector, callback: Box<FnMut(&mut Any) + 'a>
|
||||
&mut self, selector: &Selector, callback: Box<FnMut(&mut Any) + 'a>,
|
||||
) {
|
||||
match *self {
|
||||
ChildWrapper::Shadow(ref mut v) => {
|
||||
@ -415,7 +415,7 @@ impl StackView {
|
||||
/// Has no effect on fullscreen layers
|
||||
/// Has no effect if layer is not found
|
||||
pub fn reposition_layer(
|
||||
&mut self, layer: LayerPosition, position: Position
|
||||
&mut self, layer: LayerPosition, position: Position,
|
||||
) {
|
||||
let i = self.get_index(layer);
|
||||
let child = match self.layers.get_mut(i) {
|
||||
@ -675,21 +675,45 @@ mod tests {
|
||||
.layer(TextView::new("1"))
|
||||
.layer(TextView::new("2"));
|
||||
|
||||
assert!(stack.get(LayerPosition::FromFront(0)).unwrap()
|
||||
.as_any().downcast_ref::<ViewBox>().unwrap()
|
||||
.with_view(|v| v.as_any().is::<TextView>()).unwrap()
|
||||
assert!(
|
||||
stack
|
||||
.get(LayerPosition::FromFront(0))
|
||||
.unwrap()
|
||||
.as_any()
|
||||
.downcast_ref::<ViewBox>()
|
||||
.unwrap()
|
||||
.with_view(|v| v.as_any().is::<TextView>())
|
||||
.unwrap()
|
||||
);
|
||||
assert!(stack.get(LayerPosition::FromBack(0)).unwrap()
|
||||
.as_any().downcast_ref::<ViewBox>().unwrap()
|
||||
.with_view(|v| v.as_any().is::<TextView>()).unwrap()
|
||||
assert!(
|
||||
stack
|
||||
.get(LayerPosition::FromBack(0))
|
||||
.unwrap()
|
||||
.as_any()
|
||||
.downcast_ref::<ViewBox>()
|
||||
.unwrap()
|
||||
.with_view(|v| v.as_any().is::<TextView>())
|
||||
.unwrap()
|
||||
);
|
||||
assert!(stack.get_mut(LayerPosition::FromFront(0)).unwrap()
|
||||
.as_any_mut().downcast_mut::<ViewBox>().unwrap()
|
||||
.with_view_mut(|v| v.as_any_mut().is::<TextView>()).unwrap()
|
||||
assert!(
|
||||
stack
|
||||
.get_mut(LayerPosition::FromFront(0))
|
||||
.unwrap()
|
||||
.as_any_mut()
|
||||
.downcast_mut::<ViewBox>()
|
||||
.unwrap()
|
||||
.with_view_mut(|v| v.as_any_mut().is::<TextView>())
|
||||
.unwrap()
|
||||
);
|
||||
assert!(stack.get_mut(LayerPosition::FromBack(0)).unwrap()
|
||||
.as_any_mut().downcast_mut::<ViewBox>().unwrap()
|
||||
.with_view_mut(|v| v.as_any_mut().is::<TextView>()).unwrap()
|
||||
assert!(
|
||||
stack
|
||||
.get_mut(LayerPosition::FromBack(0))
|
||||
.unwrap()
|
||||
.as_any_mut()
|
||||
.downcast_mut::<ViewBox>()
|
||||
.unwrap()
|
||||
.with_view_mut(|v| v.as_any_mut().is::<TextView>())
|
||||
.unwrap()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
use {Printer, With, XY};
|
||||
use direction::Direction;
|
||||
use event::{Event, EventResult, Key, MouseButton, MouseEvent};
|
||||
use std::cmp::min;
|
||||
@ -8,6 +7,7 @@ use unicode_width::UnicodeWidthStr;
|
||||
use utils::lines::simple::{prefix, simple_prefix, LinesIterator, Row};
|
||||
use vec::Vec2;
|
||||
use view::{ScrollBase, SizeCache, View};
|
||||
use {Printer, With, XY};
|
||||
|
||||
/// Multi-lines text editor.
|
||||
///
|
||||
@ -437,7 +437,8 @@ impl View for TextArea {
|
||||
debug!("{:?}", self.rows);
|
||||
let scroll_width = if self.rows.len() > constraint.y { 1 } else { 0 };
|
||||
Vec2::new(
|
||||
scroll_width + 1
|
||||
scroll_width
|
||||
+ 1
|
||||
+ self.rows.iter().map(|r| r.width).max().unwrap_or(1),
|
||||
self.rows.len(),
|
||||
)
|
||||
|
@ -1,19 +1,19 @@
|
||||
use Printer;
|
||||
use With;
|
||||
use XY;
|
||||
use align::*;
|
||||
use direction::Direction;
|
||||
use event::*;
|
||||
use owning_ref::{ArcRef, OwningHandle};
|
||||
use std::ops::Deref;
|
||||
use std::sync::{Mutex, MutexGuard};
|
||||
use std::sync::Arc;
|
||||
use std::sync::{Mutex, MutexGuard};
|
||||
use theme::Effect;
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
use utils::lines::spans::{LinesIterator, Row};
|
||||
use utils::markup::StyledString;
|
||||
use vec::Vec2;
|
||||
use view::{ScrollBase, ScrollStrategy, SizeCache, View};
|
||||
use Printer;
|
||||
use With;
|
||||
use XY;
|
||||
|
||||
/// Provides access to the content of a [`TextView`].
|
||||
///
|
||||
@ -421,7 +421,8 @@ impl TextView {
|
||||
}
|
||||
|
||||
// Desired width, including the scrollbar_width.
|
||||
self.width = self.rows
|
||||
self.width = self
|
||||
.rows
|
||||
.iter()
|
||||
.map(|row| row.width)
|
||||
.max()
|
||||
|
@ -1,8 +1,8 @@
|
||||
use Printer;
|
||||
use std::cell::Cell;
|
||||
use vec::Vec2;
|
||||
use view::{View, ViewWrapper};
|
||||
use views::IdView;
|
||||
use Printer;
|
||||
|
||||
/// Wrapper around a view that remembers its position.
|
||||
pub struct TrackedView<T: View> {
|
||||
|
Loading…
Reference in New Issue
Block a user