Nice work Dirk,
The problem with icon buttons becomes apparent which you want them to
have some text. To get that to work, you need to stack three objects
like I've done here:
function namedButton (container,name,size,color){
color = color || [0.1, 0.4, 0.9, 0.3];
size = size || [100,20];
var grp = container.add('group');
grp.orientation = 'stack';
var btn = grp.add('iconbutton', undefined, undefined, {style:'toolbutton'});
btn.size = size;
grp.add('statictext',undefined,name);
btn.fillBrush=btn.graphics.newBrush( btn.graphics.BrushType.SOLID_COLOR, color );
btn.onDraw = function (){
this.graphics.drawOSControl();
this.graphics.rectPath(0,0,this.size[0],this.size[1]);
this.graphics.fillPath(this.fillBrush);
}
var clickButton = grp.add('iconbutton', undefined, undefined, {style:'toolbutton'});
clickButton.size = size;
clickButton.fillBrush=clickButton.graphics.newBrush( clickButton.graphics.BrushType.SOLID_COLOR,[0,0,0,0] );
clickButton.onDraw = function (){
//this.graphics.drawOSControl();
this.graphics.rectPath(0,0,this.size[0],this.size[1]);
this.graphics.fillPath(this.fillBrush);
}
return clickButton;
}
var dlg = new Window('dialog', 'Test');
var pnl = dlg.add('panel', undefined, 'My Panel');
var btn = pnl.add('button', undefined, 'Standard Button', {name:'ok'});
var btn2 = new namedButton(pnl,"Cool Button");
btn2.onClick = function(){
alert("Yep. This is cool!");
}
dlg.show();
Harbs
http://www.in-tools.com
Innovations in Automation
> To get that to work, you need to stack three objects like I've done here:
or add three lines, like I've done here ...
function customDraw()
{ with( this ) {
graphics.drawOSControl();
graphics.rectPath(0,0,size[0],size[1]);
graphics.fillPath(fillBrush);
if( text ) graphics.drawString(text,textPen,(size[0]-graphics.measureString (text,graphics.font,size[0])[0])/2,3,graphics.font);
}}
var dlg = new Window('dialog', 'Test');
var pnl = dlg.add('panel', undefined, 'My Panel');
var btn = pnl.add('button', undefined, 'My Button', {name:'ok'});
var btn2 = pnl.add('iconbutton', undefined, undefined, {name:'orange', style: 'toolbutton'});
btn2.size = [200,20];
btn2.fillBrush = btn2.graphics.newBrush( btn2.graphics.BrushType.SOLID_COLOR, [1, 0.7, 0, 0.5] );
btn2.text = "Hello, Harbs";
btn2.textPen = btn2.graphics.newPen (btn2.graphics.PenType.SOLID_COLOR,[0,0.5,0,1], 1);
btn2.onDraw = customDraw;
dlg.show();