Skip to content

Commit 2a2200f

Browse files
committed
Take zoom into account when sizing the main viewport
1 parent a3b0996 commit 2a2200f

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

apps/desktop/src/components/v3/MainViewport.svelte

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ the window, then enlarge it and retain the original widths of the layout.
2727
import Resizer from '$components/Resizer.svelte';
2828
import { Focusable } from '$lib/focus/focusManager.svelte';
2929
import { focusable } from '$lib/focus/focusable.svelte';
30+
import { SETTINGS, type Settings } from '$lib/settings/userSettings';
31+
import { getContextStoreBySymbol } from '@gitbutler/shared/context';
3032
import { persisted } from '@gitbutler/shared/persisted';
3133
import { pxToRem } from '@gitbutler/ui/utils/pxToRem';
3234
import type { Snippet } from 'svelte';
@@ -48,19 +50,22 @@ the window, then enlarge it and retain the original widths of the layout.
4850
4951
const { name, left, middle, right, leftWidth, rightWidth }: Props = $props();
5052
53+
const userSettings = getContextStoreBySymbol<Settings>(SETTINGS);
54+
const zoom = $derived($userSettings.zoom);
55+
5156
let leftPreferredWidth = $derived(
52-
persisted(pxToRem(leftWidth.default), `$main_view_left_${name}`)
57+
persisted(pxToRem(leftWidth.default, zoom), `$main_view_left_${name}`)
5358
);
5459
let rightPreferredWidth = $derived(
55-
persisted(pxToRem(rightWidth.default), `$main_view_right_${name}`)
60+
persisted(pxToRem(rightWidth.default, zoom), `$main_view_right_${name}`)
5661
);
5762
5863
let leftDiv = $state<HTMLDivElement>();
5964
let middleDiv = $state<HTMLDivElement>();
6065
let rightDiv = $state<HTMLDivElement>();
6166
62-
const leftMinWidth = $derived(pxToRem(leftWidth.min));
63-
const rightMinWidth = $derived(pxToRem(rightWidth.min));
67+
const leftMinWidth = $derived(pxToRem(leftWidth.min, zoom));
68+
const rightMinWidth = $derived(pxToRem(rightWidth.min, zoom));
6469
6570
// These need to stay in px since they are bound to elements.
6671
let containerBindWidth = $state<number>(1000); // TODO: What initial value should we give this?
@@ -74,25 +79,25 @@ the window, then enlarge it and retain the original widths of the layout.
7479
7580
// Total width we cannot go below.
7681
const padding = $derived(containerBindWidth - window.innerWidth);
77-
const containerMinWidth = $derived(800 - padding);
82+
const containerMinWidth = $derived(804 - padding);
7883
79-
const middleMinWidth = $derived(pxToRem(containerMinWidth) - leftMinWidth - rightMinWidth);
84+
const middleMinWidth = $derived(pxToRem(containerMinWidth, zoom) - leftMinWidth - rightMinWidth);
8085
8186
// Left side max width depends on teh size of the right side, unless
8287
// `reverse` is true.
8388
const leftMaxWidth = $derived(
84-
pxToRem(containerBindWidth) -
89+
pxToRem(containerBindWidth, zoom) -
8590
middleMinWidth -
86-
(reverse ? rightMinWidth : pxToRem(rightBindWidth)) -
91+
(reverse ? rightMinWidth : pxToRem(rightBindWidth, zoom)) -
8792
1 // From the flex box gaps
8893
);
8994
9095
// Right side has priority over the left (unless `reverse` is true), so
9196
// its max size is the theoretical max.
9297
const rightMaxWidth = $derived(
93-
pxToRem(containerBindWidth) -
98+
pxToRem(containerBindWidth, zoom) -
9499
middleMinWidth -
95-
(reverse ? pxToRem(leftBindWidth) : leftMinWidth) -
100+
(reverse ? pxToRem(leftBindWidth, zoom) : leftMinWidth) -
96101
1 // From the flex box gaps
97102
);
98103
@@ -126,14 +131,14 @@ the window, then enlarge it and retain the original widths of the layout.
126131
borderRadius="ml"
127132
onWidth={(value) => {
128133
leftPreferredWidth.set(value);
129-
rightPreferredWidth.set(pxToRem(rightBindWidth));
134+
rightPreferredWidth.set(pxToRem(rightBindWidth, zoom));
130135
}}
131136
onResizing={(isResizing) => {
132137
if (isResizing) {
133138
// Before flipping the reverse bool we need to set the
134139
// preferred width to the actual width, to prevent content
135140
// from shifting.
136-
leftPreferredWidth.set(pxToRem(leftBindWidth));
141+
leftPreferredWidth.set(pxToRem(leftBindWidth, zoom));
137142
}
138143
reverse = isResizing;
139144
}}
@@ -165,7 +170,7 @@ the window, then enlarge it and retain the original widths of the layout.
165170
borderRadius="ml"
166171
onWidth={(value) => {
167172
rightPreferredWidth.set(value);
168-
leftPreferredWidth.set(pxToRem(leftBindWidth));
173+
leftPreferredWidth.set(pxToRem(leftBindWidth, zoom));
169174
}}
170175
/>
171176
</div>

packages/ui/src/lib/utils/pxToRem.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
export function pxToRem(px: number | undefined) {
1+
export function pxToRem(px: number | undefined, zoom = 1.0) {
22
if (px === undefined) {
33
return 0;
44
}
5-
return px / 16;
5+
return px / (zoom * 16);
66
}
77

88
export function remToPx(rem: number | undefined) {

0 commit comments

Comments
 (0)