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

Account for minimum motion for node clicks #109

Merged
merged 2 commits into from
Sep 29, 2023
Merged
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
23 changes: 19 additions & 4 deletions src/viser/client/src/SceneTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ export function SceneNodeThreeObject(props: {
false;
const [obj, setRef] = React.useState<THREE.Object3D | null>(null);

const dragInfo = React.useRef({
dragging: false,
startClientX: 0,
startClientY: 0,
brentyi marked this conversation as resolved.
Show resolved Hide resolved
});

// Create object + children.
//
// For not-fully-understood reasons, wrapping makeObject with useMemo() fixes
Expand Down Expand Up @@ -200,7 +206,6 @@ export function SceneNodeThreeObject(props: {
50
);
const [hovered, setHovered] = React.useState(false);
const [dragged, setDragged] = React.useState(false);
useCursor(hovered);
if (!clickable && hovered) setHovered(false);

Expand All @@ -219,17 +224,27 @@ export function SceneNodeThreeObject(props: {
onPointerDown={(e) => {
if (!isDisplayed()) return;
e.stopPropagation();
setDragged(false);
const state = dragInfo.current;
state.startClientX = e.clientX;
state.startClientY = e.clientY;
state.dragging = false;
}}
onPointerMove={(e) => {
if (!isDisplayed()) return;
e.stopPropagation();
setDragged(true);
const state = dragInfo.current;
const deltaX = e.clientX - state.startClientX;
const deltaY = e.clientY - state.startClientY;
// Minimum motion.
console.log(deltaX, deltaY);
if (Math.abs(deltaX) <= 3 && Math.abs(deltaY) <= 3) return;
state.dragging = true;
}}
onPointerUp={(e) => {
if (!isDisplayed()) return;
e.stopPropagation();
if (dragged) return;
const state = dragInfo.current;
if (state.dragging) return;
sendClicksThrottled({
type: "SceneNodeClickedMessage",
name: props.name,
Expand Down
Loading