/**
 * Generated by Apache Royale Compiler from org\apache\royale\html\beads\layouts\HorizontalFlowLayout.as
 * org.apache.royale.html.beads.layouts.HorizontalFlowLayout
 *
 * @fileoverview
 *
 * @suppress {checkTypes|accessControls}
 */

goog.provide('org.apache.royale.html.beads.layouts.HorizontalFlowLayout');

goog.require('org.apache.royale.core.IParentIUIBase');
goog.require('org.apache.royale.core.LayoutBase');
goog.require('org.apache.royale.core.UIBase');
goog.require('org.apache.royale.core.IBeadLayout');
goog.require('org.apache.royale.utils.Language');



/**
 *  constructor.
 *
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion Royale 0.0
 * @constructor
 * @extends {org.apache.royale.core.LayoutBase}
 * @implements {org.apache.royale.core.IBeadLayout}
 */
org.apache.royale.html.beads.layouts.HorizontalFlowLayout = function() {
  
  this.org_apache_royale_html_beads_layouts_HorizontalFlowLayout__computedColumnWidth = Number["NaN"];
  org.apache.royale.html.beads.layouts.HorizontalFlowLayout.base(this, 'constructor');
};
goog.inherits(org.apache.royale.html.beads.layouts.HorizontalFlowLayout, org.apache.royale.core.LayoutBase);


/**
 * Prevent renaming of class. Needed for reflection.
 */
goog.exportSymbol('org.apache.royale.html.beads.layouts.HorizontalFlowLayout', org.apache.royale.html.beads.layouts.HorizontalFlowLayout);


/**
 * @private
 * @type {number}
 */
org.apache.royale.html.beads.layouts.HorizontalFlowLayout.prototype.org_apache_royale_html_beads_layouts_HorizontalFlowLayout__defaultColumnCount = 4;


/**
 * @private
 * @type {number}
 */
org.apache.royale.html.beads.layouts.HorizontalFlowLayout.prototype.org_apache_royale_html_beads_layouts_HorizontalFlowLayout__computedColumnWidth;


/**
 * @private
 * @type {number}
 */
org.apache.royale.html.beads.layouts.HorizontalFlowLayout.prototype.org_apache_royale_html_beads_layouts_HorizontalFlowLayout__columnGap = 4;


/**
 * @private
 * @type {number}
 */
org.apache.royale.html.beads.layouts.HorizontalFlowLayout.prototype.org_apache_royale_html_beads_layouts_HorizontalFlowLayout__rowGap = 4;


/**
 * @private
 * @type {boolean}
 */
org.apache.royale.html.beads.layouts.HorizontalFlowLayout.prototype.org_apache_royale_html_beads_layouts_HorizontalFlowLayout__useChildWidth = false;


/**
 * @copy org.apache.royale.core.IBeadLayout#layout
 *  @royaleignorecoercion org.apache.royale.core.IBorderPaddingMarginValuesImpl
 * @export
 * @override
 */
org.apache.royale.html.beads.layouts.HorizontalFlowLayout.prototype.layout = function() {
  
  var /** @type {Array} */ children;
  var /** @type {number} */ i = 0;
  var /** @type {number} */ n = 0;
  var /** @type {org.apache.royale.core.UIBase} */ child;
  var /** @type {number} */ xpos;
  var /** @type {number} */ ypos;
  var /** @type {number} */ useWidth;
  var /** @type {number} */ useHeight;
  var /** @type {org.apache.royale.core.IParentIUIBase} */ area = org.apache.royale.utils.Language.as(this.layoutView, org.apache.royale.core.IParentIUIBase);
  children = area.internalChildren();
  n = children.length;
  if (n === 0)
    return false;
  area.width = this.host.width;
  var /** @type {HTMLElement} */ element = org.apache.royale.utils.Language.as(area.element, HTMLElement);
  element.style["flexFlow"] = "row wrap";
  element.style["display"] = "flex";
  if (isNaN(this.computedColumnWidth)) {
    this.org_apache_royale_html_beads_layouts_HorizontalFlowLayout__computedColumnWidth = this.host.width / this.defaultColumnCount;
    this.org_apache_royale_html_beads_layouts_HorizontalFlowLayout__computedColumnWidth -= this.org_apache_royale_html_beads_layouts_HorizontalFlowLayout__columnGap;
  }
  for (i = 0; i < n; i++) {
    child = children[i].royale_wrapper;
    if (!child.visible)
      continue;
    children[i].style["position"] = null;
    if (this.useChildWidth) {
      if (!isNaN(child.explicitWidth))
        useWidth = child.explicitWidth;
      else if (!isNaN(child.percentWidth))
        useWidth = this.host.width * (child.percentWidth / 100.0);
      else
        useWidth = this.org_apache_royale_html_beads_layouts_HorizontalFlowLayout__computedColumnWidth;
      child.width = useWidth;
    } else {
      child.width = this.org_apache_royale_html_beads_layouts_HorizontalFlowLayout__computedColumnWidth;
    }
    if (this.org_apache_royale_html_beads_layouts_HorizontalFlowLayout__rowGap > 0) {
      children[i].style["margin-top"] = String(this.org_apache_royale_html_beads_layouts_HorizontalFlowLayout__rowGap / 2) + "px";
      children[i].style["margin-bottom"] = String(this.org_apache_royale_html_beads_layouts_HorizontalFlowLayout__rowGap / 2) + "px";
      children[i].style["margin-left"] = String(this.org_apache_royale_html_beads_layouts_HorizontalFlowLayout__columnGap / 2) + "px";
      children[i].style["margin-right"] = String(this.org_apache_royale_html_beads_layouts_HorizontalFlowLayout__columnGap / 2) + "px";
    }
  }
  return true;
};


org.apache.royale.html.beads.layouts.HorizontalFlowLayout.prototype.get__columnGap = function() {
  return this.org_apache_royale_html_beads_layouts_HorizontalFlowLayout__columnGap;
};


org.apache.royale.html.beads.layouts.HorizontalFlowLayout.prototype.set__columnGap = function(value) {
  this.org_apache_royale_html_beads_layouts_HorizontalFlowLayout__columnGap = value;
};


org.apache.royale.html.beads.layouts.HorizontalFlowLayout.prototype.get__rowGap = function() {
  return this.org_apache_royale_html_beads_layouts_HorizontalFlowLayout__rowGap;
};


org.apache.royale.html.beads.layouts.HorizontalFlowLayout.prototype.set__rowGap = function(value) {
  this.org_apache_royale_html_beads_layouts_HorizontalFlowLayout__rowGap = value;
};


org.apache.royale.html.beads.layouts.HorizontalFlowLayout.prototype.get__defaultColumnCount = function() {
  return this.org_apache_royale_html_beads_layouts_HorizontalFlowLayout__defaultColumnCount;
};


org.apache.royale.html.beads.layouts.HorizontalFlowLayout.prototype.set__defaultColumnCount = function(value) {
  this.org_apache_royale_html_beads_layouts_HorizontalFlowLayout__defaultColumnCount = value;
};


org.apache.royale.html.beads.layouts.HorizontalFlowLayout.prototype.get__computedColumnWidth = function() {
  return this.org_apache_royale_html_beads_layouts_HorizontalFlowLayout__computedColumnWidth;
};


org.apache.royale.html.beads.layouts.HorizontalFlowLayout.prototype.set__computedColumnWidth = function(value) {
  this.org_apache_royale_html_beads_layouts_HorizontalFlowLayout__computedColumnWidth = value;
};


org.apache.royale.html.beads.layouts.HorizontalFlowLayout.prototype.get__useChildWidth = function() {
  return this.org_apache_royale_html_beads_layouts_HorizontalFlowLayout__useChildWidth;
};


org.apache.royale.html.beads.layouts.HorizontalFlowLayout.prototype.set__useChildWidth = function(value) {
  this.org_apache_royale_html_beads_layouts_HorizontalFlowLayout__useChildWidth = value;
};


Object.defineProperties(org.apache.royale.html.beads.layouts.HorizontalFlowLayout.prototype, /** @lends {org.apache.royale.html.beads.layouts.HorizontalFlowLayout.prototype} */ {
/**
  * @export
  * @type {number} */
columnGap: {
get: org.apache.royale.html.beads.layouts.HorizontalFlowLayout.prototype.get__columnGap,
set: org.apache.royale.html.beads.layouts.HorizontalFlowLayout.prototype.set__columnGap},
/**
  * @export
  * @type {number} */
rowGap: {
get: org.apache.royale.html.beads.layouts.HorizontalFlowLayout.prototype.get__rowGap,
set: org.apache.royale.html.beads.layouts.HorizontalFlowLayout.prototype.set__rowGap},
/**
  * @export
  * @type {number} */
defaultColumnCount: {
get: org.apache.royale.html.beads.layouts.HorizontalFlowLayout.prototype.get__defaultColumnCount,
set: org.apache.royale.html.beads.layouts.HorizontalFlowLayout.prototype.set__defaultColumnCount},
/**
  * @export
  * @type {number} */
computedColumnWidth: {
get: org.apache.royale.html.beads.layouts.HorizontalFlowLayout.prototype.get__computedColumnWidth,
set: org.apache.royale.html.beads.layouts.HorizontalFlowLayout.prototype.set__computedColumnWidth},
/**
  * @export
  * @type {boolean} */
useChildWidth: {
get: org.apache.royale.html.beads.layouts.HorizontalFlowLayout.prototype.get__useChildWidth,
set: org.apache.royale.html.beads.layouts.HorizontalFlowLayout.prototype.set__useChildWidth}}
);


/**
 * Metadata
 *
 * @type {Object.<string, Array.<Object>>}
 */
org.apache.royale.html.beads.layouts.HorizontalFlowLayout.prototype.ROYALE_CLASS_INFO = { names: [{ name: 'HorizontalFlowLayout', qName: 'org.apache.royale.html.beads.layouts.HorizontalFlowLayout', kind: 'class' }], interfaces: [org.apache.royale.core.IBeadLayout] };



/**
 * Reflection
 *
 * @return {Object.<string, Function>}
 */
org.apache.royale.html.beads.layouts.HorizontalFlowLayout.prototype.ROYALE_REFLECTION_INFO = function () {
  return {
    variables: function () {return {};},
    accessors: function () {
      return {
        'columnGap': { type: 'int', access: 'readwrite', declaredBy: 'org.apache.royale.html.beads.layouts.HorizontalFlowLayout'},
        'rowGap': { type: 'int', access: 'readwrite', declaredBy: 'org.apache.royale.html.beads.layouts.HorizontalFlowLayout'},
        'defaultColumnCount': { type: 'Number', access: 'readwrite', declaredBy: 'org.apache.royale.html.beads.layouts.HorizontalFlowLayout'},
        'computedColumnWidth': { type: 'Number', access: 'readwrite', declaredBy: 'org.apache.royale.html.beads.layouts.HorizontalFlowLayout'},
        'useChildWidth': { type: 'Boolean', access: 'readwrite', declaredBy: 'org.apache.royale.html.beads.layouts.HorizontalFlowLayout'}
      };
    },
    methods: function () {
      return {
        'HorizontalFlowLayout': { type: '', declaredBy: 'org.apache.royale.html.beads.layouts.HorizontalFlowLayout'},
        'layout': { type: 'Boolean', declaredBy: 'org.apache.royale.html.beads.layouts.HorizontalFlowLayout'}
      };
    }
  };
};