mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-12-02 12:43:53 +08:00
PiP: Lock Each Independently
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -192,7 +192,7 @@ export const ONROAD_LAYOUT_TEMPLATE = `
|
||||
<div ref="widgetsHelp" class="gx-layout__subhead gx-layout__help-anchor"><h3>Widgets</h3><span>{{ activeWidgets.length }} active</span>
|
||||
<button class="gx-icon-btn gx-layout__info" type="button" :aria-expanded="state.widgetsHelpOpen" aria-controls="gx-layout-widgets-help" aria-label="How the widget list works" title="How the widget list works" @click="toggleFloating('widgetsHelpOpen', 'widgetsHelp')"><i class="bi bi-info-circle" aria-hidden="true"></i></button>
|
||||
<GxCollapse><div v-show="state.widgetsHelpOpen" id="gx-layout-widgets-help" class="gx-layout__popover" @click="closeFloating('widgetsHelpOpen')" @keydown.esc="closeFloating('widgetsHelpOpen')">
|
||||
<p>Tap a widget to edit it.</p><p>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.</p><p>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.</p>
|
||||
<p>Tap a widget to edit it.</p><p>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.</p><p>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.</p>
|
||||
</div></GxCollapse>
|
||||
</div>
|
||||
<div class="gx-layout__widget-list"><div v-for="widget in listWidgets" :key="widget.id" class="gx-layout__layer" :data-layer-id="widget.id"
|
||||
@@ -207,9 +207,9 @@ export const ONROAD_LAYOUT_TEMPLATE = `
|
||||
<button class="gx-layout__layer-name" type="button" :aria-pressed="state.selected === widget.id" :disabled="!!state.drag || !!state.layerDrag"
|
||||
@click="selectWidget(widget.id)">{{ widget.label }}</button>
|
||||
<button v-if="cameraIds.includes(widget.id)" class="gx-layout__visibility gx-icon-btn" type="button" :disabled="!editAvailable || !!state.drag || !!state.layerDrag"
|
||||
:aria-label="camerasLocked ? 'Unlock side cameras' : 'Lock side cameras in front'" :title="camerasLocked ? 'Locked in front. Tap to unlock.' : 'Tap to lock side cameras in front.'"
|
||||
:aria-pressed="camerasLocked" @click="toggleCameraLock">
|
||||
<i class="bi" :class="camerasLocked ? 'bi-lock-fill' : 'bi-unlock'" aria-hidden="true"></i>
|
||||
:aria-label="cameraLocked(widget.id) ? 'Unlock ' + widget.label : 'Lock ' + widget.label + ' in front'" :title="cameraLocked(widget.id) ? 'Locked in front. Tap to unlock.' : 'Tap to lock in front.'"
|
||||
:aria-pressed="cameraLocked(widget.id)" @click="toggleCameraLock(widget.id)">
|
||||
<i class="bi" :class="cameraLocked(widget.id) ? 'bi-lock-fill' : 'bi-unlock'" aria-hidden="true"></i>
|
||||
</button>
|
||||
<button v-if="!projection || widget.id !== 'car_exit'" class="gx-layout__visibility gx-icon-btn" type="button" :disabled="!!state.drag || !!state.layerDrag || sceneHidden(widget.id)"
|
||||
:aria-label="visibilityTitle(widget.id, widget.label)"
|
||||
@@ -415,8 +415,8 @@ export const ONROAD_LAYOUT_TEMPLATE = `
|
||||
</div>
|
||||
</GxDialog>
|
||||
<GxDialog v-if="state.pipUnlockConfirm" labelledby="gx-layout-pip-unlock-title" describedby="gx-layout-pip-unlock-body" alert @close="cancelCameraUnlock">
|
||||
<div><h3 id="gx-layout-pip-unlock-title">Unlock side cameras?</h3>
|
||||
<p id="gx-layout-pip-unlock-body">Warning: moving other widgets on top of the side cameras may block your view of the blind-spot camera. Are you sure?</p></div>
|
||||
<div><h3 id="gx-layout-pip-unlock-title">Unlock {{ profile?.widgets[state.pipUnlockConfirm]?.label }}?</h3>
|
||||
<p id="gx-layout-pip-unlock-body">Warning: moving other widgets on top of this side camera may block your view of the blind-spot camera. Are you sure?</p></div>
|
||||
<div class="gx-settings__controls gx-actions">
|
||||
<button type="button" class="gx-btn gx-btn--tonal" @click="cancelCameraUnlock">Cancel</button>
|
||||
<button type="button" class="gx-btn gx-btn--danger" @click="confirmCameraUnlock">Unlock</button>
|
||||
|
||||
@@ -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 = ""
|
||||
|
||||
Reference in New Issue
Block a user