Skip to content

Commit e7e874f

Browse files
fix(ui): increase padding when fitting layers to stage
1 parent 95445c1 commit e7e874f

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

invokeai/frontend/web/src/features/controlLayers/konva/CanvasStageModule.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,17 @@ type CanvasStageModuleConfig = {
2222
* The factor by which the canvas should be scaled when zooming in/out
2323
*/
2424
SCALE_FACTOR: number;
25+
/**
26+
* The padding in pixels to use when fitting the layers to the stage.
27+
*/
28+
FIT_LAYERS_TO_STAGE_PADDING_PX: number;
2529
};
2630

2731
const DEFAULT_CONFIG: CanvasStageModuleConfig = {
2832
MIN_SCALE: 0.1,
2933
MAX_SCALE: 20,
3034
SCALE_FACTOR: 0.999,
35+
FIT_LAYERS_TO_STAGE_PADDING_PX: 48,
3136
};
3237

3338
export class CanvasStageModule extends CanvasModuleBase {
@@ -175,18 +180,20 @@ export class CanvasStageModule extends CanvasModuleBase {
175180
return;
176181
}
177182

178-
const padding = 20; // Padding in absolute pixels
179-
180-
const availableWidth = width - padding * 2;
181-
const availableHeight = height - padding * 2;
183+
const availableWidth = width - this.config.FIT_LAYERS_TO_STAGE_PADDING_PX * 2;
184+
const availableHeight = height - this.config.FIT_LAYERS_TO_STAGE_PADDING_PX * 2;
182185

183186
// Make sure we don't accidentally set the scale to something nonsensical, like a negative number, 0 or something
184187
// outside the valid range
185188
const scale = this.constrainScale(
186189
Math.min(Math.min(availableWidth / rect.width, availableHeight / rect.height), 1)
187190
);
188-
const x = Math.floor(-rect.x * scale + padding + (availableWidth - rect.width * scale) / 2);
189-
const y = Math.floor(-rect.y * scale + padding + (availableHeight - rect.height * scale) / 2);
191+
const x = Math.floor(
192+
-rect.x * scale + this.config.FIT_LAYERS_TO_STAGE_PADDING_PX + (availableWidth - rect.width * scale) / 2
193+
);
194+
const y = Math.floor(
195+
-rect.y * scale + this.config.FIT_LAYERS_TO_STAGE_PADDING_PX + (availableHeight - rect.height * scale) / 2
196+
);
190197

191198
this.konva.stage.setAttrs({
192199
x,

0 commit comments

Comments
 (0)