mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-06 12:12:42 +00:00
Add a toFit() method to fit largest page in view
Adding a real toFit() button that takes the page with the largest single dimension (height or width) and makes it fit within the pane.
This commit is contained in:
@@ -59,7 +59,31 @@ const ToolBar = ({ onZoomChange, currentPage, onPageChange, totalPages })=>{
|
|||||||
const desiredZoom = (iframeWidth / widestPage) * 100;
|
const desiredZoom = (iframeWidth / widestPage) * 100;
|
||||||
const deltaZoom = (desiredZoom - zoomLevel) - margin;
|
const deltaZoom = (desiredZoom - zoomLevel) - margin;
|
||||||
return deltaZoom;
|
return deltaZoom;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
const toFit = ()=>{
|
||||||
|
const iframe = document.getElementById('BrewRenderer');
|
||||||
|
const iframeWidth = iframe.getBoundingClientRect().width;
|
||||||
|
const iframeHeight = iframe.getBoundingClientRect().height;
|
||||||
|
const pages = iframe.contentWindow.document.getElementsByClassName('page');
|
||||||
|
|
||||||
|
let maxDimRatio = 0;
|
||||||
|
|
||||||
|
[...pages].forEach((page)=>{
|
||||||
|
const widthRatio = iframeWidth / page.offsetWidth;
|
||||||
|
const heightRatio = iframeHeight / page.offsetHeight;
|
||||||
|
const dimensionRatio = Math.min(widthRatio, heightRatio);
|
||||||
|
if(dimensionRatio < maxDimRatio || maxDimRatio == 0){
|
||||||
|
maxDimRatio = dimensionRatio;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const margin = 5;
|
||||||
|
const desiredZoom = maxDimRatio * 100;
|
||||||
|
const deltaZoom = desiredZoom - zoomLevel - margin;
|
||||||
|
|
||||||
|
return deltaZoom;
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='toolBar'>
|
<div className='toolBar'>
|
||||||
@@ -71,6 +95,13 @@ const ToolBar = ({ onZoomChange, currentPage, onPageChange, totalPages })=>{
|
|||||||
>
|
>
|
||||||
toFill
|
toFill
|
||||||
</button>
|
</button>
|
||||||
|
<button
|
||||||
|
id='zoom-to-fit'
|
||||||
|
className='tool'
|
||||||
|
onClick={()=>handleZoomChange(toFit())}
|
||||||
|
>
|
||||||
|
toFit
|
||||||
|
</button>
|
||||||
<button
|
<button
|
||||||
id='zoom-out'
|
id='zoom-out'
|
||||||
className='tool'
|
className='tool'
|
||||||
|
|||||||
Reference in New Issue
Block a user