forge
Explore
Log in

Don't you dare go Hollow

screenshot_ui: Move selection with a second touch too

Browse files at this commit

97dfd2b1a00bcb9b765a8fa92ce39d2e0c79abc2Ivan MolodetskikhParent: 730eab0
src/ui/screenshot_ui.rsmodified+56 -10
@@ -66,14 +66,22 @@ pub enum ScreenshotUi {
66 },66 },
67 }67 }
68 68
69+/// State for moving the selection (as opposed to just drawing).
70+pub struct MoveState {
71+ // Cursor offset from selection.1 when starting the move.
72+ pointer_offset: Point<i32, Physical>,
73+ // If the move is initiated by a touch, this is the slot. If `None`, the move was initiated by
74+ // holding Space.
75+ touch_slot: Option<TouchSlot>,
76+}
77+
69 pub enum Button {78 pub enum Button {
70 Up,79 Up,
71 Down {80 Down {
72 touch_slot: Option<TouchSlot>,81 touch_slot: Option<TouchSlot>,
73 on_capture_button: bool,82 on_capture_button: bool,
74 last_pos: (Output, Point<i32, Physical>),83 last_pos: (Output, Point<i32, Physical>),
75- /// Offset from the selection.1 corner to cursor grab point when moving the selection.84+ move_state: Option<MoveState>,
76- move_cursor_offset: Option<Point<i32, Physical>>,
77 },85 },
78 }86 }
79 87
@@ -274,7 +282,7 @@ impl ScreenshotUi {
274 selection,282 selection,
275 button:283 button:
276 Button::Down {284 Button::Down {
277- move_cursor_offset,285+ move_state,
278 last_pos,286 last_pos,
279 ..287 ..
280 },288 },
@@ -282,9 +290,20 @@ impl ScreenshotUi {
282 } = self290 } = self
283 {291 {
284 if down {292 if down {
285- *move_cursor_offset = Some(last_pos.1 - selection.1);293+ if move_state.is_none() {
294+ *move_state = Some(MoveState {
295+ pointer_offset: last_pos.1 - selection.1,
296+ touch_slot: None,
297+ });
298+ }
286 } else {299 } else {
287- *move_cursor_offset = None;300+ // Only clear if moving with Space.
301+ if let Some(MoveState {
302+ touch_slot: None, ..
303+ }) = move_state
304+ {
305+ *move_state = None;
306+ }
288 }307 }
289 }308 }
290 }309 }
@@ -790,7 +809,7 @@ impl ScreenshotUi {
790 touch_slot,809 touch_slot,
791 on_capture_button,810 on_capture_button,
792 last_pos,811 last_pos,
793- move_cursor_offset,812+ move_state,
794 },813 },
795 ..814 ..
796 } = self815 } = self
@@ -808,9 +827,9 @@ impl ScreenshotUi {
808 return;827 return;
809 }828 }
810 829
811- if let Some(cursor_offset) = move_cursor_offset {830+ if let Some(move_state) = move_state {
812 // The cursor offset is relative to selection.1.831 // The cursor offset is relative to selection.1.
813- let delta = point - (selection.1 + *cursor_offset);832+ let delta = point - (selection.1 + move_state.pointer_offset);
814 833
815 let desired = rect_from_corner_points(selection.1 + delta, selection.2 + delta);834 let desired = rect_from_corner_points(selection.1 + delta, selection.2 + delta);
816 let bounds = Rectangle::from_size(output_data[&selection.0].size - desired.size);835 let bounds = Rectangle::from_size(output_data[&selection.0].size - desired.size);
@@ -843,6 +862,24 @@ impl ScreenshotUi {
843 return false;862 return false;
844 };863 };
845 864
865+ // Check if this is a second touch (different slot) while already dragging.
866+ if let Some(new_slot) = slot {
867+ if let Button::Down {
868+ on_capture_button: false,
869+ move_state,
870+ last_pos,
871+ ..
872+ } = button
873+ {
874+ if move_state.is_none() {
875+ *move_state = Some(MoveState {
876+ pointer_offset: last_pos.1 - selection.1,
877+ touch_slot: Some(new_slot),
878+ });
879+ }
880+ }
881+ }
882+
846 if button.is_down() {883 if button.is_down() {
847 return false;884 return false;
848 }885 }
@@ -861,7 +898,7 @@ impl ScreenshotUi {
861 touch_slot: slot,898 touch_slot: slot,
862 on_capture_button: true,899 on_capture_button: true,
863 last_pos: (output, point),900 last_pos: (output, point),
864- move_cursor_offset: None,901+ move_state: None,
865 };902 };
866 return false;903 return false;
867 }904 }
@@ -871,7 +908,7 @@ impl ScreenshotUi {
871 touch_slot: slot,908 touch_slot: slot,
872 on_capture_button: false,909 on_capture_button: false,
873 last_pos: (output.clone(), point),910 last_pos: (output.clone(), point),
874- move_cursor_offset: None,911+ move_state: None,
875 };912 };
876 *selection = (output, point, point);913 *selection = (output, point, point);
877 914
@@ -896,12 +933,21 @@ impl ScreenshotUi {
896 touch_slot,933 touch_slot,
897 on_capture_button,934 on_capture_button,
898 ref last_pos,935 ref last_pos,
936+ ref mut move_state,
899 ..937 ..
900 } = *button938 } = *button
901 else {939 else {
902 return None;940 return None;
903 };941 };
904 942
943+ // Check if this is a move touch and if so, stop the move.
944+ if let Some(state) = move_state {
945+ if state.touch_slot.is_some_and(|m_slot| Some(m_slot) == slot) {
946+ *move_state = None;
947+ return None;
948+ }
949+ };
950+
905 if touch_slot != slot {951 if touch_slot != slot {
906 return None;952 return None;
907 }953 }