mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 09:25:01 +00:00
Rustfmt
This commit is contained in:
parent
799ec812e4
commit
e4cd68a4eb
@ -21,10 +21,9 @@ fn main() {
|
||||
.fixed_width(20),
|
||||
)
|
||||
.button("Ok", |s| {
|
||||
let name = s.call_on_id(
|
||||
"name",
|
||||
|view: &mut EditView| view.get_content(),
|
||||
).unwrap();
|
||||
let name = s.call_on_id("name", |view: &mut EditView| {
|
||||
view.get_content()
|
||||
}).unwrap();
|
||||
show_popup(s, &name);
|
||||
}),
|
||||
);
|
||||
|
@ -4,7 +4,6 @@ use cursive::{Cursive, Printer};
|
||||
use cursive::event::{Event, EventResult};
|
||||
use cursive::traits::*;
|
||||
|
||||
|
||||
fn main() {
|
||||
let mut siv = Cursive::new();
|
||||
|
||||
|
@ -17,16 +17,16 @@ fn main() {
|
||||
.child("Name", EditView::new().fixed_width(10))
|
||||
.child(
|
||||
"Receive spam?",
|
||||
Checkbox::new().on_change(
|
||||
|s, checked| for name in &["email1", "email2"] {
|
||||
Checkbox::new().on_change(|s, checked| {
|
||||
for name in &["email1", "email2"] {
|
||||
s.call_on_id(name, |view: &mut EditView| {
|
||||
view.set_enabled(checked)
|
||||
});
|
||||
if checked {
|
||||
s.focus_id("email1").unwrap();
|
||||
}
|
||||
},
|
||||
),
|
||||
}
|
||||
}),
|
||||
)
|
||||
.child(
|
||||
"Email",
|
||||
@ -55,11 +55,13 @@ fn main() {
|
||||
.item_str("31-40")
|
||||
.item_str("41+"),
|
||||
)
|
||||
.with(|list| for i in 0..50 {
|
||||
list.add_child(
|
||||
&format!("Item {}", i),
|
||||
EditView::new(),
|
||||
);
|
||||
.with(|list| {
|
||||
for i in 0..50 {
|
||||
list.add_child(
|
||||
&format!("Item {}", i),
|
||||
EditView::new(),
|
||||
);
|
||||
}
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
@ -31,7 +31,6 @@ fn main() {
|
||||
siv.run();
|
||||
}
|
||||
|
||||
|
||||
fn show_options(siv: &mut Cursive) {
|
||||
siv.add_layer(
|
||||
Dialog::new()
|
||||
|
@ -16,10 +16,9 @@ fn main() {
|
||||
.value(7)
|
||||
.on_change(|s, v| {
|
||||
let title = format!("[ {} ]", v);
|
||||
s.call_on_id(
|
||||
"dialog",
|
||||
|view: &mut Dialog| view.set_title(title),
|
||||
);
|
||||
s.call_on_id("dialog", |view: &mut Dialog| {
|
||||
view.set_title(title)
|
||||
});
|
||||
})
|
||||
.on_enter(|s, v| {
|
||||
s.pop_layer();
|
||||
|
@ -1,11 +1,9 @@
|
||||
extern crate cursive;
|
||||
|
||||
|
||||
use cursive::Cursive;
|
||||
use cursive::theme::{Color, Theme};
|
||||
use cursive::views::TextView;
|
||||
|
||||
|
||||
fn custom_theme_from_cursive(siv: &Cursive) -> Theme {
|
||||
let mut theme = siv.current_theme().clone();
|
||||
theme.colors.background = Color::TerminalDefault;
|
||||
|
@ -25,45 +25,45 @@ impl Concrete {
|
||||
&mut self, kc: KeyCode, shift: bool, ctrl: bool
|
||||
) -> Event {
|
||||
match kc {
|
||||
KeyCode::F1 |
|
||||
KeyCode::F2 |
|
||||
KeyCode::F3 |
|
||||
KeyCode::F4 |
|
||||
KeyCode::F5 |
|
||||
KeyCode::F6 |
|
||||
KeyCode::F7 |
|
||||
KeyCode::F8 |
|
||||
KeyCode::F9 |
|
||||
KeyCode::F10 |
|
||||
KeyCode::F11 |
|
||||
KeyCode::F12 |
|
||||
KeyCode::NumEnter |
|
||||
KeyCode::Enter |
|
||||
KeyCode::Escape |
|
||||
KeyCode::Backspace |
|
||||
KeyCode::Tab |
|
||||
KeyCode::Pause |
|
||||
KeyCode::Insert |
|
||||
KeyCode::Home |
|
||||
KeyCode::PageUp |
|
||||
KeyCode::Delete |
|
||||
KeyCode::End |
|
||||
KeyCode::PageDown |
|
||||
KeyCode::Right |
|
||||
KeyCode::Left |
|
||||
KeyCode::Down |
|
||||
KeyCode::Up => match (shift, ctrl) {
|
||||
KeyCode::F1
|
||||
| KeyCode::F2
|
||||
| KeyCode::F3
|
||||
| KeyCode::F4
|
||||
| KeyCode::F5
|
||||
| KeyCode::F6
|
||||
| KeyCode::F7
|
||||
| KeyCode::F8
|
||||
| KeyCode::F9
|
||||
| KeyCode::F10
|
||||
| KeyCode::F11
|
||||
| KeyCode::F12
|
||||
| KeyCode::NumEnter
|
||||
| KeyCode::Enter
|
||||
| KeyCode::Escape
|
||||
| KeyCode::Backspace
|
||||
| KeyCode::Tab
|
||||
| KeyCode::Pause
|
||||
| KeyCode::Insert
|
||||
| KeyCode::Home
|
||||
| KeyCode::PageUp
|
||||
| KeyCode::Delete
|
||||
| KeyCode::End
|
||||
| KeyCode::PageDown
|
||||
| KeyCode::Right
|
||||
| KeyCode::Left
|
||||
| KeyCode::Down
|
||||
| KeyCode::Up => match (shift, ctrl) {
|
||||
(true, true) => Event::CtrlShift(blt_keycode_to_key(kc)),
|
||||
(true, false) => Event::Shift(blt_keycode_to_key(kc)),
|
||||
(false, true) => Event::Ctrl(blt_keycode_to_key(kc)),
|
||||
(false, false) => Event::Key(blt_keycode_to_key(kc)),
|
||||
},
|
||||
// TODO: mouse support
|
||||
KeyCode::MouseLeft |
|
||||
KeyCode::MouseRight |
|
||||
KeyCode::MouseMiddle |
|
||||
KeyCode::MouseFourth |
|
||||
KeyCode::MouseFifth => blt_keycode_to_mouse_button(kc)
|
||||
KeyCode::MouseLeft
|
||||
| KeyCode::MouseRight
|
||||
| KeyCode::MouseMiddle
|
||||
| KeyCode::MouseFourth
|
||||
| KeyCode::MouseFifth => blt_keycode_to_mouse_button(kc)
|
||||
.map(|btn| {
|
||||
self.buttons_pressed.insert(btn);
|
||||
Event::Mouse {
|
||||
@ -73,69 +73,69 @@ impl Concrete {
|
||||
}
|
||||
})
|
||||
.unwrap_or(Event::Unknown(vec![])),
|
||||
KeyCode::A |
|
||||
KeyCode::B |
|
||||
KeyCode::C |
|
||||
KeyCode::D |
|
||||
KeyCode::E |
|
||||
KeyCode::F |
|
||||
KeyCode::G |
|
||||
KeyCode::H |
|
||||
KeyCode::I |
|
||||
KeyCode::J |
|
||||
KeyCode::K |
|
||||
KeyCode::L |
|
||||
KeyCode::M |
|
||||
KeyCode::N |
|
||||
KeyCode::O |
|
||||
KeyCode::P |
|
||||
KeyCode::Q |
|
||||
KeyCode::R |
|
||||
KeyCode::S |
|
||||
KeyCode::T |
|
||||
KeyCode::U |
|
||||
KeyCode::V |
|
||||
KeyCode::W |
|
||||
KeyCode::X |
|
||||
KeyCode::Y |
|
||||
KeyCode::Z |
|
||||
KeyCode::Row1 |
|
||||
KeyCode::Row2 |
|
||||
KeyCode::Row3 |
|
||||
KeyCode::Row4 |
|
||||
KeyCode::Row5 |
|
||||
KeyCode::Row6 |
|
||||
KeyCode::Row7 |
|
||||
KeyCode::Row8 |
|
||||
KeyCode::Row9 |
|
||||
KeyCode::Row0 |
|
||||
KeyCode::Grave |
|
||||
KeyCode::Minus |
|
||||
KeyCode::Equals |
|
||||
KeyCode::LeftBracket |
|
||||
KeyCode::RightBracket |
|
||||
KeyCode::Backslash |
|
||||
KeyCode::Semicolon |
|
||||
KeyCode::Apostrophe |
|
||||
KeyCode::Comma |
|
||||
KeyCode::Period |
|
||||
KeyCode::Slash |
|
||||
KeyCode::Space |
|
||||
KeyCode::NumDivide |
|
||||
KeyCode::NumMultiply |
|
||||
KeyCode::NumMinus |
|
||||
KeyCode::NumPlus |
|
||||
KeyCode::NumPeriod |
|
||||
KeyCode::Num1 |
|
||||
KeyCode::Num2 |
|
||||
KeyCode::Num3 |
|
||||
KeyCode::Num4 |
|
||||
KeyCode::Num5 |
|
||||
KeyCode::Num6 |
|
||||
KeyCode::Num7 |
|
||||
KeyCode::Num8 |
|
||||
KeyCode::Num9 |
|
||||
KeyCode::Num0 => if ctrl {
|
||||
KeyCode::A
|
||||
| KeyCode::B
|
||||
| KeyCode::C
|
||||
| KeyCode::D
|
||||
| KeyCode::E
|
||||
| KeyCode::F
|
||||
| KeyCode::G
|
||||
| KeyCode::H
|
||||
| KeyCode::I
|
||||
| KeyCode::J
|
||||
| KeyCode::K
|
||||
| KeyCode::L
|
||||
| KeyCode::M
|
||||
| KeyCode::N
|
||||
| KeyCode::O
|
||||
| KeyCode::P
|
||||
| KeyCode::Q
|
||||
| KeyCode::R
|
||||
| KeyCode::S
|
||||
| KeyCode::T
|
||||
| KeyCode::U
|
||||
| KeyCode::V
|
||||
| KeyCode::W
|
||||
| KeyCode::X
|
||||
| KeyCode::Y
|
||||
| KeyCode::Z
|
||||
| KeyCode::Row1
|
||||
| KeyCode::Row2
|
||||
| KeyCode::Row3
|
||||
| KeyCode::Row4
|
||||
| KeyCode::Row5
|
||||
| KeyCode::Row6
|
||||
| KeyCode::Row7
|
||||
| KeyCode::Row8
|
||||
| KeyCode::Row9
|
||||
| KeyCode::Row0
|
||||
| KeyCode::Grave
|
||||
| KeyCode::Minus
|
||||
| KeyCode::Equals
|
||||
| KeyCode::LeftBracket
|
||||
| KeyCode::RightBracket
|
||||
| KeyCode::Backslash
|
||||
| KeyCode::Semicolon
|
||||
| KeyCode::Apostrophe
|
||||
| KeyCode::Comma
|
||||
| KeyCode::Period
|
||||
| KeyCode::Slash
|
||||
| KeyCode::Space
|
||||
| KeyCode::NumDivide
|
||||
| KeyCode::NumMultiply
|
||||
| KeyCode::NumMinus
|
||||
| KeyCode::NumPlus
|
||||
| KeyCode::NumPeriod
|
||||
| KeyCode::Num1
|
||||
| KeyCode::Num2
|
||||
| KeyCode::Num3
|
||||
| KeyCode::Num4
|
||||
| KeyCode::Num5
|
||||
| KeyCode::Num6
|
||||
| KeyCode::Num7
|
||||
| KeyCode::Num8
|
||||
| KeyCode::Num9
|
||||
| KeyCode::Num0 => if ctrl {
|
||||
Event::CtrlChar(blt_keycode_to_char(kc, shift))
|
||||
} else {
|
||||
Event::Char(blt_keycode_to_char(kc, shift))
|
||||
@ -200,9 +200,10 @@ impl backend::Backend for Concrete {
|
||||
}
|
||||
|
||||
fn clear(&self, color: Color) {
|
||||
terminal::set_background(
|
||||
colour_to_blt_colour(color, ColorRole::Background),
|
||||
);
|
||||
terminal::set_background(colour_to_blt_colour(
|
||||
color,
|
||||
ColorRole::Background,
|
||||
));
|
||||
terminal::clear(None);
|
||||
}
|
||||
|
||||
|
@ -89,12 +89,10 @@ impl Concrete {
|
||||
| ncurses::BUTTON_CTRL)
|
||||
as mmask_t;
|
||||
|
||||
let make_event = |event| {
|
||||
Event::Mouse {
|
||||
offset: Vec2::zero(),
|
||||
position: Vec2::new(mevent.x as usize, mevent.y as usize),
|
||||
event: event,
|
||||
}
|
||||
let make_event = |event| Event::Mouse {
|
||||
offset: Vec2::zero(),
|
||||
position: Vec2::new(mevent.x as usize, mevent.y as usize),
|
||||
event: event,
|
||||
};
|
||||
|
||||
if mevent.bstate == ncurses::REPORT_MOUSE_POSITION as mmask_t {
|
||||
@ -214,7 +212,6 @@ impl backend::Backend for Concrete {
|
||||
ncurses::endwin();
|
||||
}
|
||||
|
||||
|
||||
fn with_color<F: FnOnce()>(&self, colors: ColorPair, f: F) {
|
||||
let current = self.current_style.get();
|
||||
if current != colors {
|
||||
@ -284,31 +281,31 @@ impl backend::Backend for Concrete {
|
||||
/// Returns the Key enum corresponding to the given ncurses event.
|
||||
fn get_mouse_button(bare_event: i32) -> MouseButton {
|
||||
match bare_event {
|
||||
ncurses::BUTTON1_RELEASED |
|
||||
ncurses::BUTTON1_PRESSED |
|
||||
ncurses::BUTTON1_CLICKED |
|
||||
ncurses::BUTTON1_DOUBLE_CLICKED |
|
||||
ncurses::BUTTON1_TRIPLE_CLICKED => MouseButton::Left,
|
||||
ncurses::BUTTON2_RELEASED |
|
||||
ncurses::BUTTON2_PRESSED |
|
||||
ncurses::BUTTON2_CLICKED |
|
||||
ncurses::BUTTON2_DOUBLE_CLICKED |
|
||||
ncurses::BUTTON2_TRIPLE_CLICKED => MouseButton::Middle,
|
||||
ncurses::BUTTON3_RELEASED |
|
||||
ncurses::BUTTON3_PRESSED |
|
||||
ncurses::BUTTON3_CLICKED |
|
||||
ncurses::BUTTON3_DOUBLE_CLICKED |
|
||||
ncurses::BUTTON3_TRIPLE_CLICKED => MouseButton::Right,
|
||||
ncurses::BUTTON4_RELEASED |
|
||||
ncurses::BUTTON4_PRESSED |
|
||||
ncurses::BUTTON4_CLICKED |
|
||||
ncurses::BUTTON4_DOUBLE_CLICKED |
|
||||
ncurses::BUTTON4_TRIPLE_CLICKED => MouseButton::Button4,
|
||||
ncurses::BUTTON5_RELEASED |
|
||||
ncurses::BUTTON5_PRESSED |
|
||||
ncurses::BUTTON5_CLICKED |
|
||||
ncurses::BUTTON5_DOUBLE_CLICKED |
|
||||
ncurses::BUTTON5_TRIPLE_CLICKED => MouseButton::Button5,
|
||||
ncurses::BUTTON1_RELEASED
|
||||
| ncurses::BUTTON1_PRESSED
|
||||
| ncurses::BUTTON1_CLICKED
|
||||
| ncurses::BUTTON1_DOUBLE_CLICKED
|
||||
| ncurses::BUTTON1_TRIPLE_CLICKED => MouseButton::Left,
|
||||
ncurses::BUTTON2_RELEASED
|
||||
| ncurses::BUTTON2_PRESSED
|
||||
| ncurses::BUTTON2_CLICKED
|
||||
| ncurses::BUTTON2_DOUBLE_CLICKED
|
||||
| ncurses::BUTTON2_TRIPLE_CLICKED => MouseButton::Middle,
|
||||
ncurses::BUTTON3_RELEASED
|
||||
| ncurses::BUTTON3_PRESSED
|
||||
| ncurses::BUTTON3_CLICKED
|
||||
| ncurses::BUTTON3_DOUBLE_CLICKED
|
||||
| ncurses::BUTTON3_TRIPLE_CLICKED => MouseButton::Right,
|
||||
ncurses::BUTTON4_RELEASED
|
||||
| ncurses::BUTTON4_PRESSED
|
||||
| ncurses::BUTTON4_CLICKED
|
||||
| ncurses::BUTTON4_DOUBLE_CLICKED
|
||||
| ncurses::BUTTON4_TRIPLE_CLICKED => MouseButton::Button4,
|
||||
ncurses::BUTTON5_RELEASED
|
||||
| ncurses::BUTTON5_PRESSED
|
||||
| ncurses::BUTTON5_CLICKED
|
||||
| ncurses::BUTTON5_DOUBLE_CLICKED
|
||||
| ncurses::BUTTON5_TRIPLE_CLICKED => MouseButton::Button5,
|
||||
_ => MouseButton::Other,
|
||||
}
|
||||
}
|
||||
@ -328,36 +325,36 @@ where
|
||||
match bare_event {
|
||||
ncurses::BUTTON4_PRESSED => f(MouseEvent::WheelUp),
|
||||
ncurses::BUTTON5_PRESSED => f(MouseEvent::WheelDown),
|
||||
ncurses::BUTTON1_RELEASED |
|
||||
ncurses::BUTTON2_RELEASED |
|
||||
ncurses::BUTTON3_RELEASED |
|
||||
ncurses::BUTTON4_RELEASED |
|
||||
ncurses::BUTTON5_RELEASED => f(MouseEvent::Release(button)),
|
||||
ncurses::BUTTON1_PRESSED |
|
||||
ncurses::BUTTON2_PRESSED |
|
||||
ncurses::BUTTON3_PRESSED => f(MouseEvent::Press(button)),
|
||||
ncurses::BUTTON1_CLICKED |
|
||||
ncurses::BUTTON2_CLICKED |
|
||||
ncurses::BUTTON3_CLICKED |
|
||||
ncurses::BUTTON4_CLICKED |
|
||||
ncurses::BUTTON5_CLICKED => {
|
||||
ncurses::BUTTON1_RELEASED
|
||||
| ncurses::BUTTON2_RELEASED
|
||||
| ncurses::BUTTON3_RELEASED
|
||||
| ncurses::BUTTON4_RELEASED
|
||||
| ncurses::BUTTON5_RELEASED => f(MouseEvent::Release(button)),
|
||||
ncurses::BUTTON1_PRESSED
|
||||
| ncurses::BUTTON2_PRESSED
|
||||
| ncurses::BUTTON3_PRESSED => f(MouseEvent::Press(button)),
|
||||
ncurses::BUTTON1_CLICKED
|
||||
| ncurses::BUTTON2_CLICKED
|
||||
| ncurses::BUTTON3_CLICKED
|
||||
| ncurses::BUTTON4_CLICKED
|
||||
| ncurses::BUTTON5_CLICKED => {
|
||||
f(MouseEvent::Press(button));
|
||||
f(MouseEvent::Release(button));
|
||||
}
|
||||
// Well, we disabled click detection
|
||||
ncurses::BUTTON1_DOUBLE_CLICKED |
|
||||
ncurses::BUTTON2_DOUBLE_CLICKED |
|
||||
ncurses::BUTTON3_DOUBLE_CLICKED |
|
||||
ncurses::BUTTON4_DOUBLE_CLICKED |
|
||||
ncurses::BUTTON5_DOUBLE_CLICKED => for _ in 0..2 {
|
||||
ncurses::BUTTON1_DOUBLE_CLICKED
|
||||
| ncurses::BUTTON2_DOUBLE_CLICKED
|
||||
| ncurses::BUTTON3_DOUBLE_CLICKED
|
||||
| ncurses::BUTTON4_DOUBLE_CLICKED
|
||||
| ncurses::BUTTON5_DOUBLE_CLICKED => for _ in 0..2 {
|
||||
f(MouseEvent::Press(button));
|
||||
f(MouseEvent::Release(button));
|
||||
},
|
||||
ncurses::BUTTON1_TRIPLE_CLICKED |
|
||||
ncurses::BUTTON2_TRIPLE_CLICKED |
|
||||
ncurses::BUTTON3_TRIPLE_CLICKED |
|
||||
ncurses::BUTTON4_TRIPLE_CLICKED |
|
||||
ncurses::BUTTON5_TRIPLE_CLICKED => for _ in 0..3 {
|
||||
ncurses::BUTTON1_TRIPLE_CLICKED
|
||||
| ncurses::BUTTON2_TRIPLE_CLICKED
|
||||
| ncurses::BUTTON3_TRIPLE_CLICKED
|
||||
| ncurses::BUTTON4_TRIPLE_CLICKED
|
||||
| ncurses::BUTTON5_TRIPLE_CLICKED => for _ in 0..3 {
|
||||
f(MouseEvent::Press(button));
|
||||
f(MouseEvent::Release(button));
|
||||
},
|
||||
|
@ -73,27 +73,20 @@ impl Concrete {
|
||||
Ok(event) => event,
|
||||
};
|
||||
|
||||
let _shift =
|
||||
(mevent.bstate & pancurses::BUTTON_SHIFT as mmask_t) != 0;
|
||||
let _alt =
|
||||
(mevent.bstate & pancurses::BUTTON_ALT as mmask_t) != 0;
|
||||
let _ctrl =
|
||||
(mevent.bstate & pancurses::BUTTON_CTRL as mmask_t) != 0;
|
||||
let _shift = (mevent.bstate & pancurses::BUTTON_SHIFT as mmask_t) != 0;
|
||||
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
|
||||
| pancurses::BUTTON_CTRL)
|
||||
as mmask_t;
|
||||
| pancurses::BUTTON_CTRL) as mmask_t;
|
||||
|
||||
let make_event = |event| {
|
||||
Event::Mouse {
|
||||
offset: Vec2::zero(),
|
||||
position: Vec2::new(mevent.x as usize, mevent.y as usize),
|
||||
event: event,
|
||||
}
|
||||
let make_event = |event| Event::Mouse {
|
||||
offset: Vec2::zero(),
|
||||
position: Vec2::new(mevent.x as usize, mevent.y as usize),
|
||||
event: event,
|
||||
};
|
||||
|
||||
if mevent.bstate == pancurses::REPORT_MOUSE_POSITION as mmask_t
|
||||
{
|
||||
if mevent.bstate == pancurses::REPORT_MOUSE_POSITION as mmask_t {
|
||||
// The event is either a mouse drag event,
|
||||
// or a weird double-release event. :S
|
||||
self.last_mouse_button
|
||||
@ -221,206 +214,216 @@ impl backend::Backend for Concrete {
|
||||
|
||||
fn poll_event(&mut self) -> Event {
|
||||
self.event_queue.pop().unwrap_or_else(|| {
|
||||
if let Some(ev) = self.window.getch() {
|
||||
match ev {
|
||||
pancurses::Input::Character('\n') => Event::Key(Key::Enter),
|
||||
// TODO: wait for a very short delay. If more keys are
|
||||
// pipelined, it may be an escape sequence.
|
||||
pancurses::Input::Character('\u{7f}') |
|
||||
pancurses::Input::Character('\u{8}') => {
|
||||
Event::Key(Key::Backspace)
|
||||
}
|
||||
pancurses::Input::Character('\u{9}') => Event::Key(Key::Tab),
|
||||
pancurses::Input::Character('\u{1b}') => Event::Key(Key::Esc),
|
||||
pancurses::Input::Character(c)
|
||||
if 32 <= (c as u32) && (c as u32) <= 255 =>
|
||||
{
|
||||
Event::Char(
|
||||
utf8::read_char(c as u8, || {
|
||||
self.window.getch().and_then(|i| match i {
|
||||
pancurses::Input::Character(c) => {
|
||||
Some(c as u8)
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
}).unwrap(),
|
||||
)
|
||||
}
|
||||
pancurses::Input::Character(c) if (c as u32) <= 26 => {
|
||||
Event::CtrlChar((b'a' - 1 + c as u8) as char)
|
||||
}
|
||||
pancurses::Input::Character(c) => {
|
||||
let mut bytes = [0u8; 4];
|
||||
Event::Unknown(
|
||||
c.encode_utf8(&mut bytes).as_bytes().to_vec(),
|
||||
)
|
||||
}
|
||||
// TODO: Some key combos are not recognized by pancurses,
|
||||
// but are sent as Unknown. We could still parse them here.
|
||||
pancurses::Input::Unknown(code) => match code {
|
||||
220 => Event::Ctrl(Key::Del),
|
||||
|
||||
224 => Event::Alt(Key::Down),
|
||||
225 => Event::AltShift(Key::Down),
|
||||
226 => Event::Ctrl(Key::Down),
|
||||
227 => Event::CtrlShift(Key::Down),
|
||||
|
||||
229 => Event::Alt(Key::End),
|
||||
230 => Event::AltShift(Key::End),
|
||||
231 => Event::Ctrl(Key::End),
|
||||
232 => Event::CtrlShift(Key::End),
|
||||
|
||||
235 => Event::Alt(Key::Home),
|
||||
236 => Event::AltShift(Key::Home),
|
||||
237 => Event::Ctrl(Key::Home),
|
||||
238 => Event::CtrlShift(Key::Home),
|
||||
|
||||
246 => Event::Alt(Key::Left),
|
||||
247 => Event::AltShift(Key::Left),
|
||||
248 => Event::Ctrl(Key::Left),
|
||||
249 => Event::CtrlShift(Key::Left),
|
||||
|
||||
251 => Event::Alt(Key::PageDown),
|
||||
252 => Event::AltShift(Key::PageDown),
|
||||
253 => Event::Ctrl(Key::PageDown),
|
||||
254 => Event::CtrlShift(Key::PageDown),
|
||||
|
||||
256 => Event::Alt(Key::PageUp),
|
||||
257 => Event::AltShift(Key::PageUp),
|
||||
258 => Event::Ctrl(Key::PageUp),
|
||||
259 => Event::CtrlShift(Key::PageUp),
|
||||
|
||||
261 => Event::Alt(Key::Right),
|
||||
262 => Event::AltShift(Key::Right),
|
||||
263 => Event::Ctrl(Key::Right),
|
||||
264 => Event::CtrlShift(Key::Right),
|
||||
|
||||
267 => Event::Alt(Key::Up),
|
||||
268 => Event::AltShift(Key::Up),
|
||||
269 => Event::Ctrl(Key::Up),
|
||||
270 => Event::CtrlShift(Key::Up),
|
||||
other => {
|
||||
warn!("Unknown: {}", other);
|
||||
Event::Unknown(split_i32(other))
|
||||
if let Some(ev) = self.window.getch() {
|
||||
match ev {
|
||||
pancurses::Input::Character('\n') => {
|
||||
Event::Key(Key::Enter)
|
||||
}
|
||||
},
|
||||
// TODO: I honestly have no fucking idea what KeyCodeYes is
|
||||
pancurses::Input::KeyCodeYes => Event::Refresh,
|
||||
pancurses::Input::KeyBreak => Event::Key(Key::PauseBreak),
|
||||
pancurses::Input::KeyDown => Event::Key(Key::Down),
|
||||
pancurses::Input::KeyUp => Event::Key(Key::Up),
|
||||
pancurses::Input::KeyLeft => Event::Key(Key::Left),
|
||||
pancurses::Input::KeyRight => Event::Key(Key::Right),
|
||||
pancurses::Input::KeyHome => Event::Key(Key::Home),
|
||||
pancurses::Input::KeyBackspace => Event::Key(Key::Backspace),
|
||||
pancurses::Input::KeyF0 => Event::Key(Key::F0),
|
||||
pancurses::Input::KeyF1 => Event::Key(Key::F1),
|
||||
pancurses::Input::KeyF2 => Event::Key(Key::F2),
|
||||
pancurses::Input::KeyF3 => Event::Key(Key::F3),
|
||||
pancurses::Input::KeyF4 => Event::Key(Key::F4),
|
||||
pancurses::Input::KeyF5 => Event::Key(Key::F5),
|
||||
pancurses::Input::KeyF6 => Event::Key(Key::F6),
|
||||
pancurses::Input::KeyF7 => Event::Key(Key::F7),
|
||||
pancurses::Input::KeyF8 => Event::Key(Key::F8),
|
||||
pancurses::Input::KeyF9 => Event::Key(Key::F9),
|
||||
pancurses::Input::KeyF10 => Event::Key(Key::F10),
|
||||
pancurses::Input::KeyF11 => Event::Key(Key::F11),
|
||||
pancurses::Input::KeyF12 => Event::Key(Key::F12),
|
||||
pancurses::Input::KeyF13 => Event::Shift(Key::F1),
|
||||
pancurses::Input::KeyF14 => Event::Shift(Key::F2),
|
||||
pancurses::Input::KeyF15 => Event::Shift(Key::F3),
|
||||
pancurses::Input::KeyDL => Event::Refresh,
|
||||
pancurses::Input::KeyIL => Event::Refresh,
|
||||
pancurses::Input::KeyDC => Event::Key(Key::Del),
|
||||
pancurses::Input::KeyIC => Event::Key(Key::Ins),
|
||||
pancurses::Input::KeyEIC => Event::Refresh,
|
||||
pancurses::Input::KeyClear => Event::Refresh,
|
||||
pancurses::Input::KeyEOS => Event::Refresh,
|
||||
pancurses::Input::KeyEOL => Event::Refresh,
|
||||
pancurses::Input::KeySF => Event::Shift(Key::Down),
|
||||
pancurses::Input::KeySR => Event::Shift(Key::Up),
|
||||
pancurses::Input::KeyNPage => Event::Key(Key::PageDown),
|
||||
pancurses::Input::KeyPPage => Event::Key(Key::PageUp),
|
||||
pancurses::Input::KeySTab => Event::Shift(Key::Tab),
|
||||
pancurses::Input::KeyCTab => Event::Ctrl(Key::Tab),
|
||||
pancurses::Input::KeyCATab => Event::CtrlAlt(Key::Tab),
|
||||
pancurses::Input::KeyEnter => Event::Key(Key::Enter),
|
||||
pancurses::Input::KeySReset => Event::Refresh,
|
||||
pancurses::Input::KeyReset => Event::Refresh,
|
||||
pancurses::Input::KeyPrint => Event::Refresh,
|
||||
pancurses::Input::KeyLL => Event::Refresh,
|
||||
pancurses::Input::KeyAbort => Event::Refresh,
|
||||
pancurses::Input::KeySHelp => Event::Refresh,
|
||||
pancurses::Input::KeyLHelp => Event::Refresh,
|
||||
pancurses::Input::KeyBTab => Event::Shift(Key::Tab),
|
||||
pancurses::Input::KeyBeg => Event::Refresh,
|
||||
pancurses::Input::KeyCancel => Event::Refresh,
|
||||
pancurses::Input::KeyClose => Event::Refresh,
|
||||
pancurses::Input::KeyCommand => Event::Refresh,
|
||||
pancurses::Input::KeyCopy => Event::Refresh,
|
||||
pancurses::Input::KeyCreate => Event::Refresh,
|
||||
pancurses::Input::KeyEnd => Event::Key(Key::End),
|
||||
pancurses::Input::KeyExit => Event::Refresh,
|
||||
pancurses::Input::KeyFind => Event::Refresh,
|
||||
pancurses::Input::KeyHelp => Event::Refresh,
|
||||
pancurses::Input::KeyMark => Event::Refresh,
|
||||
pancurses::Input::KeyMessage => Event::Refresh,
|
||||
pancurses::Input::KeyMove => Event::Refresh,
|
||||
pancurses::Input::KeyNext => Event::Refresh,
|
||||
pancurses::Input::KeyOpen => Event::Refresh,
|
||||
pancurses::Input::KeyOptions => Event::Refresh,
|
||||
pancurses::Input::KeyPrevious => Event::Refresh,
|
||||
pancurses::Input::KeyRedo => Event::Refresh,
|
||||
pancurses::Input::KeyReference => Event::Refresh,
|
||||
pancurses::Input::KeyRefresh => Event::Refresh,
|
||||
pancurses::Input::KeyReplace => Event::Refresh,
|
||||
pancurses::Input::KeyRestart => Event::Refresh,
|
||||
pancurses::Input::KeyResume => Event::Refresh,
|
||||
pancurses::Input::KeySave => Event::Refresh,
|
||||
pancurses::Input::KeySBeg => Event::Refresh,
|
||||
pancurses::Input::KeySCancel => Event::Refresh,
|
||||
pancurses::Input::KeySCommand => Event::Refresh,
|
||||
pancurses::Input::KeySCopy => Event::Refresh,
|
||||
pancurses::Input::KeySCreate => Event::Refresh,
|
||||
pancurses::Input::KeySDC => Event::Shift(Key::Del),
|
||||
pancurses::Input::KeySDL => Event::Refresh,
|
||||
pancurses::Input::KeySelect => Event::Refresh,
|
||||
pancurses::Input::KeySEnd => Event::Shift(Key::End),
|
||||
pancurses::Input::KeySEOL => Event::Refresh,
|
||||
pancurses::Input::KeySExit => Event::Refresh,
|
||||
pancurses::Input::KeySFind => Event::Refresh,
|
||||
pancurses::Input::KeySHome => Event::Shift(Key::Home),
|
||||
pancurses::Input::KeySIC => Event::Shift(Key::Ins),
|
||||
pancurses::Input::KeySLeft => Event::Shift(Key::Left),
|
||||
pancurses::Input::KeySMessage => Event::Refresh,
|
||||
pancurses::Input::KeySMove => Event::Refresh,
|
||||
pancurses::Input::KeySNext => Event::Shift(Key::PageDown),
|
||||
pancurses::Input::KeySOptions => Event::Refresh,
|
||||
pancurses::Input::KeySPrevious => Event::Shift(Key::PageUp),
|
||||
pancurses::Input::KeySPrint => Event::Refresh,
|
||||
pancurses::Input::KeySRedo => Event::Refresh,
|
||||
pancurses::Input::KeySReplace => Event::Refresh,
|
||||
pancurses::Input::KeySRight => Event::Shift(Key::Right),
|
||||
pancurses::Input::KeySResume => Event::Refresh,
|
||||
pancurses::Input::KeySSave => Event::Refresh,
|
||||
pancurses::Input::KeySSuspend => Event::Refresh,
|
||||
pancurses::Input::KeySUndo => Event::Refresh,
|
||||
pancurses::Input::KeySuspend => Event::Refresh,
|
||||
pancurses::Input::KeyUndo => Event::Refresh,
|
||||
pancurses::Input::KeyResize => Event::WindowResize,
|
||||
pancurses::Input::KeyEvent => Event::Refresh,
|
||||
// TODO: mouse support
|
||||
pancurses::Input::KeyMouse => self.parse_mouse_event(),
|
||||
pancurses::Input::KeyA1 => Event::Refresh,
|
||||
pancurses::Input::KeyA3 => Event::Refresh,
|
||||
pancurses::Input::KeyB2 => Event::Key(Key::NumpadCenter),
|
||||
pancurses::Input::KeyC1 => Event::Refresh,
|
||||
pancurses::Input::KeyC3 => Event::Refresh,
|
||||
// TODO: wait for a very short delay. If more keys are
|
||||
// pipelined, it may be an escape sequence.
|
||||
pancurses::Input::Character('\u{7f}')
|
||||
| pancurses::Input::Character('\u{8}') => {
|
||||
Event::Key(Key::Backspace)
|
||||
}
|
||||
pancurses::Input::Character('\u{9}') => {
|
||||
Event::Key(Key::Tab)
|
||||
}
|
||||
pancurses::Input::Character('\u{1b}') => {
|
||||
Event::Key(Key::Esc)
|
||||
}
|
||||
pancurses::Input::Character(c)
|
||||
if 32 <= (c as u32) && (c as u32) <= 255 =>
|
||||
{
|
||||
Event::Char(
|
||||
utf8::read_char(c as u8, || {
|
||||
self.window.getch().and_then(|i| match i {
|
||||
pancurses::Input::Character(c) => {
|
||||
Some(c as u8)
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
}).unwrap(),
|
||||
)
|
||||
}
|
||||
pancurses::Input::Character(c) if (c as u32) <= 26 => {
|
||||
Event::CtrlChar((b'a' - 1 + c as u8) as char)
|
||||
}
|
||||
pancurses::Input::Character(c) => {
|
||||
let mut bytes = [0u8; 4];
|
||||
Event::Unknown(
|
||||
c.encode_utf8(&mut bytes).as_bytes().to_vec(),
|
||||
)
|
||||
}
|
||||
// TODO: Some key combos are not recognized by pancurses,
|
||||
// but are sent as Unknown. We could still parse them here.
|
||||
pancurses::Input::Unknown(code) => match code {
|
||||
220 => Event::Ctrl(Key::Del),
|
||||
|
||||
224 => Event::Alt(Key::Down),
|
||||
225 => Event::AltShift(Key::Down),
|
||||
226 => Event::Ctrl(Key::Down),
|
||||
227 => Event::CtrlShift(Key::Down),
|
||||
|
||||
229 => Event::Alt(Key::End),
|
||||
230 => Event::AltShift(Key::End),
|
||||
231 => Event::Ctrl(Key::End),
|
||||
232 => Event::CtrlShift(Key::End),
|
||||
|
||||
235 => Event::Alt(Key::Home),
|
||||
236 => Event::AltShift(Key::Home),
|
||||
237 => Event::Ctrl(Key::Home),
|
||||
238 => Event::CtrlShift(Key::Home),
|
||||
|
||||
246 => Event::Alt(Key::Left),
|
||||
247 => Event::AltShift(Key::Left),
|
||||
248 => Event::Ctrl(Key::Left),
|
||||
249 => Event::CtrlShift(Key::Left),
|
||||
|
||||
251 => Event::Alt(Key::PageDown),
|
||||
252 => Event::AltShift(Key::PageDown),
|
||||
253 => Event::Ctrl(Key::PageDown),
|
||||
254 => Event::CtrlShift(Key::PageDown),
|
||||
|
||||
256 => Event::Alt(Key::PageUp),
|
||||
257 => Event::AltShift(Key::PageUp),
|
||||
258 => Event::Ctrl(Key::PageUp),
|
||||
259 => Event::CtrlShift(Key::PageUp),
|
||||
|
||||
261 => Event::Alt(Key::Right),
|
||||
262 => Event::AltShift(Key::Right),
|
||||
263 => Event::Ctrl(Key::Right),
|
||||
264 => Event::CtrlShift(Key::Right),
|
||||
|
||||
267 => Event::Alt(Key::Up),
|
||||
268 => Event::AltShift(Key::Up),
|
||||
269 => Event::Ctrl(Key::Up),
|
||||
270 => Event::CtrlShift(Key::Up),
|
||||
other => {
|
||||
warn!("Unknown: {}", other);
|
||||
Event::Unknown(split_i32(other))
|
||||
}
|
||||
},
|
||||
// TODO: I honestly have no fucking idea what KeyCodeYes is
|
||||
pancurses::Input::KeyCodeYes => Event::Refresh,
|
||||
pancurses::Input::KeyBreak => Event::Key(Key::PauseBreak),
|
||||
pancurses::Input::KeyDown => Event::Key(Key::Down),
|
||||
pancurses::Input::KeyUp => Event::Key(Key::Up),
|
||||
pancurses::Input::KeyLeft => Event::Key(Key::Left),
|
||||
pancurses::Input::KeyRight => Event::Key(Key::Right),
|
||||
pancurses::Input::KeyHome => Event::Key(Key::Home),
|
||||
pancurses::Input::KeyBackspace => {
|
||||
Event::Key(Key::Backspace)
|
||||
}
|
||||
pancurses::Input::KeyF0 => Event::Key(Key::F0),
|
||||
pancurses::Input::KeyF1 => Event::Key(Key::F1),
|
||||
pancurses::Input::KeyF2 => Event::Key(Key::F2),
|
||||
pancurses::Input::KeyF3 => Event::Key(Key::F3),
|
||||
pancurses::Input::KeyF4 => Event::Key(Key::F4),
|
||||
pancurses::Input::KeyF5 => Event::Key(Key::F5),
|
||||
pancurses::Input::KeyF6 => Event::Key(Key::F6),
|
||||
pancurses::Input::KeyF7 => Event::Key(Key::F7),
|
||||
pancurses::Input::KeyF8 => Event::Key(Key::F8),
|
||||
pancurses::Input::KeyF9 => Event::Key(Key::F9),
|
||||
pancurses::Input::KeyF10 => Event::Key(Key::F10),
|
||||
pancurses::Input::KeyF11 => Event::Key(Key::F11),
|
||||
pancurses::Input::KeyF12 => Event::Key(Key::F12),
|
||||
pancurses::Input::KeyF13 => Event::Shift(Key::F1),
|
||||
pancurses::Input::KeyF14 => Event::Shift(Key::F2),
|
||||
pancurses::Input::KeyF15 => Event::Shift(Key::F3),
|
||||
pancurses::Input::KeyDL => Event::Refresh,
|
||||
pancurses::Input::KeyIL => Event::Refresh,
|
||||
pancurses::Input::KeyDC => Event::Key(Key::Del),
|
||||
pancurses::Input::KeyIC => Event::Key(Key::Ins),
|
||||
pancurses::Input::KeyEIC => Event::Refresh,
|
||||
pancurses::Input::KeyClear => Event::Refresh,
|
||||
pancurses::Input::KeyEOS => Event::Refresh,
|
||||
pancurses::Input::KeyEOL => Event::Refresh,
|
||||
pancurses::Input::KeySF => Event::Shift(Key::Down),
|
||||
pancurses::Input::KeySR => Event::Shift(Key::Up),
|
||||
pancurses::Input::KeyNPage => Event::Key(Key::PageDown),
|
||||
pancurses::Input::KeyPPage => Event::Key(Key::PageUp),
|
||||
pancurses::Input::KeySTab => Event::Shift(Key::Tab),
|
||||
pancurses::Input::KeyCTab => Event::Ctrl(Key::Tab),
|
||||
pancurses::Input::KeyCATab => Event::CtrlAlt(Key::Tab),
|
||||
pancurses::Input::KeyEnter => Event::Key(Key::Enter),
|
||||
pancurses::Input::KeySReset => Event::Refresh,
|
||||
pancurses::Input::KeyReset => Event::Refresh,
|
||||
pancurses::Input::KeyPrint => Event::Refresh,
|
||||
pancurses::Input::KeyLL => Event::Refresh,
|
||||
pancurses::Input::KeyAbort => Event::Refresh,
|
||||
pancurses::Input::KeySHelp => Event::Refresh,
|
||||
pancurses::Input::KeyLHelp => Event::Refresh,
|
||||
pancurses::Input::KeyBTab => Event::Shift(Key::Tab),
|
||||
pancurses::Input::KeyBeg => Event::Refresh,
|
||||
pancurses::Input::KeyCancel => Event::Refresh,
|
||||
pancurses::Input::KeyClose => Event::Refresh,
|
||||
pancurses::Input::KeyCommand => Event::Refresh,
|
||||
pancurses::Input::KeyCopy => Event::Refresh,
|
||||
pancurses::Input::KeyCreate => Event::Refresh,
|
||||
pancurses::Input::KeyEnd => Event::Key(Key::End),
|
||||
pancurses::Input::KeyExit => Event::Refresh,
|
||||
pancurses::Input::KeyFind => Event::Refresh,
|
||||
pancurses::Input::KeyHelp => Event::Refresh,
|
||||
pancurses::Input::KeyMark => Event::Refresh,
|
||||
pancurses::Input::KeyMessage => Event::Refresh,
|
||||
pancurses::Input::KeyMove => Event::Refresh,
|
||||
pancurses::Input::KeyNext => Event::Refresh,
|
||||
pancurses::Input::KeyOpen => Event::Refresh,
|
||||
pancurses::Input::KeyOptions => Event::Refresh,
|
||||
pancurses::Input::KeyPrevious => Event::Refresh,
|
||||
pancurses::Input::KeyRedo => Event::Refresh,
|
||||
pancurses::Input::KeyReference => Event::Refresh,
|
||||
pancurses::Input::KeyRefresh => Event::Refresh,
|
||||
pancurses::Input::KeyReplace => Event::Refresh,
|
||||
pancurses::Input::KeyRestart => Event::Refresh,
|
||||
pancurses::Input::KeyResume => Event::Refresh,
|
||||
pancurses::Input::KeySave => Event::Refresh,
|
||||
pancurses::Input::KeySBeg => Event::Refresh,
|
||||
pancurses::Input::KeySCancel => Event::Refresh,
|
||||
pancurses::Input::KeySCommand => Event::Refresh,
|
||||
pancurses::Input::KeySCopy => Event::Refresh,
|
||||
pancurses::Input::KeySCreate => Event::Refresh,
|
||||
pancurses::Input::KeySDC => Event::Shift(Key::Del),
|
||||
pancurses::Input::KeySDL => Event::Refresh,
|
||||
pancurses::Input::KeySelect => Event::Refresh,
|
||||
pancurses::Input::KeySEnd => Event::Shift(Key::End),
|
||||
pancurses::Input::KeySEOL => Event::Refresh,
|
||||
pancurses::Input::KeySExit => Event::Refresh,
|
||||
pancurses::Input::KeySFind => Event::Refresh,
|
||||
pancurses::Input::KeySHome => Event::Shift(Key::Home),
|
||||
pancurses::Input::KeySIC => Event::Shift(Key::Ins),
|
||||
pancurses::Input::KeySLeft => Event::Shift(Key::Left),
|
||||
pancurses::Input::KeySMessage => Event::Refresh,
|
||||
pancurses::Input::KeySMove => Event::Refresh,
|
||||
pancurses::Input::KeySNext => Event::Shift(Key::PageDown),
|
||||
pancurses::Input::KeySOptions => Event::Refresh,
|
||||
pancurses::Input::KeySPrevious => {
|
||||
Event::Shift(Key::PageUp)
|
||||
}
|
||||
pancurses::Input::KeySPrint => Event::Refresh,
|
||||
pancurses::Input::KeySRedo => Event::Refresh,
|
||||
pancurses::Input::KeySReplace => Event::Refresh,
|
||||
pancurses::Input::KeySRight => Event::Shift(Key::Right),
|
||||
pancurses::Input::KeySResume => Event::Refresh,
|
||||
pancurses::Input::KeySSave => Event::Refresh,
|
||||
pancurses::Input::KeySSuspend => Event::Refresh,
|
||||
pancurses::Input::KeySUndo => Event::Refresh,
|
||||
pancurses::Input::KeySuspend => Event::Refresh,
|
||||
pancurses::Input::KeyUndo => Event::Refresh,
|
||||
pancurses::Input::KeyResize => Event::WindowResize,
|
||||
pancurses::Input::KeyEvent => Event::Refresh,
|
||||
// TODO: mouse support
|
||||
pancurses::Input::KeyMouse => self.parse_mouse_event(),
|
||||
pancurses::Input::KeyA1 => Event::Refresh,
|
||||
pancurses::Input::KeyA3 => Event::Refresh,
|
||||
pancurses::Input::KeyB2 => Event::Key(Key::NumpadCenter),
|
||||
pancurses::Input::KeyC1 => Event::Refresh,
|
||||
pancurses::Input::KeyC3 => Event::Refresh,
|
||||
}
|
||||
} else {
|
||||
Event::Refresh
|
||||
}
|
||||
} else {
|
||||
Event::Refresh
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn set_refresh_rate(&mut self, fps: u32) {
|
||||
@ -447,36 +450,36 @@ where
|
||||
match bare_event {
|
||||
pancurses::BUTTON4_PRESSED => f(MouseEvent::WheelUp),
|
||||
pancurses::BUTTON5_PRESSED => f(MouseEvent::WheelDown),
|
||||
pancurses::BUTTON1_RELEASED |
|
||||
pancurses::BUTTON2_RELEASED |
|
||||
pancurses::BUTTON3_RELEASED |
|
||||
pancurses::BUTTON4_RELEASED |
|
||||
pancurses::BUTTON5_RELEASED => f(MouseEvent::Release(button)),
|
||||
pancurses::BUTTON1_PRESSED |
|
||||
pancurses::BUTTON2_PRESSED |
|
||||
pancurses::BUTTON3_PRESSED => f(MouseEvent::Press(button)),
|
||||
pancurses::BUTTON1_CLICKED |
|
||||
pancurses::BUTTON2_CLICKED |
|
||||
pancurses::BUTTON3_CLICKED |
|
||||
pancurses::BUTTON4_CLICKED |
|
||||
pancurses::BUTTON5_CLICKED => {
|
||||
pancurses::BUTTON1_RELEASED
|
||||
| pancurses::BUTTON2_RELEASED
|
||||
| pancurses::BUTTON3_RELEASED
|
||||
| pancurses::BUTTON4_RELEASED
|
||||
| pancurses::BUTTON5_RELEASED => f(MouseEvent::Release(button)),
|
||||
pancurses::BUTTON1_PRESSED
|
||||
| pancurses::BUTTON2_PRESSED
|
||||
| pancurses::BUTTON3_PRESSED => f(MouseEvent::Press(button)),
|
||||
pancurses::BUTTON1_CLICKED
|
||||
| pancurses::BUTTON2_CLICKED
|
||||
| pancurses::BUTTON3_CLICKED
|
||||
| pancurses::BUTTON4_CLICKED
|
||||
| pancurses::BUTTON5_CLICKED => {
|
||||
f(MouseEvent::Press(button));
|
||||
f(MouseEvent::Release(button));
|
||||
}
|
||||
// Well, we disabled click detection
|
||||
pancurses::BUTTON1_DOUBLE_CLICKED |
|
||||
pancurses::BUTTON2_DOUBLE_CLICKED |
|
||||
pancurses::BUTTON3_DOUBLE_CLICKED |
|
||||
pancurses::BUTTON4_DOUBLE_CLICKED |
|
||||
pancurses::BUTTON5_DOUBLE_CLICKED => for _ in 0..2 {
|
||||
pancurses::BUTTON1_DOUBLE_CLICKED
|
||||
| pancurses::BUTTON2_DOUBLE_CLICKED
|
||||
| pancurses::BUTTON3_DOUBLE_CLICKED
|
||||
| pancurses::BUTTON4_DOUBLE_CLICKED
|
||||
| pancurses::BUTTON5_DOUBLE_CLICKED => for _ in 0..2 {
|
||||
f(MouseEvent::Press(button));
|
||||
f(MouseEvent::Release(button));
|
||||
},
|
||||
pancurses::BUTTON1_TRIPLE_CLICKED |
|
||||
pancurses::BUTTON2_TRIPLE_CLICKED |
|
||||
pancurses::BUTTON3_TRIPLE_CLICKED |
|
||||
pancurses::BUTTON4_TRIPLE_CLICKED |
|
||||
pancurses::BUTTON5_TRIPLE_CLICKED => for _ in 0..3 {
|
||||
pancurses::BUTTON1_TRIPLE_CLICKED
|
||||
| pancurses::BUTTON2_TRIPLE_CLICKED
|
||||
| pancurses::BUTTON3_TRIPLE_CLICKED
|
||||
| pancurses::BUTTON4_TRIPLE_CLICKED
|
||||
| pancurses::BUTTON5_TRIPLE_CLICKED => for _ in 0..3 {
|
||||
f(MouseEvent::Press(button));
|
||||
f(MouseEvent::Release(button));
|
||||
},
|
||||
@ -487,32 +490,31 @@ where
|
||||
/// Returns the Key enum corresponding to the given pancurses event.
|
||||
fn get_mouse_button(bare_event: mmask_t) -> MouseButton {
|
||||
match bare_event {
|
||||
pancurses::BUTTON1_RELEASED |
|
||||
pancurses::BUTTON1_PRESSED |
|
||||
pancurses::BUTTON1_CLICKED |
|
||||
pancurses::BUTTON1_DOUBLE_CLICKED |
|
||||
pancurses::BUTTON1_TRIPLE_CLICKED => MouseButton::Left,
|
||||
pancurses::BUTTON2_RELEASED |
|
||||
pancurses::BUTTON2_PRESSED |
|
||||
pancurses::BUTTON2_CLICKED |
|
||||
pancurses::BUTTON2_DOUBLE_CLICKED |
|
||||
pancurses::BUTTON2_TRIPLE_CLICKED => MouseButton::Middle,
|
||||
pancurses::BUTTON3_RELEASED |
|
||||
pancurses::BUTTON3_PRESSED |
|
||||
pancurses::BUTTON3_CLICKED |
|
||||
pancurses::BUTTON3_DOUBLE_CLICKED |
|
||||
pancurses::BUTTON3_TRIPLE_CLICKED => MouseButton::Right,
|
||||
pancurses::BUTTON4_RELEASED |
|
||||
pancurses::BUTTON4_PRESSED |
|
||||
pancurses::BUTTON4_CLICKED |
|
||||
pancurses::BUTTON4_DOUBLE_CLICKED |
|
||||
pancurses::BUTTON4_TRIPLE_CLICKED => MouseButton::Button4,
|
||||
pancurses::BUTTON5_RELEASED |
|
||||
pancurses::BUTTON5_PRESSED |
|
||||
pancurses::BUTTON5_CLICKED |
|
||||
pancurses::BUTTON5_DOUBLE_CLICKED |
|
||||
pancurses::BUTTON5_TRIPLE_CLICKED => MouseButton::Button5,
|
||||
pancurses::BUTTON1_RELEASED
|
||||
| pancurses::BUTTON1_PRESSED
|
||||
| pancurses::BUTTON1_CLICKED
|
||||
| pancurses::BUTTON1_DOUBLE_CLICKED
|
||||
| pancurses::BUTTON1_TRIPLE_CLICKED => MouseButton::Left,
|
||||
pancurses::BUTTON2_RELEASED
|
||||
| pancurses::BUTTON2_PRESSED
|
||||
| pancurses::BUTTON2_CLICKED
|
||||
| pancurses::BUTTON2_DOUBLE_CLICKED
|
||||
| pancurses::BUTTON2_TRIPLE_CLICKED => MouseButton::Middle,
|
||||
pancurses::BUTTON3_RELEASED
|
||||
| pancurses::BUTTON3_PRESSED
|
||||
| pancurses::BUTTON3_CLICKED
|
||||
| pancurses::BUTTON3_DOUBLE_CLICKED
|
||||
| pancurses::BUTTON3_TRIPLE_CLICKED => MouseButton::Right,
|
||||
pancurses::BUTTON4_RELEASED
|
||||
| pancurses::BUTTON4_PRESSED
|
||||
| pancurses::BUTTON4_CLICKED
|
||||
| pancurses::BUTTON4_DOUBLE_CLICKED
|
||||
| pancurses::BUTTON4_TRIPLE_CLICKED => MouseButton::Button4,
|
||||
pancurses::BUTTON5_RELEASED
|
||||
| pancurses::BUTTON5_PRESSED
|
||||
| pancurses::BUTTON5_CLICKED
|
||||
| pancurses::BUTTON5_DOUBLE_CLICKED
|
||||
| pancurses::BUTTON5_TRIPLE_CLICKED => MouseButton::Button5,
|
||||
_ => MouseButton::Other,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -143,9 +143,11 @@ impl backend::Backend for Concrete {
|
||||
|
||||
let (sender, receiver) = chan::async();
|
||||
|
||||
thread::spawn(move || for key in ::std::io::stdin().events() {
|
||||
if let Ok(key) = key {
|
||||
sender.send(key)
|
||||
thread::spawn(move || {
|
||||
for key in ::std::io::stdin().events() {
|
||||
if let Ok(key) = key {
|
||||
sender.send(key)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -464,7 +464,6 @@ impl Cursive {
|
||||
self.running
|
||||
}
|
||||
|
||||
|
||||
/// Runs the event loop.
|
||||
///
|
||||
/// It will wait for user input (key presses)
|
||||
|
@ -198,10 +198,10 @@ impl Absolute {
|
||||
/// orientation (ex: `Left` and `Vertical`).
|
||||
pub fn relative(self, orientation: Orientation) -> Option<Relative> {
|
||||
match (orientation, self) {
|
||||
(Orientation::Horizontal, Absolute::Left) |
|
||||
(Orientation::Vertical, Absolute::Up) => Some(Relative::Front),
|
||||
(Orientation::Horizontal, Absolute::Right) |
|
||||
(Orientation::Vertical, Absolute::Down) => Some(Relative::Back),
|
||||
(Orientation::Horizontal, Absolute::Left)
|
||||
| (Orientation::Vertical, Absolute::Up) => Some(Relative::Front),
|
||||
(Orientation::Horizontal, Absolute::Right)
|
||||
| (Orientation::Vertical, Absolute::Down) => Some(Relative::Back),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,6 @@
|
||||
//! [global callback](../struct.Cursive.html#method.add_global_callback)
|
||||
//! table is checked.
|
||||
|
||||
|
||||
use Cursive;
|
||||
use std::ops::Deref;
|
||||
use std::rc::Rc;
|
||||
|
@ -59,10 +59,10 @@
|
||||
//! Or you can use gdb as usual.
|
||||
#![deny(missing_docs)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate maplit;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
#[macro_use]
|
||||
extern crate maplit;
|
||||
extern crate num;
|
||||
extern crate owning_ref;
|
||||
extern crate toml;
|
||||
@ -109,7 +109,6 @@ mod utf8;
|
||||
#[doc(hidden)]
|
||||
pub mod backend;
|
||||
|
||||
|
||||
pub use cursive::{Cursive, ScreenId};
|
||||
pub use printer::Printer;
|
||||
pub use with::With;
|
||||
|
@ -113,7 +113,6 @@ impl MenuTree {
|
||||
.insert(i, MenuItem::Leaf(title, Callback::from_fn(cb)));
|
||||
}
|
||||
|
||||
|
||||
/// Adds a actionnable leaf to the end of this tree - chainable variant.
|
||||
pub fn leaf<S, F>(self, title: S, cb: F) -> Self
|
||||
where
|
||||
@ -173,13 +172,13 @@ impl MenuTree {
|
||||
/// Returns `None` if the given title was not found,
|
||||
/// or if it wasn't a subtree.
|
||||
pub fn find_subtree(&mut self, title: &str) -> Option<&mut MenuTree> {
|
||||
self.find_item(title).and_then(
|
||||
|item| if let MenuItem::Subtree(_, ref mut tree) = *item {
|
||||
self.find_item(title).and_then(|item| {
|
||||
if let MenuItem::Subtree(_, ref mut tree) = *item {
|
||||
Some(Rc::make_mut(tree))
|
||||
} else {
|
||||
None
|
||||
},
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Removes the item at the given position.
|
||||
|
@ -1,6 +1,5 @@
|
||||
//! Makes drawing on ncurses windows easier.
|
||||
|
||||
|
||||
use backend::{self, Backend};
|
||||
use std::cell::Cell;
|
||||
use std::cmp::min;
|
||||
|
@ -517,9 +517,11 @@ impl Color {
|
||||
let rgb: Vec<_> =
|
||||
value.chars().map(|c| c as i16 - '0' as i16).collect();
|
||||
if rgb.iter().all(|&i| i >= 0 && i < 6) {
|
||||
Some(
|
||||
Color::RgbLowRes(rgb[0] as u8, rgb[1] as u8, rgb[2] as u8),
|
||||
)
|
||||
Some(Color::RgbLowRes(
|
||||
rgb[0] as u8,
|
||||
rgb[1] as u8,
|
||||
rgb[2] as u8,
|
||||
))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
use With;
|
||||
use unicode_segmentation::UnicodeSegmentation;
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
|
@ -10,7 +10,6 @@ pub struct ProgressReader<R: Read> {
|
||||
counter: Counter,
|
||||
}
|
||||
|
||||
|
||||
impl<R: Read> ProgressReader<R> {
|
||||
/// Creates a new `ProgressReader` around `reader`.
|
||||
///
|
||||
|
@ -320,7 +320,6 @@ impl<T: Into<Vec4>> Sub<T> for Vec4 {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl Div<usize> for Vec4 {
|
||||
type Output = Vec4;
|
||||
|
||||
|
@ -49,7 +49,6 @@ mod scroll;
|
||||
mod identifiable;
|
||||
mod boxable;
|
||||
|
||||
|
||||
pub use self::boxable::Boxable;
|
||||
pub use self::identifiable::Identifiable;
|
||||
pub use self::position::{Offset, Position};
|
||||
@ -182,14 +181,15 @@ impl<T: View> Finder for T {
|
||||
let result_ref = &mut result;
|
||||
|
||||
let mut callback = Some(callback);
|
||||
let callback = |v: &mut Any| if let Some(callback) =
|
||||
callback.take()
|
||||
{
|
||||
if v.is::<V>() {
|
||||
*result_ref = v.downcast_mut::<V>().map(|v| callback(v));
|
||||
} else if v.is::<IdView<V>>() {
|
||||
*result_ref = v.downcast_mut::<IdView<V>>()
|
||||
.and_then(|v| v.with_view_mut(callback));
|
||||
let callback = |v: &mut Any| {
|
||||
if let Some(callback) = callback.take() {
|
||||
if v.is::<V>() {
|
||||
*result_ref =
|
||||
v.downcast_mut::<V>().map(|v| callback(v));
|
||||
} else if v.is::<IdView<V>>() {
|
||||
*result_ref = v.downcast_mut::<IdView<V>>()
|
||||
.and_then(|v| v.with_view_mut(callback));
|
||||
}
|
||||
}
|
||||
};
|
||||
self.call_on_any(sel, Box::new(callback));
|
||||
|
@ -178,7 +178,6 @@ impl ScrollBase {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Now, did we hit the thumb? Or should we direct-jump?
|
||||
let height = self.scrollbar_thumb_height();
|
||||
let thumb_y = self.scrollbar_thumb_y(height);
|
||||
@ -218,7 +217,6 @@ impl ScrollBase {
|
||||
self.thumb_grab = None;
|
||||
}
|
||||
|
||||
|
||||
/// Draws the scroll bar and the content using the given drawer.
|
||||
///
|
||||
/// `line_drawer` will be called once for each line that needs to be drawn.
|
||||
@ -269,7 +267,6 @@ impl ScrollBase {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// And draw the scrollbar if needed
|
||||
if self.view_height < self.content_height {
|
||||
// We directly compute the size of the scrollbar
|
||||
|
@ -25,9 +25,9 @@ impl SizeConstraint {
|
||||
/// When `available` is offered to the `BoxView`.
|
||||
pub fn available(self, available: usize) -> usize {
|
||||
match self {
|
||||
SizeConstraint::Free |
|
||||
SizeConstraint::Full |
|
||||
SizeConstraint::AtLeast(_) => available,
|
||||
SizeConstraint::Free
|
||||
| SizeConstraint::Full
|
||||
| SizeConstraint::AtLeast(_) => available,
|
||||
// If the available space is too small, always give in.
|
||||
SizeConstraint::Fixed(value) | SizeConstraint::AtMost(value) => {
|
||||
min(value, available)
|
||||
|
@ -34,7 +34,6 @@ pub trait ViewWrapper: 'static {
|
||||
where
|
||||
F: FnOnce(&mut Self::V) -> R;
|
||||
|
||||
|
||||
/// Attempts to retrieve the inner view.
|
||||
fn into_inner(self) -> Result<Self::V, Self>
|
||||
where
|
||||
@ -74,9 +73,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));
|
||||
}
|
||||
@ -96,7 +93,8 @@ pub trait ViewWrapper: 'static {
|
||||
// Some types easily implement ViewWrapper.
|
||||
// This includes Box<T: View>
|
||||
use std::ops::{Deref, DerefMut};
|
||||
impl<U: View + ?Sized, T: Deref<Target = U> + DerefMut + 'static> ViewWrapper for T {
|
||||
impl<U: View + ?Sized, T: Deref<Target = U> + DerefMut + 'static> ViewWrapper
|
||||
for T {
|
||||
type V = U;
|
||||
|
||||
fn with_view<F, R>(&self, f: F) -> Option<R>
|
||||
@ -137,9 +135,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,5 +1,3 @@
|
||||
|
||||
|
||||
use {Cursive, Printer, With};
|
||||
use align::HAlign;
|
||||
use direction::Direction;
|
||||
|
@ -161,7 +161,6 @@ impl<T> Canvas<T> {
|
||||
self.needs_relayout = Box::new(f);
|
||||
}
|
||||
|
||||
|
||||
/// Sets the closure for `needs_relayout()`.
|
||||
///
|
||||
/// Chainable variant.
|
||||
|
@ -8,7 +8,6 @@ use theme::ColorStyle;
|
||||
use vec::Vec2;
|
||||
use view::View;
|
||||
|
||||
|
||||
/// Checkable box.
|
||||
pub struct Checkbox {
|
||||
checked: bool,
|
||||
@ -116,15 +115,13 @@ impl View for Checkbox {
|
||||
|
||||
fn draw(&self, printer: &Printer) {
|
||||
if self.enabled {
|
||||
printer.with_selection(
|
||||
printer.focused,
|
||||
|printer| self.draw_internal(printer),
|
||||
);
|
||||
printer.with_selection(printer.focused, |printer| {
|
||||
self.draw_internal(printer)
|
||||
});
|
||||
} else {
|
||||
printer.with_color(
|
||||
ColorStyle::Secondary,
|
||||
|printer| self.draw_internal(printer),
|
||||
);
|
||||
printer.with_color(ColorStyle::Secondary, |printer| {
|
||||
self.draw_internal(printer)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -216,7 +216,6 @@ impl Dialog {
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
// Private methods
|
||||
|
||||
// An event is received while the content is in focus
|
||||
@ -373,10 +372,9 @@ impl Dialog {
|
||||
printer.print((x + len, 0), " ├");
|
||||
});
|
||||
|
||||
printer.with_color(
|
||||
ColorStyle::TitlePrimary,
|
||||
|p| p.print((x, 0), &self.title),
|
||||
);
|
||||
printer.with_color(ColorStyle::TitlePrimary, |p| {
|
||||
p.print((x, 0), &self.title)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
use {Cursive, Printer, With};
|
||||
use direction::Direction;
|
||||
use event::{Callback, Event, EventResult, Key, MouseEvent};
|
||||
@ -188,7 +186,6 @@ impl EditView {
|
||||
self.style = style;
|
||||
}
|
||||
|
||||
|
||||
/// Sets the style used for this view.
|
||||
///
|
||||
/// When the view is enabled, the style will be reversed.
|
||||
@ -278,11 +275,11 @@ impl EditView {
|
||||
// Instead, have some generic function immutify()
|
||||
// or something that wraps a FnMut closure.
|
||||
let callback = RefCell::new(callback);
|
||||
self.set_on_submit(
|
||||
move |s, text| if let Ok(mut f) = callback.try_borrow_mut() {
|
||||
self.set_on_submit(move |s, text| {
|
||||
if let Ok(mut f) = callback.try_borrow_mut() {
|
||||
(&mut *f)(s, text);
|
||||
},
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Sets a callback to be called when `<Enter>` is pressed.
|
||||
@ -516,8 +513,7 @@ impl View for EditView {
|
||||
.next()
|
||||
.expect(&format!(
|
||||
"Found no char at cursor {} in {}",
|
||||
self.cursor,
|
||||
&self.content
|
||||
self.cursor, &self.content
|
||||
));
|
||||
if self.secret {
|
||||
make_small_stars(selected.width())
|
||||
|
@ -192,7 +192,11 @@ impl LinearLayout {
|
||||
) -> Box<Iterator<Item = (usize, &mut Child)> + 'a> {
|
||||
match source {
|
||||
direction::Relative::Front => {
|
||||
let start = if from_focus { self.focus } else { 0 };
|
||||
let start = if from_focus {
|
||||
self.focus
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
Box::new(self.children.iter_mut().enumerate().skip(start))
|
||||
}
|
||||
@ -347,7 +351,6 @@ impl View for LinearLayout {
|
||||
let ideal = self.orientation.stack(ideal_sizes.iter());
|
||||
debug!("Ideal result: {:?}", ideal);
|
||||
|
||||
|
||||
// Does it fit?
|
||||
if ideal.fits_in(req) {
|
||||
// Champagne!
|
||||
|
@ -73,7 +73,6 @@ impl ListView {
|
||||
self.children.is_empty()
|
||||
}
|
||||
|
||||
|
||||
/// Returns a reference to the children
|
||||
pub fn children(&self) -> &[ListChild] {
|
||||
&self.children[..]
|
||||
@ -155,7 +154,11 @@ impl ListView {
|
||||
) -> Box<Iterator<Item = (usize, &mut ListChild)> + 'a> {
|
||||
match source {
|
||||
direction::Relative::Front => {
|
||||
let start = if from_focus { self.focus } else { 0 };
|
||||
let start = if from_focus {
|
||||
self.focus
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
Box::new(self.children.iter_mut().enumerate().skip(start))
|
||||
}
|
||||
@ -365,7 +368,6 @@ impl View for ListView {
|
||||
_ => (),
|
||||
}
|
||||
|
||||
|
||||
// Then: some events can move the focus around.
|
||||
self.check_focus_grab(&event);
|
||||
|
||||
|
@ -87,7 +87,6 @@ impl MenuPopup {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Sets the alignment for this view.
|
||||
///
|
||||
/// Chainable variant.
|
||||
@ -152,8 +151,8 @@ impl MenuPopup {
|
||||
let action_cb = action_cb.clone();
|
||||
s.screen_mut().add_layer_at(
|
||||
Position::parent(offset),
|
||||
OnEventView::new(
|
||||
MenuPopup::new(Rc::clone(&tree)).on_action(move |s| {
|
||||
OnEventView::new(MenuPopup::new(Rc::clone(&tree)).on_action(
|
||||
move |s| {
|
||||
// This will happen when the subtree popup
|
||||
// activates something;
|
||||
// First, remove ourselve.
|
||||
@ -161,8 +160,8 @@ impl MenuPopup {
|
||||
if let Some(ref action_cb) = action_cb {
|
||||
action_cb.clone()(s);
|
||||
}
|
||||
}),
|
||||
).on_event(Key::Left, |s| s.pop_layer()),
|
||||
},
|
||||
)).on_event(Key::Left, |s| s.pop_layer()),
|
||||
);
|
||||
})
|
||||
}
|
||||
@ -258,7 +257,6 @@ impl View for MenuPopup {
|
||||
.unwrap_or(1);
|
||||
let h = 2 + self.menu.children.len();
|
||||
|
||||
|
||||
let scrolling = req.y < h;
|
||||
|
||||
let w = if scrolling { w + 1 } else { w };
|
||||
@ -346,10 +344,13 @@ impl View for MenuPopup {
|
||||
position.checked_sub(offset + (1, 1)).map(
|
||||
// `position` is not relative to the content
|
||||
// (It's inside the border)
|
||||
|position| if position < inner_size {
|
||||
let focus = position.y + self.scrollbase.start_line;
|
||||
if !self.menu.children[focus].is_delimiter() {
|
||||
self.focus = focus;
|
||||
|position| {
|
||||
if position < inner_size {
|
||||
let focus =
|
||||
position.y + self.scrollbase.start_line;
|
||||
if !self.menu.children[focus].is_delimiter() {
|
||||
self.focus = focus;
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
@ -82,7 +82,7 @@ pub use self::select_view::SelectView;
|
||||
pub use self::shadow_view::ShadowView;
|
||||
pub use self::sized_view::SizedView;
|
||||
pub use self::slider_view::SliderView;
|
||||
pub use self::stack_view::{StackView, LayerPosition};
|
||||
pub use self::stack_view::{LayerPosition, StackView};
|
||||
pub use self::text_area::TextArea;
|
||||
pub use self::text_view::{TextView, TextContent, TextContentRef};
|
||||
pub use self::text_view::{TextContent, TextContentRef, TextView};
|
||||
pub use self::tracked_view::TrackedView;
|
||||
|
@ -16,7 +16,6 @@ impl<V: View> Panel<V> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl<V: View> ViewWrapper for Panel<V> {
|
||||
wrap_impl!(self.view: V);
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
use Printer;
|
||||
use align::HAlign;
|
||||
use std::cmp;
|
||||
@ -68,7 +66,6 @@ pub struct ProgressBar {
|
||||
label_maker: Box<Fn(usize, (usize, usize)) -> String>,
|
||||
}
|
||||
|
||||
|
||||
fn make_percentage(value: usize, (min, max): (usize, usize)) -> String {
|
||||
if value < min {
|
||||
// ?? Negative progress?
|
||||
|
@ -100,7 +100,6 @@ pub struct RadioButton<T> {
|
||||
label: String,
|
||||
}
|
||||
|
||||
|
||||
impl<T> RadioButton<T> {
|
||||
impl_enabled!(self.enabled);
|
||||
|
||||
@ -165,15 +164,13 @@ impl<T: 'static> View for RadioButton<T> {
|
||||
|
||||
fn draw(&self, printer: &Printer) {
|
||||
if self.enabled {
|
||||
printer.with_selection(
|
||||
printer.focused,
|
||||
|printer| self.draw_internal(printer),
|
||||
);
|
||||
printer.with_selection(printer.focused, |printer| {
|
||||
self.draw_internal(printer)
|
||||
});
|
||||
} else {
|
||||
printer.with_color(
|
||||
ColorStyle::Secondary,
|
||||
|printer| self.draw_internal(printer),
|
||||
);
|
||||
printer.with_color(ColorStyle::Secondary, |printer| {
|
||||
self.draw_internal(printer)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -175,7 +175,6 @@ impl<T: 'static> SelectView<T> {
|
||||
self.with(|s| s.set_on_submit(cb))
|
||||
}
|
||||
|
||||
|
||||
/// Sets the alignment for this view.
|
||||
pub fn align(mut self, align: Align) -> Self {
|
||||
self.align = align;
|
||||
|
@ -255,7 +255,7 @@ impl StackView {
|
||||
}
|
||||
|
||||
/// Moves a layer to a new position in the stack.
|
||||
///
|
||||
///
|
||||
/// This only affects the elevation of a layer (whether it is drawn over
|
||||
/// or under other views).
|
||||
pub fn move_layer(&mut self, from: LayerPosition, to: LayerPosition) {
|
||||
@ -266,11 +266,7 @@ impl StackView {
|
||||
let removed = self.layers.remove(from_i);
|
||||
|
||||
// Shift the position if needed
|
||||
let to_i = if to_i > from_i {
|
||||
to_i - 1
|
||||
} else {
|
||||
to_i
|
||||
};
|
||||
let to_i = if to_i > from_i { to_i - 1 } else { to_i };
|
||||
|
||||
self.layers.insert(to_i, removed);
|
||||
}
|
||||
@ -333,8 +329,11 @@ impl View for StackView {
|
||||
StackPositionIterator::new(self.layers.iter(), printer.size)
|
||||
.enumerate()
|
||||
{
|
||||
v.view
|
||||
.draw(&printer.sub_printer(offset, v.size, i + 1 == last));
|
||||
v.view.draw(&printer.sub_printer(
|
||||
offset,
|
||||
v.size,
|
||||
i + 1 == last,
|
||||
));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -423,12 +423,11 @@ impl View for TextArea {
|
||||
} else {
|
||||
printer.size.x
|
||||
};
|
||||
printer.with_effect(
|
||||
effect,
|
||||
|printer| for y in 0..printer.size.y {
|
||||
printer.with_effect(effect, |printer| {
|
||||
for y in 0..printer.size.y {
|
||||
printer.print_hline((0, y), w, " ");
|
||||
},
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
debug!("Content: `{}`", &self.content);
|
||||
self.scrollbase.draw(printer, |printer, i| {
|
||||
|
@ -33,6 +33,8 @@ impl TextContent {
|
||||
|
||||
/// A reference to the text content.
|
||||
///
|
||||
/// It implements `Deref<Target=str>`.
|
||||
///
|
||||
/// This keeps the content locked. Do not store this!
|
||||
pub struct TextContentRef {
|
||||
handle: OwningHandle<
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
/// Generic trait to enable chainable API
|
||||
pub trait With: Sized {
|
||||
/// Calls the given closure on `self`.
|
||||
|
Loading…
Reference in New Issue
Block a user