Skip to content

Commit e8c0018

Browse files
committed
Improve responsive layout accuracy by using getBoundingClientRect for width measurements and add buffer for subpixel rendering
1 parent 272eb53 commit e8c0018

10 files changed

Lines changed: 70 additions & 26 deletions

File tree

‎packages/shared/src/hooks/use-compacting.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ export const use_compacting = (max_compact_step = 4) => {
77

88
const report_width = useCallback((width: number, step: number) => {
99
set_thresholds((prev) => {
10-
if (prev[step] == width) return prev
11-
return { ...prev, [step]: width }
10+
// Round up and add 1px buffer to account for subpixel rendering differences
11+
const threshold = Math.ceil(width) + 1
12+
if (prev[step] == threshold) return prev
13+
return { ...prev, [step]: threshold }
1214
})
1315
}, [])
1416

‎packages/ui/src/components/editor/panel/BrowserExtensionMessage/BrowserExtensionMessage.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const BrowserExtensionMessage: React.FC = () => {
1515
const child = children[i] as HTMLElement
1616
const style = getComputedStyle(child)
1717
width +=
18-
child.offsetWidth +
18+
child.getBoundingClientRect().width +
1919
parseFloat(style.marginLeft) +
2020
parseFloat(style.marginRight)
2121
}

‎packages/ui/src/components/editor/panel/PromptField/hooks/use-edit-format-compacting.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ export const use_edit_format_compacting = () => {
1919
if (refs.every((ref) => ref.current)) {
2020
// Calculate total width of all elements
2121
const total_width = refs.reduce(
22-
(acc, ref) => acc + (ref.current?.offsetWidth || 0),
22+
(acc, ref) => acc + (ref.current?.getBoundingClientRect().width || 0),
2323
0
2424
)
2525
// Add gap (4px * 3 gaps)
26-
const width = total_width + 12
26+
const width = total_width
2727

2828
report_width(width, compact_step)
2929
}

‎packages/ui/src/components/editor/panel/ResponsePreviewFooter/ResponsePreviewFooter.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ export const ResponsePreviewFooter: React.FC<Props> = ({
2626
// Padding & icon (approx 44px per button) + gap (8px * 2)
2727
const padding_and_gap = 3 * 40 + 2 * 8
2828
const width =
29-
back_ref.current.offsetWidth +
30-
reject_ref.current.offsetWidth +
31-
accept_ref.current.offsetWidth +
29+
back_ref.current.getBoundingClientRect().width +
30+
reject_ref.current.getBoundingClientRect().width +
31+
accept_ref.current.getBoundingClientRect().width +
3232
padding_and_gap
3333
report_width(width, compact_step)
3434
}

‎packages/vscode/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "gemini-coder",
33
"displayName": "Code Web Chat",
44
"description": "CWC, the autofill for chatbots",
5-
"version": "1.702.0",
5+
"version": "1.703.0",
66
"scripts": {
77
"build": "npx vsce package --no-dependencies",
88
"vscode:prepublish": "rimraf out && npm run compile",

‎packages/vscode/src/views/panel/frontend/Panel.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,10 @@ export const Panel = () => {
210210
<LayoutContext.Provider value={layout_context_value}>
211211
<div className={styles.container}>
212212
<div className={styles.slot}>
213-
<Layout on_donate_click={() => set_viewing_donations(true)}>
213+
<Layout
214+
on_donate_click={() => set_viewing_donations(true)}
215+
are_links_dimmed={active_view == 'main'}
216+
>
214217
<div
215218
className={cn(styles.content, {
216219
[styles['content--hidden']]: active_view != 'main'

‎packages/vscode/src/views/panel/frontend/components/Layout/Footer/Footer.module.scss‎

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,35 @@
55
z-index: -1; // Makes context menu of a preset appear above
66
display: flex;
77
justify-content: space-between;
8-
gap: 4px;
9-
padding: 8px 12px;
8+
align-items: center;
9+
padding-right: 12px;
10+
height: 41px;
1011
border-top: 1px solid var(--cwc-border-color-dimmed);
1112

1213
> div {
1314
display: flex;
1415
gap: 6px;
1516
}
1617

18+
&__left {
19+
display: flex;
20+
align-items: center;
21+
height: 100%;
22+
gap: 6px;
23+
padding-left: 12px;
24+
padding-right: 6px;
25+
transition: var(--transition-duration-250) opacity
26+
var(--transition-timing-function);
27+
28+
&--dimmed {
29+
opacity: 0.3;
30+
31+
&:hover {
32+
opacity: 1;
33+
}
34+
}
35+
}
36+
1737
&__icon-button {
1838
display: flex;
1939
align-items: center;
@@ -28,20 +48,16 @@
2848
height: 16px;
2949
}
3050

31-
&--cwc {
32-
background-color: black;
33-
34-
> svg {
35-
fill: white;
36-
}
37-
}
38-
3951
&--buy-me-a-coffee {
4052
background-color: #f7d600;
4153

4254
> svg {
4355
fill: black;
4456
}
57+
58+
&:hover {
59+
background-color: color-mix(in srgb, #f7d600, black 10%);
60+
}
4561
}
4662

4763
&--reddit {
@@ -50,6 +66,10 @@
5066
> svg {
5167
fill: white;
5268
}
69+
70+
&:hover {
71+
background-color: color-mix(in srgb, #ff4500, black 10%);
72+
}
5373
}
5474

5575
&--discord {
@@ -58,6 +78,10 @@
5878
> svg {
5979
fill: white;
6080
}
81+
82+
&:hover {
83+
background-color: color-mix(in srgb, #5765f2, black 10%);
84+
}
6185
}
6286
}
6387

‎packages/vscode/src/views/panel/frontend/components/Layout/Footer/Footer.tsx‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { LayoutContext } from '../../../contexts/LayoutContext'
77

88
type Props = {
99
on_donate_click: () => void
10+
are_links_dimmed?: boolean
1011
}
1112

1213
export const Footer: React.FC<Props> = (props) => {
@@ -32,7 +33,8 @@ export const Footer: React.FC<Props> = (props) => {
3233
useLayoutEffect(() => {
3334
if (left_ref.current && right_ref.current) {
3435
const width =
35-
left_ref.current.offsetWidth + right_ref.current.offsetWidth + 6
36+
left_ref.current.getBoundingClientRect().width +
37+
right_ref.current.getBoundingClientRect().width
3638
report_width(width, compact_step)
3739
}
3840
}, [compact_step, report_width])
@@ -69,7 +71,12 @@ export const Footer: React.FC<Props> = (props) => {
6971
return (
7072
<>
7173
<div className={styles.footer} ref={container_ref}>
72-
<div ref={left_ref}>
74+
<div
75+
ref={left_ref}
76+
className={cn(styles.footer__left, {
77+
[styles['footer__left--dimmed']]: props.are_links_dimmed
78+
})}
79+
>
7380
<a
7481
className={cn(
7582
styles['footer__icon-button'],

‎packages/vscode/src/views/panel/frontend/components/Layout/Layout.tsx‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,21 @@ import { Footer } from './Footer'
44
type Props = {
55
children: React.ReactNode
66
on_donate_click: () => void
7+
are_links_dimmed?: boolean
78
}
89

9-
export const Layout: React.FC<Props> = ({ children, on_donate_click }) => {
10+
export const Layout: React.FC<Props> = ({
11+
children,
12+
on_donate_click,
13+
are_links_dimmed
14+
}) => {
1015
return (
1116
<div className={styles.container}>
1217
<div className={styles.content}>{children}</div>
13-
<Footer on_donate_click={on_donate_click} />
18+
<Footer
19+
on_donate_click={on_donate_click}
20+
are_links_dimmed={are_links_dimmed}
21+
/>
1422
</div>
1523
)
1624
}

‎packages/vscode/src/views/panel/frontend/components/donations/DonationsFooter/DonationsFooter.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ export const DonationsFooter: React.FC<Props> = (props) => {
1717
if (close_ref.current && coffee_ref.current) {
1818
const padding_and_gap = 2 * 24 + 8
1919
const width =
20-
close_ref.current.offsetWidth +
21-
coffee_ref.current.offsetWidth +
20+
close_ref.current.getBoundingClientRect().width +
21+
coffee_ref.current.getBoundingClientRect().width +
2222
padding_and_gap
2323
report_width(width, compact_step)
2424
}

0 commit comments

Comments
 (0)