Closed magnetophon closed 6 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.
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.
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.
wrapping the constructor parameters in a
Res
I'm not sure I understood correctly; this is something you need to do, right?
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.
Actually, I just checked and the ranges and scalings are already wrapped in Res
. So this should already be possible, no?
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.
Just like
PeakBuffer
andMinimaBuffer
haveset_duration()
to set the scale in one direction, the views that include a range should have aset_range()
to set the scale in the other direction.