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

where a plugin can contrôle mouse speed/frequency ? #471

Closed
jonlepage opened this issue Feb 4, 2023 · 7 comments
Closed

where a plugin can contrôle mouse speed/frequency ? #471

jonlepage opened this issue Feb 4, 2023 · 7 comments
Milestone

Comments

@jonlepage
Copy link

jonlepage commented Feb 4, 2023

sup friend, on my side i contrôle mouse frequency update like this for some of my inputs.

<button
	style={{ cursor: 'w-resize' }}
	onPointerDown={(e) => {
		const { min, max, step, speed } = metas ?? {}; // metas options of the input

		const sdx = (e.clientX - e.clientY);
		const pointermove = (e: PointerEvent) => {
			const dx = (e.clientX - e.clientY);
			let v = value + ((dx - sdx) * (speed ?? 0.5)); // speed of mouse 🟢
			if (step) v = Math.round(v / step) * step; // apply step if need 
			if (min !== undefined) v = Math.max(min, v); // apply clamping
			if (max !== undefined) v = Math.min(max, v);
			v = +v.toFixed(3);
			setValue(v);
			onChange?.(v);
		};
		document.addEventListener('pointermove', pointermove);
		document.addEventListener('pointerup', (e) => document.removeEventListener('pointermove', pointermove), { once: true });
		e.stopPropagation();
		e.preventDefault();
	}}
>
	{`${vkey}:`}
</button>

did you or can you expose a way to allow user hack mouse speed/frequency ?
1 pixel update is too face for lot of case.
can you guide how archive this with your api ?
related to this issu, thanks
0b5vr/tweakpane-plugin-rotation#1


expected behavior
8uuuj

@cocopon
Copy link
Owner

cocopon commented Feb 4, 2023

You mean you want to change a scale for dragging, right?

In the current spec it's estimated from its initial value or step option.

export function getSuitableDraggingScale(
constraint: Constraint<number> | undefined,
rawValue: number,
): number {
const sc = constraint && findConstraint(constraint, StepConstraint);
const base = Math.abs(sc?.step ?? rawValue);
return base === 0 ? 0.1 : Math.pow(10, Math.floor(Math.log10(base)) - 1);
}

@jonlepage
Copy link
Author

thanks

@cocopon
Copy link
Owner

cocopon commented Feb 5, 2023

Wait wait, I'm positive to add an option for changing the scale.

@cocopon cocopon reopened this Feb 5, 2023
@jonlepage
Copy link
Author

Wait wait, I'm positive to add an option for changing the scale.

ho oups, oki i will try done a monkey patch for my app and keep a eye on your commit 😊

@cocopon cocopon added this to the 4.0.0 milestone Mar 21, 2023
@cocopon cocopon mentioned this issue Mar 21, 2023
24 tasks
@cocopon
Copy link
Owner

cocopon commented Jun 22, 2023

Added keyScale and pointerScale option to NumberInputParams in v4 beta.

pane.addBinding(PARAMS, 'foo', {
  keyScale: 10,
  pointerScale: 1,
  ...
});

https://tweakpane.github.io/docs/api/interfaces/NumberInputParams.html

You can try it with npm install tweakpane@beta or downloading it manually: https://github.com/cocopon/tweakpane/releases/tag/4.0.0-beta.1

@jonlepage
Copy link
Author

hey thank i will give a try maybe this week

@cocopon
Copy link
Owner

cocopon commented Aug 6, 2023

Released in v4.0.0.

@cocopon cocopon closed this as completed Aug 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants