Skip to content

Commit

Permalink
fix: Fix onSizeChange
Browse files Browse the repository at this point in the history
onSizeChange hasn't been called.

Fixes #476
  • Loading branch information
alexanderGugel committed Sep 9, 2015
1 parent 68dd034 commit dd73c5a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 12 deletions.
31 changes: 27 additions & 4 deletions core/Size.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ var ZEROS = [0, 0, 0];
* @param {Size} parent the parent size
*/
function Size (parent) {

this.finalSize = new Float32Array(3);
this.sizeChanged = false;

Expand Down Expand Up @@ -266,6 +265,25 @@ Size.prototype.getDifferential = function getDifferential () {
return this.differentialSize;
};

/**
* Gets the render size of this size representation
*
* @method
*
* @return {array} array of render size
*/
Size.prototype.getRender = function getRender () {
return this.renderSize;
};

/**
* Preserved for backwards compatibility.
*
* @deprecated
* @alias {Size#getRender}
*/
Size.prototype.getRenderSize = Size.prototype.getRender;

/**
* Sets the size of this size representation.
*
Expand Down Expand Up @@ -301,6 +319,7 @@ Size.prototype.fromComponents = function fromComponents (components) {
var changed = false;
var len = components.length;
var j;
var candidate;
for (var i = 0 ; i < 3 ; i++) {
prev = target[i];
switch (mode[i]) {
Expand All @@ -311,13 +330,18 @@ Size.prototype.fromComponents = function fromComponents (components) {
target[i] = this.absoluteSize[i];
break;
case Size.RENDER:
var candidate;
var component;
for (j = 0; j < len ; j++) {
component = components[j];
if (component && component.getRenderSize) {
candidate = component.getRenderSize()[i];
target[i] = target[i] < candidate || target[i] === 0 ? candidate : target[i];

if (this.renderSize[i] !== candidate) {
this.renderSize[i] = candidate;
this.renderSizeChanged = true;
}

target[i] = candidate;
}
}
break;
Expand All @@ -329,4 +353,3 @@ Size.prototype.fromComponents = function fromComponents (components) {
};

module.exports = Size;

12 changes: 7 additions & 5 deletions core/SizeSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
var PathStore = require('./PathStore');
var Size = require('./Size');
var Dispatch = require('./Dispatch');
var TransformSystem = require('./TransformSystem');
var PathUtils = require('./Path');

/**
Expand Down Expand Up @@ -118,12 +119,10 @@ SizeSystem.prototype.update = function update () {
if (size.proportionalSizeChanged) proportionalSizeChanged(node, components, size);
if (size.differentialSizeChanged) differentialSizeChanged(node, components, size);
if (size.renderSizeChanged) renderSizeChanged(node, components, size);
if (size.fromComponents(components)) sizeChanged(node, components, size);
if (size.fromComponents(components)) sizeChanged(node, components, size, paths[i]);
}
};

// private methods

/**
* Private method to alert the node and components that size mode changed.
*
Expand Down Expand Up @@ -233,7 +232,7 @@ function differentialSizeChanged (node, components, size) {
* @return {undefined} undefined
*/
function renderSizeChanged (node, components, size) {
var renderSize = size.getRenderSize();
var renderSize = size.getRender();
var x = renderSize[0];
var y = renderSize[1];
var z = renderSize[2];
Expand All @@ -256,7 +255,7 @@ function renderSizeChanged (node, components, size) {
*
* @return {undefined} undefined
*/
function sizeChanged (node, components, size) {
function sizeChanged (node, components, size, path) {
var finalSize = size.get();
var x = finalSize[0];
var y = finalSize[1];
Expand All @@ -266,6 +265,9 @@ function sizeChanged (node, components, size) {
if (components[i] && components[i].onSizeChange)
components[i].onSizeChange(x, y, z);
size.sizeChanged = false;

var transform = TransformSystem.get(path);
transform._dirtyFromSizeChange = true;
}

module.exports = new SizeSystem();
25 changes: 22 additions & 3 deletions core/Transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function Transform (parent) {
this.parent = parent ? parent : null;
this.breakPoint = false;
this.calculatingWorldMatrix = false;
this._dirty = false;
}

Transform.IDENT = [ 1, 0, 0, 0,
Expand Down Expand Up @@ -464,9 +465,27 @@ Transform.prototype.calculateWorldMatrix = function calculateWorldMatrix () {
while (nearestBreakPoint && !nearestBreakPoint.isBreakPoint())
nearestBreakPoint = nearestBreakPoint.parent;

if (nearestBreakPoint) return multiply(this.global, nearestBreakPoint.getWorldTransform(), this.local);
if (nearestBreakPoint) {
return multiply(this.global, nearestBreakPoint.getWorldTransform(), this.local);
}
else {
for (var i = 0; i < 16 ; i++) this.global[i] = this.local[i];
this.global[0] = this.local[0];
this.global[1] = this.local[1];
this.global[2] = this.local[2];
this.global[3] = this.local[3];
this.global[4] = this.local[4];
this.global[5] = this.local[5];
this.global[6] = this.local[6];
this.global[7] = this.local[7];
this.global[8] = this.local[8];
this.global[9] = this.local[9];
this.global[10] = this.local[10];
this.global[11] = this.local[11];
this.global[12] = this.local[12];
this.global[13] = this.local[13];
this.global[14] = this.local[14];
this.global[15] = this.local[15];

return false;
}
};
Expand Down Expand Up @@ -715,7 +734,7 @@ function multiply (out, a, b) {
var res;

// Cache only the current line of the second matrix
var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];
var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];

res = b0*a00 + b1*a10 + b2*a20 + b3*a30;
changed = changed ? changed : out[0] === res;
Expand Down

0 comments on commit dd73c5a

Please sign in to comment.