Hello
As EZGui classes don’t work (yet) with layouts,, I wanted to do my own View which would be composed of a Slider and a NumberBox.
My first instinct was to subclass View
MySlider : View {
var slider;
var numberBox;
*new {
^super.new.init();
}
init {
numberBox = NumberBox(this, Rect(0,0, 60, 60));
slider = Slider(this, Rect(60, 0, 200, 60));
this.layout = HLayout([numberBox, stretch: 1], [slider, stretch: 5]);
slider.action = {
numberBox.value = slider.value;
};
numberBox.action = {
slider.value = numberBox.value;
};
}
}
The slider and numberBox are synced.
But of course, other elements should register to MySlider value changes with something like
(
~window = Window();
~slider = MySlider();
~window.layout = HLayout(~slider);
~slider.action = { |slider|
slider.value.postln;
};
~window.front;
)
But I haven’t done the plumbing between the slider/numberbox in MySlider and the window.
How do I propagate the value to MySlider listeners ?
*** EDIT ***
I did that, but is it the most elegant way ?
MySlider : View {
var <>action;
var slider;
var numberBox;
var <value;
*new {
^super.new.init();
}
init {
numberBox = NumberBox(this, Rect(0,0, 60, 60));
slider = Slider(this, Rect(60, 0, 200, 60));
this.layout = HLayout([numberBox, stretch: 1], [slider, stretch: 5]);
slider.action = {
this.value = slider.value;
this.doAction();
};
numberBox.action = {
this.value = numberBox.value;
this.doAction();
};
}
value_ { |v|
numberBox.value = v;
slider.value = v;
value = v;
}
doAction {
this.action.value(this);
}
}
Thanks !
Geoffroy