if (this["txt"]) this.txt.setAttribute('text', this.text); var lw = (this["left"] ? this.left.width : 0) + (this["showleftborder"] ? 1 : 0); var rw = (this["right"] ? this.right.width : 0) + (this["showrightborder"] ? 1 : 0); var iw = (this["icon"] ? this.icon.width : 0); var tw = (this["txt"] ? this.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"]) { this.leftborder.setAttribute('x', curX); curX += 1; } // show the left resource if (this["left"]) { this.left.setAttribute('x', curX); curX += this.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"]) { this.icon.setAttribute('x', Math.round(curX-(.25*iw*(nside)))); curX += this.icon.width; // Center icon vertically unless icony has been set explicitly this.icon.setAttribute('y', (icony != 0) ? icony : Math.round(height-this.icon.height )/2); } if (this["txt"]) { // position the text this.txt.setAttribute('x', curX); this.txt.setAttribute('text', this.text); // Center text vertically unless texty was set explicitly this.txt.setAttribute('y', (texty != 0) ? texty : (height-this.txt.height )/2); curX += this.txt.width; curX += spacing; } curX += extraWidth; middle.setAttribute('width', curX - middle.x); // position the right thingy if (this["right"]) { this.right.setAttribute('x', curX); curX += this.right.width; } if (this["rightborder"]) { this.rightborder.setAttribute('x', curX - 1); } this.setAttribute('width', curX);