Hi all,
I’m taking some time to understand the MVC (model-view-controller) paradigm more deeply. I’m noticing some odd behavior when a block of GUI code begins with Window.closeAll. One the first evaluation, the following code works fine AFAICT. However, if re-evaluated as-is, the MVC relationships disappear — the sliders and number box no longer move together. But, if I manually close the window first, or run Window.closeAll (or ~win.close) as a separate statement before re-evaluating the code chunk, things work fine.
I would guess this is related to the precise order in which the interpreter deals with these tasks (removing the old dependent, closing the window, creating a new window, creating a new dependent), but I’m pretty clueless. Is this a bug, or am I doing something wrong?
Eli
(
Window.closeAll;
~model = [0.75];
~ctrl = SimpleController.new(~model);
~ctrl.put(\val, {~view.do({ |v| v.value_(~model[0]) }) });
~win = Window.new(bounds:Rect(100,100,100,325))
.alwaysOnTop_(true).front;
~win.onClose_({ ~ctrl.remove });
~view = [
Slider(~win, Rect(25,25,25,250))
.value_(~model[0])
.action_({ |v| ~model.put(0, v.value).changed(\val) }),
Slider(~win, Rect(50,25,25,250))
.value_(~model[0])
.action_({ |v| ~model.put(0, v.value).changed(\val) }),
NumberBox(~win, Rect(25,275,50,25)).align_(\center)
.value_(~model[0])
.action_({ |v| ~model.put(0, v.value).changed(\val) })
];
)