[英]Multiselect in fabric js without key modifier
I was wondering if there is a way to actively set multi-selection "mode" in fabric js canvas without holding down the shift? 我想知道是否有一种方法可以在不降低移位的情况下在fabric js画布中主动设置多选“模式”?
I wish to activate multiselection by listening on a boolean value thats tied to a checkbox. 我希望通过侦听绑定到复选框的布尔值来激活多选。
I have been reading through the fabricjs docs and haven't found anything regarding multi-select without the shift modifier key. 我一直在阅读fabricjs文档,并且在没有shift修改键的情况下没有找到任何有关多重选择的信息。
I'm uncertain if my request is valid but any pointers would be appreciated. 我不确定我的请求是否有效,但任何指针都将不胜感激。
So basically I listen on the mouse:down event and checks if my boolean value is true/false, and if it's true i would like to go into multi-selection mode. 因此,基本上,我在mouse:down事件上侦听并检查我的布尔值是否为true / false,如果为true,我想进入多选模式。
canvas.on('mouse:down', evt => {
if(this.multiSelect) {
// activate multi-select
}
}
You can listen to the selection:created
event and then push each new selection into an array that you will then use to create an ActiveSelection
with multiple objects. 您可以侦听
selection:created
事件,然后将每个新选择推送到一个数组中,然后使用该数组创建具有多个对象的ActiveSelection
。 When you set this.multiSelect
to false you will need to also empty the multiSelection
array. 将
this.multiSelect
设置为false时,还需要清空multiSelection
数组。 Something like this: 像这样:
var multiSelection = [];
canvas.on('selection:created', selected => {
if(this.multiSelect) {
multiSelection.push(selected);
var groupSelection = new fabric.ActiveSelection(multiSelection)
canvas.setActiveObject(groupSelection);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.