mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Rustfmt
This commit is contained in:
parent
acd3bbfcca
commit
2610b697a8
@ -20,7 +20,6 @@ use event::{Event, Key, MouseButton, MouseEvent};
|
|||||||
use theme::{BaseColor, Color, ColorPair, Effect};
|
use theme::{BaseColor, Color, ColorPair, Effect};
|
||||||
use vec::Vec2;
|
use vec::Vec2;
|
||||||
|
|
||||||
|
|
||||||
enum ColorRole {
|
enum ColorRole {
|
||||||
Foreground,
|
Foreground,
|
||||||
Background,
|
Background,
|
||||||
@ -309,7 +308,8 @@ impl backend::Backend for Backend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn prepare_input(
|
fn prepare_input(
|
||||||
&mut self, event_sink: &Sender<Option<Event>>, input_request: backend::InputRequest,
|
&mut self, event_sink: &Sender<Option<Event>>,
|
||||||
|
input_request: backend::InputRequest,
|
||||||
) {
|
) {
|
||||||
match input_request {
|
match input_request {
|
||||||
backend::InputRequest::Peek => event_sink.send(self.parse_next()),
|
backend::InputRequest::Peek => event_sink.send(self.parse_next()),
|
||||||
@ -326,8 +326,6 @@ impl backend::Backend for Backend {
|
|||||||
event_sink.send(Some(Event::Refresh));
|
event_sink.send(Some(Event::Refresh));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ use event;
|
|||||||
use theme;
|
use theme;
|
||||||
use vec::Vec2;
|
use vec::Vec2;
|
||||||
|
|
||||||
use crossbeam_channel::{Sender};
|
use crossbeam_channel::Sender;
|
||||||
|
|
||||||
pub struct Backend;
|
pub struct Backend;
|
||||||
|
|
||||||
|
@ -173,8 +173,11 @@ impl View for Button {
|
|||||||
event: MouseEvent::Release(MouseButton::Left),
|
event: MouseEvent::Release(MouseButton::Left),
|
||||||
position,
|
position,
|
||||||
offset,
|
offset,
|
||||||
} if position
|
}
|
||||||
.fits_in_rect(offset + (self_offset, 0), self.req_size()) =>
|
if position.fits_in_rect(
|
||||||
|
offset + (self_offset, 0),
|
||||||
|
self.req_size(),
|
||||||
|
) =>
|
||||||
{
|
{
|
||||||
EventResult::Consumed(Some(self.callback.clone()))
|
EventResult::Consumed(Some(self.callback.clone()))
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,8 @@ impl View for Checkbox {
|
|||||||
event: MouseEvent::Release(MouseButton::Left),
|
event: MouseEvent::Release(MouseButton::Left),
|
||||||
position,
|
position,
|
||||||
offset,
|
offset,
|
||||||
} if position.fits_in_rect(offset, (3, 1)) =>
|
}
|
||||||
|
if position.fits_in_rect(offset, (3, 1)) =>
|
||||||
{
|
{
|
||||||
self.toggle()
|
self.toggle()
|
||||||
}
|
}
|
||||||
|
@ -670,7 +670,8 @@ impl View for EditView {
|
|||||||
event: MouseEvent::Press(_),
|
event: MouseEvent::Press(_),
|
||||||
position,
|
position,
|
||||||
offset,
|
offset,
|
||||||
} if position.fits_in_rect(offset, (self.last_length, 1)) =>
|
}
|
||||||
|
if position.fits_in_rect(offset, (self.last_length, 1)) =>
|
||||||
{
|
{
|
||||||
if let Some(position) = position.checked_sub(offset) {
|
if let Some(position) = position.checked_sub(offset) {
|
||||||
self.cursor = self.offset
|
self.cursor = self.offset
|
||||||
|
@ -345,12 +345,13 @@ impl View for ListView {
|
|||||||
event: MouseEvent::Press(MouseButton::Left),
|
event: MouseEvent::Press(MouseButton::Left),
|
||||||
position,
|
position,
|
||||||
offset,
|
offset,
|
||||||
} if position
|
}
|
||||||
.checked_sub(offset)
|
if position
|
||||||
.map(|position| {
|
.checked_sub(offset)
|
||||||
self.scrollbase.start_drag(position, self.last_size.x)
|
.map(|position| {
|
||||||
})
|
self.scrollbase.start_drag(position, self.last_size.x)
|
||||||
.unwrap_or(false) =>
|
})
|
||||||
|
.unwrap_or(false) =>
|
||||||
{
|
{
|
||||||
return EventResult::Consumed(None);
|
return EventResult::Consumed(None);
|
||||||
}
|
}
|
||||||
@ -358,7 +359,8 @@ impl View for ListView {
|
|||||||
event: MouseEvent::Hold(MouseButton::Left),
|
event: MouseEvent::Hold(MouseButton::Left),
|
||||||
position,
|
position,
|
||||||
offset,
|
offset,
|
||||||
} if self.scrollbase.is_dragging() =>
|
}
|
||||||
|
if self.scrollbase.is_dragging() =>
|
||||||
{
|
{
|
||||||
let position = position.saturating_sub(offset);
|
let position = position.saturating_sub(offset);
|
||||||
self.scrollbase.drag(position);
|
self.scrollbase.drag(position);
|
||||||
@ -367,7 +369,8 @@ impl View for ListView {
|
|||||||
Event::Mouse {
|
Event::Mouse {
|
||||||
event: MouseEvent::Release(MouseButton::Left),
|
event: MouseEvent::Release(MouseButton::Left),
|
||||||
..
|
..
|
||||||
} if self.scrollbase.is_dragging() =>
|
}
|
||||||
|
if self.scrollbase.is_dragging() =>
|
||||||
{
|
{
|
||||||
self.scrollbase.release_grab();
|
self.scrollbase.release_grab();
|
||||||
return EventResult::Consumed(None);
|
return EventResult::Consumed(None);
|
||||||
@ -420,7 +423,8 @@ impl View for ListView {
|
|||||||
Event::Mouse {
|
Event::Mouse {
|
||||||
event: MouseEvent::WheelDown,
|
event: MouseEvent::WheelDown,
|
||||||
..
|
..
|
||||||
} if self.scrollbase.can_scroll_down() =>
|
}
|
||||||
|
if self.scrollbase.can_scroll_down() =>
|
||||||
{
|
{
|
||||||
self.scrollbase.scroll_down(5);
|
self.scrollbase.scroll_down(5);
|
||||||
EventResult::Consumed(None)
|
EventResult::Consumed(None)
|
||||||
@ -428,7 +432,8 @@ impl View for ListView {
|
|||||||
Event::Mouse {
|
Event::Mouse {
|
||||||
event: MouseEvent::WheelUp,
|
event: MouseEvent::WheelUp,
|
||||||
..
|
..
|
||||||
} if self.scrollbase.can_scroll_up() =>
|
}
|
||||||
|
if self.scrollbase.can_scroll_up() =>
|
||||||
{
|
{
|
||||||
self.scrollbase.scroll_up(5);
|
self.scrollbase.scroll_up(5);
|
||||||
EventResult::Consumed(None)
|
EventResult::Consumed(None)
|
||||||
|
@ -297,7 +297,8 @@ 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);
|
||||||
@ -305,7 +306,8 @@ impl View for MenuPopup {
|
|||||||
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);
|
||||||
@ -314,13 +316,15 @@ impl View for MenuPopup {
|
|||||||
event: MouseEvent::Press(MouseButton::Left),
|
event: MouseEvent::Press(MouseButton::Left),
|
||||||
position,
|
position,
|
||||||
offset,
|
offset,
|
||||||
} if self.scrollbase.scrollable()
|
}
|
||||||
&& position
|
if self.scrollbase.scrollable()
|
||||||
.checked_sub(offset + (0, 1))
|
&& position
|
||||||
.map(|position| {
|
.checked_sub(offset + (0, 1))
|
||||||
self.scrollbase.start_drag(position, self.last_size.x)
|
.map(|position| {
|
||||||
})
|
self.scrollbase
|
||||||
.unwrap_or(false) =>
|
.start_drag(position, self.last_size.x)
|
||||||
|
})
|
||||||
|
.unwrap_or(false) =>
|
||||||
{
|
{
|
||||||
fix_scroll = false;
|
fix_scroll = false;
|
||||||
}
|
}
|
||||||
@ -338,7 +342,8 @@ 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);
|
||||||
|
@ -318,7 +318,8 @@ 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)
|
||||||
@ -336,7 +337,8 @@ 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)
|
||||||
|
@ -184,7 +184,8 @@ impl<T: 'static> View for RadioButton<T> {
|
|||||||
event: MouseEvent::Release(MouseButton::Left),
|
event: MouseEvent::Release(MouseButton::Left),
|
||||||
position,
|
position,
|
||||||
offset,
|
offset,
|
||||||
} if position.fits_in_rect(offset, self.req_size()) =>
|
}
|
||||||
|
if position.fits_in_rect(offset, self.req_size()) =>
|
||||||
{
|
{
|
||||||
self.select();
|
self.select();
|
||||||
EventResult::Consumed(None)
|
EventResult::Consumed(None)
|
||||||
|
@ -459,16 +459,18 @@ 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
|
}
|
||||||
&& (self.offset.y + self.available_size().y
|
if self.enabled.y
|
||||||
< self.inner_size.y) =>
|
&& (self.offset.y + self.available_size().y
|
||||||
|
< self.inner_size.y) =>
|
||||||
{
|
{
|
||||||
self.offset.y = min(
|
self.offset.y = min(
|
||||||
self.inner_size
|
self.inner_size
|
||||||
@ -481,11 +483,12 @@ where
|
|||||||
event: MouseEvent::Press(MouseButton::Left),
|
event: MouseEvent::Press(MouseButton::Left),
|
||||||
position,
|
position,
|
||||||
offset,
|
offset,
|
||||||
} if self.show_scrollbars
|
}
|
||||||
&& position
|
if self.show_scrollbars
|
||||||
.checked_sub(offset)
|
&& position
|
||||||
.map(|position| self.start_drag(position))
|
.checked_sub(offset)
|
||||||
.unwrap_or(false) =>
|
.map(|position| self.start_drag(position))
|
||||||
|
.unwrap_or(false) =>
|
||||||
{
|
{
|
||||||
// Just consume the event.
|
// Just consume the event.
|
||||||
}
|
}
|
||||||
@ -493,7 +496,8 @@ 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);
|
||||||
|
@ -435,7 +435,8 @@ impl<T: 'static> SelectView<T> {
|
|||||||
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(5);
|
self.scrollbase.scroll_down(5);
|
||||||
@ -443,7 +444,8 @@ impl<T: 'static> SelectView<T> {
|
|||||||
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(5);
|
self.scrollbase.scroll_up(5);
|
||||||
@ -452,12 +454,13 @@ impl<T: 'static> SelectView<T> {
|
|||||||
event: MouseEvent::Press(MouseButton::Left),
|
event: MouseEvent::Press(MouseButton::Left),
|
||||||
position,
|
position,
|
||||||
offset,
|
offset,
|
||||||
} if position
|
}
|
||||||
.checked_sub(offset)
|
if position
|
||||||
.map(|position| {
|
.checked_sub(offset)
|
||||||
self.scrollbase.start_drag(position, self.last_size.x)
|
.map(|position| {
|
||||||
})
|
self.scrollbase.start_drag(position, self.last_size.x)
|
||||||
.unwrap_or(false) =>
|
})
|
||||||
|
.unwrap_or(false) =>
|
||||||
{
|
{
|
||||||
fix_scroll = false;
|
fix_scroll = false;
|
||||||
}
|
}
|
||||||
@ -620,7 +623,8 @@ impl<T: 'static> SelectView<T> {
|
|||||||
event: MouseEvent::Release(MouseButton::Left),
|
event: MouseEvent::Release(MouseButton::Left),
|
||||||
position,
|
position,
|
||||||
offset,
|
offset,
|
||||||
} if position.fits_in_rect(offset, self.last_size) =>
|
}
|
||||||
|
if position.fits_in_rect(offset, self.last_size) =>
|
||||||
{
|
{
|
||||||
self.open_popup()
|
self.open_popup()
|
||||||
}
|
}
|
||||||
|
@ -169,7 +169,8 @@ 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);
|
||||||
@ -184,7 +185,8 @@ 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;
|
||||||
|
@ -535,7 +535,8 @@ impl View for TextArea {
|
|||||||
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(5);
|
self.scrollbase.scroll_up(5);
|
||||||
@ -543,7 +544,8 @@ impl View for TextArea {
|
|||||||
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(5);
|
self.scrollbase.scroll_down(5);
|
||||||
@ -552,12 +554,13 @@ impl View for TextArea {
|
|||||||
event: MouseEvent::Press(MouseButton::Left),
|
event: MouseEvent::Press(MouseButton::Left),
|
||||||
position,
|
position,
|
||||||
offset,
|
offset,
|
||||||
} if position
|
}
|
||||||
.checked_sub(offset)
|
if position
|
||||||
.map(|position| {
|
.checked_sub(offset)
|
||||||
self.scrollbase.start_drag(position, self.last_size.x)
|
.map(|position| {
|
||||||
})
|
self.scrollbase.start_drag(position, self.last_size.x)
|
||||||
.unwrap_or(false) =>
|
})
|
||||||
|
.unwrap_or(false) =>
|
||||||
{
|
{
|
||||||
fix_scroll = false;
|
fix_scroll = false;
|
||||||
}
|
}
|
||||||
@ -574,8 +577,9 @@ impl View for TextArea {
|
|||||||
event: MouseEvent::Press(_),
|
event: MouseEvent::Press(_),
|
||||||
position,
|
position,
|
||||||
offset,
|
offset,
|
||||||
} if !self.rows.is_empty()
|
}
|
||||||
&& position.fits_in_rect(offset, self.last_size) =>
|
if !self.rows.is_empty()
|
||||||
|
&& position.fits_in_rect(offset, self.last_size) =>
|
||||||
{
|
{
|
||||||
if let Some(position) = position.checked_sub(offset) {
|
if let Some(position) = position.checked_sub(offset) {
|
||||||
let y = position.y + self.scrollbase.start_line;
|
let y = position.y + self.scrollbase.start_line;
|
||||||
|
Loading…
Reference in New Issue
Block a user