fancy-canvas icon indicating copy to clipboard operation
fancy-canvas copied to clipboard

Added possibility to filter & ignore suggested size change events

Open kirchet opened this issue 1 year ago • 0 comments

Added possibility to filter & ignore suggested size change events

Before:

const binding = bindCanvasElementBitmapSizeTo(canvas, {
  type: 'device-pixel-content-box',
  transform: (bitmapSize: Size, canvasElementClientSize: Size) => ({
    // no way to ignore `subscribeSuggestedBitmapSizeChanged` listeners 😒
    width: Math.max(bitmapSize.width, canvasElementClientSize.width),
    height: Math.max(bitmapSize.height, canvasElementClientSize.height),
  }),
});

Now:

const binding = bindCanvasElementBitmapSizeTo(canvas, {
  type: 'device-pixel-content-box',
  transform: (bitmapSize: Size, canvasElementClientSize: Size) => {
    if (bitmapSize.width === 0 && bitmapSize.height === 0) {
      // ignore zero size resize events 🎉
      return null;
    }
    return {
      width: Math.max(bitmapSize.width, canvasElementClientSize.width),
      height: Math.max(bitmapSize.height, canvasElementClientSize.height),
    }
  }),
});

kirchet avatar Jun 09 '23 15:06 kirchet