Merge pull request #133 from robbert-vdh/feature/horizontal-scrolling
Support horizontal scrolling on Linux and Windows
This commit is contained in:
commit
ee156fb884
|
@ -9,10 +9,11 @@ use winapi::um::winuser::{
|
||||||
SetWindowPos, TranslateMessage, UnregisterClassW, CS_OWNDC, GET_XBUTTON_WPARAM, GWLP_USERDATA,
|
SetWindowPos, TranslateMessage, UnregisterClassW, CS_OWNDC, GET_XBUTTON_WPARAM, GWLP_USERDATA,
|
||||||
IDC_ARROW, MSG, SWP_NOMOVE, SWP_NOZORDER, WHEEL_DELTA, WM_CHAR, WM_CLOSE, WM_CREATE,
|
IDC_ARROW, MSG, SWP_NOMOVE, SWP_NOZORDER, WHEEL_DELTA, WM_CHAR, WM_CLOSE, WM_CREATE,
|
||||||
WM_DPICHANGED, WM_INPUTLANGCHANGE, WM_KEYDOWN, WM_KEYUP, WM_LBUTTONDOWN, WM_LBUTTONUP,
|
WM_DPICHANGED, WM_INPUTLANGCHANGE, WM_KEYDOWN, WM_KEYUP, WM_LBUTTONDOWN, WM_LBUTTONUP,
|
||||||
WM_MBUTTONDOWN, WM_MBUTTONUP, WM_MOUSEMOVE, WM_MOUSEWHEEL, WM_NCDESTROY, WM_RBUTTONDOWN,
|
WM_MBUTTONDOWN, WM_MBUTTONUP, WM_MOUSEHWHEEL, WM_MOUSEMOVE, WM_MOUSEWHEEL, WM_NCDESTROY,
|
||||||
WM_RBUTTONUP, WM_SHOWWINDOW, WM_SIZE, WM_SYSCHAR, WM_SYSKEYDOWN, WM_SYSKEYUP, WM_TIMER,
|
WM_RBUTTONDOWN, WM_RBUTTONUP, WM_SHOWWINDOW, WM_SIZE, WM_SYSCHAR, WM_SYSKEYDOWN, WM_SYSKEYUP,
|
||||||
WM_USER, WM_XBUTTONDOWN, WM_XBUTTONUP, WNDCLASSW, WS_CAPTION, WS_CHILD, WS_CLIPSIBLINGS,
|
WM_TIMER, WM_USER, WM_XBUTTONDOWN, WM_XBUTTONUP, WNDCLASSW, WS_CAPTION, WS_CHILD,
|
||||||
WS_MAXIMIZEBOX, WS_MINIMIZEBOX, WS_POPUPWINDOW, WS_SIZEBOX, WS_VISIBLE, XBUTTON1, XBUTTON2,
|
WS_CLIPSIBLINGS, WS_MAXIMIZEBOX, WS_MINIMIZEBOX, WS_POPUPWINDOW, WS_SIZEBOX, WS_VISIBLE,
|
||||||
|
XBUTTON1, XBUTTON2,
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
@ -147,7 +148,7 @@ unsafe extern "system" fn wnd_proc(
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
WM_MOUSEWHEEL => {
|
WM_MOUSEWHEEL | WM_MOUSEHWHEEL => {
|
||||||
let mut window_state = (*window_state_ptr).borrow_mut();
|
let mut window_state = (*window_state_ptr).borrow_mut();
|
||||||
let mut window = window_state.create_window(hwnd);
|
let mut window = window_state.create_window(hwnd);
|
||||||
let mut window = crate::Window::new(&mut window);
|
let mut window = crate::Window::new(&mut window);
|
||||||
|
@ -157,7 +158,11 @@ unsafe extern "system" fn wnd_proc(
|
||||||
let value = value as f32 / WHEEL_DELTA as f32;
|
let value = value as f32 / WHEEL_DELTA as f32;
|
||||||
|
|
||||||
let event = Event::Mouse(MouseEvent::WheelScrolled {
|
let event = Event::Mouse(MouseEvent::WheelScrolled {
|
||||||
delta: ScrollDelta::Lines { x: 0.0, y: value },
|
delta: if msg == WM_MOUSEWHEEL {
|
||||||
|
ScrollDelta::Lines { x: 0.0, y: value }
|
||||||
|
} else {
|
||||||
|
ScrollDelta::Lines { x: value, y: 0.0 }
|
||||||
|
},
|
||||||
modifiers: window_state.keyboard_state.get_modifiers_from_mouse_wparam(wparam),
|
modifiers: window_state.keyboard_state.get_modifiers_from_mouse_wparam(wparam),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -596,20 +596,17 @@ impl Window {
|
||||||
let detail = event.detail();
|
let detail = event.detail();
|
||||||
|
|
||||||
match detail {
|
match detail {
|
||||||
4 => {
|
4..=7 => {
|
||||||
handler.on_event(
|
handler.on_event(
|
||||||
&mut crate::Window::new(self),
|
&mut crate::Window::new(self),
|
||||||
Event::Mouse(MouseEvent::WheelScrolled {
|
Event::Mouse(MouseEvent::WheelScrolled {
|
||||||
delta: ScrollDelta::Lines { x: 0.0, y: 1.0 },
|
delta: match detail {
|
||||||
modifiers: key_mods(event.state()),
|
4 => ScrollDelta::Lines { x: 0.0, y: 1.0 },
|
||||||
}),
|
5 => ScrollDelta::Lines { x: 0.0, y: -1.0 },
|
||||||
);
|
6 => ScrollDelta::Lines { x: -1.0, y: 0.0 },
|
||||||
}
|
7 => ScrollDelta::Lines { x: 1.0, y: 0.0 },
|
||||||
5 => {
|
_ => unreachable!(),
|
||||||
handler.on_event(
|
},
|
||||||
&mut crate::Window::new(self),
|
|
||||||
Event::Mouse(MouseEvent::WheelScrolled {
|
|
||||||
delta: ScrollDelta::Lines { x: 0.0, y: -1.0 },
|
|
||||||
modifiers: key_mods(event.state()),
|
modifiers: key_mods(event.state()),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
@ -631,7 +628,7 @@ impl Window {
|
||||||
let event = unsafe { xcb::cast_event::<xcb::ButtonPressEvent>(&event) };
|
let event = unsafe { xcb::cast_event::<xcb::ButtonPressEvent>(&event) };
|
||||||
let detail = event.detail();
|
let detail = event.detail();
|
||||||
|
|
||||||
if detail != 4 && detail != 5 {
|
if !(4..=7).contains(&detail) {
|
||||||
let button_id = mouse_id(detail);
|
let button_id = mouse_id(detail);
|
||||||
handler.on_event(
|
handler.on_event(
|
||||||
&mut crate::Window::new(self),
|
&mut crate::Window::new(self),
|
||||||
|
@ -684,8 +681,8 @@ fn mouse_id(id: u8) -> MouseButton {
|
||||||
1 => MouseButton::Left,
|
1 => MouseButton::Left,
|
||||||
2 => MouseButton::Middle,
|
2 => MouseButton::Middle,
|
||||||
3 => MouseButton::Right,
|
3 => MouseButton::Right,
|
||||||
6 => MouseButton::Back,
|
8 => MouseButton::Back,
|
||||||
7 => MouseButton::Forward,
|
9 => MouseButton::Forward,
|
||||||
id => MouseButton::Other(id),
|
id => MouseButton::Other(id),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue