exa04 / cyma

Visualizers for nih-plug UIs made using VIZIA.
https://exa04.github.io/cyma/book
Mozilla Public License 2.0
35 stars 1 forks source link

set_range() for Graph, Grid, Meter, etc. #52

Closed magnetophon closed 6 months ago

magnetophon commented 7 months ago

Just like PeakBuffer and MinimaBuffer have set_duration() to set the scale in one direction, the views that include a range should have a set_range() to set the scale in the other direction.

exa04 commented 7 months ago

Are you talking about replacing the constructor parameter with a view modifier?

As in, this is what some affected view code might've looked like before:

Graph::new(cx, Data::buffer, (-32.0, 8.0) ValueScaling::Decibels);

And this being what it would look like afterwards?

Graph::new(cx, Data::buffer, ValueScaling::Decibels)
    .scale(-32.0, 8.0);

Because in that case, the new constructor would basically have to supply some default range for the graph as modifiers are always optional. I'm not exactly opposed to that solution as it could lead to more concise code and a better DX, but I'd just like to know if that's what you mean.

magnetophon commented 7 months ago

Sorry I was not clear. Whether new() should change or stay the same, is up to you, I have no opinion on that. I'm just asking for a way to change the scale at run-time, so the user can zoom in/out as needed.

exa04 commented 7 months ago

Ah, I see. In that case, wrapping the constructor parameters in a Res might be better since it allows for values or bindings to be passed to the view. Then, the properties could be modified at runtime through the data model.

magnetophon commented 7 months ago

wrapping the constructor parameters in a Res

I'm not sure I understood correctly; this is something you need to do, right?

exa04 commented 7 months ago

Yes, it's something that I would need to do. A Res would basically mean that you can either pass the range directly as a tuple of floats, or as a Lens so that the range is bound by the data model.

exa04 commented 7 months ago

Actually, I just checked and the ranges and scalings are already wrapped in Res. So this should already be possible, no?

exa04 commented 7 months ago

Alright, nevermind :sweat_smile: The Graph and other views do take in a Res, but I forgot to make them bind to it. The value is just read once upon creation. So yeah, I'm gonna add the necessary binding code now.