Skip to content

Added possibility to filter & ignore suggested size change events - #24

Open
kirchet wants to merge 1 commit into
masterfrom
possibility_to_filter_suggested_size_changes
Open

kirchet wants to merge 1 commit into
masterfrom
possibility_to_filter_suggested_size_changes

Conversation

@kirchet

@kirchet kirchet commented Jun 9, 2023

Copy link
Copy Markdown

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),
    }
  }),
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant