fix(app): leave as much room past the traffic lights as before them

This commit is contained in:
Brendonovich
2026-11-05 03:09:19 +00:00
Unverified
parent 0afc096173
commit 03a4eb555b
3 changed files with 32 additions and 24 deletions
+22 -4
View File
@@ -41,7 +41,25 @@ export function macVerticalTrafficLights(zoom: number) {
return { x, y, width: x + macTrafficLightsBaseWidth - 14 }
}
const macTrafficLightsGap = 14
/**
* The window background the content panel bends around to keep clear of the traffic lights, in CSS pixels from the
* window's top-left: the buttons, with as much room past them as they have from the window's start edge. Its corner
* is concentric with the zoom button.
*/
export function macTrafficLightsPocket(zoom: number) {
const lights = macVerticalTrafficLights(zoom)
const room = lights.x / zoom
const size = 14 / zoom
return {
right: lights.width / zoom + room,
bottom: lights.y / zoom + size + room,
corner: size / 2 + room,
}
}
// The floating toggle's gap from the pocket.
const macTrafficLightsPocketGap = 4
// The toggle's 28px plus a 4px gap before the header contents.
const slotWidth = 32
@@ -151,11 +169,11 @@ function useCollapsedSlot() {
return {
visible: () => desktop() && !windows() && settings.appearance.tabLayout() !== "horizontal",
open: settings.appearance.sidebarOpen,
// Lays the toggle out as if the traffic lights were the header's first control.
// Lays the toggle out just past the traffic lights' pocket.
width: () =>
mac()
? macVerticalTrafficLights(platform.webviewZoom?.() ?? 1).width / (platform.webviewZoom?.() ?? 1) +
macTrafficLightsGap -
? macTrafficLightsPocket(platform.webviewZoom?.() ?? 1).right +
macTrafficLightsPocketGap -
contentStart +
slotWidth
: slotWidth,
@@ -1,18 +1,18 @@
import { expect, it } from "bun:test"
import { trafficLightsPocket } from "./traffic-lights-notch"
it("bends the closed sidebar's content panel around the traffic lights, its corner concentric with the zoom button", () => {
// The buttons span 20–80px across and 25–39px down at 1x.
expect(trafficLightsPocket(0, 1)).toEqual({ left: 8, right: 90, bottom: 49, top: 8, outer: 10, inner: 17 })
it("bends the closed sidebar's content panel around the traffic lights, leaving as much room past them as before them", () => {
// The buttons span 20–80px across and 25–39px down at 1x, 20px from the window's start edge.
expect(trafficLightsPocket(0, 1)).toEqual({ left: 8, right: 100, bottom: 59, top: 8, outer: 10, inner: 27 })
})
it("flattens the bend into the panel's own corner as the panel's edge reaches the pocket's", () => {
const pocket = trafficLightsPocket(70, 1)
expect(pocket?.outer).toBeCloseTo(10 * (12 / 27), 5)
expect(pocket?.inner).toBeCloseTo(17 * (12 / 27), 5)
expect(trafficLightsPocket(81.99, 1)?.outer).toBeCloseTo(0, 2)
expect(trafficLightsPocket(82, 1)).toBeUndefined()
expect(pocket?.outer).toBeCloseTo(10 * (22 / 37), 5)
expect(pocket?.inner).toBeCloseTo(27 * (22 / 37), 5)
expect(trafficLightsPocket(91.99, 1)?.outer).toBeCloseTo(0, 2)
expect(trafficLightsPocket(92, 1)).toBeUndefined()
expect(trafficLightsPocket(240, 1)).toBeUndefined()
})
@@ -20,7 +20,7 @@ it("stays concentric with the zoom button, which keeps its native size, under re
const pocket = trafficLightsPocket(0, 2)
// At 2x the buttons are 7px across on an 11.5px pitch, the first still centered 27px across and 32px down.
expect(pocket?.inner).toBe(13.5)
expect(pocket?.inner).toBe(27)
expect(pocket && pocket.right - pocket.inner).toBe(27 + 2 * 11.5)
expect(pocket && pocket.bottom - pocket.inner).toBe(32)
})
@@ -1,31 +1,21 @@
import { macVerticalTrafficLights } from "@/shell/sidebar-toggle"
import { macTrafficLightsPocket } from "@/shell/sidebar-toggle"
// The content panels' corner radius and their offset from the window's top and start edges.
const panelRadius = 10
const panelInset = 8
// Room between the traffic lights and the pocket the panel bends around them.
const pocketPadding = 10
// The native buttons' size in points; they keep it at every renderer zoom.
const trafficLightSize = 14
/**
* The top-left corner of the content panel once it bends around the traffic lights, in CSS pixels from the window's
* top-left. `content` is where the content area starts now. Undefined while the panel is clear of the buttons.
*/
export function trafficLightsPocket(content: number, zoom: number) {
const left = content + panelInset
const lights = macVerticalTrafficLights(zoom)
const right = lights.width / zoom + pocketPadding
const bottom = (lights.y + trafficLightSize) / zoom + pocketPadding
const { right, bottom, corner } = macTrafficLightsPocket(zoom)
const width = right - left
if (width <= 0) return
// The pocket's corner is concentric with the zoom button.
const corner = trafficLightSize / 2 / zoom + pocketPadding
// As the panel's edge reaches the pocket's, its two corners shrink together so the bend flattens into the panel's
// own rounded corner.
const scale = Math.min(1, width / (panelRadius + corner))