1 // list of named params - if single number, show EZSlider,
4 NdefParamGui : EnvirGui {
9 minSize = 320 @ (numItems * skin.buttonHeight);
11 if (parent.notNil) { skin = skin.copy.margin = 0@0; };
15 ^obj.isNil or: { obj.isKindOf(NodeProxy) };
19 // accepts strings, numbers, ... what else?
22 var key = prevState[\editKeys][i];
23 var dragged = drag.object;
24 if (dragged.isKindOf(String)) { dragged = dragged.interpret };
26 if(dragged.isKindOf(NodeProxy)) {
27 drag.string = "->" + dragged.key;
28 object.map(key, dragged);
31 if (dragged.isKindOf(SimpleNumber)) {
32 object.set(key, dragged);
41 var height = skin.buttonHeight;
45 prevState = ( settings: [], overflow: 0, keysRotation: 0, editKeys: []);
47 labelWidth = zone.bounds.width * 0.15;
49 #drags, valFields = { |i|
53 drag = DragBoth(zone, Rect(0, 0, sinkWidth, skin.buttonHeight))
54 .string_("-").align_(\center)
58 drag.action_(this.dragAction(i));
60 field = CompositeView(zone, Rect(0, 0, bounds.width - sinkWidth - 20, height))
62 .background_(skin.background);
68 widgets = nil.dup(numItems); // keep EZGui types here
70 zone.decorator.reset.shift(zone.bounds.width - 16, 0);
72 scroller = EZScroller(zone,
73 Rect(0, 0, 12, numItems * height),
76 keysRotation = sc.value.asInteger.max(0);
77 prevState.put(\dummy, \dummy);
80 scroller.slider.resize_(3);
84 var settings, newKeys, overflow;
87 ^(name: 'anon', settings: [], editKeys: [], overflow: 0, keysRotation: 0)
90 settings = object.getKeysValues;
91 newKeys = settings.collect(_[0]);
93 overflow = (newKeys.size - numItems).max(0);
94 keysRotation = keysRotation.clip(0, overflow);
95 newKeys = newKeys.drop(keysRotation).keep(numItems);
97 ^(object: object, editKeys: newKeys, settings: settings,
98 overflow: overflow, keysRotation: keysRotation)
102 var newState = this.getState;
104 if (newState == prevState) {
109 prevState = newState;
110 ^this.clearFields(0);
113 if (newState[\overflow] > 0) {
114 scroller.visible_(true);
115 scroller.numItems_(newState[\settings].size);
116 scroller.value_(newState[\keysRotation]);
119 scroller.visible_(false);
122 if (newState[\editKeys] == prevState[\editKeys]) {
123 this.setByKeys(newState[\editKeys], newState[\settings]);
125 this.setByKeys(newState[\editKeys], newState[\settings]);
126 if (newState[\overflow] == 0) { this.clearFields(newState[\editKeys].size) };
129 prevState = newState;
132 // clearFields { (object.size .. valFields.size).do(this.clearField(_)) }
135 setByKeys { |newKeys, newSettings|
137 var prevSettings = prevState[\settings] ? [];
138 var newVal, oldVal, oldKey;
140 newKeys.do { |newKey, i|
142 newVal = newSettings.detect { |pair| pair[0] == newKey };
143 if (newVal.notNil) { newVal = newVal[1] };
145 oldKey = prevState[\editKeys][i];
147 oldVal = prevSettings.detect(_[0] == oldKey);
148 if (oldVal.notNil) { oldVal = oldVal[1] };
150 if (oldKey != newKey or: { oldVal != newVal }) {
151 // "val for % has changed: %\n".postf(key, newval);
152 this.setField(i, newKey, newVal, newKey == oldKey);
158 ^{ |sl| object.set(key, sl.value) }
162 var area = valFields[index];
164 drags[index].visible_(false);
165 area.children.copy.do { |view| view.remove };
166 area.background_(skin.background);
168 widgets[index] = nil;
172 setField { |index, key, value, sameKey = false|
173 var area = valFields[index];
174 var widget = widgets[index];
176 // [replaceKeys, key].postcs;
177 if (replaceKeys[key].notNil) {
178 area.background_(skin.hiliteColor);
180 area.background_(skin.background);
182 try { // QT temp fix.
183 if (value.isKindOf(NodeProxy)) {
184 drags[index].object_(value).string_("->" ++ value.key);
186 drags[index].object_(nil).string_("-");
188 // dodgy - defer should go away eventually.
189 // needed for defer in setToSlider...
190 { drags[index].visible_(true) }.defer(0.05);
192 if (value.isKindOf(SimpleNumber) ) {
193 this.setToSlider(index, key, value, sameKey);
197 this.setToText(index, key, value, sameKey);