mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-30 00:33:41 +08:00
Layout: Show a magnified view clear of your finger while dragging widgets on touch
This commit is contained in:
@@ -608,6 +608,9 @@ input[type="range"].gx-slider:active::-moz-range-thumb {
|
||||
.gx-layout__layer.is-drop-target.is-drop-after::before { top: auto; bottom: -5px; }
|
||||
.gx-layout__drag-ghost { position: fixed; z-index: 1000; pointer-events: none; display: flex; align-items: center; gap: 12px; padding: 12px 16px; min-height: 44px; box-sizing: border-box; border: 2px solid var(--primary); border-radius: 16px; background: var(--background); color: var(--on-surface); box-shadow: 0 12px 32px #0008; transform: scale(1.03); }
|
||||
.gx-layout__drag-ghost strong { flex: 1; }
|
||||
.gx-layout__loupe { position: fixed; z-index: 1000; pointer-events: none; overflow: hidden; box-sizing: border-box; border: 2px solid var(--primary); border-radius: 16px; box-shadow: 0 12px 32px #0008;
|
||||
background: repeating-linear-gradient(135deg, #090c10 0 6px, #131820 6px 12px); }
|
||||
.gx-layout__loupe svg { display: block; width: 100%; height: 100%; }
|
||||
.gx-layout__outline { pointer-events: none; }
|
||||
.gx-layout__help > summary { cursor: pointer; min-height: 40px; align-content: center; }
|
||||
.gx-layout__layer.is-dragging { opacity: .45; }
|
||||
|
||||
@@ -73,6 +73,7 @@ export const ONROAD_LAYOUT_TEMPLATE = `
|
||||
<svg ref="preview" class="gx-layout__preview" :style="{'--layout-glow': state.profile === 'compact' ? '4px' : '14px'}" :viewBox="'0 0 ' + profile.width + ' ' + profile.height" :width="profile.width" :height="profile.height"
|
||||
@pointermove="moveDrag" @pointerup="endDrag" @pointercancel="cancelDrag" @lostpointercapture="cancelDrag"
|
||||
role="group" :aria-label="projection ? 'StarPort layout preview' : (state.profile === 'large' ? 'Big' : 'Small') + ' layout preview'">
|
||||
<g id="gx-layout-stage">
|
||||
<image v-if="nativeBackdropReady" :href="state.backdrop.url" :width="profile.width" :height="profile.height" preserveAspectRatio="none" data-preview-source="device-backdrop" />
|
||||
<template v-else>
|
||||
<rect width="100%" height="100%" fill="#252b32" />
|
||||
@@ -160,8 +161,12 @@ export const ONROAD_LAYOUT_TEMPLATE = `
|
||||
:y1="guide.axis === 'y' ? guide.value : 0" :y2="guide.axis === 'y' ? guide.value : profile.height" vector-effect="non-scaling-stroke" />
|
||||
</g>
|
||||
<rect v-if="state.showEditingAids && selectionBox" class="gx-layout__outline" :x="selectionBox.x" :y="selectionBox.y" :width="selectionBox.width" :height="selectionBox.height" rx="4" fill="none" stroke="#d4baff" stroke-width="2" vector-effect="non-scaling-stroke" />
|
||||
</g>
|
||||
</svg>
|
||||
</div>
|
||||
<Teleport to="body"><div v-if="loupe" class="gx-layout__loupe" aria-hidden="true" :style="loupe.style">
|
||||
<svg :viewBox="loupe.viewBox" preserveAspectRatio="xMidYMid meet"><use href="#gx-layout-stage" /></svg>
|
||||
</div></Teleport>
|
||||
<!-- The Small screen is too short to carry the chip over the layout; it sits underneath instead. -->
|
||||
<span v-if="!projection && state.showFavoriteZones && state.showEditingAids && state.profile === 'compact'" class="gx-layout__stage-chip gx-layout__stage-chip--below" aria-hidden="true"><i class="bi bi-grid-3x3-gap"></i>Tap areas</span>
|
||||
<GxCollapse><div v-show="state.tipsOpen" id="gx-layout-tips" class="gx-layout__tips">
|
||||
|
||||
@@ -556,6 +556,34 @@ export const OnroadLayoutPage = {
|
||||
width: widget.width, height: widget.height + widget.visualInsetTop + widget.visualInsetBottom
|
||||
}
|
||||
},
|
||||
// On touch, a magnified copy of the area around the dragged widget sits clear of the finger.
|
||||
loupe() {
|
||||
const drag = this.state.drag
|
||||
if (!drag?.touch || !drag.moved || drag.resize || (drag.fromTray && !drag.inside) || drag.clientX == null || !this.$refs.preview) return null
|
||||
const rect = this.$refs.preview.getBoundingClientRect(), viewWidth = window.innerWidth, viewHeight = window.innerHeight
|
||||
if (!rect.width) return null
|
||||
const gap = 48, edge = 8, x = drag.clientX, y = drag.clientY
|
||||
let width = Math.round(Math.max(150, Math.min(240, viewWidth / 2 - 8))), height = Math.round(width * .62)
|
||||
let left = Math.max(edge, Math.min(viewWidth - width - edge, x - width / 2)), top = y - gap - height
|
||||
if (top < edge) {
|
||||
// No room above: sit beside the finger on the roomier side, narrower if needed, before falling back to below.
|
||||
const right = x < viewWidth / 2, beside = Math.min(width, Math.floor((right ? viewWidth - x : x) - 24 - edge))
|
||||
if (beside >= 140) {
|
||||
width = beside
|
||||
height = Math.round(width * .62)
|
||||
left = right ? x + 24 : x - 24 - width
|
||||
top = Math.max(edge, Math.min(viewHeight - height - edge, y - height / 2))
|
||||
} else top = Math.min(viewHeight - height - edge, y + gap)
|
||||
}
|
||||
const [widgetWidth, widgetHeight] = widgetSize(this.profile.widgets[drag.id], this.layout[drag.id])
|
||||
const span = Math.max(width / (rect.width / this.profile.width * 2), widgetWidth * 1.5, widgetHeight * 1.5 * width / height)
|
||||
const spanY = span * height / width
|
||||
const centerX = this.previewX(drag.id) + widgetWidth / 2, centerY = this.layout[drag.id].y + widgetHeight / 2
|
||||
return {
|
||||
viewBox: [centerX - span / 2, centerY - spanY / 2, span, spanY].map(value => Math.round(value * 10) / 10).join(" "),
|
||||
style: { left: Math.round(left) + "px", top: Math.round(top) + "px", width: width + "px", height: height + "px" }
|
||||
}
|
||||
},
|
||||
activeWidgets() { return this.widgets.filter(({ id }) => this.layout[id].enabled) },
|
||||
renderWidgets() {
|
||||
return this.layerWidgets.filter(item => !this.previewHidden(item.id)).reverse().map((item) => {
|
||||
@@ -1242,6 +1270,8 @@ export const OnroadLayoutPage = {
|
||||
// A finger wobbles a few pixels on every tap; only a deliberate move drags the widget.
|
||||
if (!drag.moved && Math.hypot(event.clientX - drag.startX, event.clientY - drag.startY) < DRAG_SLOP) return
|
||||
drag.moved = true
|
||||
drag.clientX = event.clientX
|
||||
drag.clientY = event.clientY
|
||||
drag.inside = point.x >= 0 && point.y >= 0 && point.x <= this.profile.width && point.y <= this.profile.height
|
||||
if (!drag.fromTray || drag.inside) {
|
||||
const raw = { x: point.x - drag.offsetX, y: point.y - drag.offsetY }
|
||||
|
||||
Reference in New Issue
Block a user