diff --git a/openpilot/starpilot/galaxy/tests/browser/widget-layers.cjs b/openpilot/starpilot/galaxy/tests/browser/widget-layers.cjs index ed9ead6946..cf4aef836a 100644 --- a/openpilot/starpilot/galaxy/tests/browser/widget-layers.cjs +++ b/openpilot/starpilot/galaxy/tests/browser/widget-layers.cjs @@ -39,8 +39,10 @@ const projection = JSON.parse(execFileSync(process.env.PYTHON || 'python3', ['-c const initialIds = await rows.evaluateAll(elements => elements.map(row => row.dataset.layerId)) assert.match(initialIds[0], /^pip_/, 'side cameras start locked in front') assert.equal(await rows.first().locator('.gx-layout__row-grip').isDisabled(), true) - await page.getByRole('button', {name:'Unlock side cameras'}).first().click() - await page.getByRole('button', {name:'Unlock', exact:true}).click() + for (const side of ['left', 'right']) { + await page.getByRole('button', {name:`Unlock PiP ${side} side camera`}).click() + await page.getByRole('button', {name:'Unlock', exact:true}).click() + } assert.equal(await rows.first().locator('.gx-layout__row-grip').isDisabled(), false) const source = await rows.last().boundingBox(), destination = await rows.first().boundingBox() const beforeMouse = await page.evaluate(() => JSON.stringify(window.editor.state.draft)) diff --git a/openpilot/starpilot/galaxy/tests/test_projection_map_widgets.mjs b/openpilot/starpilot/galaxy/tests/test_projection_map_widgets.mjs index 3dc968dfce..239a259c9f 100644 --- a/openpilot/starpilot/galaxy/tests/test_projection_map_widgets.mjs +++ b/openpilot/starpilot/galaxy/tests/test_projection_map_widgets.mjs @@ -110,9 +110,9 @@ Object.defineProperties(vm, { layout: { get: () => vm.state.draft.layouts.large }, selectedWidget: { get: () => profile.widgets[vm.state.selected] }, selectedPosition: { get: () => vm.state.draft.layouts.large[vm.state.selected] }, - ...Object.fromEntries(["cameraIds", "camerasOnTop", "camerasLocked"].map(name => [name, { get: () => OnroadLayoutPage.computed[name].call(vm) }])), + ...Object.fromEntries(["cameraIds", "camerasOnTop", "lockedCameraIds"].map(name => [name, { get: () => OnroadLayoutPage.computed[name].call(vm) }])), }) -for (const name of ["watchRelease", "unwatchRelease", "recordChange", "resizeBox", "boxInput", "opacityInput", "setWidgetBackground", "undo", "redo", "startResize", "moveDrag", "endDrag", "releaseDrag", "changePosition", "add", "remove", "requestRemove", "reorderLayer", "startLayerDrag", "setFavoriteDisplay", "layerFixed", "toggleCameraLock", "confirmCameraUnlock", "cancelCameraUnlock", "clearPendingTouch"]) +for (const name of ["watchRelease", "unwatchRelease", "recordChange", "resizeBox", "boxInput", "opacityInput", "setWidgetBackground", "undo", "redo", "startResize", "moveDrag", "endDrag", "releaseDrag", "changePosition", "add", "remove", "requestRemove", "reorderLayer", "startLayerDrag", "setFavoriteDisplay", "layerFixed", "cameraLocked", "pinLockedCameras", "toggleCameraLock", "confirmCameraUnlock", "cancelCameraUnlock", "clearPendingTouch"]) vm[name] = OnroadLayoutPage.methods[name].bind(vm) const pointer = (x, y) => ({ clientX: x, clientY: y, pointerId: 7, button: 0, preventDefault() {}, stopPropagation() {} }) vm.startResize("nav_map", pointer(1950 + 860, 625 + 410)) @@ -253,37 +253,46 @@ vm.reorderLayer('car_exit', 'nav_map') vm.reorderLayer('nav_map', 'car_exit') assert.deepEqual(orderedWidgetIds(vm.state.draft, data.metadata, 'large'), pinnedOrder) -// Side cameras lock just under Exit to car; unlocking needs a confirmation. -assert.equal(vm.camerasLocked, false, "an order with widgets above the cameras opens unlocked") -vm.toggleCameraLock() +// Each side camera locks on its own, just under Exit to car; unlocking needs a confirmation. +vm.state.pipUnlocked = {} +const layerOrder = () => [...orderedWidgetIds(vm.state.draft, data.metadata, 'large')] +assert.deepEqual(vm.lockedCameraIds, [], "cameras under other widgets open unlocked") +vm.toggleCameraLock('pip_left') assert.equal(vm.state.pipUnlockConfirm, undefined, "locking needs no warning") -const lockedOrder = [...orderedWidgetIds(vm.state.draft, data.metadata, 'large')] -assert.deepEqual(lockedOrder.slice(-3), ['pip_left', 'pip_right', 'car_exit']) -assert.equal(vm.camerasLocked, true) +assert.deepEqual(layerOrder().slice(-2), ['pip_left', 'car_exit']) +assert.equal(vm.cameraLocked('pip_left'), true) +assert.equal(vm.cameraLocked('pip_right'), false, "the other camera keeps its own lock") +vm.toggleCameraLock('pip_right') +const lockedOrder = layerOrder() +assert.deepEqual(lockedOrder.slice(-3), ['pip_right', 'pip_left', 'car_exit'], "a newly locked camera joins the locked ones under Exit to car") vm.reorderLayer('nav_map', 'pip_left') vm.reorderLayer('pip_left', 'nav_map') vm.startLayerDrag({ button: 0 }, 'pip_right') assert.equal(vm.state.layerDrag, undefined) -assert.deepEqual(orderedWidgetIds(vm.state.draft, data.metadata, 'large'), lockedOrder) -vm.toggleCameraLock() -assert.equal(vm.state.pipUnlockConfirm, true) -assert.equal(vm.camerasLocked, true, "the lock holds until the warning is confirmed") +assert.deepEqual(layerOrder(), lockedOrder) +vm.toggleCameraLock('pip_right') +assert.equal(vm.state.pipUnlockConfirm, 'pip_right') +assert.equal(vm.cameraLocked('pip_right'), true, "the lock holds until the warning is confirmed") vm.cancelCameraUnlock() -vm.toggleCameraLock() +vm.toggleCameraLock('pip_right') vm.confirmCameraUnlock() -assert.equal(vm.camerasLocked, false) +assert.equal(vm.cameraLocked('pip_right'), false) +assert.equal(vm.cameraLocked('pip_left'), true, "unlocking one camera leaves the other locked") vm.reorderLayer('nav_map', 'pip_right') -assert.deepEqual(orderedWidgetIds(vm.state.draft, data.metadata, 'large').slice(-3), ['pip_right', 'nav_map', 'car_exit']) +assert.deepEqual(layerOrder().slice(-4), ['pip_right', 'nav_map', 'pip_left', 'car_exit'], "a widget can go above the unlocked camera only") assert.equal(validDocument(vm.state.draft, data.metadata), true) -vm.toggleCameraLock() -assert.equal(vm.camerasLocked, true, "locking moves the cameras back under Exit to car") -assert.deepEqual(orderedWidgetIds(vm.state.draft, data.metadata, 'large').slice(-3), ['pip_left', 'pip_right', 'car_exit']) +vm.reorderLayer('nav_map', 'pip_left') +assert.deepEqual(layerOrder().slice(-4), ['pip_right', 'nav_map', 'pip_left', 'car_exit']) +vm.toggleCameraLock('pip_right') +assert.equal(vm.cameraLocked('pip_right'), true, "locking moves the camera back under Exit to car") +assert.deepEqual(layerOrder().slice(-3), ['pip_right', 'pip_left', 'car_exit']) vm.undo() vm.undo() -assert.deepEqual(orderedWidgetIds(vm.state.draft, data.metadata, 'large'), lockedOrder) +assert.deepEqual(layerOrder(), lockedOrder) vm.undo() -assert.deepEqual(orderedWidgetIds(vm.state.draft, data.metadata, 'large'), pinnedOrder) -vm.state.pipUnlocked = false +vm.undo() +assert.deepEqual(layerOrder(), pinnedOrder) +vm.state.pipUnlocked = {} const disabledExit = copy(vm.state.draft) disabledExit.layouts.large.car_exit.enabled = false assert.equal(validDocument(disabledExit, data.metadata), false) diff --git a/openpilot/starpilot/galaxy/web/js/onroad-layout-template.js b/openpilot/starpilot/galaxy/web/js/onroad-layout-template.js index 2f49d44ff4..29a1a52c52 100644 --- a/openpilot/starpilot/galaxy/web/js/onroad-layout-template.js +++ b/openpilot/starpilot/galaxy/web/js/onroad-layout-template.js @@ -192,7 +192,7 @@ export const ONROAD_LAYOUT_TEMPLATE = `

Widgets

{{ activeWidgets.length }} active
-

Tap a widget to edit it.

Drag ⠿ to reorder. The top row is in front, and alerts stay above all widgets. Side cameras are locked to the front; unlock them to move widgets above.

The eyes follow the chosen scene. Choose General edit to arrange every enabled widget. Hiding a widget with the eye affects only this scene's preview.

+

Tap a widget to edit it.

Drag ⠿ to reorder. The top row is in front, and alerts stay above all widgets. Each side camera can be locked to the front; unlock it to move widgets above.

The eyes follow the chosen scene. Choose General edit to arrange every enabled widget. Hiding a widget with the eye affects only this scene's preview.

{{ widget.label }} diff --git a/openpilot/starpilot/galaxy/web/js/onroad-layout.js b/openpilot/starpilot/galaxy/web/js/onroad-layout.js index 31d1284397..9a490242be 100644 --- a/openpilot/starpilot/galaxy/web/js/onroad-layout.js +++ b/openpilot/starpilot/galaxy/web/js/onroad-layout.js @@ -406,7 +406,7 @@ export const OnroadLayoutPage = { setup(props) { const state = reactive({ status: "idle", data: null, draft: null, needsReload: false, error: "", notice: "", - profile: "large", scene: "general", selected: null, layerDrag: null, drag: null, discard: null, leavePresentation: null, removeConfirm: null, pipUnlocked: false, pipUnlockConfirm: false, colorError: "", placementError: "", + profile: "large", scene: "general", selected: null, layerDrag: null, drag: null, discard: null, leavePresentation: null, removeConfirm: null, pipUnlocked: {}, pipUnlockConfirm: null, colorError: "", placementError: "", inspectorPanel: ["widgets", "edit", "road", "display"].includes(props.initialPanel) && !props.projection ? props.initialPanel : "widgets", showFavoriteZones: false, showEditingAids: loadAidsPreference(), aboutOpen: false, tipsOpen: false, moreOpen: false, widgetsHelpOpen: false, stuck: { leaveBar: false, pinned: false, sections: false }, shrunk: false, touchArmed: null, openColor: null, art: { status: "idle", error: "", url: null, sprites: null }, backdrop: { status: "idle", error: "", url: null }, hiddenPreviewWidgets: loadPreviewVisibility(props.projection), sceneHiddenPreviewWidgets: {}, snapEnabled: loadSnapPreference(), snapGuides: [], history: { undo: [], redo: [], group: null } @@ -568,14 +568,16 @@ export const OnroadLayoutPage = { .slice().reverse().map(id => this.widgets.find(widget => widget.id === id)).filter(widget => widget && this.layout[widget.id].enabled) }, cameraIds() { return CAMERA_IDS.filter(id => Object.hasOwn(this.profile?.widgets || {}, id)) }, - // Locked side cameras hold the front slots, under only the always-frontmost controls. + // Side cameras in the unbroken run of front slots, under only the always-frontmost controls. camerasOnTop() { - if (!this.cameraIds.length) return false const order = orderedWidgetIds(this.state.draft, this.state.data.metadata, this.state.profile) .filter(id => !this.profile.widgets[id]?.frontmost) - return order.slice(-this.cameraIds.length).every(id => this.cameraIds.includes(id)) + const top = [] + for (let index = order.length - 1; index >= 0 && this.cameraIds.includes(order[index]); index--) top.push(order[index]) + return top }, - camerasLocked() { return !this.state.pipUnlocked && this.camerasOnTop }, + // Each side camera locks on its own; a locked one stays in front of every unlocked widget. + lockedCameraIds() { return this.camerasOnTop.filter(id => !this.state.pipUnlocked[id]) }, listWidgets() { return this.state.layerDrag ? this.state.layerDrag.rows.map(id => this.widgets.find(widget => widget.id === id)) : this.layerWidgets }, selectionBox() { if (!this.state.layerDrag) return null @@ -868,36 +870,42 @@ export const OnroadLayoutPage = { try { navigator.vibrate?.(10) } catch { } this.startDrag(pending.id, { ...pending, button: 0, preventDefault() { } }) }, - layerFixed(id) { return this.profile.widgets[id]?.frontmost || this.camerasLocked && this.cameraIds.includes(id) }, - toggleCameraLock() { - if (!this.editable || this.state.drag || this.state.layerDrag) return - if (this.camerasLocked) { this.state.pipUnlockConfirm = true; return } - this.state.pipUnlocked = false - if (this.camerasOnTop) return - const before = clone(this.state.draft) - const order = orderedWidgetIds(this.state.draft, this.state.data.metadata, this.state.profile) + cameraLocked(id) { return this.lockedCameraIds.includes(id) }, + layerFixed(id) { return this.profile.widgets[id]?.frontmost || this.cameraLocked(id) }, + // Keeps the locked cameras directly under the frontmost controls, in their current relative order. + pinLockedCameras(order, locked) { const front = order.filter(id => this.profile.widgets[id]?.frontmost) - const rest = order.filter(id => !front.includes(id)) + return [...order.filter(id => !front.includes(id) && !locked.includes(id)), ...order.filter(id => locked.includes(id)), ...front] + }, + toggleCameraLock(id) { + if (!this.editable || this.state.drag || this.state.layerDrag || !this.cameraIds.includes(id)) return + if (this.cameraLocked(id)) { this.state.pipUnlockConfirm = id; return } + const locked = [...this.lockedCameraIds, id] + this.state.pipUnlocked = { ...this.state.pipUnlocked, [id]: false } + const order = orderedWidgetIds(this.state.draft, this.state.data.metadata, this.state.profile) + const pinned = this.pinLockedCameras(order, locked) + if (pinned.every((key, index) => key === order[index])) return + const before = clone(this.state.draft) this.state.draft.widgetOrder ||= {} - this.state.draft.widgetOrder[this.state.profile] = [...rest.filter(id => !this.cameraIds.includes(id)), - ...rest.filter(id => this.cameraIds.includes(id)), ...front] + this.state.draft.widgetOrder[this.state.profile] = pinned this.recordChange(before) }, - cancelCameraUnlock() { this.state.pipUnlockConfirm = false }, + cancelCameraUnlock() { this.state.pipUnlockConfirm = null }, confirmCameraUnlock() { - this.state.pipUnlockConfirm = false - this.state.pipUnlocked = true + const id = this.state.pipUnlockConfirm + this.state.pipUnlockConfirm = null + if (id) this.state.pipUnlocked = { ...this.state.pipUnlocked, [id]: true } }, reorderLayer(id, target) { if (!this.editable || this.state.drag || id === target || this.layerFixed(id) || this.layerFixed(target)) return const order = [...orderedWidgetIds(this.state.draft, this.state.data.metadata, this.state.profile)] const from = order.indexOf(id), to = order.indexOf(target) if (from < 0 || to < 0) return - const before = clone(this.state.draft) + const before = clone(this.state.draft), locked = this.lockedCameraIds order.splice(from, 1) order.splice(to, 0, id) this.state.draft.widgetOrder ||= {} - this.state.draft.widgetOrder[this.state.profile] = order + this.state.draft.widgetOrder[this.state.profile] = this.pinLockedCameras(order, locked) this.state.selected = id this.recordChange(before) }, @@ -911,7 +919,7 @@ export const OnroadLayoutPage = { this.state.layerDrag = { id, pointerId: event.pointerId, target: null, startX: event.clientX, startY: event.clientY, x: rect.x, y: rect.y, width: rect.width, offsetX: event.clientX - rect.x, offsetY: event.clientY - rect.y, - rows: this.layerWidgets.map(widget => widget.id), before: clone(this.state.draft), moved: false + rows: this.layerWidgets.map(widget => widget.id), before: clone(this.state.draft), locked: [...this.lockedCameraIds], moved: false } this._layerTarget = event.currentTarget this.watchRelease() @@ -960,7 +968,7 @@ export const OnroadLayoutPage = { order.splice(from, 1) order.splice(to, 0, drag.id) this.state.draft.widgetOrder ||= {} - this.state.draft.widgetOrder[this.state.profile] = order + this.state.draft.widgetOrder[this.state.profile] = this.pinLockedCameras(order, drag.locked || []) } }, // Scrolls while a dragged row is held near the visible edges; the top edge is the bottom of the pinned tabs. @@ -1051,7 +1059,7 @@ export const OnroadLayoutPage = { this.state.snapGuides = [] this.finishColorEdit() this.state.profile = profile - this.state.pipUnlocked = false + this.state.pipUnlocked = {} this.state.touchArmed = null this.state.selected = Object.keys(this.profile.widgets)[0] || null this.state.placementError = ""