if (this["txt"]) txt.setAttribute('text', this.text);
var lw = (this["left"] ? left.width : 0) + (this["showleftborder"] ? 1 : 0);
var rw = (this["right"] ? right.width : 0) + (this["showrightborder"] ? 1 : 0);
var iw = (this["icon"] ? icon.width : 0);
var tw = (this["txt"] ? txt.width : 0);
// used to offset the icon - 0 for no offset
var nside=0;
var curX = 0;
var spacing = 0;
var needsWidth = lw + rw + iw + tw;
var extraWidth = Math.max(0, Math.round( (width - needsWidth) / 2));
if (this["leftborder"]) {
leftborder.setAttribute('x', curX);
curX += 1;
}
// show the left resource
if (this["left"]) {
left.setAttribute('x', curX);
curX += left.width;
// add to offset left
nside+=1;
}
// check if this is the right side of the set and adjust icon layout
if (this["right"]) {
// subtract to offset right
nside-=1;
}
// position the middle view.
// it goes behind the icon and text
middle.setAttribute('x', curX);
curX += extraWidth;
// position the icon
if (this["icon"]) {
icon.setAttribute('x', Math.round(curX-(.25*iw*(nside))));
curX += icon.width;
// Center icon vertically unless icony has been set explicitly
icon.setAttribute('y', (icony != 0) ? icony : Math.round(height-icon.height )/2);
}
if (this["txt"]) {
// position the text
txt.setAttribute('x', curX);
txt.setAttribute('text', this.text);
// Center text vertically unless texty was set explicitly
txt.setAttribute('y', (texty != 0) ? texty : (height-txt.height )/2);
curX += txt.width;
curX += spacing;
}
curX += extraWidth;
middle.setAttribute('width', curX - middle.x);
// position the right thingy
if (this["right"]) {
right.setAttribute('x', curX);
curX += right.width;
}
if (this["rightborder"]) {
rightborder.setAttribute('x', curX - 1);
}
this.setAttribute('width', curX);