frameworks/uki/src/uki-view/view/flow.js in uki-1.1.1 vs frameworks/uki/src/uki-view/view/flow.js in uki-1.1.2
- old
+ new
@@ -1,5 +1,14 @@
+/**
+ * Vertical Flow
+ * Arranges child views verticaly, one after another
+ *
+ * @author voloko
+ * @name uki.view.VFlow
+ * @class
+ * @extends uki.view.Container
+ */
uki.view.declare('uki.view.VFlow', uki.view.Container, function(Base) {
this.contentsSize = function() {
var value = uki.reduce(0, this._childViews, function(sum, e) {
return sum + (e.visible() ? e.rect().height : 0);
} );
@@ -11,25 +20,16 @@
this.resizeToContents = function(autosizeStr) {
this._resizeChildViews(this._rect);
return Base.resizeToContents.call(this, autosizeStr);
}
- uki.each(['appendChild', 'removeChild', 'insertBefore'], function(i, name) {
- this[name] = function(arg1, arg2) {
- this._contentChanged = true;
- return Base[name].call(this, arg1, arg2);
- };
- }, this)
-
this.layout = function() {
- if (this._contentChanged) this._resizeChildViews(this._rect);
return Base.layout.call(this);
};
// resize in layout
this._resizeChildViews = function(oldRect) {
- this._contentChanged = false;
var offset = 0, rect, view;
for (var i=0, childViews = this.childViews(); i < childViews.length; i++) {
view = childViews[i];
view.parentResized(oldRect, this._rect);
view.rect().y = offset;
@@ -38,12 +38,35 @@
view.visible(view._rect.height + offset <= this._rect.height);
}
if (view.visible()) offset += view._rect.height;
};
};
+
+ this.childResized = function() {
+ this._needsLayout = true;
+ uki.after(uki.proxy(this._afterChildResized, this));
+ };
+
+ this._contentChanged = this.childResized;
+
+ this._afterChildResized = function() {
+ this.resizeToContents('height');
+ this.parent().childResized(this);
+ this.layoutIfNeeded();
+ };
+
});
+/**
+ * Horizontla Flow
+ * Arranges child views horizontally
+ *
+ * @author voloko
+ * @name uki.view.HFlow
+ * @class
+ * @extends uki.view.VFlow
+ */
uki.view.declare('uki.view.HFlow', uki.view.VFlow, function(Base) {
this.contentsSize = function() {
var value = uki.reduce(0, this._childViews, function(sum, e) {
return sum + (e.visible() ? e.rect().width : 0);
} );
@@ -62,6 +85,11 @@
}
if (view.visible()) offset += view._rect.width;
};
};
+ this._afterChildResized = function() {
+ this.resizeToContents('width');
+ this.parent().childResized(this);
+ this.layoutIfNeeded();
+ };
});