-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scale the zoom out mode to fit available space (#59342)
* Scale zoom out mode frame based on available content width When there's a small area available to scale the editor, we want to have the editor larger. This implements a smooth sloped clamped scale to scale the zoomed out editor to better fit its available space. We moved the scale calculation inside of the iframe components so when this is used within the edit post and other packages, they won't need to implement their own scaling. * update variable name * Add an explanatory comment * Add shouldZoom prop to only use zooming if desired --------- Co-authored-by: scruffian <[email protected]> Co-authored-by: jeryj <[email protected]> Co-authored-by: scruffian <[email protected]>
- Loading branch information
1 parent
fa902df
commit 944ff08
Showing
3 changed files
with
65 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const clamp = ( lowerlimit, width, upperlimit ) => { | ||
if ( width < lowerlimit ) return lowerlimit; | ||
if ( width > upperlimit ) return upperlimit; | ||
return width; | ||
}; | ||
|
||
export default function calculateScale( scaleConfig, width ) { | ||
const scaleSlope = | ||
( scaleConfig.maxScale - scaleConfig.minScale ) / | ||
( scaleConfig.maxWidth - scaleConfig.minWidth ); | ||
|
||
const scaleIntercept = | ||
scaleConfig.minScale - scaleSlope * scaleConfig.minWidth; | ||
|
||
return clamp( | ||
scaleConfig.maxScale, | ||
scaleSlope * width + scaleIntercept, | ||
scaleConfig.minScale | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters