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

Customizable drag length for AudioKnob #12

Open
andersforsgren opened this issue Jan 1, 2023 · 3 comments
Open

Customizable drag length for AudioKnob #12

andersforsgren opened this issue Jan 1, 2023 · 3 comments

Comments

@andersforsgren
Copy link
Contributor

andersforsgren commented Jan 1, 2023

Thanks for a great little lib. I think the drag is a bit coarse on the AudioKnob, e.g. when the knob is say 32px, then the drag is just divided into 32 steps

Existing impl:

new_value += delta * (self.range.end() - self.range.start()) / self.diameter;

I have tried this with some success, simply introducing a scale factor so the user can drag N times the diameter (So you'd use 3 or 4). E.g.:

// self.drag_length: f32; a scale for how many diameters need to be dragged to cover the knob range
new_value += delta * (self.range.end() - self.range.start()) / (self.diameter * self.drag_length);

There are obviously other ways off accomplishing the same thing (E.g. using Some(100.0) as an optional fixed override might be better because it gives the user a way to provide the same drag-length for all knob sizes if they vary across the UI). E.g.:

// self.drag_length: Option<f32> an override to indicate how long to drag. 
new_value += delta * (self.range.end() - self.range.start()) / self.drag_length.unwrap_or(self.diameter);

I just use fixed 32px knobs so my use case was fine with a simple multiplier. I can submit a PR for this but I thought you might have some input on the api first.

Btw is there an issue with the shift-drag snapping for the AudioKnob? I can't quite get that working.

@BillyDM
Copy link

BillyDM commented Jan 8, 2023

I'd reference how I do this in my code. My version also has the ability to fine-tune controls by scrolling the mouse wheel and/or holding down shift while dragging.

In fact, you can even use this logic for sliders to have fine-tune controls for those as well.

This is a concept called a "virtual slider" where every control has the same input behavior. The only difference between controls is how they are drawn.

https://github.com/MeadowlarkDAW/Meadowlark/blob/dev/src/ui/generic_views/virtual_slider.rs

@xTibor
Copy link
Owner

xTibor commented Jan 11, 2023

I stole that drag_length commit from your fork. Hope you don't mind it.

@xTibor
Copy link
Owner

xTibor commented Jan 11, 2023

Shift-snapping works for me, at least how it's used in the widget gallery:

simplescreenrecorder-2023-01-11_09.47.31.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants