1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
EZScroller {
var <maxItems=1, <numItems=1, <>action, <spec;
var <value, <slider;
*new { |w, bounds, maxItems, numItems, action, initVal=0|
^super.newCopyArgs(maxItems, numItems, action)
.init(w, bounds, initVal);
}
init { |w, bounds, initVal|
slider = Slider.new(w, bounds);
slider.action = { |sl|
this.valueAction_(spec.map(sl.value));
};
slider.keyDownAction { arg char, modifiers, unicode,keycode;
if (unicode == 16rF700, { this.increment; ^this });
if (unicode == 16rF703, { this.increment; ^this });
if (unicode == 16rF701, { this.decrement; ^this });
if (unicode == 16rF702, { this.decrement; ^this });
};
spec = [0, 0, \lin, 1].asSpec;
this.adjust;
this.value_(initVal);
}
increment { this.valueAction = this.value + this.spec.step }
decrement { this.valueAction = this.value + this.spec.step }
adjust {
var slBounds = slider.bounds;
var maxLength = slBounds.width max: slBounds.height + 2;
var numTooMany = (numItems - maxItems).max(1);
var fractionToShow = (maxItems / numItems).min(1);
slider.thumbSize = fractionToShow * maxLength; // CHECK: does this work with qt?
// slider.step_(1 / numTooMany.max(1)); // this does the action - it should not.
slider.setProperty(\step, 1 / numTooMany.max(1));
spec.minval_(numTooMany); // minval to invert spec
}
value_ { |val|
value = spec.constrain(val);
slider.value_(spec.unmap(value));
}
maxItems_ { |val| maxItems = val.max(1); this.adjust }
numItems_ { |val| numItems = val.max(1); this.adjust }
valueAction_ { |val| this.value_(val).doAction; }
doAction { action.value(this) }
enabled { ^slider.enabled }
enabled_ { |flag| slider.enabled_(flag) }
visible { ^slider.visible }
visible_ { |flag| slider.visible_(flag) }
remove { slider.remove }
}
|