Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve scaling of screenshot width #1306

Merged
merged 4 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/renderer/components/Inspector/Inspector.css
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@

.inspector-main .interaction-tab-container {
position: relative;
flex-grow: 3;
flex-grow: 1;
flex-basis: 550px;
min-width: 380px;
padding-left: 1em;
Expand Down
12 changes: 7 additions & 5 deletions app/renderer/components/Inspector/Inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const {SELECT, TAP_SWIPE} = SCREENSHOT_INTERACTION_MODE;

const MIN_WIDTH = 870;
const MIN_HEIGHT = 610;
const MAX_SCREENSHOT_WIDTH = 500;
const MAX_IMAGE_WIDTH_WINDOW_FRACTION = 0.4;

const MJPEG_STREAM_CHECK_INTERVAL = 1000;
const SESSION_EXPIRY_PROMPT_TIMEOUT = 60 * 60 * 1000; // Give user 1 hour to reply
Expand Down Expand Up @@ -129,10 +129,12 @@ const Inspector = (props) => {
const imgRect = img.getBoundingClientRect();
const screenshotRect = screenshotBox.getBoundingClientRect();
if (imgRect.height < screenshotRect.height) {
// get what the img width would be if it fills screenshot box height
const attemptedWidth = (screenshotRect.height / imgRect.height) * imgRect.width;
screenshotBox.style.maxWidth =
attemptedWidth > MAX_SCREENSHOT_WIDTH ? `${MAX_SCREENSHOT_WIDTH}px` : `${attemptedWidth}px`;
// get the expected image width if the image would fill the screenshot box height
const attemptedImgWidth = (screenshotRect.height / imgRect.height) * imgRect.width;
// get the maximum image width as a fraction of the current window width
const maxImgWidth = window.innerWidth * MAX_IMAGE_WIDTH_WINDOW_FRACTION;
const curMaxImgWidth = Math.min(maxImgWidth, attemptedImgWidth);
screenshotBox.style.maxWidth = `${curMaxImgWidth}px`;
} else if (imgRect.width < screenshotRect.width) {
screenshotBox.style.maxWidth = `${imgRect.width}px`;
}
Expand Down