mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Remove "extern crate" and rustfmt
This commit is contained in:
parent
e096dc9740
commit
06b02e4665
@ -29,10 +29,12 @@ fn main() {
|
|||||||
.button("Ok", |s| {
|
.button("Ok", |s| {
|
||||||
// This will run the given closure, *ONLY* if a view with the
|
// This will run the given closure, *ONLY* if a view with the
|
||||||
// correct type and the given ID is found.
|
// correct type and the given ID is found.
|
||||||
let name = s.call_on_id("name", |view: &mut EditView| {
|
let name = s
|
||||||
|
.call_on_id("name", |view: &mut EditView| {
|
||||||
// We can return content from the closure!
|
// We can return content from the closure!
|
||||||
view.get_content()
|
view.get_content()
|
||||||
}).unwrap();
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// Run the next step
|
// Run the next step
|
||||||
show_popup(s, &name);
|
show_popup(s, &name);
|
||||||
|
@ -29,7 +29,8 @@ fn main() {
|
|||||||
.child(TextView::new(text).scrollable())
|
.child(TextView::new(text).scrollable())
|
||||||
.child(TextView::new(text).scrollable())
|
.child(TextView::new(text).scrollable())
|
||||||
.fixed_width(30),
|
.fixed_width(30),
|
||||||
).button("Quit", |s| s.quit())
|
)
|
||||||
|
.button("Quit", |s| s.quit())
|
||||||
.h_align(HAlign::Center),
|
.h_align(HAlign::Center),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -19,7 +19,8 @@ fn main() {
|
|||||||
// The menubar is a list of (label, menu tree) pairs.
|
// The menubar is a list of (label, menu tree) pairs.
|
||||||
siv.menubar()
|
siv.menubar()
|
||||||
// We add a new "File" tree
|
// We add a new "File" tree
|
||||||
.add_subtree("File",
|
.add_subtree(
|
||||||
|
"File",
|
||||||
MenuTree::new()
|
MenuTree::new()
|
||||||
// Trees are made of leaves, with are directly actionable...
|
// Trees are made of leaves, with are directly actionable...
|
||||||
.leaf("New", move |s| {
|
.leaf("New", move |s| {
|
||||||
@ -27,14 +28,18 @@ fn main() {
|
|||||||
// in the list of "Recent" items.
|
// in the list of "Recent" items.
|
||||||
let i = counter.fetch_add(1, Ordering::Relaxed);
|
let i = counter.fetch_add(1, Ordering::Relaxed);
|
||||||
let filename = format!("New {}", i);
|
let filename = format!("New {}", i);
|
||||||
s.menubar().find_subtree("File").unwrap()
|
s.menubar()
|
||||||
.find_subtree("Recent").unwrap()
|
.find_subtree("File")
|
||||||
|
.unwrap()
|
||||||
|
.find_subtree("Recent")
|
||||||
|
.unwrap()
|
||||||
.insert_leaf(0, filename, |_| ());
|
.insert_leaf(0, filename, |_| ());
|
||||||
|
|
||||||
s.add_layer(Dialog::info("New file!"));
|
s.add_layer(Dialog::info("New file!"));
|
||||||
})
|
})
|
||||||
// ... and of sub-trees, which open up when selected.
|
// ... and of sub-trees, which open up when selected.
|
||||||
.subtree("Recent",
|
.subtree(
|
||||||
|
"Recent",
|
||||||
// The `.with()` method can help when running loops
|
// The `.with()` method can help when running loops
|
||||||
// within builder patterns.
|
// within builder patterns.
|
||||||
MenuTree::new().with(|tree| {
|
MenuTree::new().with(|tree| {
|
||||||
@ -43,7 +48,8 @@ fn main() {
|
|||||||
// but you could!
|
// but you could!
|
||||||
tree.add_leaf(format!("Item {}", i), |_| ())
|
tree.add_leaf(format!("Item {}", i), |_| ())
|
||||||
}
|
}
|
||||||
}))
|
}),
|
||||||
|
)
|
||||||
// Delimiter are simple lines between items,
|
// Delimiter are simple lines between items,
|
||||||
// and cannot be selected.
|
// and cannot be selected.
|
||||||
.delimiter()
|
.delimiter()
|
||||||
@ -51,10 +57,13 @@ fn main() {
|
|||||||
for i in 1..10 {
|
for i in 1..10 {
|
||||||
tree.add_leaf(format!("Option {}", i), |_| ());
|
tree.add_leaf(format!("Option {}", i), |_| ());
|
||||||
}
|
}
|
||||||
}))
|
}),
|
||||||
.add_subtree("Help",
|
)
|
||||||
|
.add_subtree(
|
||||||
|
"Help",
|
||||||
MenuTree::new()
|
MenuTree::new()
|
||||||
.subtree("Help",
|
.subtree(
|
||||||
|
"Help",
|
||||||
MenuTree::new()
|
MenuTree::new()
|
||||||
.leaf("General", |s| {
|
.leaf("General", |s| {
|
||||||
s.add_layer(Dialog::info("Help message!"))
|
s.add_layer(Dialog::info("Help message!"))
|
||||||
@ -63,9 +72,12 @@ fn main() {
|
|||||||
let text = "Google it yourself!\n\
|
let text = "Google it yourself!\n\
|
||||||
Kids, these days...";
|
Kids, these days...";
|
||||||
s.add_layer(Dialog::info(text))
|
s.add_layer(Dialog::info(text))
|
||||||
}))
|
}),
|
||||||
.leaf("About",
|
)
|
||||||
|s| s.add_layer(Dialog::info("Cursive v0.0.0"))))
|
.leaf("About", |s| {
|
||||||
|
s.add_layer(Dialog::info("Cursive v0.0.0"))
|
||||||
|
}),
|
||||||
|
)
|
||||||
.add_delimiter()
|
.add_delimiter()
|
||||||
.add_leaf("Quit", |s| s.quit());
|
.add_leaf("Quit", |s| s.quit());
|
||||||
|
|
||||||
|
@ -39,7 +39,8 @@ fn show_popup(siv: &mut Cursive) {
|
|||||||
let content = reverse(view.get_content().source());
|
let content = reverse(view.get_content().source());
|
||||||
view.set_content(content);
|
view.set_content(content);
|
||||||
});
|
});
|
||||||
}).dismiss_button("Ok"),
|
})
|
||||||
|
.dismiss_button("Ok"),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,22 +16,28 @@ fn main() {
|
|||||||
Dialog::new()
|
Dialog::new()
|
||||||
.title("Make your selection")
|
.title("Make your selection")
|
||||||
// We'll have two columns side-by-side
|
// We'll have two columns side-by-side
|
||||||
.content(LinearLayout::horizontal()
|
.content(
|
||||||
.child(LinearLayout::vertical()
|
LinearLayout::horizontal()
|
||||||
|
.child(
|
||||||
|
LinearLayout::vertical()
|
||||||
// The color group uses the label itself as stored value
|
// The color group uses the label itself as stored value
|
||||||
// By default, the first item is selected.
|
// By default, the first item is selected.
|
||||||
.child(color_group.button_str("Red"))
|
.child(color_group.button_str("Red"))
|
||||||
.child(color_group.button_str("Green"))
|
.child(color_group.button_str("Green"))
|
||||||
.child(color_group.button_str("Blue")))
|
.child(color_group.button_str("Blue")),
|
||||||
|
)
|
||||||
// A DummyView is used as a spacer
|
// A DummyView is used as a spacer
|
||||||
.child(DummyView)
|
.child(DummyView)
|
||||||
.child(LinearLayout::vertical()
|
.child(
|
||||||
|
LinearLayout::vertical()
|
||||||
// For the size, we store a number separately
|
// For the size, we store a number separately
|
||||||
.child(size_group.button(5, "Small"))
|
.child(size_group.button(5, "Small"))
|
||||||
// The initial selection can also be overriden
|
// The initial selection can also be overriden
|
||||||
.child(size_group.button(15, "Medium").selected())
|
.child(size_group.button(15, "Medium").selected())
|
||||||
// The large size is out of stock, sorry!
|
// The large size is out of stock, sorry!
|
||||||
.child(size_group.button(25, "Large").disabled())))
|
.child(size_group.button(25, "Large").disabled()),
|
||||||
|
),
|
||||||
|
)
|
||||||
.button("Ok", move |s| {
|
.button("Ok", move |s| {
|
||||||
// We retrieve the stored value for both group.
|
// We retrieve the stored value for both group.
|
||||||
let color = color_group.selection();
|
let color = color_group.selection();
|
||||||
@ -40,8 +46,7 @@ fn main() {
|
|||||||
s.pop_layer();
|
s.pop_layer();
|
||||||
// And we simply print the result.
|
// And we simply print the result.
|
||||||
let text = format!("Color: {}\nSize: {}cm", color, size);
|
let text = format!("Color: {}\nSize: {}cm", color, size);
|
||||||
s.add_layer(Dialog::text(text)
|
s.add_layer(Dialog::text(text).button("Ok", |s| s.quit()));
|
||||||
.button("Ok", |s| s.quit()));
|
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -18,7 +18,8 @@ fn main() {
|
|||||||
.child(EditView::new().on_edit(on_edit).with_id("2"))
|
.child(EditView::new().on_edit(on_edit).with_id("2"))
|
||||||
.child(TextView::new("match").with_id("match"))
|
.child(TextView::new("match").with_id("match"))
|
||||||
.fixed_width(10),
|
.fixed_width(10),
|
||||||
).button("Quit", Cursive::quit),
|
)
|
||||||
|
.button("Quit", Cursive::quit),
|
||||||
);
|
);
|
||||||
|
|
||||||
siv.run();
|
siv.run();
|
||||||
|
@ -16,7 +16,8 @@ fn main() {
|
|||||||
.child(Button::new("Bar", |s| s.add_layer(Dialog::info("Uh"))))
|
.child(Button::new("Bar", |s| s.add_layer(Dialog::info("Uh"))))
|
||||||
.scrollable()
|
.scrollable()
|
||||||
.scroll_x(true),
|
.scroll_x(true),
|
||||||
).fixed_size((60, 30)),
|
)
|
||||||
|
.fixed_size((60, 30)),
|
||||||
);
|
);
|
||||||
|
|
||||||
siv.add_global_callback('q', |s| s.quit());
|
siv.add_global_callback('q', |s| s.quit());
|
||||||
|
@ -31,7 +31,8 @@ fn main() {
|
|||||||
.button("Ok", Cursive::quit),
|
.button("Ok", Cursive::quit),
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
).title("[ 7 ]")
|
)
|
||||||
|
.title("[ 7 ]")
|
||||||
.with_id("dialog"),
|
.with_id("dialog"),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -33,14 +33,18 @@ fn main() {
|
|||||||
.on_submit(find)
|
.on_submit(find)
|
||||||
.with_id("edit")
|
.with_id("edit")
|
||||||
.min_width(10),
|
.min_width(10),
|
||||||
).button("Ok", |s| {
|
)
|
||||||
|
.button("Ok", |s| {
|
||||||
let text = s
|
let text = s
|
||||||
.call_on_id("edit", |view: &mut EditView| {
|
.call_on_id("edit", |view: &mut EditView| {
|
||||||
view.get_content()
|
view.get_content()
|
||||||
}).unwrap();
|
})
|
||||||
|
.unwrap();
|
||||||
find(s, &text);
|
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();
|
s.pop_layer();
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
@ -15,7 +15,8 @@ fn main() {
|
|||||||
Dialog::around(TextView::new(
|
Dialog::around(TextView::new(
|
||||||
"This application uses a \
|
"This application uses a \
|
||||||
custom theme!",
|
custom theme!",
|
||||||
)).title("Themed dialog")
|
))
|
||||||
|
.title("Themed dialog")
|
||||||
.button("Quit", |s| s.quit()),
|
.button("Quit", |s| s.quit()),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -29,7 +29,8 @@ fn main() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
s.set_theme(theme);
|
s.set_theme(theme);
|
||||||
}).button("Quit", Cursive::quit),
|
})
|
||||||
|
.button("Quit", Cursive::quit),
|
||||||
);
|
);
|
||||||
|
|
||||||
siv.run();
|
siv.run();
|
||||||
|
@ -7,6 +7,7 @@ use std::collections::HashMap;
|
|||||||
|
|
||||||
use crate::event::{Event, Key};
|
use crate::event::{Event, Key};
|
||||||
use crate::theme::{BaseColor, Color, ColorPair};
|
use crate::theme::{BaseColor, Color, ColorPair};
|
||||||
|
use maplit::hashmap;
|
||||||
|
|
||||||
#[cfg(feature = "ncurses-backend")]
|
#[cfg(feature = "ncurses-backend")]
|
||||||
pub mod n;
|
pub mod n;
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
//! Ncurses-specific backend.
|
//! Ncurses-specific backend.
|
||||||
|
use log::{debug, warn};
|
||||||
|
use maplit::hashmap;
|
||||||
use ncurses;
|
use ncurses;
|
||||||
|
|
||||||
use std::cell::{Cell, RefCell};
|
use std::cell::{Cell, RefCell};
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
//! Pancuses-specific backend.
|
//! Pancuses-specific backend.
|
||||||
|
use log::{debug, warn};
|
||||||
use pancurses;
|
use pancurses;
|
||||||
|
|
||||||
use std::cell::{Cell, RefCell};
|
use std::cell::{Cell, RefCell};
|
||||||
|
@ -14,7 +14,7 @@ use self::termion::input::{MouseTerminal, TermRead};
|
|||||||
use self::termion::raw::{IntoRawMode, RawTerminal};
|
use self::termion::raw::{IntoRawMode, RawTerminal};
|
||||||
use self::termion::screen::AlternateScreen;
|
use self::termion::screen::AlternateScreen;
|
||||||
use self::termion::style as tstyle;
|
use self::termion::style as tstyle;
|
||||||
use crossbeam_channel::{self, Receiver};
|
use crossbeam_channel::{self, select, Receiver};
|
||||||
|
|
||||||
use crate::backend;
|
use crate::backend;
|
||||||
use crate::event::{Event, Key, MouseButton, MouseEvent};
|
use crate::event::{Event, Key, MouseButton, MouseEvent};
|
||||||
|
@ -13,12 +13,12 @@
|
|||||||
//! [global callback](../struct.Cursive.html#method.add_global_callback)
|
//! [global callback](../struct.Cursive.html#method.add_global_callback)
|
||||||
//! table is checked.
|
//! table is checked.
|
||||||
|
|
||||||
|
use crate::vec::Vec2;
|
||||||
|
use crate::Cursive;
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use crate::vec::Vec2;
|
|
||||||
use crate::Cursive;
|
|
||||||
|
|
||||||
/// Callback is a function that can be triggered by an event.
|
/// Callback is a function that can be triggered by an event.
|
||||||
/// It has a mutable access to the cursive root.
|
/// It has a mutable access to the cursive root.
|
||||||
|
25
src/lib.rs
25
src/lib.rs
@ -61,34 +61,9 @@
|
|||||||
//! Or you can use gdb as usual.
|
//! Or you can use gdb as usual.
|
||||||
#![deny(missing_docs)]
|
#![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.
|
// We use chan_signal to detect SIGWINCH.
|
||||||
// It's not how windows work, so no need to use that.
|
// It's not how windows work, so no need to use that.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
macro_rules! new_default(
|
macro_rules! new_default(
|
||||||
($c:ty) => {
|
($c:ty) => {
|
||||||
impl Default for $c {
|
impl Default for $c {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
//! Logging utilities
|
//! Logging utilities
|
||||||
|
|
||||||
|
use lazy_static::lazy_static;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
|
||||||
|
@ -13,9 +13,9 @@
|
|||||||
//! [menubar]: ../struct.Cursive.html#method.menubar
|
//! [menubar]: ../struct.Cursive.html#method.menubar
|
||||||
|
|
||||||
use crate::event::Callback;
|
use crate::event::Callback;
|
||||||
use std::rc::Rc;
|
|
||||||
use crate::Cursive;
|
use crate::Cursive;
|
||||||
use crate::With;
|
use crate::With;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
/// Root of a menu tree.
|
/// Root of a menu tree.
|
||||||
#[derive(Default, Clone)]
|
#[derive(Default, Clone)]
|
||||||
|
@ -2,14 +2,16 @@
|
|||||||
|
|
||||||
use crate::backend::Backend;
|
use crate::backend::Backend;
|
||||||
use crate::direction::Orientation;
|
use crate::direction::Orientation;
|
||||||
use enumset::EnumSet;
|
use crate::theme::{
|
||||||
use std::cmp::min;
|
BorderStyle, ColorStyle, Effect, PaletteColor, Style, Theme,
|
||||||
use crate::theme::{BorderStyle, ColorStyle, Effect, PaletteColor, Style, Theme};
|
};
|
||||||
use unicode_segmentation::UnicodeSegmentation;
|
|
||||||
use unicode_width::UnicodeWidthStr;
|
|
||||||
use crate::utils::lines::simple::{prefix, suffix};
|
use crate::utils::lines::simple::{prefix, suffix};
|
||||||
use crate::vec::Vec2;
|
use crate::vec::Vec2;
|
||||||
use crate::with::With;
|
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.
|
/// 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,
|
/// * If the printer currently has the focus,
|
||||||
/// uses `ColorStyle::highlight()`.
|
/// uses `ColorStyle::highlight()`.
|
||||||
/// * Otherwise, uses `ColorStyle::highlight_inactive()`.
|
/// * 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(
|
self.with_color(
|
||||||
if selection {
|
if selection {
|
||||||
if self.focused {
|
if self.focused {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//! Rectangles on the 2D character grid.
|
//! Rectangles on the 2D character grid.
|
||||||
use std::ops::Add;
|
|
||||||
use crate::vec::Vec2;
|
use crate::vec::Vec2;
|
||||||
|
use std::ops::Add;
|
||||||
|
|
||||||
/// A non-empty rectangle on the 2D grid.
|
/// A non-empty rectangle on the 2D grid.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
enum_set_type! {
|
use enumset::EnumSetType;
|
||||||
/// Text effect
|
|
||||||
pub enum Effect {
|
/// Text effect
|
||||||
|
#[derive(EnumSetType, Debug)]
|
||||||
|
pub enum Effect {
|
||||||
/// No effect
|
/// No effect
|
||||||
Simple,
|
Simple,
|
||||||
/// Reverses foreground and background colors
|
/// Reverses foreground and background colors
|
||||||
@ -11,5 +13,4 @@ enum_set_type! {
|
|||||||
Italic,
|
Italic,
|
||||||
/// Prints foreground with underline
|
/// Prints foreground with underline
|
||||||
Underline,
|
Underline,
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use super::Color;
|
use super::Color;
|
||||||
use enum_map::EnumMap;
|
use enum_map::{enum_map, Enum, EnumMap};
|
||||||
|
use log::warn;
|
||||||
use toml;
|
use toml;
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
@ -150,7 +151,7 @@ impl Default for Palette {
|
|||||||
use crate::theme::Color::*;
|
use crate::theme::Color::*;
|
||||||
|
|
||||||
Palette {
|
Palette {
|
||||||
basic: enum_map!{
|
basic: enum_map! {
|
||||||
Background => Dark(Blue),
|
Background => Dark(Blue),
|
||||||
Shadow => Dark(Black),
|
Shadow => Dark(Black),
|
||||||
View => Dark(White),
|
View => Dark(White),
|
||||||
@ -198,7 +199,7 @@ fn iterate_toml<'a>(
|
|||||||
}
|
}
|
||||||
other => {
|
other => {
|
||||||
// Other - error?
|
// Other - error?
|
||||||
debug!(
|
warn!(
|
||||||
"Found unexpected value in theme: {} = {:?}",
|
"Found unexpected value in theme: {} = {:?}",
|
||||||
key, other
|
key, other
|
||||||
);
|
);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use super::{Color, ColorStyle, ColorType, Effect, PaletteColor};
|
use super::{Color, ColorStyle, ColorType, Effect, PaletteColor};
|
||||||
use enumset::EnumSet;
|
use enumset::{enum_set, EnumSet};
|
||||||
|
|
||||||
/// Combine a color and an effect.
|
/// Combine a color and an effect.
|
||||||
///
|
///
|
||||||
|
@ -72,7 +72,8 @@ where
|
|||||||
current_width += delimiter_width;
|
current_width += delimiter_width;
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}).map(|token| token.len() + delimiter_len)
|
})
|
||||||
|
.map(|token| token.len() + delimiter_len)
|
||||||
.sum();
|
.sum();
|
||||||
|
|
||||||
// We counted delimiter once too many times,
|
// We counted delimiter once too many times,
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use super::chunk::Chunk;
|
use super::chunk::Chunk;
|
||||||
use super::segment::Segment;
|
use super::segment::Segment;
|
||||||
|
use crate::utils::span::SpannedText;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use unicode_width::UnicodeWidthStr;
|
use unicode_width::UnicodeWidthStr;
|
||||||
use crate::utils::span::SpannedText;
|
|
||||||
use xi_unicode::LineBreakLeafIter;
|
use xi_unicode::LineBreakLeafIter;
|
||||||
|
|
||||||
/// Iterator that returns non-breakable chunks of text.
|
/// Iterator that returns non-breakable chunks of text.
|
||||||
@ -123,7 +123,8 @@ where
|
|||||||
while let Some(true) =
|
while let Some(true) =
|
||||||
self.source.spans().get(self.current_span).map(|span| {
|
self.source.spans().get(self.current_span).map(|span| {
|
||||||
span.as_ref().resolve(self.source.source()).is_empty()
|
span.as_ref().resolve(self.source.source()).is_empty()
|
||||||
}) {
|
})
|
||||||
|
{
|
||||||
self.current_span += 1;
|
self.current_span += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,11 +4,11 @@ use super::prefix::prefix;
|
|||||||
use super::row::Row;
|
use super::row::Row;
|
||||||
use super::segment::Segment;
|
use super::segment::Segment;
|
||||||
use super::segment_merge_iterator::SegmentMergeIterator;
|
use super::segment_merge_iterator::SegmentMergeIterator;
|
||||||
|
use crate::utils::span::SpannedText;
|
||||||
use std::iter::Peekable;
|
use std::iter::Peekable;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use unicode_segmentation::UnicodeSegmentation;
|
use unicode_segmentation::UnicodeSegmentation;
|
||||||
use unicode_width::UnicodeWidthStr;
|
use unicode_width::UnicodeWidthStr;
|
||||||
use crate::utils::span::SpannedText;
|
|
||||||
|
|
||||||
/// Generates rows of text in constrainted width.
|
/// Generates rows of text in constrainted width.
|
||||||
///
|
///
|
||||||
@ -168,7 +168,8 @@ where
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.flat_map(|chunk| chunk.segments)
|
.flat_map(|chunk| chunk.segments)
|
||||||
//.filter(|segment| segment.start != segment.end),
|
//.filter(|segment| segment.start != segment.end),
|
||||||
).collect();
|
)
|
||||||
|
.collect();
|
||||||
|
|
||||||
// TODO: merge consecutive segments of the same span
|
// TODO: merge consecutive segments of the same span
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use std::io::{self, Read};
|
|
||||||
use crate::utils::Counter;
|
use crate::utils::Counter;
|
||||||
|
use std::io::{self, Read};
|
||||||
|
|
||||||
/// Wrapper around a `Read` that reports the progress made.
|
/// Wrapper around a `Read` that reports the progress made.
|
||||||
///
|
///
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use std::any::Any;
|
|
||||||
use crate::view::View;
|
use crate::view::View;
|
||||||
|
use std::any::Any;
|
||||||
|
|
||||||
/// A view that can be downcasted to its concrete type.
|
/// A view that can be downcasted to its concrete type.
|
||||||
///
|
///
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use std::any::Any;
|
|
||||||
use crate::view::{View, ViewPath, ViewWrapper};
|
use crate::view::{View, ViewPath, ViewWrapper};
|
||||||
use crate::views::{IdView, ViewRef};
|
use crate::views::{IdView, ViewRef};
|
||||||
|
use std::any::Any;
|
||||||
|
|
||||||
/// Provides `call_on<V: View>` to views.
|
/// 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,
|
/// If the view is not found, or if it is not of the asked type,
|
||||||
/// it returns `None`.
|
/// 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
|
where
|
||||||
V: View + Any,
|
V: View + Any,
|
||||||
F: FnOnce(&mut V) -> R;
|
F: FnOnce(&mut V) -> R;
|
||||||
@ -42,7 +44,9 @@ pub trait Finder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<T: View> Finder for T {
|
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
|
where
|
||||||
V: View + Any,
|
V: View + Any,
|
||||||
F: FnOnce(&mut V) -> R,
|
F: FnOnce(&mut V) -> R,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use std::ops::{Add, Div, Mul, Sub};
|
|
||||||
use crate::vec::Vec2;
|
use crate::vec::Vec2;
|
||||||
|
use std::ops::{Add, Div, Mul, Sub};
|
||||||
|
|
||||||
/// Four values representing each direction.
|
/// Four values representing each direction.
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use std::cmp::min;
|
|
||||||
use crate::vec::Vec2;
|
use crate::vec::Vec2;
|
||||||
use crate::XY;
|
use crate::XY;
|
||||||
|
use std::cmp::min;
|
||||||
|
|
||||||
/// Location of the view on screen
|
/// Location of the view on screen
|
||||||
pub type Position = XY<Offset>;
|
pub type Position = XY<Offset>;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use crate::div::div_up;
|
use crate::div::div_up;
|
||||||
use std::cmp::{max, min};
|
|
||||||
use crate::theme::ColorStyle;
|
use crate::theme::ColorStyle;
|
||||||
use crate::vec::Vec2;
|
use crate::vec::Vec2;
|
||||||
use crate::Printer;
|
use crate::Printer;
|
||||||
|
use std::cmp::{max, min};
|
||||||
|
|
||||||
/// Provide scrolling functionalities to a view.
|
/// Provide scrolling functionalities to a view.
|
||||||
///
|
///
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
use crate::direction::Direction;
|
use crate::direction::Direction;
|
||||||
use crate::event::{AnyCb, Event, EventResult};
|
use crate::event::{AnyCb, Event, EventResult};
|
||||||
use crate::rect::Rect;
|
use crate::rect::Rect;
|
||||||
use std::any::Any;
|
|
||||||
use crate::vec::Vec2;
|
use crate::vec::Vec2;
|
||||||
use crate::view::{AnyView, Selector};
|
use crate::view::{AnyView, Selector};
|
||||||
use crate::Printer;
|
use crate::Printer;
|
||||||
|
use std::any::Any;
|
||||||
|
|
||||||
/// Main trait defining a view behaviour.
|
/// Main trait defining a view behaviour.
|
||||||
///
|
///
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
use crate::direction::Direction;
|
use crate::direction::Direction;
|
||||||
use crate::event::{AnyCb, Event, EventResult};
|
use crate::event::{AnyCb, Event, EventResult};
|
||||||
use crate::rect::Rect;
|
use crate::rect::Rect;
|
||||||
use std::any::Any;
|
|
||||||
use crate::vec::Vec2;
|
use crate::vec::Vec2;
|
||||||
use crate::view::{Selector, View};
|
use crate::view::{Selector, View};
|
||||||
use crate::Printer;
|
use crate::Printer;
|
||||||
|
use std::any::Any;
|
||||||
|
|
||||||
/// Generic wrapper around a view.
|
/// Generic wrapper around a view.
|
||||||
///
|
///
|
||||||
@ -125,7 +125,8 @@ impl<T: ViewWrapper> View for T {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn call_on_any<'a>(
|
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)
|
self.wrap_call_on_any(selector, callback)
|
||||||
}
|
}
|
||||||
|
@ -220,8 +220,6 @@ impl<T: View> ViewWrapper for BoxView<T> {
|
|||||||
.size
|
.size
|
||||||
.zip_map(child_size.zip(req), SizeConstraint::result);
|
.zip_map(child_size.zip(req), SizeConstraint::result);
|
||||||
|
|
||||||
debug!("{:?}", result);
|
|
||||||
|
|
||||||
if !self.squishable {
|
if !self.squishable {
|
||||||
result
|
result
|
||||||
} else {
|
} else {
|
||||||
|
@ -3,10 +3,10 @@ use crate::direction::Direction;
|
|||||||
use crate::event::*;
|
use crate::event::*;
|
||||||
use crate::rect::Rect;
|
use crate::rect::Rect;
|
||||||
use crate::theme::ColorStyle;
|
use crate::theme::ColorStyle;
|
||||||
use unicode_width::UnicodeWidthStr;
|
|
||||||
use crate::vec::Vec2;
|
use crate::vec::Vec2;
|
||||||
use crate::view::View;
|
use crate::view::View;
|
||||||
use crate::{Cursive, Printer, With};
|
use crate::{Cursive, Printer, With};
|
||||||
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
|
||||||
/// Simple text label with a callback when <Enter> is pressed.
|
/// Simple text label with a callback when <Enter> is pressed.
|
||||||
///
|
///
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
use crate::direction::Direction;
|
use crate::direction::Direction;
|
||||||
use crate::event::{Event, EventResult, Key, MouseButton, MouseEvent};
|
use crate::event::{Event, EventResult, Key, MouseButton, MouseEvent};
|
||||||
use std::rc::Rc;
|
|
||||||
use crate::theme::ColorStyle;
|
use crate::theme::ColorStyle;
|
||||||
use crate::vec::Vec2;
|
use crate::vec::Vec2;
|
||||||
use crate::view::View;
|
use crate::view::View;
|
||||||
use crate::Cursive;
|
use crate::Cursive;
|
||||||
use crate::Printer;
|
use crate::Printer;
|
||||||
use crate::With;
|
use crate::With;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
/// Checkable box.
|
/// Checkable box.
|
||||||
pub struct Checkbox {
|
pub struct Checkbox {
|
||||||
|
@ -4,7 +4,7 @@ use crate::vec::Vec2;
|
|||||||
use crate::view::View;
|
use crate::view::View;
|
||||||
use crate::Printer;
|
use crate::Printer;
|
||||||
|
|
||||||
use unicode_width::UnicodeWidthStr;
|
use unicode_width::UnicodeWidthStr as _;
|
||||||
|
|
||||||
/// View used for debugging, showing logs.
|
/// View used for debugging, showing logs.
|
||||||
pub struct DebugView {
|
pub struct DebugView {
|
||||||
|
@ -2,16 +2,16 @@ use crate::align::*;
|
|||||||
use crate::direction::{Absolute, Direction, Relative};
|
use crate::direction::{Absolute, Direction, Relative};
|
||||||
use crate::event::{AnyCb, Event, EventResult, Key};
|
use crate::event::{AnyCb, Event, EventResult, Key};
|
||||||
use crate::rect::Rect;
|
use crate::rect::Rect;
|
||||||
use std::cell::Cell;
|
|
||||||
use std::cmp::max;
|
|
||||||
use crate::theme::ColorStyle;
|
use crate::theme::ColorStyle;
|
||||||
use unicode_width::UnicodeWidthStr;
|
|
||||||
use crate::vec::Vec2;
|
use crate::vec::Vec2;
|
||||||
use crate::view::{Margins, Selector, View};
|
use crate::view::{Margins, Selector, View};
|
||||||
use crate::views::{Button, DummyView, SizedView, TextView, ViewBox};
|
use crate::views::{Button, DummyView, SizedView, TextView, ViewBox};
|
||||||
use crate::Cursive;
|
use crate::Cursive;
|
||||||
use crate::Printer;
|
use crate::Printer;
|
||||||
use crate::With;
|
use crate::With;
|
||||||
|
use std::cell::Cell;
|
||||||
|
use std::cmp::max;
|
||||||
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
|
||||||
/// Identifies currently focused element in [`Dialog`].
|
/// 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);
|
self.content.call_on_any(selector, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
use crate::direction::Direction;
|
use crate::direction::Direction;
|
||||||
use crate::event::{Callback, Event, EventResult, Key, MouseEvent};
|
use crate::event::{Callback, Event, EventResult, Key, MouseEvent};
|
||||||
use crate::rect::Rect;
|
use crate::rect::Rect;
|
||||||
use std::cell::RefCell;
|
|
||||||
use std::rc::Rc;
|
|
||||||
use crate::theme::{ColorStyle, Effect};
|
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::utils::lines::simple::{simple_prefix, simple_suffix};
|
||||||
use crate::vec::Vec2;
|
use crate::vec::Vec2;
|
||||||
use crate::view::View;
|
use crate::view::View;
|
||||||
use crate::{Cursive, Printer, With};
|
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.
|
/// Closure type for callbacks when the content is modified.
|
||||||
///
|
///
|
||||||
@ -597,7 +597,6 @@ impl View for EditView {
|
|||||||
|
|
||||||
fn layout(&mut self, size: Vec2) {
|
fn layout(&mut self, size: Vec2) {
|
||||||
self.last_length = size.x;
|
self.last_length = size.x;
|
||||||
debug!("Promised: {}", size.x);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn take_focus(&mut self, _: Direction) -> bool {
|
fn take_focus(&mut self, _: Direction) -> bool {
|
||||||
|
@ -91,7 +91,8 @@ impl<V: View> ViewWrapper for HideableView<V> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn wrap_call_on_any<'a>(
|
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.
|
// We always run callbacks, even when invisible.
|
||||||
self.view.call_on_any(selector, callback)
|
self.view.call_on_any(selector, callback)
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
|
use crate::view::{Selector, View, ViewWrapper};
|
||||||
use owning_ref::{OwningHandle, RcRef};
|
use owning_ref::{OwningHandle, RcRef};
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::cell::{RefCell, RefMut};
|
use std::cell::{RefCell, RefMut};
|
||||||
use std::ops::DerefMut;
|
use std::ops::DerefMut;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use crate::view::{Selector, View, ViewWrapper};
|
|
||||||
|
|
||||||
/// Wrapper around a view to provide interior mutability.
|
/// Wrapper around a view to provide interior mutability.
|
||||||
pub struct IdView<V: View> {
|
pub struct IdView<V: View> {
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
use crate::direction;
|
use crate::direction;
|
||||||
use crate::event::{AnyCb, Event, EventResult, Key};
|
use crate::event::{AnyCb, Event, EventResult, Key};
|
||||||
use crate::rect::Rect;
|
use crate::rect::Rect;
|
||||||
use std::cmp::min;
|
|
||||||
use std::ops::Deref;
|
|
||||||
use crate::vec::Vec2;
|
use crate::vec::Vec2;
|
||||||
use crate::view::{Selector, SizeCache, View};
|
use crate::view::{Selector, SizeCache, View};
|
||||||
use crate::Printer;
|
use crate::Printer;
|
||||||
use crate::With;
|
use crate::With;
|
||||||
use crate::XY;
|
use crate::XY;
|
||||||
|
use log::debug;
|
||||||
|
use std::cmp::min;
|
||||||
|
use std::ops::Deref;
|
||||||
|
|
||||||
/// Arranges its children linearly according to its orientation.
|
/// Arranges its children linearly according to its orientation.
|
||||||
pub struct LinearLayout {
|
pub struct LinearLayout {
|
||||||
@ -305,7 +306,8 @@ impl LinearLayout {
|
|||||||
self.orientation,
|
self.orientation,
|
||||||
// TODO: get actual width (not super important)
|
// TODO: get actual width (not super important)
|
||||||
usize::max_value(),
|
usize::max_value(),
|
||||||
).enumerate()
|
)
|
||||||
|
.enumerate()
|
||||||
{
|
{
|
||||||
// Get the child size:
|
// Get the child size:
|
||||||
// this will give us the allowed window for a click.
|
// this will give us the allowed window for a click.
|
||||||
@ -341,7 +343,8 @@ impl View for LinearLayout {
|
|||||||
self.children.iter(),
|
self.children.iter(),
|
||||||
self.orientation,
|
self.orientation,
|
||||||
*printer.size.get(self.orientation),
|
*printer.size.get(self.orientation),
|
||||||
).enumerate()
|
)
|
||||||
|
.enumerate()
|
||||||
{
|
{
|
||||||
// debug!("Printer size: {:?}", printer.size);
|
// debug!("Printer size: {:?}", printer.size);
|
||||||
// debug!("Child size: {:?}", item.child.size);
|
// debug!("Child size: {:?}", item.child.size);
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
use crate::direction;
|
use crate::direction;
|
||||||
use crate::event::{AnyCb, Callback, Event, EventResult, Key};
|
use crate::event::{AnyCb, Callback, Event, EventResult, Key};
|
||||||
use crate::rect::Rect;
|
use crate::rect::Rect;
|
||||||
use std::rc::Rc;
|
|
||||||
use unicode_width::UnicodeWidthStr;
|
|
||||||
use crate::vec::Vec2;
|
use crate::vec::Vec2;
|
||||||
use crate::view::{Selector, View};
|
use crate::view::{Selector, View};
|
||||||
use crate::Cursive;
|
use crate::Cursive;
|
||||||
use crate::Printer;
|
use crate::Printer;
|
||||||
use crate::With;
|
use crate::With;
|
||||||
|
use log::debug;
|
||||||
|
use std::rc::Rc;
|
||||||
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
|
||||||
/// Represents a child from a [`ListView`].
|
/// Represents a child from a [`ListView`].
|
||||||
///
|
///
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
use crate::align::Align;
|
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::menu::{MenuItem, MenuTree};
|
||||||
use crate::rect::Rect;
|
use crate::rect::Rect;
|
||||||
use std::cmp::min;
|
|
||||||
use std::rc::Rc;
|
|
||||||
use unicode_width::UnicodeWidthStr;
|
|
||||||
use crate::vec::Vec2;
|
use crate::vec::Vec2;
|
||||||
use crate::view::{Position, ScrollBase, View};
|
use crate::view::{Position, ScrollBase, View};
|
||||||
use crate::views::OnEventView;
|
use crate::views::OnEventView;
|
||||||
use crate::Cursive;
|
use crate::Cursive;
|
||||||
use crate::Printer;
|
use crate::Printer;
|
||||||
use crate::With;
|
use crate::With;
|
||||||
|
use std::cmp::min;
|
||||||
|
use std::rc::Rc;
|
||||||
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
|
||||||
/// Popup that shows a list of items.
|
/// Popup that shows a list of items.
|
||||||
pub struct MenuPopup {
|
pub struct MenuPopup {
|
||||||
@ -162,7 +164,8 @@ impl MenuPopup {
|
|||||||
action_cb.clone()(s);
|
action_cb.clone()(s);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)).on_event(Key::Left, |s| {
|
))
|
||||||
|
.on_event(Key::Left, |s| {
|
||||||
s.pop_layer();
|
s.pop_layer();
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@ -297,18 +300,14 @@ impl View for MenuPopup {
|
|||||||
Event::Mouse {
|
Event::Mouse {
|
||||||
event: MouseEvent::WheelUp,
|
event: MouseEvent::WheelUp,
|
||||||
..
|
..
|
||||||
}
|
} if self.scrollbase.can_scroll_up() => {
|
||||||
if self.scrollbase.can_scroll_up() =>
|
|
||||||
{
|
|
||||||
fix_scroll = false;
|
fix_scroll = false;
|
||||||
self.scrollbase.scroll_up(1);
|
self.scrollbase.scroll_up(1);
|
||||||
}
|
}
|
||||||
Event::Mouse {
|
Event::Mouse {
|
||||||
event: MouseEvent::WheelDown,
|
event: MouseEvent::WheelDown,
|
||||||
..
|
..
|
||||||
}
|
} if self.scrollbase.can_scroll_down() => {
|
||||||
if self.scrollbase.can_scroll_down() =>
|
|
||||||
{
|
|
||||||
fix_scroll = false;
|
fix_scroll = false;
|
||||||
self.scrollbase.scroll_down(1);
|
self.scrollbase.scroll_down(1);
|
||||||
}
|
}
|
||||||
@ -316,12 +315,13 @@ impl View for MenuPopup {
|
|||||||
event: MouseEvent::Press(MouseButton::Left),
|
event: MouseEvent::Press(MouseButton::Left),
|
||||||
position,
|
position,
|
||||||
offset,
|
offset,
|
||||||
}
|
} if self.scrollbase.scrollable()
|
||||||
if self.scrollbase.scrollable() && position
|
&& position
|
||||||
.checked_sub(offset + (0, 1))
|
.checked_sub(offset + (0, 1))
|
||||||
.map(|position| {
|
.map(|position| {
|
||||||
self.scrollbase.start_drag(position, self.last_size.x)
|
self.scrollbase.start_drag(position, self.last_size.x)
|
||||||
}).unwrap_or(false) =>
|
})
|
||||||
|
.unwrap_or(false) =>
|
||||||
{
|
{
|
||||||
fix_scroll = false;
|
fix_scroll = false;
|
||||||
}
|
}
|
||||||
@ -339,9 +339,7 @@ impl View for MenuPopup {
|
|||||||
event: MouseEvent::Press(_),
|
event: MouseEvent::Press(_),
|
||||||
position,
|
position,
|
||||||
offset,
|
offset,
|
||||||
}
|
} if position.fits_in_rect(offset, self.last_size) => {
|
||||||
if position.fits_in_rect(offset, self.last_size) =>
|
|
||||||
{
|
|
||||||
// eprintln!("Position: {:?} / {:?}", position, offset);
|
// eprintln!("Position: {:?} / {:?}", position, offset);
|
||||||
// eprintln!("Last size: {:?}", self.last_size);
|
// eprintln!("Last size: {:?}", self.last_size);
|
||||||
let inner_size = self.last_size.saturating_sub((2, 2));
|
let inner_size = self.last_size.saturating_sub((2, 2));
|
||||||
|
@ -2,14 +2,14 @@ use crate::direction;
|
|||||||
use crate::event::*;
|
use crate::event::*;
|
||||||
use crate::menu::{MenuItem, MenuTree};
|
use crate::menu::{MenuItem, MenuTree};
|
||||||
use crate::rect::Rect;
|
use crate::rect::Rect;
|
||||||
use std::rc::Rc;
|
|
||||||
use crate::theme::ColorStyle;
|
use crate::theme::ColorStyle;
|
||||||
use unicode_width::UnicodeWidthStr;
|
|
||||||
use crate::vec::Vec2;
|
use crate::vec::Vec2;
|
||||||
use crate::view::{Position, View};
|
use crate::view::{Position, View};
|
||||||
use crate::views::{MenuPopup, OnEventView};
|
use crate::views::{MenuPopup, OnEventView};
|
||||||
use crate::Cursive;
|
use crate::Cursive;
|
||||||
use crate::Printer;
|
use crate::Printer;
|
||||||
|
use std::rc::Rc;
|
||||||
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
|
||||||
/// Current state of the menubar
|
/// Current state of the menubar
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Debug)]
|
||||||
@ -236,7 +236,8 @@ fn show_child(s: &mut Cursive, offset: Vec2, menu: Rc<MenuTree>) {
|
|||||||
MenuPopup::new(menu)
|
MenuPopup::new(menu)
|
||||||
.on_dismiss(|s| s.select_menubar())
|
.on_dismiss(|s| s.select_menubar())
|
||||||
.on_action(|s| s.menubar().state = State::Inactive),
|
.on_action(|s| s.menubar().state = State::Inactive),
|
||||||
).on_event(Key::Right, |s| {
|
)
|
||||||
|
.on_event(Key::Right, |s| {
|
||||||
s.pop_layer();
|
s.pop_layer();
|
||||||
s.select_menubar();
|
s.select_menubar();
|
||||||
// Act as if we sent "Right" then "Down"
|
// 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);
|
cb(s);
|
||||||
}
|
}
|
||||||
}).on_event(Key::Left, |s| {
|
})
|
||||||
|
.on_event(Key::Left, |s| {
|
||||||
s.pop_layer();
|
s.pop_layer();
|
||||||
s.select_menubar();
|
s.select_menubar();
|
||||||
// Act as if we sent "Left" then "Down"
|
// Act as if we sent "Left" then "Down"
|
||||||
@ -319,9 +321,7 @@ impl View for Menubar {
|
|||||||
event: MouseEvent::Press(btn),
|
event: MouseEvent::Press(btn),
|
||||||
position,
|
position,
|
||||||
offset,
|
offset,
|
||||||
}
|
} if position.fits(offset) && position.y == offset.y => {
|
||||||
if position.fits(offset) && position.y == offset.y =>
|
|
||||||
{
|
|
||||||
if let Some(child) = position
|
if let Some(child) = position
|
||||||
.checked_sub(offset)
|
.checked_sub(offset)
|
||||||
.and_then(|pos| self.child_at(pos.x))
|
.and_then(|pos| self.child_at(pos.x))
|
||||||
@ -338,9 +338,7 @@ impl View for Menubar {
|
|||||||
event: MouseEvent::Release(btn),
|
event: MouseEvent::Release(btn),
|
||||||
position,
|
position,
|
||||||
offset,
|
offset,
|
||||||
}
|
} if position.fits(offset) && position.y == offset.y => {
|
||||||
if position.fits(offset) && position.y == offset.y =>
|
|
||||||
{
|
|
||||||
if let Some(child) = position
|
if let Some(child) = position
|
||||||
.checked_sub(offset)
|
.checked_sub(offset)
|
||||||
.and_then(|pos| self.child_at(pos.x))
|
.and_then(|pos| self.child_at(pos.x))
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use crate::event::{Callback, Event, EventResult, EventTrigger};
|
use crate::event::{Callback, Event, EventResult, EventTrigger};
|
||||||
use std::rc::Rc;
|
|
||||||
use crate::view::{View, ViewWrapper};
|
use crate::view::{View, ViewWrapper};
|
||||||
use crate::Cursive;
|
use crate::Cursive;
|
||||||
use crate::With;
|
use crate::With;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
/// A wrapper view that can react to events.
|
/// A wrapper view that can react to events.
|
||||||
///
|
///
|
||||||
|
@ -2,11 +2,11 @@ use crate::align::*;
|
|||||||
use crate::event::{Event, EventResult};
|
use crate::event::{Event, EventResult};
|
||||||
use crate::rect::Rect;
|
use crate::rect::Rect;
|
||||||
use crate::theme::ColorStyle;
|
use crate::theme::ColorStyle;
|
||||||
use unicode_width::UnicodeWidthStr;
|
|
||||||
use crate::vec::Vec2;
|
use crate::vec::Vec2;
|
||||||
use crate::view::{View, ViewWrapper};
|
use crate::view::{View, ViewWrapper};
|
||||||
use crate::Printer;
|
use crate::Printer;
|
||||||
use crate::With;
|
use crate::With;
|
||||||
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
|
||||||
/// Draws a border around a wrapped view.
|
/// Draws a border around a wrapped view.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -69,7 +69,8 @@ impl<V: View> Panel<V> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let spacing = 3; //minimum distance to borders
|
let spacing = 3; //minimum distance to borders
|
||||||
let x = spacing + self
|
let x = spacing
|
||||||
|
+ self
|
||||||
.title_position
|
.title_position
|
||||||
.get_offset(len, printer.size.x - 2 * spacing);
|
.get_offset(len, printer.size.x - 2 * spacing);
|
||||||
printer.with_high_border(false, |printer| {
|
printer.with_high_border(false, |printer| {
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
use crate::align::HAlign;
|
use crate::align::HAlign;
|
||||||
use std::cmp;
|
|
||||||
use std::thread;
|
|
||||||
use crate::theme::{ColorStyle, ColorType, Effect};
|
use crate::theme::{ColorStyle, ColorType, Effect};
|
||||||
use crate::utils::Counter;
|
use crate::utils::Counter;
|
||||||
use crate::view::View;
|
use crate::view::View;
|
||||||
use crate::{Printer, With};
|
use crate::{Printer, With};
|
||||||
|
use std::cmp;
|
||||||
|
use std::thread;
|
||||||
|
|
||||||
// pub type CbPromise = Option<Box<Fn(&mut Cursive) + Send>>;
|
// pub type CbPromise = Option<Box<Fn(&mut Cursive) + Send>>;
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
use crate::direction::Direction;
|
use crate::direction::Direction;
|
||||||
use crate::event::{Event, EventResult, Key, MouseButton, MouseEvent};
|
use crate::event::{Event, EventResult, Key, MouseButton, MouseEvent};
|
||||||
use std::cell::RefCell;
|
|
||||||
use std::rc::Rc;
|
|
||||||
use crate::theme::ColorStyle;
|
use crate::theme::ColorStyle;
|
||||||
use crate::vec::Vec2;
|
use crate::vec::Vec2;
|
||||||
use crate::view::View;
|
use crate::view::View;
|
||||||
use crate::Cursive;
|
use crate::Cursive;
|
||||||
use crate::{Printer, With};
|
use crate::{Printer, With};
|
||||||
|
use std::cell::RefCell;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
struct SharedState<T> {
|
struct SharedState<T> {
|
||||||
selection: usize,
|
selection: usize,
|
||||||
@ -207,9 +207,7 @@ impl<T: 'static> View for RadioButton<T> {
|
|||||||
|
|
||||||
fn on_event(&mut self, event: Event) -> EventResult {
|
fn on_event(&mut self, event: Event) -> EventResult {
|
||||||
match event {
|
match event {
|
||||||
Event::Key(Key::Enter) | Event::Char(' ') => {
|
Event::Key(Key::Enter) | Event::Char(' ') => self.select(),
|
||||||
self.select()
|
|
||||||
}
|
|
||||||
Event::Mouse {
|
Event::Mouse {
|
||||||
event: MouseEvent::Release(MouseButton::Left),
|
event: MouseEvent::Release(MouseButton::Left),
|
||||||
position,
|
position,
|
||||||
|
@ -343,9 +343,12 @@ where
|
|||||||
/// Returns `(inner_size, desired_size)`
|
/// Returns `(inner_size, desired_size)`
|
||||||
fn sizes(&mut self, constraint: Vec2, strict: bool) -> (Vec2, Vec2) {
|
fn sizes(&mut self, constraint: Vec2, strict: bool) -> (Vec2, Vec2) {
|
||||||
// First: try the cache
|
// First: try the cache
|
||||||
if !self.inner.needs_relayout() && self
|
if !self.inner.needs_relayout()
|
||||||
|
&& self
|
||||||
.size_cache
|
.size_cache
|
||||||
.map(|cache| cache.zip_map(constraint, SizeCache::accept).both())
|
.map(|cache| {
|
||||||
|
cache.zip_map(constraint, SizeCache::accept).both()
|
||||||
|
})
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
{
|
{
|
||||||
// eprintln!("Cache: {:?}; constraint: {:?}", self.size_cache, constraint);
|
// eprintln!("Cache: {:?}; constraint: {:?}", self.size_cache, constraint);
|
||||||
@ -534,16 +537,13 @@ where
|
|||||||
Event::Mouse {
|
Event::Mouse {
|
||||||
event: MouseEvent::WheelUp,
|
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);
|
self.offset.y = self.offset.y.saturating_sub(3);
|
||||||
}
|
}
|
||||||
Event::Mouse {
|
Event::Mouse {
|
||||||
event: MouseEvent::WheelDown,
|
event: MouseEvent::WheelDown,
|
||||||
..
|
..
|
||||||
}
|
} if self.enabled.y
|
||||||
if self.enabled.y
|
|
||||||
&& (self.offset.y + self.available_size().y
|
&& (self.offset.y + self.available_size().y
|
||||||
< self.inner_size.y) =>
|
< self.inner_size.y) =>
|
||||||
{
|
{
|
||||||
@ -558,8 +558,8 @@ where
|
|||||||
event: MouseEvent::Press(MouseButton::Left),
|
event: MouseEvent::Press(MouseButton::Left),
|
||||||
position,
|
position,
|
||||||
offset,
|
offset,
|
||||||
}
|
} if self.show_scrollbars
|
||||||
if self.show_scrollbars && position
|
&& position
|
||||||
.checked_sub(offset)
|
.checked_sub(offset)
|
||||||
.map(|position| self.start_drag(position))
|
.map(|position| self.start_drag(position))
|
||||||
.unwrap_or(false) =>
|
.unwrap_or(false) =>
|
||||||
@ -570,9 +570,7 @@ where
|
|||||||
event: MouseEvent::Hold(MouseButton::Left),
|
event: MouseEvent::Hold(MouseButton::Left),
|
||||||
position,
|
position,
|
||||||
offset,
|
offset,
|
||||||
}
|
} if self.show_scrollbars => {
|
||||||
if self.show_scrollbars =>
|
|
||||||
{
|
|
||||||
let position = position.saturating_sub(offset);
|
let position = position.saturating_sub(offset);
|
||||||
self.drag(position);
|
self.drag(position);
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
use crate::align::{Align, HAlign, VAlign};
|
use crate::align::{Align, HAlign, VAlign};
|
||||||
use crate::direction::Direction;
|
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::menu::MenuTree;
|
||||||
use crate::rect::Rect;
|
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::theme::ColorStyle;
|
||||||
use crate::utils::markup::StyledString;
|
use crate::utils::markup::StyledString;
|
||||||
use crate::vec::Vec2;
|
use crate::vec::Vec2;
|
||||||
@ -15,6 +13,10 @@ use crate::views::MenuPopup;
|
|||||||
use crate::Cursive;
|
use crate::Cursive;
|
||||||
use crate::Printer;
|
use crate::Printer;
|
||||||
use crate::With;
|
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 to select an item among a list.
|
||||||
///
|
///
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
use crate::direction::{Direction, Orientation};
|
use crate::direction::{Direction, Orientation};
|
||||||
use crate::event::{Callback, Event, EventResult, Key, MouseButton, MouseEvent};
|
use crate::event::{
|
||||||
use std::rc::Rc;
|
Callback, Event, EventResult, Key, MouseButton, MouseEvent,
|
||||||
|
};
|
||||||
use crate::theme::ColorStyle;
|
use crate::theme::ColorStyle;
|
||||||
use crate::vec::Vec2;
|
use crate::vec::Vec2;
|
||||||
use crate::view::View;
|
use crate::view::View;
|
||||||
use crate::With;
|
use crate::With;
|
||||||
use crate::{Cursive, Printer};
|
use crate::{Cursive, Printer};
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
/// A horizontal or vertical slider.
|
/// A horizontal or vertical slider.
|
||||||
pub struct SliderView {
|
pub struct SliderView {
|
||||||
@ -169,9 +171,7 @@ impl View for SliderView {
|
|||||||
event: MouseEvent::Hold(MouseButton::Left),
|
event: MouseEvent::Hold(MouseButton::Left),
|
||||||
position,
|
position,
|
||||||
offset,
|
offset,
|
||||||
}
|
} if self.dragging => {
|
||||||
if self.dragging =>
|
|
||||||
{
|
|
||||||
let position = position.saturating_sub(offset);
|
let position = position.saturating_sub(offset);
|
||||||
let position = self.orientation.get(&position);
|
let position = self.orientation.get(&position);
|
||||||
let position = ::std::cmp::min(
|
let position = ::std::cmp::min(
|
||||||
@ -185,9 +185,7 @@ impl View for SliderView {
|
|||||||
event: MouseEvent::Press(MouseButton::Left),
|
event: MouseEvent::Press(MouseButton::Left),
|
||||||
position,
|
position,
|
||||||
offset,
|
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) {
|
if let Some(position) = position.checked_sub(offset) {
|
||||||
self.dragging = true;
|
self.dragging = true;
|
||||||
self.value = self.orientation.get(&position);
|
self.value = self.orientation.get(&position);
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
use crate::direction::Direction;
|
use crate::direction::Direction;
|
||||||
use crate::event::{AnyCb, Event, EventResult};
|
use crate::event::{AnyCb, Event, EventResult};
|
||||||
use std::cell;
|
|
||||||
use std::ops::Deref;
|
|
||||||
use crate::theme::ColorStyle;
|
use crate::theme::ColorStyle;
|
||||||
use crate::vec::Vec2;
|
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::views::{CircularFocus, Layer, ShadowView, ViewBox};
|
||||||
use crate::Printer;
|
use crate::Printer;
|
||||||
use crate::With;
|
use crate::With;
|
||||||
|
use std::cell;
|
||||||
|
use std::ops::Deref;
|
||||||
|
|
||||||
/// Simple stack of views.
|
/// Simple stack of views.
|
||||||
/// Only the top-most view is active and can receive input.
|
/// Only the top-most view is active and can receive input.
|
||||||
@ -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 {
|
match *self {
|
||||||
ChildWrapper::Shadow(ref mut v) => {
|
ChildWrapper::Shadow(ref mut v) => {
|
||||||
v.call_on_any(selector, callback)
|
v.call_on_any(selector, callback)
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
use crate::direction::Direction;
|
use crate::direction::Direction;
|
||||||
use crate::event::{Event, EventResult, Key, MouseButton, MouseEvent};
|
use crate::event::{Event, EventResult, Key, MouseButton, MouseEvent};
|
||||||
use crate::rect::Rect;
|
use crate::rect::Rect;
|
||||||
use std::cmp::min;
|
|
||||||
use crate::theme::{ColorStyle, Effect};
|
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::utils::lines::simple::{prefix, simple_prefix, LinesIterator, Row};
|
||||||
use crate::vec::Vec2;
|
use crate::vec::Vec2;
|
||||||
use crate::view::{ScrollBase, SizeCache, View};
|
use crate::view::{ScrollBase, SizeCache, View};
|
||||||
use crate::{Printer, With, XY};
|
use crate::{Printer, With, XY};
|
||||||
|
use log::debug;
|
||||||
|
use std::cmp::min;
|
||||||
|
use unicode_segmentation::UnicodeSegmentation;
|
||||||
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
|
||||||
/// Multi-lines text editor.
|
/// Multi-lines text editor.
|
||||||
///
|
///
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use std::cell::Cell;
|
|
||||||
use crate::vec::Vec2;
|
use crate::vec::Vec2;
|
||||||
use crate::view::{View, ViewWrapper};
|
use crate::view::{View, ViewWrapper};
|
||||||
use crate::views::IdView;
|
use crate::views::IdView;
|
||||||
use crate::Printer;
|
use crate::Printer;
|
||||||
|
use std::cell::Cell;
|
||||||
|
|
||||||
/// Wrapper around a view that remembers its position.
|
/// Wrapper around a view that remembers its position.
|
||||||
pub struct TrackedView<T: View> {
|
pub struct TrackedView<T: View> {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use std::ops::{Deref, DerefMut};
|
|
||||||
use crate::view::{IntoBoxedView, View, ViewWrapper};
|
use crate::view::{IntoBoxedView, View, ViewWrapper};
|
||||||
|
use std::ops::{Deref, DerefMut};
|
||||||
|
|
||||||
/// A boxed `View`.
|
/// A boxed `View`.
|
||||||
///
|
///
|
||||||
|
Loading…
Reference in New Issue
Block a user