fix(ui): ensure compositing rect is rendered correctly

This fixes an issue uncovered by the previous commit in which we do not exit filter/select-object on save-as.
This commit is contained in:
psychedelicious
2024-10-31 16:47:23 +10:00
committed by Kent Keirsey
parent 65bddfcd93
commit e032ab1179
2 changed files with 37 additions and 7 deletions

View File

@@ -529,6 +529,22 @@ export abstract class CanvasEntityAdapterBase<
}
this.log.trace(isVisible ? 'Showing' : 'Hiding');
this.konva.layer.visible(isVisible);
if (isVisible) {
/**
* When a layer is created and initially not visible, its compositing rect won't be set up properly. Then, when
* we show it in this method, it the layer will not render as it should.
*
* For example, if an inpaint mask is created via select-object while the isolated layer preview feature is
* enabled, it will be hidden on its first render, and the compositing rect will not be sized/positioned/filled.
* When next show the layer, the its underlying objects will be rendered directly, without the compositing rect
* providing the correct fill.
*
* The simplest way to ensure this doesn't happen is to always update the compositing rect when showing the layer.
*/
this.renderer.updateCompositingRectSize();
this.renderer.updateCompositingRectPosition();
this.renderer.updateCompositingRectFill();
}
this.renderer.syncKonvaCache();
};

View File

@@ -223,10 +223,14 @@ export class CanvasEntityObjectRenderer extends CanvasModuleBase {
return;
}
this.log.trace('Updating compositing rect fill');
if (
!this.konva.compositing ||
(this.parent.state.type !== 'inpaint_mask' && this.parent.state.type !== 'regional_guidance')
) {
return;
}
assert(this.konva.compositing, 'Missing compositing rect');
assert(this.parent.state.type === 'inpaint_mask' || this.parent.state.type === 'regional_guidance');
this.log.trace('Updating compositing rect fill');
const fill = this.parent.state.fill;
@@ -252,9 +256,14 @@ export class CanvasEntityObjectRenderer extends CanvasModuleBase {
return;
}
this.log.trace('Updating compositing rect size');
if (
!this.konva.compositing ||
(this.parent.state.type !== 'inpaint_mask' && this.parent.state.type !== 'regional_guidance')
) {
return;
}
assert(this.konva.compositing, 'Missing compositing rect');
this.log.trace('Updating compositing rect size');
const scale = this.manager.stage.unscale(1);
@@ -274,9 +283,14 @@ export class CanvasEntityObjectRenderer extends CanvasModuleBase {
return;
}
this.log.trace('Updating compositing rect position');
if (
!this.konva.compositing ||
(this.parent.state.type !== 'inpaint_mask' && this.parent.state.type !== 'regional_guidance')
) {
return;
}
assert(this.konva.compositing, 'Missing compositing rect');
this.log.trace('Updating compositing rect position');
this.konva.compositing.rect.setAttrs({
...this.manager.stage.getScaledStageRect(),