mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-25 15:42:14 +00:00
M1, #1758: mouse buttons 4 and 5 pan the canvas like the middle button
This commit is contained in:
@@ -101,3 +101,6 @@ sync_github_name = true
|
||||
|
||||
[people.aleksei-suholita]
|
||||
real_name = "Oleksii Sukholita"
|
||||
|
||||
[people.ashokram-si]
|
||||
real_name = "Ashok Ram"
|
||||
|
||||
@@ -25,6 +25,14 @@ impl HoverKey {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether a button that pans the canvas is held: the middle button, or a mouse's side buttons
|
||||
/// (4 and 5), which the incumbent treats the same way (#1758). Space + primary pans too, handled
|
||||
/// with the Space key.
|
||||
fn pan_button_down(i: &egui::InputState) -> bool {
|
||||
use egui::PointerButton::{Extra1, Extra2, Middle};
|
||||
[Middle, Extra1, Extra2].into_iter().any(|b| i.pointer.button_down(b))
|
||||
}
|
||||
|
||||
/// The pointer left the canvas (or something over it took the pointer): nothing is hovered there.
|
||||
fn left(app: &mut FigApp) {
|
||||
app.canvas.last_hover = None;
|
||||
@@ -180,7 +188,7 @@ pub(super) fn input(app: &mut FigApp, ui: &mut Ui, resp: &egui::Response) -> boo
|
||||
left(app);
|
||||
}
|
||||
// A pan whose button was released off the canvas is over.
|
||||
if !ctx.input(|i| i.pointer.button_down(egui::PointerButton::Middle) || i.pointer.primary_down()) {
|
||||
if !ctx.input(|i| pan_button_down(i) || i.pointer.primary_down()) {
|
||||
app.canvas.middle_pan = None;
|
||||
}
|
||||
return true;
|
||||
@@ -211,8 +219,8 @@ pub(super) fn input(app: &mut FigApp, ui: &mut Ui, resp: &egui::Response) -> boo
|
||||
if zoom_tool(app, ui, resp, pos, mods, editing_text || typing_elsewhere) {
|
||||
return true;
|
||||
}
|
||||
// Middle-button / space panning.
|
||||
let middle_down = ctx.input(|i| i.pointer.button_down(egui::PointerButton::Middle));
|
||||
// Middle-button (or side-button) / space panning.
|
||||
let middle_down = ctx.input(pan_button_down);
|
||||
if (middle_down || (app.canvas.space_pan && ctx.input(|i| i.pointer.primary_down()))) && resp.hovered() || app.canvas.middle_pan.is_some() {
|
||||
if let Ok(ds) = app.session.ds_mut() {
|
||||
match app.canvas.middle_pan {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! A canvas pan (middle button or Space + primary) ends when its button is released, even when the
|
||||
//! release happens over a panel: returning to the canvas with no button held must not move the view.
|
||||
//! A canvas pan (middle button, a side button, or Space + primary) ends when its button is
|
||||
//! released, even when the release happens over a panel: returning to the canvas with no button held
|
||||
//! must not move the view.
|
||||
|
||||
use egui::{Event, Key, PointerButton, Pos2, RawInput, Rect, vec2};
|
||||
use figcraft_engine::Session;
|
||||
@@ -45,6 +46,12 @@ fn space(pressed: bool) -> Event {
|
||||
}
|
||||
|
||||
fn check(space_pan: bool, outside: bool) {
|
||||
check_button(if space_pan { PointerButton::Primary } else { PointerButton::Middle }, space_pan, outside);
|
||||
}
|
||||
|
||||
/// A pan with button `b` (with Space held when `space_pan`) moves the view, ends when `b` is
|
||||
/// released (`outside` the canvas or over it), and a new one moves it again.
|
||||
fn check_button(b: PointerButton, space_pan: bool, outside: bool) {
|
||||
let mut u = Frames::new();
|
||||
let rect = u.app.canvas.rect;
|
||||
let start = Pos2::new(rect.min.x + 200.0, rect.center().y);
|
||||
@@ -55,7 +62,6 @@ fn check(space_pan: bool, outside: bool) {
|
||||
if space_pan {
|
||||
u.frame(vec![space(true)]);
|
||||
}
|
||||
let b = if space_pan { PointerButton::Primary } else { PointerButton::Middle };
|
||||
let before = u.cx();
|
||||
u.frame(vec![button(start, b, true)]);
|
||||
u.frame(vec![Event::PointerMoved(dragged)]);
|
||||
@@ -93,3 +99,13 @@ fn space_pan_released_over_panel_does_not_move_view_on_return() {
|
||||
fn middle_pan_released_inside_canvas_keeps_view() {
|
||||
check(false, false);
|
||||
}
|
||||
|
||||
/// #1758: a mouse's side buttons (4 and 5) pan the canvas as the middle button does, and the pan
|
||||
/// ends on release, over the canvas or off it.
|
||||
#[test]
|
||||
fn side_buttons_pan_like_the_middle_button() {
|
||||
for b in [PointerButton::Extra1, PointerButton::Extra2] {
|
||||
check_button(b, false, false);
|
||||
check_button(b, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user