mirror of
https://github.com/konvajs/konva.git
synced 2025-10-15 12:34:52 +08:00
more warnings and methods
This commit is contained in:
@@ -2,8 +2,6 @@ import { Util, Collection } from './Util';
|
||||
import { Container } from './Container';
|
||||
import { BaseLayer } from './BaseLayer';
|
||||
|
||||
// TODO: deprecate it
|
||||
|
||||
/**
|
||||
* FastLayer constructor. Layers are tied to their own canvas element and are used
|
||||
* to contain shapes only. If you don't need node nesting, mouse and touch interactions,
|
||||
|
11
src/Node.ts
11
src/Node.ts
@@ -1240,13 +1240,20 @@ export abstract class Node {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// TODO: validate z index
|
||||
// it should be >= 0 and < length
|
||||
setZIndex(zIndex) {
|
||||
if (!this.parent) {
|
||||
Util.warn('Node has no parent. zIndex parameter is ignored.');
|
||||
return false;
|
||||
}
|
||||
if (zIndex < 0 || zIndex >= this.parent.children.length) {
|
||||
Util.warn(
|
||||
'Unexpected value ' +
|
||||
zIndex +
|
||||
' for zIndex property. zIndex is just index of a node in children of its parent. Expected value is from 0 to ' +
|
||||
(this.parent.children.length - 1) +
|
||||
'.'
|
||||
);
|
||||
}
|
||||
var index = this.index;
|
||||
this.parent.children.splice(index, 1);
|
||||
this.parent.children.splice(zIndex, 0, this);
|
||||
|
@@ -319,6 +319,7 @@ export class Shape extends Node {
|
||||
destroy() {
|
||||
Node.prototype.destroy.call(this);
|
||||
delete shapes[this.colorKey];
|
||||
delete this.colorKey;
|
||||
return this;
|
||||
}
|
||||
// why do we need buffer canvas?
|
||||
@@ -537,6 +538,13 @@ export class Shape extends Node {
|
||||
cachedCanvas = this._cache.canvas,
|
||||
cachedHitCanvas = cachedCanvas && cachedCanvas.hit;
|
||||
|
||||
if (!this.colorKey) {
|
||||
console.log(this);
|
||||
Util.warn(
|
||||
'Looks like your canvas has a destroyed shape in it. Do not reuse shape after you destroyed it. See the shape in logs above. If you want to reuse shape you should call remove() instead of destroy()'
|
||||
);
|
||||
}
|
||||
|
||||
if (!this.shouldDrawHit() && !caching) {
|
||||
return this;
|
||||
}
|
||||
|
19
src/Util.ts
19
src/Util.ts
@@ -546,10 +546,12 @@ export const Util = {
|
||||
requestAnimFrame(callback) {
|
||||
Util.animQueue.push(callback);
|
||||
if (Util.animQueue.length === 1) {
|
||||
requestAnimationFrame(function () {
|
||||
requestAnimationFrame(function() {
|
||||
const queue = Util.animQueue;
|
||||
Util.animQueue = [];
|
||||
queue.forEach(function (cb) { cb(); });
|
||||
queue.forEach(function(cb) {
|
||||
cb();
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
@@ -755,19 +757,6 @@ export const Util = {
|
||||
};
|
||||
}
|
||||
},
|
||||
// TODO: remove it
|
||||
// o1 takes precedence over o2
|
||||
_merge(o1, o2) {
|
||||
var retObj = this._clone(o2);
|
||||
for (var key in o1) {
|
||||
if (this._isPlainObject(o1[key])) {
|
||||
retObj[key] = this._merge(o1[key], retObj[key]);
|
||||
} else {
|
||||
retObj[key] = o1[key];
|
||||
}
|
||||
}
|
||||
return retObj;
|
||||
},
|
||||
/**
|
||||
* check intersection of two client rectangles
|
||||
* @method
|
||||
|
@@ -227,7 +227,7 @@ export class Text extends Shape {
|
||||
this.partialText = letter;
|
||||
context.fillStrokeShape(this);
|
||||
context.translate(
|
||||
Math.round(this._getTextSize(letter).width) + letterSpacing,
|
||||
Math.round(this.measureSize(letter).width) + letterSpacing,
|
||||
0
|
||||
);
|
||||
}
|
||||
@@ -287,8 +287,15 @@ export class Text extends Shape {
|
||||
return this.textHeight;
|
||||
}
|
||||
|
||||
// TODO: make it public, rename to "measure text"?
|
||||
_getTextSize(text) {
|
||||
/**
|
||||
* measure string with the font of current text shape.
|
||||
* That method can't handle multiline text.
|
||||
* @method
|
||||
* @name Konva.Text#measureSize
|
||||
* @param {Number} [text] text to measure
|
||||
* @returns {Object} { width , height} of measured text
|
||||
*/
|
||||
measureSize(text) {
|
||||
var _context = getDummyContext(),
|
||||
fontSize = this.fontSize(),
|
||||
metrics;
|
||||
|
Reference in New Issue
Block a user