fix(ui): layer rendering when starting as disabled

This commit is contained in:
psychedelicious 2024-07-17 10:37:03 +10:00
parent 75f8a84c79
commit 0923a5b128

View File

@ -180,11 +180,11 @@ export class CanvasLayer {
assert(image instanceof CanvasImage || image === undefined); assert(image instanceof CanvasImage || image === undefined);
if (!image) { if (!image) {
image = await new CanvasImage(obj, {}); image = await new CanvasImage(obj);
this.objects.set(image.id, image); this.objects.set(image.id, image);
this.objectsGroup.add(image.konvaImageGroup); this.objectsGroup.add(image.konvaImageGroup);
await image.updateImageSource(obj.image.name); await image.updateImageSource(obj.image.name);
this.updateGroup(true); return true;
} else { } else {
if (await image.update(obj, force)) { if (await image.update(obj, force)) {
return true; return true;
@ -196,8 +196,12 @@ export class CanvasLayer {
} }
updateGroup(didDraw: boolean) { updateGroup(didDraw: boolean) {
this.layer.visible(this.layerState.isEnabled); if (!this.layerState.isEnabled) {
this.layer.visible(false);
return;
}
this.layer.visible(true);
this.group.opacity(this.layerState.opacity); this.group.opacity(this.layerState.opacity);
const isSelected = this.manager.stateApi.getIsSelected(this.id); const isSelected = this.manager.stateApi.getIsSelected(this.id);
const selectedTool = this.manager.stateApi.getToolState().selected; const selectedTool = this.manager.stateApi.getToolState().selected;
@ -209,10 +213,7 @@ export class CanvasLayer {
if (this.group.isCached()) { if (this.group.isCached()) {
this.group.clearCache(); this.group.clearCache();
} }
return; } else if (isSelected && selectedTool === 'move') {
}
if (isSelected && selectedTool === 'move') {
// When the layer is selected and being moved, we should always cache it. // When the layer is selected and being moved, we should always cache it.
// We should update the cache if we drew to the layer. // We should update the cache if we drew to the layer.
if (!this.group.isCached() || didDraw) { if (!this.group.isCached() || didDraw) {
@ -222,10 +223,7 @@ export class CanvasLayer {
this.layer.listening(true); this.layer.listening(true);
this.transformer.nodes([this.group]); this.transformer.nodes([this.group]);
this.transformer.forceUpdate(); this.transformer.forceUpdate();
return; } else if (isSelected && selectedTool !== 'move') {
}
if (isSelected && selectedTool !== 'move') {
// If the layer is selected but not using the move tool, we don't want the layer to be listening. // If the layer is selected but not using the move tool, we don't want the layer to be listening.
this.layer.listening(false); this.layer.listening(false);
// The transformer also does not need to be active. // The transformer also does not need to be active.
@ -243,10 +241,7 @@ export class CanvasLayer {
this.group.cache(); this.group.cache();
} }
} }
return; } else if (!isSelected) {
}
if (!isSelected) {
// Unselected layers should not be listening // Unselected layers should not be listening
this.layer.listening(false); this.layer.listening(false);
// The transformer also does not need to be active. // The transformer also does not need to be active.
@ -255,8 +250,6 @@ export class CanvasLayer {
if (!this.group.isCached() || didDraw) { if (!this.group.isCached() || didDraw) {
this.group.cache(); this.group.cache();
} }
return;
} }
} }
} }