1 /**
  2  * @author Gillis Haasnoot <gillis.haasnoot@gmail.com>
  3  * @package Banana.Controls
  4  * @summary HBox control  
  5  */
  6 
  7 goog.provide('Banana.Controls.HBox');
  8 
  9 goog.require('Banana.Controls.Panel');
 10 
 11 /** @namespace Banana.Controls.HBox */
 12 namespace('Banana.Control').HBox = Banana.Controls.Panel.extend(
 13 /** @lends Banana.Controls.HBox.prototype */
 14 {
 15 	/**
 16 	 * Creates a HBox in which all added controls are aligned horizontally.
 17 	 * @constructs
 18 	 * @extends Banana.Controls.Panel
 19 	 */
 20 	init : function()
 21 	{
 22 		this._super();
 23 		this.setStyle('width:100%;position:relative;');
 24 	},
 25 
 26 	/**
 27 	 * sets space between controls
 28 	 * @param {int} s 
 29 	 */
 30 	setSpacing : function(s)
 31 	{
 32 		this.spacing = s;
 33 		return this;
 34 	},
 35 
 36 	/**
 37 	 * @override
 38 	 * @ignore
 39 	 */
 40 	updateDisplay : function()
 41 	{
 42 		this._super();
 43 		
 44 		var controlCount = this.controls.length;
 45 		var thisWidth = this.getDemensions().width;
 46 		var targetWidth = thisWidth/controlCount;
 47 
 48 		for (var i = 0, len = controlCount; i < len; i++)
 49 		{
 50 			var c = this.controls[i];
 51 			var margin = c.getDemensions().offset.left - this.getDemensions().offset.left;
 52 
 53 		}
 54 
 55 		targetWidth -=12;
 56 
 57 		for (var i = 0, len = controlCount; i < len; i++)
 58 		{
 59 			var c = this.controls[i];
 60 
 61 			if (i !=0)
 62 			{
 63 				c.setCss({'width':targetWidth+'px','float':'left','margin-left':this.spacing+'px'});
 64 			}
 65 			else
 66 			{
 67 				c.setCss({'width':targetWidth+'px','float':'left'});
 68 			}
 69 		}
 70 	}
 71 });