MinBox a minimal gui


Inherits from: UserView


MinBox is a custom GUI widget that attempts to emulate slider, knob, numberbox, button, and the "EZ" container classes, all in a minimal amount of space.  You may also specify a ControlSpec, as well as step and round values.


You may change the value using the mouse, programmatically, using the arrow keys, or using the number keys to set the value directly.  The Ctrl and Alt keys change the step value when changing the value via mouse.


See also: CV [some other help files]


Some Important Issues Regarding SCMinBox


SwingOSC compatability is not yet complete!  


Creation / Class Methods


Use this widget factory to explore the various customization options of MinBox:


(

~win = FlowView.new;

~minbox = MinBox.new(~win, 150@150).label_("a minbox").resize_(5);

~flow = FlowView.new(~win, 150@150);

StaticText(~flow, 60@20).align_(\right).string_("mode");

~mode = PopUpMenu.new(~flow, 60@20)

.items_(MinBox.modes)

.value_(0)

.action_({|v| ~minbox.mode = v.item; ~minbox.refresh  });

StaticText(~flow, 60@20).align_(\right).string_("textMode");

~textMode = PopUpMenu.new(~flow, 60@20)

.items_(MinBox.textModes)

.value_(1)

.action_({|v| ~minbox.textMode = v.item; ~minbox.refresh  });

StaticText(~flow, 60@20).align_(\right).string_("align");

~align = PopUpMenu.new(~flow, 60@20)

.items_(MinBox.aligns)

.value_(2)

.action_({|v| ~minbox.align = v.item; ~minbox.refresh  });

StaticText(~flow, 60@20).align_(\right).string_("spec");

~spec = PopUpMenu.new(~flow, 60@20)

.items_(Spec.specs.select({|x| x.isKindOf(ControlSpec)}).keys.asArray.sort)

.action_({|v| ~minbox.spec = Spec.specs.at(v.item).postln; ~minbox.refresh  });

~spec.valueAction = ~spec.items.indexOf(\unipolar);

StaticText(~flow, 60@20).align_(\right).string_("step");

~step = NumberBox(~flow, 60@20)

.value_(~minbox.step)

.action_({|v| ~minbox.step = v.value });

StaticText(~flow, 60@20).align_(\right).string_("round");

~round = NumberBox(~flow, 60@20)

.value_(~minbox.round)

.action_({|v| ~minbox.round = v.value });

StaticText(~flow, 60@20).align_(\right).string_("label");

~label = TextField(~flow, 60@20)

.value_(~minbox.label)

.action_({|v| ~minbox.label = v.value.asString });


~win.startRow;


~result = Button.new(~win, 100@40).states_([["Compile String"]]);

~result.action_({|view|

var str = "MinBox.new(parent, bounds)";

str = str++"\n\t.label_(%)\n\t.spec_(%)"

.format(~minbox.label.asCompileString,~minbox.spec.asCompileString);

str = str++"\n\t.mode_(%).textMode_(%).align_(%)"

.format(~minbox.mode.asCompileString,~minbox.textMode.asCompileString,~minbox.align.asCompileString);

str = str++"\n\t.step_(%).round_(%)".format(~minbox.step, ~minbox.round);

str.postln

})


/* uncomment this if you'd like to create your own custom skin.  Drag colors into the dragsinks and the minbox will show the changes


~colors = Array.fill(5, {|i|

DragSink(~win, 100@20)

.string_(["hi","lo","line","text","type"][i])

.align_(\center)

.receiveDragHandler={|v|

v.object = View.currentDrag.value;

v.string = ["hi","lo","line","text","type"][i];

v.background_(v.object.asColor);

~minbox.perform([\hiColor,\loColor,\lineColor,\normalColor,\typingColor][i].asSetter,v.object.asColor);

~minbox.refresh;

}

});


~makeSkin = Button.new(~win,100@20).states_([["make skin"]]);

~makeSkin.action_({|v| 

(

hi: ~colors[0].object,

lo: ~colors[1].object,

text: ~colors[3].object,

type: ~colors[4].object,

line: ~colors[2].object

).asCompileString.postln

})

*/

)


Accessing Instance and Class Variables

defaultMode

classvar.  the default mode for MinBox may be changed.  

Default value is \vert

modes

lists the possible display modes

textModes

lists the possible textModes

aligns

lists the possible values for align

round

when a value is set it is rounded using this value.  This rounds the spec-mapped value.  See step for rounding the unmapped value

Default is 0.01

mode

this sets the display mode.  See example above for what the options look like.

Default is \vert

spec

A ControlSpec.  When this is set the value of this view is mapped to the spec.

Default value is \unipolar

Note: changing the step value of the ControlSpec does not change the round or step of the MinBox

value

The value of the view mapped to the view's current spec.

Default value is 0.0;

align_(arg1)

align

Sets the align of the text within the view

Default value is \center

textMode

Changes the mode for the text display

Default value is nil.


label

A String.  Default value is ""


hiColor_(arg1)

hiColor

A Color.  Sets the color for the max value

loColor_(arg1)

loColor

A Color.  Sets the color for the min value

lineColor_(arg1)

lineColor

A Color.  Sets the color for the min value

font_(arg1)

font

A Font.  Sets the font

typingColor_(arg1)

typingColor

A Color.  See [NumberBox]

normalColor_(arg1)

normalColor

A Color.  See [NumberBox]

editable_(arg1)

editable

Sets the view editable or not.

skin

Use this to change the view's display settings all at once.  Here are some examples:

// grayscale

~minbox.skin = (

hi: Color.gray(0.85),

lo: Color.gray(0.5),

text: Color.gray(0.1,0.8),

type: Color.red(0.8,0.8),

line: Color.gray(0.98),

font: Font("Verdana-Bold", 12.0),

defaultMode: 'blend'

)

~minbox.font = Font("Verdana-Bold", 12); ~minbox.refresh

// 70's

~minbox.skin = ( 

hi: Color(0.8, 0.4, 0.0, 1.0), 

lo: Color(0.74, 0.72, 0.42, 1.0), 

line: Color(0.15, 0.25, 0.55, 0.7), 

text: Color(0.1, 0.1, 0.1, 1.0), 

type: Color(1.0, 1.0, 1.0, 1.0), 

font: Font("Verdana-Bold", 12.0),

defaultMode: 'blend'

)

// iXi-inspired

~minbox.skin = (

hi: Color(1.0, 0.4, 0.0, 0.63),

lo: Color(0.4, 0.58, 0.4, 1.0),

line: Color(0.61, 0.8, 0.61, 1.0),

text: Color(0.88, 0.94, 0.88, 1.0),

type: Color(0.5, 0.2, 0.0, 0.81),

//Color(1.0, 0.82, 0.7, 0.89),

font: Font("Helvetica", 15.0),

defaultMode: 'horiz'

)

~minbox.skin = GUI.skins.default.minbox


step_(arg1)

step

Sets the step size for changing the value.  This is mapped to the 0-1 range, not the ControlSpec value

Default value is 0.001.

input_ (in)

input

returns or sets the unmapped value (0-1 range) of the view



Examples


// what this example does

e = SCMinBox.new;

e.instanceMethod(someObject);

e.cleanUp;


...