简体   繁体   English

Fabric JS 多个 object 选择忽略移动 isDisabled

[英]Fabric JS multiple object selection ignores movement isDisabled

I have set these following attributes to all of my objects on my Fabric JS canvas.我已经为我的 Fabric JS canvas 上的所有对象设置了以下这些属性。

lockMovementX: isDisabled,
lockMovementY: isDisabled,
lockScalingX: isDisabled,
lockScalingY: isDisabled,
lockUniScaling: isDisabled,
lockRotation: isDisabled,

However, when I select multiple objects by holding the shift key, these objects get movable again, but as a group, any idea how I disable this possibility as well?但是,当我通过按住 shift 键 select 多个对象时,这些对象再次可移动,但作为一个整体,知道我如何禁用这种可能性吗?

canvas.selection = false

In this way, you can disable the group selection but the objects will still be selectable.这样,您可以禁用组选择,但对象仍然可以选择。

Did you try setting the selectable property to false?您是否尝试将可选属性设置为 false? That will prevent objects from being selected but events will still fire on them这将阻止选择对象,但事件仍会在它们上触发

http://fabricjs.com/docs/fabric.Object.html#selectable http://fabricjs.com/docs/fabric.Object.html#selectable

selectable:Boolean When set to false , an object can not be selected for modification (using either point-click-based or group-based selection). selectable:Boolean 设置为false时,不能选择 object 进行修改(使用基于点单击或基于组的选择)。 But events still fire on it.但事件仍然发生在它身上。

Wondering how many people do not understand a simple question.想知道有多少人不明白一个简单的问题。

Yes, it is possible.是的,有可能。 You have to listen to selection:updated and check if in the selection something is locked, then lock the target.你必须听 selection:updated 并检查选择中是否有东西被锁定,然后锁定目标。

This worked for me with fabric 4.4.0.这适用于 fabric 4.4.0。 I cut it out from my project and hope this code example work.我将其从我的项目中删除并希望此代码示例有效。 At least it should demonstrate the “how”.至少它应该展示“如何”。

var canvas = window._canvas = new fabric.Canvas('c');

isLockedInSelection()
{
    let activeObjects = canvas.getActiveObjects();
    for (let i in activeObjects)
    {
        if (activeObjects[i].lockMovementX)
            return true;
    }
    return false;
}

canvas.on('selection:updated', ({selected, target}) =>
{
    if (isLockedInSelection())
    {
        target.lockMovementX = true;
        target.lockMovementY = true;
        target.lockSkewingX  = true;
        target.lockSkewingY  = true;
        target.lockRotation  = true;
        target.lockScalingX  = true;
        target.lockScalingY  = true;
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM