@@ -22,12 +22,17 @@ type CanvasStageModuleConfig = {
22
22
* The factor by which the canvas should be scaled when zooming in/out
23
23
*/
24
24
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 ;
25
29
} ;
26
30
27
31
const DEFAULT_CONFIG : CanvasStageModuleConfig = {
28
32
MIN_SCALE : 0.1 ,
29
33
MAX_SCALE : 20 ,
30
34
SCALE_FACTOR : 0.999 ,
35
+ FIT_LAYERS_TO_STAGE_PADDING_PX : 48 ,
31
36
} ;
32
37
33
38
export class CanvasStageModule extends CanvasModuleBase {
@@ -175,18 +180,20 @@ export class CanvasStageModule extends CanvasModuleBase {
175
180
return ;
176
181
}
177
182
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 ;
182
185
183
186
// Make sure we don't accidentally set the scale to something nonsensical, like a negative number, 0 or something
184
187
// outside the valid range
185
188
const scale = this . constrainScale (
186
189
Math . min ( Math . min ( availableWidth / rect . width , availableHeight / rect . height ) , 1 )
187
190
) ;
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
+ ) ;
190
197
191
198
this . konva . stage . setAttrs ( {
192
199
x,
0 commit comments