Code: Select all
if(component == knob1) {
if(doubleValue < 0.0)
knob1.SetValue(-1.0, true);
}
Code: Select all
if(component == knob1) {
if(doubleValue < 0.0)
knob1.SetValue(-1.0, true);
}
Code: Select all
if(component == knob1) {
if(doubleValue < 0.0)
knob1.SetValue(0.0, true);
}
That's what I was trying to say. When you drag the knob with the mouse it updates the knob and calls Notify() which then resets the knobs value. I don't think it's a bug.UrbanCyborg wrote: ↑Mon Feb 14, 2022 11:30 pm I don't think it's a recursion problem; I think it's a problem with mouse handler updating.
Code: Select all
double knob1Value = 0.0;
Code: Select all
if (component == knob1) {
knob1Value = Math.max(0.0, doubleValue);
}
From the API documentation:
Code: Select all
public void SetValue(double newValue,
boolean bUpdateGUI)
Sets the value of the knob.
Overrides:
SetValue in class VoltageComponent
Parameters:
newValue - the new value of the knob.
bUpdateGUI - should the gui be updated?
What I'm trying to do is to prevent the user from dragging a control to a value that breaks a module invariant. The invariant takes the form of one control which must never be less than the value of another control. So if the user drags to a value that would break the invariant, the knob handler fixes it by resetting the value on the fly to a reasonable alternative value. I could have done this by mangling the controls' min and max values on the fly, so that the user couldn't drag to an invalid location, but doing that runs into recursion problems almost immediately, and making the visual travel on a knob be consistent with both its new limits and the old would be an awful mess. One of those instances where getting it to look pretty would come to dominate the code.honki-bobo wrote:
That's what I was trying to say. When you drag the knob with the mouse it updates the knob and calls Notify() which then resets the knobs value. I don't think it's a bug.
I don't know what you are trying to achieve, but you could circumvent this problem by storing the knobs value into a variable, i.e.
Code: Select all
double knob1Val = 0.5; // knob default value
double knob2Val = 0.5; // knob default value
Code: Select all
if (component == knob1) {
knob2.SetRange(
Math.max(doubleValue, 0.0), // 0.0 := button min value
1.0,
Math.max(doubleValue, 0.5), // 0.5 := button default value
false,
0);
knob2.SetValue(Math.max(doubleValue, knob2Val));
knob1Val = doubleValue;
} else if (component == knob2) {
knob2Val = doubleValue;
}