Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Event::MouseMoved to Event::MouseMove #825

Merged
merged 2 commits into from
Apr 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion druid/examples/game_of_life.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ impl Widget<AppData> for GameOfLifeWidget {
data.drawing = false;
}
}
Event::MouseMoved(e) => {
Event::MouseMove(e) => {
if data.drawing {
let grid_pos_opt = self.grid_pos(e.pos);
grid_pos_opt.iter().for_each(|pos| data.grid[*pos] = true);
Expand Down
4 changes: 2 additions & 2 deletions druid/src/contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ impl<'a> EventCtx<'a> {
/// only has the effect of the last one (ie no need to worry about
/// flashing).
///
/// This method is expected to be called mostly from the [`MouseMoved`]
/// This method is expected to be called mostly from the [`MouseMove`]
/// event handler, but can also be called in response to other events,
/// for example pressing a key to change the behavior of a widget.
///
/// [`MouseMoved`]: enum.Event.html#variant.MouseDown
/// [`MouseMove`]: enum.Event.html#variant.MouseMove
pub fn set_cursor(&mut self, cursor: &Cursor) {
*self.cursor = Some(cursor.clone());
}
Expand Down
4 changes: 2 additions & 2 deletions druid/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ impl<T: Data, W: Widget<T>> WidgetPod<T, W> {
mouse_event.pos -= rect.origin().to_vec2();
Event::MouseUp(mouse_event)
}
Event::MouseMoved(mouse_event) => {
Event::MouseMove(mouse_event) => {
let had_hot = child_ctx.base_state.is_hot;
child_ctx.base_state.is_hot = rect.winding(mouse_event.pos) != 0;
if had_hot != child_ctx.base_state.is_hot {
Expand All @@ -415,7 +415,7 @@ impl<T: Data, W: Widget<T>> WidgetPod<T, W> {
recurse = had_active || had_hot || child_ctx.base_state.is_hot;
let mut mouse_event = mouse_event.clone();
mouse_event.pos -= rect.origin().to_vec2();
Event::MouseMoved(mouse_event)
Event::MouseMove(mouse_event)
}
Event::KeyDown(e) => {
recurse = child_ctx.has_focus();
Expand Down
14 changes: 7 additions & 7 deletions druid/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@ pub enum Event {
MouseUp(MouseEvent),
/// Called when the mouse is moved.
///
/// The `MouseMoved` event is propagated to the active widget, if
/// The `MouseMove` event is propagated to the active widget, if
/// there is one, otherwise to hot widgets (see `HotChanged`).
///
/// The `MouseMoved` event is also the primary mechanism for widgets
/// The `MouseMove` event is also the primary mechanism for widgets
/// to set a cursor, for example to an I-bar inside a text widget. A
/// simple tactic is for the widget to unconditionally call
/// [`set_cursor`] in the MouseMoved handler, as `MouseMove` is only
/// [`set_cursor`] in the MouseMove handler, as `MouseMove` is only
/// propagated to active or hot widgets.
///
/// [`set_cursor`]: struct.EventCtx.html#method.set_cursor
MouseMoved(MouseEvent),
MouseMove(MouseEvent),
/// Called when a key is pressed.
///
/// Note: the intent is for each physical key press to correspond to
Expand Down Expand Up @@ -172,7 +172,7 @@ pub enum LifeCycle {
///
/// This will always be called _before_ the event that triggered it; that is,
/// when the mouse moves over a widget, that widget will receive
/// `LifeCycle::HotChanged` before it receives `Event::MouseMoved`.
/// `LifeCycle::HotChanged` before it receives `Event::MouseMove`.
///
/// See [`is_hot`](struct.EventCtx.html#method.is_hot) for
/// discussion about the hot status.
Expand Down Expand Up @@ -259,11 +259,11 @@ impl Event {
None
}
}
Event::MouseMoved(mouse_event) => {
Event::MouseMove(mouse_event) => {
if force || viewport.winding(mouse_event.pos) != 0 {
let mut mouse_event = mouse_event.clone();
mouse_event.pos += offset;
Some(Event::MouseMoved(mouse_event))
Some(Event::MouseMove(mouse_event))
} else {
None
}
Expand Down
26 changes: 13 additions & 13 deletions druid/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,50 +72,50 @@ fn propogate_hot() {
// and verifying both the widget's `is_hot` status and also that
// each widget received the expected HotChanged messages.

harness.event(Event::MouseMoved(make_mouse(10., 10.)));
harness.event(Event::MouseMove(make_mouse(10., 10.)));
assert!(harness.get_state(root).is_hot);
assert!(harness.get_state(empty).is_hot);
assert!(!harness.get_state(pad).is_hot);

assert_matches!(root_rec.next(), Record::L(LifeCycle::HotChanged(true)));
assert_matches!(root_rec.next(), Record::E(Event::MouseMoved(_)));
assert_matches!(root_rec.next(), Record::E(Event::MouseMove(_)));
assert!(root_rec.is_empty() && padding_rec.is_empty() && button_rec.is_empty());

harness.event(Event::MouseMoved(make_mouse(210., 10.)));
harness.event(Event::MouseMove(make_mouse(210., 10.)));

assert!(harness.get_state(root).is_hot);
assert!(!harness.get_state(empty).is_hot);
assert!(!harness.get_state(button).is_hot);
assert!(harness.get_state(pad).is_hot);

assert_matches!(root_rec.next(), Record::E(Event::MouseMoved(_)));
assert_matches!(root_rec.next(), Record::E(Event::MouseMove(_)));
assert_matches!(padding_rec.next(), Record::L(LifeCycle::HotChanged(true)));
assert_matches!(padding_rec.next(), Record::E(Event::MouseMoved(_)));
assert_matches!(padding_rec.next(), Record::E(Event::MouseMove(_)));
assert!(root_rec.is_empty() && padding_rec.is_empty() && button_rec.is_empty());

harness.event(Event::MouseMoved(make_mouse(260., 60.)));
harness.event(Event::MouseMove(make_mouse(260., 60.)));
assert!(harness.get_state(root).is_hot);
assert!(!harness.get_state(empty).is_hot);
assert!(harness.get_state(button).is_hot);
assert!(harness.get_state(pad).is_hot);

assert_matches!(root_rec.next(), Record::E(Event::MouseMoved(_)));
assert_matches!(padding_rec.next(), Record::E(Event::MouseMoved(_)));
assert_matches!(root_rec.next(), Record::E(Event::MouseMove(_)));
assert_matches!(padding_rec.next(), Record::E(Event::MouseMove(_)));
assert_matches!(button_rec.next(), Record::L(LifeCycle::HotChanged(true)));
assert_matches!(button_rec.next(), Record::E(Event::MouseMoved(_)));
assert_matches!(button_rec.next(), Record::E(Event::MouseMove(_)));
assert!(root_rec.is_empty() && padding_rec.is_empty() && button_rec.is_empty());

harness.event(Event::MouseMoved(make_mouse(10., 10.)));
harness.event(Event::MouseMove(make_mouse(10., 10.)));
assert!(harness.get_state(root).is_hot);
assert!(harness.get_state(empty).is_hot);
assert!(!harness.get_state(button).is_hot);
assert!(!harness.get_state(pad).is_hot);

assert_matches!(root_rec.next(), Record::E(Event::MouseMoved(_)));
assert_matches!(root_rec.next(), Record::E(Event::MouseMove(_)));
assert_matches!(padding_rec.next(), Record::L(LifeCycle::HotChanged(false)));
assert_matches!(padding_rec.next(), Record::E(Event::MouseMoved(_)));
assert_matches!(padding_rec.next(), Record::E(Event::MouseMove(_)));
assert_matches!(button_rec.next(), Record::L(LifeCycle::HotChanged(false)));
assert_matches!(button_rec.next(), Record::E(Event::MouseMoved(_)));
assert_matches!(button_rec.next(), Record::E(Event::MouseMove(_)));
assert!(root_rec.is_empty() && padding_rec.is_empty() && button_rec.is_empty());
});
}
Expand Down
8 changes: 4 additions & 4 deletions druid/src/widget/scroll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ impl<T: Data, W: Widget<T>> Widget<T> for Scroll<T, W> {
let viewport = Rect::from_origin_size(Point::ORIGIN, size);

let scrollbar_is_hovered = match event {
Event::MouseMoved(e) | Event::MouseUp(e) | Event::MouseDown(e) => {
Event::MouseMove(e) | Event::MouseUp(e) | Event::MouseDown(e) => {
let offset_pos = e.pos + self.scroll_offset;
self.point_hits_vertical_bar(viewport, offset_pos, &env)
|| self.point_hits_horizontal_bar(viewport, offset_pos, &env)
Expand All @@ -308,7 +308,7 @@ impl<T: Data, W: Widget<T>> Widget<T> for Scroll<T, W> {
if self.scrollbars.are_held() {
// if we're dragging a scrollbar
match event {
Event::MouseMoved(event) => {
Event::MouseMove(event) => {
match self.scrollbars.held {
BarHeldState::Vertical(offset) => {
let scale_y = viewport.height() / self.child_size.height;
Expand Down Expand Up @@ -342,7 +342,7 @@ impl<T: Data, W: Widget<T>> Widget<T> for Scroll<T, W> {
} else if scrollbar_is_hovered {
// if we're over a scrollbar but not dragging
match event {
Event::MouseMoved(event) => {
Event::MouseMove(event) => {
let offset_pos = event.pos + self.scroll_offset;
if self.point_hits_vertical_bar(viewport, offset_pos, &env) {
self.scrollbars.hovered = BarHoveredState::Vertical;
Expand Down Expand Up @@ -381,7 +381,7 @@ impl<T: Data, W: Widget<T>> Widget<T> for Scroll<T, W> {
};

match event {
Event::MouseMoved(_) => {
Event::MouseMove(_) => {
// if we have just stopped hovering
if self.scrollbars.hovered.is_hovered() && !scrollbar_is_hovered {
self.scrollbars.hovered = BarHoveredState::None;
Expand Down
2 changes: 1 addition & 1 deletion druid/src/widget/slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl Widget<f64> for Slider {
ctx.request_paint();
}
}
Event::MouseMoved(mouse) => {
Event::MouseMove(mouse) => {
if ctx.is_active() {
*data = self.calculate_value(mouse.pos.x, knob_size, slider_width);
ctx.request_paint();
Expand Down
2 changes: 1 addition & 1 deletion druid/src/widget/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ impl<T: Data> Widget<T> for Split<T> {
ctx.request_paint();
}
}
Event::MouseMoved(mouse) => {
Event::MouseMove(mouse) => {
if ctx.is_active() {
self.update_split_point(ctx.size(), mouse.pos);
ctx.request_layout();
Expand Down
2 changes: 1 addition & 1 deletion druid/src/widget/switch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl Widget<bool> for Switch {
self.animation_in_progress = true;
ctx.request_anim_frame();
}
Event::MouseMoved(mouse) => {
Event::MouseMove(mouse) => {
if ctx.is_active() {
self.knob_pos.x = mouse.pos.x.min(on_pos).max(off_pos);
self.knob_dragged = true;
Expand Down
2 changes: 1 addition & 1 deletion druid/src/widget/textbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ impl Widget<String> for TextBox {

ctx.request_paint();
}
Event::MouseMoved(mouse) => {
Event::MouseMove(mouse) => {
ctx.set_cursor(&Cursor::IBeam);
if ctx.is_active() {
let cursor_offset = self.offset_for_point(mouse.pos, &text_layout);
Expand Down
2 changes: 1 addition & 1 deletion druid/src/win_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ impl<T: Data> WinHandler for DruidHandler<T> {
}

fn mouse_move(&mut self, event: &MouseEvent) {
let event = Event::MouseMoved(event.clone().into());
let event = Event::MouseMove(event.clone().into());
self.app_state.do_window_event(event, self.window_id);
}

Expand Down
2 changes: 1 addition & 1 deletion druid/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl<T: Data> Window<T> {
env: &Env,
) -> bool {
let mut cursor = match event {
Event::MouseMoved(..) => Some(Cursor::Arrow),
Event::MouseMove(..) => Some(Cursor::Arrow),
_ => None,
};

Expand Down