1
2ParamView {
3	var <value, <label, <>action, <spec;
4	var <zone, <zones, <slider, <ranger, <textview;
5	var <ezviews, <currview, <viewType;
6	var <>useRanger = true;
7
8	*new { |parent, bounds, label, spec, action, initVal, initAction = false|
9		^super.new.init(parent, bounds, label, spec, action, initVal, initAction);
10	}
11
12	bounds { ^zone.bounds }
13	bounds_ { |bounds| zone.bounds_(bounds) }
14
15	background { ^currview.labelView.background }
16	background_ { |col|
17		ezviews.do { |ez| ez.labelView.background_(col) }
18	}
19
20	label_ { |alabel|
21		label = alabel;
22		ezviews.do { |ez| ez.labelView.string_(alabel) };
23	}
24
25	enabled_ { |bool=true| zone.enabled_(bool) }
26	enabled { ^zone.enabled }
27	visible_ { |bool=true| zone.visible_(bool) }
28	visible { ^zone.visible }
29
30	init { |parent, bounds, argLabel, argSpec, argAction, initVal, initAction, initType = 0|
31		var rect2 = bounds.moveTo(0,0);
32		zone = CompositeView(parent, bounds);
33		zones = 3.collect { |i| CompositeView(zone, rect2); };
34		zone.resize_(2);
35		zones.do(_.resize_(2));
36
37		label = argLabel ? "-";
38		spec = argSpec !? { argSpec.asSpec };
39		action = argAction;
40
41		slider = EZSlider(zones[0], rect2, label, spec);
42		ranger = EZRanger(zones[1], rect2, label, spec);
43		textview = EZText(zones[2], rect2, label);
44
45		zones.do { |z| z.children[0].resize_(2) };
46
47		ezviews = [slider, ranger, textview];
48		ezviews.do { |ez|
49			ez.action_({ |ez| this.valueAction_(ez.value) });
50		};
51		if (initVal.notNil) { this.value(initVal) };
52		if (initAction) { this.doAction };
53	}
54
55	// types: 0 = slider, 1 = ranger, 2 = text
56	viewType_ { |newType = 0, force = false|
57		if (spec.isNil or: { useRanger.value != true }) {
58			newType = newType.roundUp(2);
59		};
60		if (force or: { newType != viewType }) {
61			if (newType.inclusivelyBetween(0, 2)) {
62				zones.do { |z, i| z.visible_(newType == i) };
63				viewType = newType;
64				currview = ezviews[newType];
65			};
66		};
67	}
68
69	valueType { |newval|
70		^case
71		{ newval.isNumber } { 0 }
72		{ newval.isKindOf(Array) and:
73			{ newval.size == 2 and:
74				{ newval.every(_.isNumber) }
75			}
76		} { 1 }
77		{ 2 }
78	}
79
80	value_ { |val|
81		this.viewType_(this.valueType(val));
82		value = val;
83		currview.value_(value);
84	}
85
86	doAction { action.value(this) }
87	valueAction_ { |val| this.value_(val).doAction }
88
89	spec_ { |newspec|
90		spec = newspec !? { newspec.asSpec };
91		slider.controlSpec_(spec);
92		ranger.controlSpec_(spec);
93	}
94}
95