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

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

goog.require('org.apache.royale.core.IBorderPaddingMarginValuesImpl');
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.ValuesManager');
goog.require('org.apache.royale.core.layout.EdgeData');
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.TileLayout = function() {
  
  this.org_apache_royale_html_beads_layouts_TileLayout__columnWidth = Number["NaN"];
  this.org_apache_royale_html_beads_layouts_TileLayout__rowHeight = Number["NaN"];
  org.apache.royale.html.beads.layouts.TileLayout.base(this, 'constructor');
};
goog.inherits(org.apache.royale.html.beads.layouts.TileLayout, org.apache.royale.core.LayoutBase);


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


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


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


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


/**
 * @copy org.apache.royale.core.IBeadLayout#layout
 * @royaleignorecoercion org.apache.royale.core.IBorderPaddingMarginValuesImpl
 * @export
 * @override
 */
org.apache.royale.html.beads.layouts.TileLayout.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} */ contentView = org.apache.royale.utils.Language.as(this.layoutView, org.apache.royale.core.IParentIUIBase);
  children = contentView.internalChildren();
  n = children.length;
  if (n === 0)
    return false;
  contentView.element.style["display"] = "flex";
  contentView.element.style["flexFlow"] = "row wrap";
  contentView.element.style["alignContent"] = "flex-start";
  var /** @type {number} */ realN = n;
  for (i = 0; i < n; i++) {
    child = children[i].royale_wrapper;
    if (!child.visible)
      realN--;
  }
  xpos = 0;
  ypos = 0;
  useWidth = this.columnWidth;
  useHeight = this.rowHeight;
  var /** @type {boolean} */ needWidth = isNaN(useWidth);
  var /** @type {boolean} */ needHeight = isNaN(useHeight);
  if (needHeight || needWidth) {
    var /** @type {org.apache.royale.core.layout.EdgeData} */ borderMetrics = org.apache.royale.core.ValuesManager["valuesImpl"].getBorderMetrics(this.host);
    var /** @type {number} */ adjustedWidth = Math.floor(this.host.width - borderMetrics.left - borderMetrics.right);
    var /** @type {number} */ adjustedHeight = Math.floor(this.host.height - borderMetrics.top - borderMetrics.bottom);
    if (needWidth)
      useWidth = Math.floor(adjustedWidth / this.numColumns);
    if (needHeight) {
      var /** @type {number} */ numRows = Math.ceil(realN / this.numColumns);
      if (this.host.isHeightSizedToContent())
        useHeight = 30;
      else
        useHeight = Math.floor(adjustedHeight / numRows);
    }
  }
  for (i = 0; i < n; i++) {
    child = children[i].royale_wrapper;
    if (!child.visible)
      continue;
    child.setDisplayStyleForLayout('inline-block');
    if (useWidth > 0)
      child.width = useWidth;
    if (useHeight > 0)
      child.height = useHeight;
  }
  return true;
};


org.apache.royale.html.beads.layouts.TileLayout.prototype.get__numColumns = function() {
  return this.org_apache_royale_html_beads_layouts_TileLayout__numColumns;
};


org.apache.royale.html.beads.layouts.TileLayout.prototype.set__numColumns = function(value) {
  this.org_apache_royale_html_beads_layouts_TileLayout__numColumns = value;
};


org.apache.royale.html.beads.layouts.TileLayout.prototype.get__columnWidth = function() {
  return this.org_apache_royale_html_beads_layouts_TileLayout__columnWidth;
};


org.apache.royale.html.beads.layouts.TileLayout.prototype.set__columnWidth = function(value) {
  this.org_apache_royale_html_beads_layouts_TileLayout__columnWidth = value;
};


org.apache.royale.html.beads.layouts.TileLayout.prototype.get__rowHeight = function() {
  return this.org_apache_royale_html_beads_layouts_TileLayout__rowHeight;
};


org.apache.royale.html.beads.layouts.TileLayout.prototype.set__rowHeight = function(value) {
  this.org_apache_royale_html_beads_layouts_TileLayout__rowHeight = value;
};


Object.defineProperties(org.apache.royale.html.beads.layouts.TileLayout.prototype, /** @lends {org.apache.royale.html.beads.layouts.TileLayout.prototype} */ {
/**
  * @export
  * @type {number} */
numColumns: {
get: org.apache.royale.html.beads.layouts.TileLayout.prototype.get__numColumns,
set: org.apache.royale.html.beads.layouts.TileLayout.prototype.set__numColumns},
/**
  * @export
  * @type {number} */
columnWidth: {
get: org.apache.royale.html.beads.layouts.TileLayout.prototype.get__columnWidth,
set: org.apache.royale.html.beads.layouts.TileLayout.prototype.set__columnWidth},
/**
  * @export
  * @type {number} */
rowHeight: {
get: org.apache.royale.html.beads.layouts.TileLayout.prototype.get__rowHeight,
set: org.apache.royale.html.beads.layouts.TileLayout.prototype.set__rowHeight}}
);


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



/**
 * Reflection
 *
 * @return {Object.<string, Function>}
 */
org.apache.royale.html.beads.layouts.TileLayout.prototype.ROYALE_REFLECTION_INFO = function () {
  return {
    variables: function () {return {};},
    accessors: function () {
      return {
        'numColumns': { type: 'Number', access: 'readwrite', declaredBy: 'org.apache.royale.html.beads.layouts.TileLayout'},
        'columnWidth': { type: 'Number', access: 'readwrite', declaredBy: 'org.apache.royale.html.beads.layouts.TileLayout'},
        'rowHeight': { type: 'Number', access: 'readwrite', declaredBy: 'org.apache.royale.html.beads.layouts.TileLayout'}
      };
    },
    methods: function () {
      return {
        'TileLayout': { type: '', declaredBy: 'org.apache.royale.html.beads.layouts.TileLayout'},
        'layout': { type: 'Boolean', declaredBy: 'org.apache.royale.html.beads.layouts.TileLayout'}
      };
    }
  };
};