new anchorStyleFunc for transformer. close #1552

This commit is contained in:
Anton Lavrenov
2023-06-02 15:27:59 -05:00
parent 2550a34754
commit 3e7d5ce7af
3 changed files with 71 additions and 1 deletions

View File

@@ -4782,4 +4782,37 @@ describe('Transformer', function () {
tr.nodes([layer]);
assert.equal(tr.nodes().length, 0);
});
it('anchorStyleFunc', function () {
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);
// manual check of correct position of node
var handler = tr.findOne<Konva.Rect>('.bottom-right');
assert.equal(handler.fill(), 'white');
tr.anchorStyleFunc((anchor) => {
if (anchor.hasName('bottom-right')) {
anchor.fill('red');
}
});
assert.equal(handler.fill(), 'red');
tr.anchorStyleFunc(null);
assert.equal(handler.fill(), 'white');
});
});