This commit is contained in:
Alexandre Bury 2018-07-19 19:44:59 -07:00
parent acd3bbfcca
commit 2610b697a8
13 changed files with 93 additions and 63 deletions

View File

@ -20,7 +20,6 @@ use event::{Event, Key, MouseButton, MouseEvent};
use theme::{BaseColor, Color, ColorPair, Effect};
use vec::Vec2;
enum ColorRole {
Foreground,
Background,
@ -309,7 +308,8 @@ impl backend::Backend for Backend {
}
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 {
backend::InputRequest::Peek => event_sink.send(self.parse_next()),
@ -326,8 +326,6 @@ impl backend::Backend for Backend {
event_sink.send(Some(Event::Refresh));
}
}
}
}

View File

@ -4,7 +4,7 @@ use event;
use theme;
use vec::Vec2;
use crossbeam_channel::{Sender};
use crossbeam_channel::Sender;
pub struct Backend;

View File

@ -173,8 +173,11 @@ impl View for Button {
event: MouseEvent::Release(MouseButton::Left),
position,
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()))
}

View File

@ -132,7 +132,8 @@ impl View for Checkbox {
event: MouseEvent::Release(MouseButton::Left),
position,
offset,
} if position.fits_in_rect(offset, (3, 1)) =>
}
if position.fits_in_rect(offset, (3, 1)) =>
{
self.toggle()
}

View File

@ -670,7 +670,8 @@ impl View for EditView {
event: MouseEvent::Press(_),
position,
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) {
self.cursor = self.offset

View File

@ -345,12 +345,13 @@ impl View for ListView {
event: MouseEvent::Press(MouseButton::Left),
position,
offset,
} if position
.checked_sub(offset)
.map(|position| {
self.scrollbase.start_drag(position, self.last_size.x)
})
.unwrap_or(false) =>
}
if position
.checked_sub(offset)
.map(|position| {
self.scrollbase.start_drag(position, self.last_size.x)
})
.unwrap_or(false) =>
{
return EventResult::Consumed(None);
}
@ -358,7 +359,8 @@ impl View for ListView {
event: MouseEvent::Hold(MouseButton::Left),
position,
offset,
} if self.scrollbase.is_dragging() =>
}
if self.scrollbase.is_dragging() =>
{
let position = position.saturating_sub(offset);
self.scrollbase.drag(position);
@ -367,7 +369,8 @@ impl View for ListView {
Event::Mouse {
event: MouseEvent::Release(MouseButton::Left),
..
} if self.scrollbase.is_dragging() =>
}
if self.scrollbase.is_dragging() =>
{
self.scrollbase.release_grab();
return EventResult::Consumed(None);
@ -420,7 +423,8 @@ impl View for ListView {
Event::Mouse {
event: MouseEvent::WheelDown,
..
} if self.scrollbase.can_scroll_down() =>
}
if self.scrollbase.can_scroll_down() =>
{
self.scrollbase.scroll_down(5);
EventResult::Consumed(None)
@ -428,7 +432,8 @@ impl View for ListView {
Event::Mouse {
event: MouseEvent::WheelUp,
..
} if self.scrollbase.can_scroll_up() =>
}
if self.scrollbase.can_scroll_up() =>
{
self.scrollbase.scroll_up(5);
EventResult::Consumed(None)

View File

@ -297,7 +297,8 @@ impl View for MenuPopup {
Event::Mouse {
event: MouseEvent::WheelUp,
..
} if self.scrollbase.can_scroll_up() =>
}
if self.scrollbase.can_scroll_up() =>
{
fix_scroll = false;
self.scrollbase.scroll_up(1);
@ -305,7 +306,8 @@ impl View for MenuPopup {
Event::Mouse {
event: MouseEvent::WheelDown,
..
} if self.scrollbase.can_scroll_down() =>
}
if self.scrollbase.can_scroll_down() =>
{
fix_scroll = false;
self.scrollbase.scroll_down(1);
@ -314,13 +316,15 @@ impl View for MenuPopup {
event: MouseEvent::Press(MouseButton::Left),
position,
offset,
} if self.scrollbase.scrollable()
&& position
.checked_sub(offset + (0, 1))
.map(|position| {
self.scrollbase.start_drag(position, self.last_size.x)
})
.unwrap_or(false) =>
}
if self.scrollbase.scrollable()
&& position
.checked_sub(offset + (0, 1))
.map(|position| {
self.scrollbase
.start_drag(position, self.last_size.x)
})
.unwrap_or(false) =>
{
fix_scroll = false;
}
@ -338,7 +342,8 @@ impl View for MenuPopup {
event: MouseEvent::Press(_),
position,
offset,
} if position.fits_in_rect(offset, self.last_size) =>
}
if position.fits_in_rect(offset, self.last_size) =>
{
// eprintln!("Position: {:?} / {:?}", position, offset);
// eprintln!("Last size: {:?}", self.last_size);

View File

@ -318,7 +318,8 @@ impl View for Menubar {
event: MouseEvent::Press(btn),
position,
offset,
} if position.fits(offset) && position.y == offset.y =>
}
if position.fits(offset) && position.y == offset.y =>
{
if let Some(child) = position
.checked_sub(offset)
@ -336,7 +337,8 @@ impl View for Menubar {
event: MouseEvent::Release(btn),
position,
offset,
} if position.fits(offset) && position.y == offset.y =>
}
if position.fits(offset) && position.y == offset.y =>
{
if let Some(child) = position
.checked_sub(offset)

View File

@ -184,7 +184,8 @@ impl<T: 'static> View for RadioButton<T> {
event: MouseEvent::Release(MouseButton::Left),
position,
offset,
} if position.fits_in_rect(offset, self.req_size()) =>
}
if position.fits_in_rect(offset, self.req_size()) =>
{
self.select();
EventResult::Consumed(None)

View File

@ -459,16 +459,18 @@ where
Event::Mouse {
event: MouseEvent::WheelUp,
..
} if self.enabled.y && self.offset.y > 0 =>
}
if self.enabled.y && self.offset.y > 0 =>
{
self.offset.y = self.offset.y.saturating_sub(3);
}
Event::Mouse {
event: MouseEvent::WheelDown,
..
} if self.enabled.y
&& (self.offset.y + self.available_size().y
< self.inner_size.y) =>
}
if self.enabled.y
&& (self.offset.y + self.available_size().y
< self.inner_size.y) =>
{
self.offset.y = min(
self.inner_size
@ -481,11 +483,12 @@ where
event: MouseEvent::Press(MouseButton::Left),
position,
offset,
} if self.show_scrollbars
&& position
.checked_sub(offset)
.map(|position| self.start_drag(position))
.unwrap_or(false) =>
}
if self.show_scrollbars
&& position
.checked_sub(offset)
.map(|position| self.start_drag(position))
.unwrap_or(false) =>
{
// Just consume the event.
}
@ -493,7 +496,8 @@ where
event: MouseEvent::Hold(MouseButton::Left),
position,
offset,
} if self.show_scrollbars =>
}
if self.show_scrollbars =>
{
let position = position.saturating_sub(offset);
self.drag(position);

View File

@ -435,7 +435,8 @@ impl<T: 'static> SelectView<T> {
Event::Mouse {
event: MouseEvent::WheelDown,
..
} if self.scrollbase.can_scroll_down() =>
}
if self.scrollbase.can_scroll_down() =>
{
fix_scroll = false;
self.scrollbase.scroll_down(5);
@ -443,7 +444,8 @@ impl<T: 'static> SelectView<T> {
Event::Mouse {
event: MouseEvent::WheelUp,
..
} if self.scrollbase.can_scroll_up() =>
}
if self.scrollbase.can_scroll_up() =>
{
fix_scroll = false;
self.scrollbase.scroll_up(5);
@ -452,12 +454,13 @@ impl<T: 'static> SelectView<T> {
event: MouseEvent::Press(MouseButton::Left),
position,
offset,
} if position
.checked_sub(offset)
.map(|position| {
self.scrollbase.start_drag(position, self.last_size.x)
})
.unwrap_or(false) =>
}
if position
.checked_sub(offset)
.map(|position| {
self.scrollbase.start_drag(position, self.last_size.x)
})
.unwrap_or(false) =>
{
fix_scroll = false;
}
@ -620,7 +623,8 @@ impl<T: 'static> SelectView<T> {
event: MouseEvent::Release(MouseButton::Left),
position,
offset,
} if position.fits_in_rect(offset, self.last_size) =>
}
if position.fits_in_rect(offset, self.last_size) =>
{
self.open_popup()
}

View File

@ -169,7 +169,8 @@ impl View for SliderView {
event: MouseEvent::Hold(MouseButton::Left),
position,
offset,
} if self.dragging =>
}
if self.dragging =>
{
let position = position.saturating_sub(offset);
let position = self.orientation.get(&position);
@ -184,7 +185,8 @@ impl View for SliderView {
event: MouseEvent::Press(MouseButton::Left),
position,
offset,
} if position.fits_in_rect(offset, self.req_size()) =>
}
if position.fits_in_rect(offset, self.req_size()) =>
{
if let Some(position) = position.checked_sub(offset) {
self.dragging = true;

View File

@ -535,7 +535,8 @@ impl View for TextArea {
Event::Mouse {
event: MouseEvent::WheelUp,
..
} if self.scrollbase.can_scroll_up() =>
}
if self.scrollbase.can_scroll_up() =>
{
fix_scroll = false;
self.scrollbase.scroll_up(5);
@ -543,7 +544,8 @@ impl View for TextArea {
Event::Mouse {
event: MouseEvent::WheelDown,
..
} if self.scrollbase.can_scroll_down() =>
}
if self.scrollbase.can_scroll_down() =>
{
fix_scroll = false;
self.scrollbase.scroll_down(5);
@ -552,12 +554,13 @@ impl View for TextArea {
event: MouseEvent::Press(MouseButton::Left),
position,
offset,
} if position
.checked_sub(offset)
.map(|position| {
self.scrollbase.start_drag(position, self.last_size.x)
})
.unwrap_or(false) =>
}
if position
.checked_sub(offset)
.map(|position| {
self.scrollbase.start_drag(position, self.last_size.x)
})
.unwrap_or(false) =>
{
fix_scroll = false;
}
@ -574,8 +577,9 @@ impl View for TextArea {
event: MouseEvent::Press(_),
position,
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) {
let y = position.y + self.scrollbase.start_line;