Skip to content

Commit

Permalink
Added possibility to filter & ignore suggested size change events
Browse files Browse the repository at this point in the history
  • Loading branch information
kirchet committed Jun 9, 2023
1 parent 7ece760 commit 3627086
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/canvas-element-bitmap-size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { BehaviorSubject } from './rx.js';
import { createObservable as createDevicePixelRatioObservable } from './device-pixel-ratio.js';

export type BitmapSizeChangedListener = (this: Binding, oldSize: Size, newSize: Size) => void;
export type BitmapSizeTransformer = (bitmapSize: Size, canvasElementClientSize: Size) => { width: number, height: number };
export type BitmapSizeTransformer = (bitmapSize: Size, canvasElementClientSize: Size) => { width: number, height: number } | null;
export type SuggestedBitmapSizeChangedListener = (this: Binding, oldSize: Size | null, newSize: Size | null) => void;

export interface Binding extends Disposable {
Expand Down Expand Up @@ -148,7 +148,13 @@ class DevicePixelContentBoxBinding implements Binding, Disposable {

private _suggestNewBitmapSize(newSize: Size): void {
const oldSuggestedSize = this._suggestedBitmapSize;
const finalNewSize = size(this._transformBitmapSize(newSize, this._canvasElementClientSize));
const transformedBitmapSize = this._transformBitmapSize(newSize, this._canvasElementClientSize);
if (transformedBitmapSize === null) {
return;
}

const finalNewSize = size(transformedBitmapSize);

const newSuggestedSize = equalSizes(this.bitmapSize, finalNewSize) ? null : finalNewSize;

if (oldSuggestedSize === null && newSuggestedSize === null) {
Expand Down

0 comments on commit 3627086

Please sign in to comment.