Remove "extern crate" and rustfmt

This commit is contained in:
Alexandre Bury 2019-02-28 16:04:14 -08:00
parent e096dc9740
commit 06b02e4665
58 changed files with 284 additions and 258 deletions

View File

@ -29,10 +29,12 @@ fn main() {
.button("Ok", |s| {
// This will run the given closure, *ONLY* if a view with the
// correct type and the given ID is found.
let name = s.call_on_id("name", |view: &mut EditView| {
// We can return content from the closure!
view.get_content()
}).unwrap();
let name = s
.call_on_id("name", |view: &mut EditView| {
// We can return content from the closure!
view.get_content()
})
.unwrap();
// Run the next step
show_popup(s, &name);

View File

@ -29,7 +29,8 @@ fn main() {
.child(TextView::new(text).scrollable())
.child(TextView::new(text).scrollable())
.fixed_width(30),
).button("Quit", |s| s.quit())
)
.button("Quit", |s| s.quit())
.h_align(HAlign::Center),
);

View File

@ -19,53 +19,65 @@ fn main() {
// The menubar is a list of (label, menu tree) pairs.
siv.menubar()
// We add a new "File" tree
.add_subtree("File",
MenuTree::new()
// Trees are made of leaves, with are directly actionable...
.leaf("New", move |s| {
// Here we use the counter to add an entry
// in the list of "Recent" items.
let i = counter.fetch_add(1, Ordering::Relaxed);
let filename = format!("New {}", i);
s.menubar().find_subtree("File").unwrap()
.find_subtree("Recent").unwrap()
.insert_leaf(0, filename, |_| ());
.add_subtree(
"File",
MenuTree::new()
// Trees are made of leaves, with are directly actionable...
.leaf("New", move |s| {
// Here we use the counter to add an entry
// in the list of "Recent" items.
let i = counter.fetch_add(1, Ordering::Relaxed);
let filename = format!("New {}", i);
s.menubar()
.find_subtree("File")
.unwrap()
.find_subtree("Recent")
.unwrap()
.insert_leaf(0, filename, |_| ());
s.add_layer(Dialog::info("New file!"));
})
// ... and of sub-trees, which open up when selected.
.subtree("Recent",
// The `.with()` method can help when running loops
// within builder patterns.
MenuTree::new().with(|tree| {
for i in 1..100 {
// We don't actually do anything here,
// but you could!
tree.add_leaf(format!("Item {}", i), |_| ())
}
}))
// Delimiter are simple lines between items,
// and cannot be selected.
.delimiter()
.with(|tree| {
for i in 1..10 {
tree.add_leaf(format!("Option {}", i), |_| ());
}
}))
.add_subtree("Help",
MenuTree::new()
.subtree("Help",
MenuTree::new()
.leaf("General", |s| {
s.add_layer(Dialog::info("Help message!"))
})
.leaf("Online", |s| {
let text = "Google it yourself!\n\
Kids, these days...";
s.add_layer(Dialog::info(text))
}))
.leaf("About",
|s| s.add_layer(Dialog::info("Cursive v0.0.0"))))
s.add_layer(Dialog::info("New file!"));
})
// ... and of sub-trees, which open up when selected.
.subtree(
"Recent",
// The `.with()` method can help when running loops
// within builder patterns.
MenuTree::new().with(|tree| {
for i in 1..100 {
// We don't actually do anything here,
// but you could!
tree.add_leaf(format!("Item {}", i), |_| ())
}
}),
)
// Delimiter are simple lines between items,
// and cannot be selected.
.delimiter()
.with(|tree| {
for i in 1..10 {
tree.add_leaf(format!("Option {}", i), |_| ());
}
}),
)
.add_subtree(
"Help",
MenuTree::new()
.subtree(
"Help",
MenuTree::new()
.leaf("General", |s| {
s.add_layer(Dialog::info("Help message!"))
})
.leaf("Online", |s| {
let text = "Google it yourself!\n\
Kids, these days...";
s.add_layer(Dialog::info(text))
}),
)
.leaf("About", |s| {
s.add_layer(Dialog::info("Cursive v0.0.0"))
}),
)
.add_delimiter()
.add_leaf("Quit", |s| s.quit());

View File

@ -39,7 +39,8 @@ fn show_popup(siv: &mut Cursive) {
let content = reverse(view.get_content().source());
view.set_content(content);
});
}).dismiss_button("Ok"),
})
.dismiss_button("Ok"),
);
}

View File

@ -14,35 +14,40 @@ fn main() {
siv.add_layer(
Dialog::new()
.title("Make your selection")
// We'll have two columns side-by-side
.content(LinearLayout::horizontal()
.child(LinearLayout::vertical()
// The color group uses the label itself as stored value
// By default, the first item is selected.
.child(color_group.button_str("Red"))
.child(color_group.button_str("Green"))
.child(color_group.button_str("Blue")))
// A DummyView is used as a spacer
.child(DummyView)
.child(LinearLayout::vertical()
// For the size, we store a number separately
.child(size_group.button(5, "Small"))
// The initial selection can also be overriden
.child(size_group.button(15, "Medium").selected())
// The large size is out of stock, sorry!
.child(size_group.button(25, "Large").disabled())))
.button("Ok", move |s| {
// We retrieve the stored value for both group.
let color = color_group.selection();
let size = size_group.selection();
.title("Make your selection")
// We'll have two columns side-by-side
.content(
LinearLayout::horizontal()
.child(
LinearLayout::vertical()
// The color group uses the label itself as stored value
// By default, the first item is selected.
.child(color_group.button_str("Red"))
.child(color_group.button_str("Green"))
.child(color_group.button_str("Blue")),
)
// A DummyView is used as a spacer
.child(DummyView)
.child(
LinearLayout::vertical()
// For the size, we store a number separately
.child(size_group.button(5, "Small"))
// The initial selection can also be overriden
.child(size_group.button(15, "Medium").selected())
// The large size is out of stock, sorry!
.child(size_group.button(25, "Large").disabled()),
),
)
.button("Ok", move |s| {
// We retrieve the stored value for both group.
let color = color_group.selection();
let size = size_group.selection();
s.pop_layer();
// And we simply print the result.
let text = format!("Color: {}\nSize: {}cm", color, size);
s.add_layer(Dialog::text(text)
.button("Ok", |s| s.quit()));
}),
s.pop_layer();
// And we simply print the result.
let text = format!("Color: {}\nSize: {}cm", color, size);
s.add_layer(Dialog::text(text).button("Ok", |s| s.quit()));
}),
);
siv.run();

View File

@ -18,7 +18,8 @@ fn main() {
.child(EditView::new().on_edit(on_edit).with_id("2"))
.child(TextView::new("match").with_id("match"))
.fixed_width(10),
).button("Quit", Cursive::quit),
)
.button("Quit", Cursive::quit),
);
siv.run();

View File

@ -16,7 +16,8 @@ fn main() {
.child(Button::new("Bar", |s| s.add_layer(Dialog::info("Uh"))))
.scrollable()
.scroll_x(true),
).fixed_size((60, 30)),
)
.fixed_size((60, 30)),
);
siv.add_global_callback('q', |s| s.quit());

View File

@ -31,7 +31,8 @@ fn main() {
.button("Ok", Cursive::quit),
);
}),
).title("[ 7 ]")
)
.title("[ 7 ]")
.with_id("dialog"),
);

View File

@ -33,14 +33,18 @@ fn main() {
.on_submit(find)
.with_id("edit")
.min_width(10),
).button("Ok", |s| {
)
.button("Ok", |s| {
let text = s
.call_on_id("edit", |view: &mut EditView| {
view.get_content()
}).unwrap();
})
.unwrap();
find(s, &text);
}).dismiss_button("Cancel"),
).on_event(Event::Key(Key::Esc), |s| {
})
.dismiss_button("Cancel"),
)
.on_event(Event::Key(Key::Esc), |s| {
s.pop_layer();
}),
)

View File

@ -15,7 +15,8 @@ fn main() {
Dialog::around(TextView::new(
"This application uses a \
custom theme!",
)).title("Themed dialog")
))
.title("Themed dialog")
.button("Quit", |s| s.quit()),
);

View File

@ -29,7 +29,8 @@ fn main() {
};
s.set_theme(theme);
}).button("Quit", Cursive::quit),
})
.button("Quit", Cursive::quit),
);
siv.run();

View File

@ -7,6 +7,7 @@ use std::collections::HashMap;
use crate::event::{Event, Key};
use crate::theme::{BaseColor, Color, ColorPair};
use maplit::hashmap;
#[cfg(feature = "ncurses-backend")]
pub mod n;

View File

@ -1,4 +1,6 @@
//! Ncurses-specific backend.
use log::{debug, warn};
use maplit::hashmap;
use ncurses;
use std::cell::{Cell, RefCell};

View File

@ -1,4 +1,5 @@
//! Pancuses-specific backend.
use log::{debug, warn};
use pancurses;
use std::cell::{Cell, RefCell};

View File

@ -14,7 +14,7 @@ use self::termion::input::{MouseTerminal, TermRead};
use self::termion::raw::{IntoRawMode, RawTerminal};
use self::termion::screen::AlternateScreen;
use self::termion::style as tstyle;
use crossbeam_channel::{self, Receiver};
use crossbeam_channel::{self, select, Receiver};
use crate::backend;
use crate::event::{Event, Key, MouseButton, MouseEvent};

View File

@ -13,12 +13,12 @@
//! [global callback](../struct.Cursive.html#method.add_global_callback)
//! table is checked.
use crate::vec::Vec2;
use crate::Cursive;
use std::any::Any;
use std::cell::RefCell;
use std::ops::Deref;
use std::rc::Rc;
use crate::vec::Vec2;
use crate::Cursive;
/// Callback is a function that can be triggered by an event.
/// It has a mutable access to the cursive root.

View File

@ -61,34 +61,9 @@
//! Or you can use gdb as usual.
#![deny(missing_docs)]
#[macro_use]
extern crate enum_map;
#[macro_use]
extern crate enumset;
#[macro_use]
extern crate log;
#[macro_use]
extern crate crossbeam_channel;
#[macro_use]
extern crate lazy_static;
#[cfg(any(feature = "ncurses", feature = "pancurses"))]
#[macro_use]
extern crate maplit;
// We use chan_signal to detect SIGWINCH.
// It's not how windows work, so no need to use that.
macro_rules! new_default(
($c:ty) => {
impl Default for $c {

View File

@ -1,5 +1,6 @@
//! Logging utilities
use lazy_static::lazy_static;
use std::collections::VecDeque;
use std::sync::Mutex;

View File

@ -13,9 +13,9 @@
//! [menubar]: ../struct.Cursive.html#method.menubar
use crate::event::Callback;
use std::rc::Rc;
use crate::Cursive;
use crate::With;
use std::rc::Rc;
/// Root of a menu tree.
#[derive(Default, Clone)]

View File

@ -2,14 +2,16 @@
use crate::backend::Backend;
use crate::direction::Orientation;
use enumset::EnumSet;
use std::cmp::min;
use crate::theme::{BorderStyle, ColorStyle, Effect, PaletteColor, Style, Theme};
use unicode_segmentation::UnicodeSegmentation;
use unicode_width::UnicodeWidthStr;
use crate::theme::{
BorderStyle, ColorStyle, Effect, PaletteColor, Style, Theme,
};
use crate::utils::lines::simple::{prefix, suffix};
use crate::vec::Vec2;
use crate::with::With;
use enumset::EnumSet;
use std::cmp::min;
use unicode_segmentation::UnicodeSegmentation;
use unicode_width::UnicodeWidthStr;
/// Convenient interface to draw on a subset of the screen.
///
@ -428,7 +430,9 @@ impl<'a, 'b> Printer<'a, 'b> {
/// * If the printer currently has the focus,
/// uses `ColorStyle::highlight()`.
/// * Otherwise, uses `ColorStyle::highlight_inactive()`.
pub fn with_selection<F: FnOnce(&Printer<'_, '_>)>(&self, selection: bool, f: F) {
pub fn with_selection<F: FnOnce(&Printer<'_, '_>)>(
&self, selection: bool, f: F,
) {
self.with_color(
if selection {
if self.focused {

View File

@ -1,6 +1,6 @@
//! Rectangles on the 2D character grid.
use std::ops::Add;
use crate::vec::Vec2;
use std::ops::Add;
/// A non-empty rectangle on the 2D grid.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]

View File

@ -1,15 +1,16 @@
enum_set_type! {
/// Text effect
pub enum Effect {
/// No effect
Simple,
/// Reverses foreground and background colors
Reverse,
/// Prints foreground in bold
Bold,
/// Prints foreground in italic
Italic,
/// Prints foreground with underline
Underline,
}
use enumset::EnumSetType;
/// Text effect
#[derive(EnumSetType, Debug)]
pub enum Effect {
/// No effect
Simple,
/// Reverses foreground and background colors
Reverse,
/// Prints foreground in bold
Bold,
/// Prints foreground in italic
Italic,
/// Prints foreground with underline
Underline,
}

View File

@ -1,5 +1,6 @@
use super::Color;
use enum_map::EnumMap;
use enum_map::{enum_map, Enum, EnumMap};
use log::warn;
use toml;
use std::collections::HashMap;
@ -150,7 +151,7 @@ impl Default for Palette {
use crate::theme::Color::*;
Palette {
basic: enum_map!{
basic: enum_map! {
Background => Dark(Blue),
Shadow => Dark(Black),
View => Dark(White),
@ -198,7 +199,7 @@ fn iterate_toml<'a>(
}
other => {
// Other - error?
debug!(
warn!(
"Found unexpected value in theme: {} = {:?}",
key, other
);

View File

@ -1,5 +1,5 @@
use super::{Color, ColorStyle, ColorType, Effect, PaletteColor};
use enumset::EnumSet;
use enumset::{enum_set, EnumSet};
/// Combine a color and an effect.
///

View File

@ -72,7 +72,8 @@ where
current_width += delimiter_width;
true
}
}).map(|token| token.len() + delimiter_len)
})
.map(|token| token.len() + delimiter_len)
.sum();
// We counted delimiter once too many times,

View File

@ -1,8 +1,8 @@
use super::chunk::Chunk;
use super::segment::Segment;
use crate::utils::span::SpannedText;
use std::rc::Rc;
use unicode_width::UnicodeWidthStr;
use crate::utils::span::SpannedText;
use xi_unicode::LineBreakLeafIter;
/// Iterator that returns non-breakable chunks of text.
@ -123,7 +123,8 @@ where
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;
}

View File

@ -4,11 +4,11 @@ use super::prefix::prefix;
use super::row::Row;
use super::segment::Segment;
use super::segment_merge_iterator::SegmentMergeIterator;
use crate::utils::span::SpannedText;
use std::iter::Peekable;
use std::rc::Rc;
use unicode_segmentation::UnicodeSegmentation;
use unicode_width::UnicodeWidthStr;
use crate::utils::span::SpannedText;
/// Generates rows of text in constrainted width.
///
@ -168,7 +168,8 @@ where
.into_iter()
.flat_map(|chunk| chunk.segments)
//.filter(|segment| segment.start != segment.end),
).collect();
)
.collect();
// TODO: merge consecutive segments of the same span

View File

@ -1,5 +1,5 @@
use std::io::{self, Read};
use crate::utils::Counter;
use std::io::{self, Read};
/// Wrapper around a `Read` that reports the progress made.
///

View File

@ -1,5 +1,5 @@
use std::any::Any;
use crate::view::View;
use std::any::Any;
/// A view that can be downcasted to its concrete type.
///

View File

@ -1,6 +1,6 @@
use std::any::Any;
use crate::view::{View, ViewPath, ViewWrapper};
use crate::views::{IdView, ViewRef};
use std::any::Any;
/// Provides `call_on<V: View>` to views.
///
@ -16,7 +16,9 @@ pub trait Finder {
///
/// If the view is not found, or if it is not of the asked type,
/// it returns `None`.
fn call_on<V, F, R>(&mut self, sel: &Selector<'_>, callback: F) -> Option<R>
fn call_on<V, F, R>(
&mut self, sel: &Selector<'_>, callback: F,
) -> Option<R>
where
V: View + Any,
F: FnOnce(&mut V) -> R;
@ -42,7 +44,9 @@ pub trait Finder {
}
impl<T: View> Finder for T {
fn call_on<V, F, R>(&mut self, sel: &Selector<'_>, callback: F) -> Option<R>
fn call_on<V, F, R>(
&mut self, sel: &Selector<'_>, callback: F,
) -> Option<R>
where
V: View + Any,
F: FnOnce(&mut V) -> R,

View File

@ -1,5 +1,5 @@
use std::ops::{Add, Div, Mul, Sub};
use crate::vec::Vec2;
use std::ops::{Add, Div, Mul, Sub};
/// Four values representing each direction.
#[derive(Clone, Copy)]

View File

@ -1,6 +1,6 @@
use std::cmp::min;
use crate::vec::Vec2;
use crate::XY;
use std::cmp::min;
/// Location of the view on screen
pub type Position = XY<Offset>;

View File

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

View File

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

View File

@ -1,10 +1,10 @@
use crate::direction::Direction;
use crate::event::{AnyCb, Event, EventResult};
use crate::rect::Rect;
use std::any::Any;
use crate::vec::Vec2;
use crate::view::{Selector, View};
use crate::Printer;
use std::any::Any;
/// Generic wrapper around a view.
///
@ -125,7 +125,8 @@ impl<T: ViewWrapper> View for T {
}
fn call_on_any<'a>(
&mut self, selector: &Selector<'_>, callback: Box<FnMut(&mut dyn Any) + 'a>,
&mut self, selector: &Selector<'_>,
callback: Box<FnMut(&mut dyn Any) + 'a>,
) {
self.wrap_call_on_any(selector, callback)
}

View File

@ -220,8 +220,6 @@ impl<T: View> ViewWrapper for BoxView<T> {
.size
.zip_map(child_size.zip(req), SizeConstraint::result);
debug!("{:?}", result);
if !self.squishable {
result
} else {

View File

@ -3,10 +3,10 @@ use crate::direction::Direction;
use crate::event::*;
use crate::rect::Rect;
use crate::theme::ColorStyle;
use unicode_width::UnicodeWidthStr;
use crate::vec::Vec2;
use crate::view::View;
use crate::{Cursive, Printer, With};
use unicode_width::UnicodeWidthStr;
/// Simple text label with a callback when <Enter> is pressed.
///

View File

@ -1,12 +1,12 @@
use crate::direction::Direction;
use crate::event::{Event, EventResult, Key, MouseButton, MouseEvent};
use std::rc::Rc;
use crate::theme::ColorStyle;
use crate::vec::Vec2;
use crate::view::View;
use crate::Cursive;
use crate::Printer;
use crate::With;
use std::rc::Rc;
/// Checkable box.
pub struct Checkbox {

View File

@ -4,7 +4,7 @@ use crate::vec::Vec2;
use crate::view::View;
use crate::Printer;
use unicode_width::UnicodeWidthStr;
use unicode_width::UnicodeWidthStr as _;
/// View used for debugging, showing logs.
pub struct DebugView {

View File

@ -2,16 +2,16 @@ use crate::align::*;
use crate::direction::{Absolute, Direction, Relative};
use crate::event::{AnyCb, Event, EventResult, Key};
use crate::rect::Rect;
use std::cell::Cell;
use std::cmp::max;
use crate::theme::ColorStyle;
use unicode_width::UnicodeWidthStr;
use crate::vec::Vec2;
use crate::view::{Margins, Selector, View};
use crate::views::{Button, DummyView, SizedView, TextView, ViewBox};
use crate::Cursive;
use crate::Printer;
use crate::With;
use std::cell::Cell;
use std::cmp::max;
use unicode_width::UnicodeWidthStr;
/// Identifies currently focused element in [`Dialog`].
///
@ -653,7 +653,9 @@ impl View for Dialog {
}
}
fn call_on_any<'a>(&mut self, selector: &Selector<'_>, callback: AnyCb<'a>) {
fn call_on_any<'a>(
&mut self, selector: &Selector<'_>, callback: AnyCb<'a>,
) {
self.content.call_on_any(selector, callback);
}

View File

@ -1,15 +1,15 @@
use crate::direction::Direction;
use crate::event::{Callback, Event, EventResult, Key, MouseEvent};
use crate::rect::Rect;
use std::cell::RefCell;
use std::rc::Rc;
use crate::theme::{ColorStyle, Effect};
use unicode_segmentation::UnicodeSegmentation;
use unicode_width::{UnicodeWidthChar, UnicodeWidthStr};
use crate::utils::lines::simple::{simple_prefix, simple_suffix};
use crate::vec::Vec2;
use crate::view::View;
use crate::{Cursive, Printer, With};
use std::cell::RefCell;
use std::rc::Rc;
use unicode_segmentation::UnicodeSegmentation;
use unicode_width::{UnicodeWidthChar, UnicodeWidthStr};
/// Closure type for callbacks when the content is modified.
///
@ -597,7 +597,6 @@ impl View for EditView {
fn layout(&mut self, size: Vec2) {
self.last_length = size.x;
debug!("Promised: {}", size.x);
}
fn take_focus(&mut self, _: Direction) -> bool {

View File

@ -91,7 +91,8 @@ impl<V: View> ViewWrapper for HideableView<V> {
}
fn wrap_call_on_any<'a>(
&mut self, selector: &Selector<'_>, callback: Box<FnMut(&mut dyn Any) + 'a>,
&mut self, selector: &Selector<'_>,
callback: Box<FnMut(&mut dyn Any) + 'a>,
) {
// We always run callbacks, even when invisible.
self.view.call_on_any(selector, callback)

View File

@ -1,9 +1,9 @@
use crate::view::{Selector, View, ViewWrapper};
use owning_ref::{OwningHandle, RcRef};
use std::any::Any;
use std::cell::{RefCell, RefMut};
use std::ops::DerefMut;
use std::rc::Rc;
use crate::view::{Selector, View, ViewWrapper};
/// Wrapper around a view to provide interior mutability.
pub struct IdView<V: View> {

View File

@ -1,13 +1,14 @@
use crate::direction;
use crate::event::{AnyCb, Event, EventResult, Key};
use crate::rect::Rect;
use std::cmp::min;
use std::ops::Deref;
use crate::vec::Vec2;
use crate::view::{Selector, SizeCache, View};
use crate::Printer;
use crate::With;
use crate::XY;
use log::debug;
use std::cmp::min;
use std::ops::Deref;
/// Arranges its children linearly according to its orientation.
pub struct LinearLayout {
@ -305,7 +306,8 @@ impl LinearLayout {
self.orientation,
// TODO: get actual width (not super important)
usize::max_value(),
).enumerate()
)
.enumerate()
{
// Get the child size:
// this will give us the allowed window for a click.
@ -341,7 +343,8 @@ impl View for LinearLayout {
self.children.iter(),
self.orientation,
*printer.size.get(self.orientation),
).enumerate()
)
.enumerate()
{
// debug!("Printer size: {:?}", printer.size);
// debug!("Child size: {:?}", item.child.size);

View File

@ -1,13 +1,14 @@
use crate::direction;
use crate::event::{AnyCb, Callback, Event, EventResult, Key};
use crate::rect::Rect;
use std::rc::Rc;
use unicode_width::UnicodeWidthStr;
use crate::vec::Vec2;
use crate::view::{Selector, View};
use crate::Cursive;
use crate::Printer;
use crate::With;
use log::debug;
use std::rc::Rc;
use unicode_width::UnicodeWidthStr;
/// Represents a child from a [`ListView`].
///

View File

@ -1,16 +1,18 @@
use crate::align::Align;
use crate::event::{Callback, Event, EventResult, Key, MouseButton, MouseEvent};
use crate::event::{
Callback, Event, EventResult, Key, MouseButton, MouseEvent,
};
use crate::menu::{MenuItem, MenuTree};
use crate::rect::Rect;
use std::cmp::min;
use std::rc::Rc;
use unicode_width::UnicodeWidthStr;
use crate::vec::Vec2;
use crate::view::{Position, ScrollBase, View};
use crate::views::OnEventView;
use crate::Cursive;
use crate::Printer;
use crate::With;
use std::cmp::min;
use std::rc::Rc;
use unicode_width::UnicodeWidthStr;
/// Popup that shows a list of items.
pub struct MenuPopup {
@ -162,7 +164,8 @@ impl MenuPopup {
action_cb.clone()(s);
}
},
)).on_event(Key::Left, |s| {
))
.on_event(Key::Left, |s| {
s.pop_layer();
}),
);
@ -297,18 +300,14 @@ impl View for MenuPopup {
Event::Mouse {
event: MouseEvent::WheelUp,
..
}
if self.scrollbase.can_scroll_up() =>
{
} if self.scrollbase.can_scroll_up() => {
fix_scroll = false;
self.scrollbase.scroll_up(1);
}
Event::Mouse {
event: MouseEvent::WheelDown,
..
}
if self.scrollbase.can_scroll_down() =>
{
} if self.scrollbase.can_scroll_down() => {
fix_scroll = false;
self.scrollbase.scroll_down(1);
}
@ -316,12 +315,13 @@ impl View for MenuPopup {
event: MouseEvent::Press(MouseButton::Left),
position,
offset,
}
if self.scrollbase.scrollable() && position
} if self.scrollbase.scrollable()
&& position
.checked_sub(offset + (0, 1))
.map(|position| {
self.scrollbase.start_drag(position, self.last_size.x)
}).unwrap_or(false) =>
})
.unwrap_or(false) =>
{
fix_scroll = false;
}
@ -339,9 +339,7 @@ impl View for MenuPopup {
event: MouseEvent::Press(_),
position,
offset,
}
if position.fits_in_rect(offset, self.last_size) =>
{
} if position.fits_in_rect(offset, self.last_size) => {
// eprintln!("Position: {:?} / {:?}", position, offset);
// eprintln!("Last size: {:?}", self.last_size);
let inner_size = self.last_size.saturating_sub((2, 2));

View File

@ -2,14 +2,14 @@ use crate::direction;
use crate::event::*;
use crate::menu::{MenuItem, MenuTree};
use crate::rect::Rect;
use std::rc::Rc;
use crate::theme::ColorStyle;
use unicode_width::UnicodeWidthStr;
use crate::vec::Vec2;
use crate::view::{Position, View};
use crate::views::{MenuPopup, OnEventView};
use crate::Cursive;
use crate::Printer;
use std::rc::Rc;
use unicode_width::UnicodeWidthStr;
/// Current state of the menubar
#[derive(PartialEq, Debug)]
@ -236,7 +236,8 @@ fn show_child(s: &mut Cursive, offset: Vec2, menu: Rc<MenuTree>) {
MenuPopup::new(menu)
.on_dismiss(|s| s.select_menubar())
.on_action(|s| s.menubar().state = State::Inactive),
).on_event(Key::Right, |s| {
)
.on_event(Key::Right, |s| {
s.pop_layer();
s.select_menubar();
// Act as if we sent "Right" then "Down"
@ -246,7 +247,8 @@ fn show_child(s: &mut Cursive, offset: Vec2, menu: Rc<MenuTree>) {
{
cb(s);
}
}).on_event(Key::Left, |s| {
})
.on_event(Key::Left, |s| {
s.pop_layer();
s.select_menubar();
// Act as if we sent "Left" then "Down"
@ -319,9 +321,7 @@ impl View for Menubar {
event: MouseEvent::Press(btn),
position,
offset,
}
if position.fits(offset) && position.y == offset.y =>
{
} if position.fits(offset) && position.y == offset.y => {
if let Some(child) = position
.checked_sub(offset)
.and_then(|pos| self.child_at(pos.x))
@ -338,9 +338,7 @@ impl View for Menubar {
event: MouseEvent::Release(btn),
position,
offset,
}
if position.fits(offset) && position.y == offset.y =>
{
} if position.fits(offset) && position.y == offset.y => {
if let Some(child) = position
.checked_sub(offset)
.and_then(|pos| self.child_at(pos.x))

View File

@ -1,8 +1,8 @@
use crate::event::{Callback, Event, EventResult, EventTrigger};
use std::rc::Rc;
use crate::view::{View, ViewWrapper};
use crate::Cursive;
use crate::With;
use std::rc::Rc;
/// A wrapper view that can react to events.
///

View File

@ -2,11 +2,11 @@ use crate::align::*;
use crate::event::{Event, EventResult};
use crate::rect::Rect;
use crate::theme::ColorStyle;
use unicode_width::UnicodeWidthStr;
use crate::vec::Vec2;
use crate::view::{View, ViewWrapper};
use crate::Printer;
use crate::With;
use unicode_width::UnicodeWidthStr;
/// Draws a border around a wrapped view.
#[derive(Debug)]
@ -69,9 +69,10 @@ impl<V: View> Panel<V> {
return;
}
let spacing = 3; //minimum distance to borders
let x = spacing + self
.title_position
.get_offset(len, printer.size.x - 2 * spacing);
let x = spacing
+ self
.title_position
.get_offset(len, printer.size.x - 2 * spacing);
printer.with_high_border(false, |printer| {
printer.print((x - 2, 0), "");
printer.print((x + len, 0), "");

View File

@ -1,10 +1,10 @@
use crate::align::HAlign;
use std::cmp;
use std::thread;
use crate::theme::{ColorStyle, ColorType, Effect};
use crate::utils::Counter;
use crate::view::View;
use crate::{Printer, With};
use std::cmp;
use std::thread;
// pub type CbPromise = Option<Box<Fn(&mut Cursive) + Send>>;

View File

@ -1,12 +1,12 @@
use crate::direction::Direction;
use crate::event::{Event, EventResult, Key, MouseButton, MouseEvent};
use std::cell::RefCell;
use std::rc::Rc;
use crate::theme::ColorStyle;
use crate::vec::Vec2;
use crate::view::View;
use crate::Cursive;
use crate::{Printer, With};
use std::cell::RefCell;
use std::rc::Rc;
struct SharedState<T> {
selection: usize,
@ -207,9 +207,7 @@ impl<T: 'static> View for RadioButton<T> {
fn on_event(&mut self, event: Event) -> EventResult {
match event {
Event::Key(Key::Enter) | Event::Char(' ') => {
self.select()
}
Event::Key(Key::Enter) | Event::Char(' ') => self.select(),
Event::Mouse {
event: MouseEvent::Release(MouseButton::Left),
position,

View File

@ -343,10 +343,13 @@ where
/// Returns `(inner_size, desired_size)`
fn sizes(&mut self, constraint: Vec2, strict: bool) -> (Vec2, Vec2) {
// First: try the cache
if !self.inner.needs_relayout() && self
.size_cache
.map(|cache| cache.zip_map(constraint, SizeCache::accept).both())
.unwrap_or(false)
if !self.inner.needs_relayout()
&& self
.size_cache
.map(|cache| {
cache.zip_map(constraint, SizeCache::accept).both()
})
.unwrap_or(false)
{
// eprintln!("Cache: {:?}; constraint: {:?}", self.size_cache, constraint);
@ -534,18 +537,15 @@ where
Event::Mouse {
event: MouseEvent::WheelUp,
..
}
if self.enabled.y && self.offset.y > 0 =>
{
} if self.enabled.y && self.offset.y > 0 => {
self.offset.y = self.offset.y.saturating_sub(3);
}
Event::Mouse {
event: MouseEvent::WheelDown,
..
}
if self.enabled.y
&& (self.offset.y + self.available_size().y
< self.inner_size.y) =>
} if self.enabled.y
&& (self.offset.y + self.available_size().y
< self.inner_size.y) =>
{
self.offset.y = min(
self.inner_size
@ -558,8 +558,8 @@ where
event: MouseEvent::Press(MouseButton::Left),
position,
offset,
}
if self.show_scrollbars && position
} if self.show_scrollbars
&& position
.checked_sub(offset)
.map(|position| self.start_drag(position))
.unwrap_or(false) =>
@ -570,9 +570,7 @@ where
event: MouseEvent::Hold(MouseButton::Left),
position,
offset,
}
if self.show_scrollbars =>
{
} if self.show_scrollbars => {
let position = position.saturating_sub(offset);
self.drag(position);
}

View File

@ -1,12 +1,10 @@
use crate::align::{Align, HAlign, VAlign};
use crate::direction::Direction;
use crate::event::{Callback, Event, EventResult, Key, MouseButton, MouseEvent};
use crate::event::{
Callback, Event, EventResult, Key, MouseButton, MouseEvent,
};
use crate::menu::MenuTree;
use crate::rect::Rect;
use std::borrow::Borrow;
use std::cell::Cell;
use std::cmp::min;
use std::rc::Rc;
use crate::theme::ColorStyle;
use crate::utils::markup::StyledString;
use crate::vec::Vec2;
@ -15,6 +13,10 @@ use crate::views::MenuPopup;
use crate::Cursive;
use crate::Printer;
use crate::With;
use std::borrow::Borrow;
use std::cell::Cell;
use std::cmp::min;
use std::rc::Rc;
/// View to select an item among a list.
///

View File

@ -1,11 +1,13 @@
use crate::direction::{Direction, Orientation};
use crate::event::{Callback, Event, EventResult, Key, MouseButton, MouseEvent};
use std::rc::Rc;
use crate::event::{
Callback, Event, EventResult, Key, MouseButton, MouseEvent,
};
use crate::theme::ColorStyle;
use crate::vec::Vec2;
use crate::view::View;
use crate::With;
use crate::{Cursive, Printer};
use std::rc::Rc;
/// A horizontal or vertical slider.
pub struct SliderView {
@ -169,9 +171,7 @@ impl View for SliderView {
event: MouseEvent::Hold(MouseButton::Left),
position,
offset,
}
if self.dragging =>
{
} if self.dragging => {
let position = position.saturating_sub(offset);
let position = self.orientation.get(&position);
let position = ::std::cmp::min(
@ -185,9 +185,7 @@ impl View for SliderView {
event: MouseEvent::Press(MouseButton::Left),
position,
offset,
}
if position.fits_in_rect(offset, self.req_size()) =>
{
} if position.fits_in_rect(offset, self.req_size()) => {
if let Some(position) = position.checked_sub(offset) {
self.dragging = true;
self.value = self.orientation.get(&position);

View File

@ -1,13 +1,15 @@
use crate::direction::Direction;
use crate::event::{AnyCb, Event, EventResult};
use std::cell;
use std::ops::Deref;
use crate::theme::ColorStyle;
use crate::vec::Vec2;
use crate::view::{IntoBoxedView, Offset, Position, Selector, View, ViewWrapper};
use crate::view::{
IntoBoxedView, Offset, Position, Selector, View, ViewWrapper,
};
use crate::views::{CircularFocus, Layer, ShadowView, ViewBox};
use crate::Printer;
use crate::With;
use std::cell;
use std::ops::Deref;
/// Simple stack of views.
/// Only the top-most view is active and can receive input.
@ -166,7 +168,9 @@ impl<T: View> View for ChildWrapper<T> {
}
}
fn call_on_any<'a>(&mut self, selector: &Selector<'_>, callback: AnyCb<'a>) {
fn call_on_any<'a>(
&mut self, selector: &Selector<'_>, callback: AnyCb<'a>,
) {
match *self {
ChildWrapper::Shadow(ref mut v) => {
v.call_on_any(selector, callback)

View File

@ -1,14 +1,15 @@
use crate::direction::Direction;
use crate::event::{Event, EventResult, Key, MouseButton, MouseEvent};
use crate::rect::Rect;
use std::cmp::min;
use crate::theme::{ColorStyle, Effect};
use unicode_segmentation::UnicodeSegmentation;
use unicode_width::UnicodeWidthStr;
use crate::utils::lines::simple::{prefix, simple_prefix, LinesIterator, Row};
use crate::vec::Vec2;
use crate::view::{ScrollBase, SizeCache, View};
use crate::{Printer, With, XY};
use log::debug;
use std::cmp::min;
use unicode_segmentation::UnicodeSegmentation;
use unicode_width::UnicodeWidthStr;
/// Multi-lines text editor.
///

View File

@ -1,8 +1,8 @@
use std::cell::Cell;
use crate::vec::Vec2;
use crate::view::{View, ViewWrapper};
use crate::views::IdView;
use crate::Printer;
use std::cell::Cell;
/// Wrapper around a view that remembers its position.
pub struct TrackedView<T: View> {

View File

@ -1,5 +1,5 @@
use std::ops::{Deref, DerefMut};
use crate::view::{IntoBoxedView, View, ViewWrapper};
use std::ops::{Deref, DerefMut};
/// A boxed `View`.
///