mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 04:42:02 +08:00
#1387 make sure the Transformer affects the client-rect if it is attached
Signed-off-by: Clemens Grabmann <clemens.grabmann@cloudflight.io>
This commit is contained in:
parent
2ce5f23c3b
commit
9cdbbd6616
@ -1220,9 +1220,13 @@ export class Transformer extends Group {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getClientRect() {
|
getClientRect() {
|
||||||
// return zero size
|
if (this.nodes().length > 0) {
|
||||||
// so it will be skipped in calculations
|
return super.getClientRect();
|
||||||
return { x: 0, y: 0, width: 0, height: 0 };
|
} else {
|
||||||
|
// if we are detached return zero size
|
||||||
|
// so it will be skipped in calculations
|
||||||
|
return { x: 0, y: 0, width: 0, height: 0 };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nodes: GetSet<Node[], this>;
|
nodes: GetSet<Node[], this>;
|
||||||
|
@ -4710,12 +4710,38 @@ describe('Transformer', function () {
|
|||||||
});
|
});
|
||||||
layer.add(tr);
|
layer.add(tr);
|
||||||
|
|
||||||
const box = layer.getClientRect();
|
const layerClientRect = layer.getClientRect();
|
||||||
|
const rectClientRect = rect.getClientRect();
|
||||||
|
|
||||||
// it should update second transformer
|
// the client rect should not be affected by the transformer
|
||||||
assert.equal(box.x, rect.x());
|
assert.deepEqual(layerClientRect, rectClientRect);
|
||||||
assert.equal(box.y, rect.y());
|
});
|
||||||
assert.equal(box.width, rect.width());
|
it('attached transformer should affect client rect', function () {
|
||||||
assert.equal(box.height, rect.height());
|
var stage = addStage();
|
||||||
|
var layer = new Konva.Layer();
|
||||||
|
stage.add(layer);
|
||||||
|
|
||||||
|
var rect = new Konva.Rect({
|
||||||
|
x: 100,
|
||||||
|
y: 60,
|
||||||
|
draggable: true,
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
fill: 'yellow',
|
||||||
|
});
|
||||||
|
layer.add(rect);
|
||||||
|
|
||||||
|
var tr = new Konva.Transformer({
|
||||||
|
nodes: [rect],
|
||||||
|
});
|
||||||
|
layer.add(tr);
|
||||||
|
|
||||||
|
const layerClientRect = layer.getClientRect();
|
||||||
|
const rectClientRect = rect.getClientRect();
|
||||||
|
const trClientRect = tr.getClientRect();
|
||||||
|
|
||||||
|
// the client rect should be affecte by the transformer
|
||||||
|
assert.notDeepEqual(layerClientRect, rectClientRect);
|
||||||
|
assert.deepEqual(layerClientRect, trClientRect);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user