From 8d604a5807a386c2cc8ff4acefb9a96a1a1a5d36 Mon Sep 17 00:00:00 2001 From: TongTongStudio Date: Fri, 27 Nov 2026 03:56:40 +0800 Subject: [PATCH] Add icon row arrangement and consistent sizing --- INTEGRATION.md | 2 +- .../app/src/main/assets/default_layout.json | 96 +++++++------- backend/deploy/deploy.yaml | 2 +- frontend/canvas.html | 6 +- frontend/src/App.vue | 123 ++++++++++++++++-- frontend/src/LayoutSurface.vue | 3 +- frontend/src/layout.ts | 29 +++++ frontend/src/styles.css | 1 + frontend/test-layout.mjs | 18 ++- 9 files changed, 213 insertions(+), 67 deletions(-) diff --git a/INTEGRATION.md b/INTEGRATION.md index 9ea6fc6..c4c7906 100644 --- a/INTEGRATION.md +++ b/INTEGRATION.md @@ -99,7 +99,7 @@ $env:LAUNCHER_DEVICE_TOKEN = '<设备令牌>' | --- | --- | | 服务器 | `175.178.213.60`,Debian 12,k3s 单节点,SSH 密钥登录 | | 命名空间 / 工作负载 | `vibe-launcher` / `deploy/vibe-launcher-backend`,单副本 `Recreate` | -| 镜像 | `docker.io/library/vibe-launcher-backend:1.1.0-deploy11`,`imagePullPolicy: IfNotPresent` | +| 镜像 | `docker.io/library/vibe-launcher-backend:1.1.0-deploy14`,`imagePullPolicy: IfNotPresent` | | 端口 | 容器 8080,Service NodePort **30830**(30800 是 youlai-boot,30810 是 tts-server,30820 是 compose-remote-server) | | 公网入口 | `https://api.ttstd.com/launcher/`(灰云直连源站,不走 Cloudflare);nginx 剥掉 `/launcher/` 前缀后反代 `127.0.0.1:30830` | | 数据 | 宿主机 `/opt/vibe-launcher/data/layouts.sqlite` 挂到容器 `/data`,Pod 重建不丢版本历史 | diff --git a/android/app/src/main/assets/default_layout.json b/android/app/src/main/assets/default_layout.json index d05f60d..4301395 100644 --- a/android/app/src/main/assets/default_layout.json +++ b/android/app/src/main/assets/default_layout.json @@ -34,10 +34,10 @@ { "id": "i0", "type": "app_icon", - "x": 150, - "y": 604, - "w": 132, - "h": 168, + "x": 142, + "y": 596, + "w": 148, + "h": 184, "z": 2, "payload": { "package": "com.tencent.mm", @@ -47,10 +47,10 @@ { "id": "i1", "type": "app_icon", - "x": 366, - "y": 604, - "w": 132, - "h": 168, + "x": 358, + "y": 596, + "w": 148, + "h": 184, "z": 2, "payload": { "package": "com.android.camera2", @@ -60,10 +60,10 @@ { "id": "i2", "type": "app_icon", - "x": 582, - "y": 604, - "w": 132, - "h": 168, + "x": 574, + "y": 596, + "w": 148, + "h": 184, "z": 2, "payload": { "package": "com.android.gallery3d", @@ -73,10 +73,10 @@ { "id": "i3", "type": "app_icon", - "x": 798, - "y": 604, - "w": 132, - "h": 168, + "x": 790, + "y": 596, + "w": 148, + "h": 184, "z": 2, "payload": { "package": "com.android.settings", @@ -86,10 +86,10 @@ { "id": "i4", "type": "app_icon", - "x": 150, - "y": 828, - "w": 132, - "h": 168, + "x": 142, + "y": 820, + "w": 148, + "h": 184, "z": 2, "payload": { "package": "com.android.chrome", @@ -99,10 +99,10 @@ { "id": "i5", "type": "app_icon", - "x": 366, - "y": 828, - "w": 132, - "h": 168, + "x": 358, + "y": 820, + "w": 148, + "h": 184, "z": 2, "payload": { "package": "com.tencent.qqmusic", @@ -112,10 +112,10 @@ { "id": "i6", "type": "app_icon", - "x": 582, - "y": 828, - "w": 132, - "h": 168, + "x": 574, + "y": 820, + "w": 148, + "h": 184, "z": 2, "payload": { "package": "com.android.dialer", @@ -125,10 +125,10 @@ { "id": "i7", "type": "app_icon", - "x": 798, - "y": 828, - "w": 132, - "h": 168, + "x": 790, + "y": 820, + "w": 148, + "h": 184, "z": 2, "payload": { "package": "com.android.calendar", @@ -164,10 +164,10 @@ { "id": "s0", "type": "app_icon", - "x": 150, - "y": 1650, - "w": 132, - "h": 168, + "x": 142, + "y": 1642, + "w": 148, + "h": 184, "z": 2, "payload": { "package": "com.android.contacts", @@ -177,10 +177,10 @@ { "id": "s1", "type": "app_icon", - "x": 366, - "y": 1650, - "w": 132, - "h": 168, + "x": 358, + "y": 1642, + "w": 148, + "h": 184, "z": 2, "payload": { "package": "com.android.messaging", @@ -190,10 +190,10 @@ { "id": "s2", "type": "app_icon", - "x": 582, - "y": 1650, - "w": 132, - "h": 168, + "x": 574, + "y": 1642, + "w": 148, + "h": 184, "z": 2, "payload": { "package": "com.android.documentsui", @@ -203,10 +203,10 @@ { "id": "s3", "type": "app_icon", - "x": 798, - "y": 1650, - "w": 132, - "h": 168, + "x": 790, + "y": 1642, + "w": 148, + "h": 184, "z": 2, "payload": { "package": "com.tencent.mobileqq", diff --git a/backend/deploy/deploy.yaml b/backend/deploy/deploy.yaml index db950ae..bea4e66 100644 --- a/backend/deploy/deploy.yaml +++ b/backend/deploy/deploy.yaml @@ -26,7 +26,7 @@ spec: spec: containers: - name: server - image: docker.io/library/vibe-launcher-backend:1.1.0-deploy11 + image: docker.io/library/vibe-launcher-backend:1.1.0-deploy14 imagePullPolicy: IfNotPresent ports: - name: http diff --git a/frontend/canvas.html b/frontend/canvas.html index ecd81e4..08acc11 100644 --- a/frontend/canvas.html +++ b/frontend/canvas.html @@ -389,7 +389,7 @@ function newState() { } function demoItems() { - const pad = 108, colW = 216, icon = 132, ih = 168; + const pad = 108, colW = 216, icon = 148, ih = 184; const colX = c => pad + c * colW + (colW - icon) / 2; const out = []; out.push({ id:'w_clock', type:'widget', x:pad, y:196, w:864, h:320, z:1, @@ -397,7 +397,7 @@ function demoItems() { [['微信','com.tencent.mm'],['相机','com.android.camera2'],['相册','com.android.gallery3d'],['设置','com.android.settings'],['浏览器','com.android.chrome'],['QQ音乐','com.tencent.qqmusic'],['电话','com.android.dialer'],['日历','com.android.calendar']].forEach(([label, pkg], i) => { const c = i % 4, r = Math.floor(i / 4); - out.push({ id:'i'+i, type:'app_icon', x:colX(c), y:604 + r*224, w:icon, h:ih, z:2, + out.push({ id:'i'+i, type:'app_icon', x:colX(c), y:596 + r*224, w:icon, h:ih, z:2, payload:{ package:pkg, label } }); }); @@ -407,7 +407,7 @@ function demoItems() { payload:{ provider:'com.tencent.qqmusic/com.tencent.qqmusiccommon.WidgetProviderSmall', label:'音乐' } }); [['联系人','com.android.contacts'],['短信','com.android.messaging'],['文件','com.android.documentsui'],['QQ','com.tencent.mobileqq']].forEach(([label, pkg], i) => { - out.push({ id:'s'+i, type:'app_icon', x:colX(i), y:1650, w:icon, h:ih, z:2, + out.push({ id:'s'+i, type:'app_icon', x:colX(i), y:1642, w:icon, h:ih, z:2, payload:{ package:pkg, label } }); }); return out; diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 16ff48b..19485cb 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -11,7 +11,7 @@ import ReleaseDialog from "./ReleaseDialog.vue"; import LayoutSurface from "./LayoutSurface.vue"; import DevicePreview from "./DevicePreview.vue"; import { - alignmentGuide, builtInLayout, clamp, copyLayout, normalizeLayout, templates, validate, + alignmentGuide, arrangeIconRow, builtInLayout, clamp, copyLayout, isIcon, normalizeLayout, resizedIconBounds, templates, validate, type Layout, type LayoutItem, type Payload, type Template, } from "./layout"; @@ -52,11 +52,32 @@ function markPublished(revision: number) { } const pageIndex = ref(0); const selectedId = ref(); +const rowSelection = ref([]); +const pickingRow = ref(false); const page = computed(() => layout.value.pages[pageIndex.value]!); const selected = computed(() => page.value.items.find(item => item.id === selectedId.value)); const tab = ref("preview"); const snap = ref(true); const guides = ref(true); +const iconSizeKey = "vibe-launcher-icon-size"; +const iconSize = ref({ enabled: false, width: 148, height: 184 }); +try { + const stored = JSON.parse(localStorage.getItem(iconSizeKey) ?? "null"); + if (stored && typeof stored.enabled === "boolean" && Number.isInteger(stored.width) && + Number.isInteger(stored.height) && stored.width > 0 && stored.height > 0) { + iconSize.value = stored; + } +} catch { + // Use the default settings when browser storage is unavailable. +} +watch(iconSize, value => { + try { + localStorage.setItem(iconSizeKey, JSON.stringify(value)); + } catch { + ElMessage.warning("无法保存图标大小设置"); + } +}, { deep: true }); + const release = ref(false); const widgetCatalog = ref(false); @@ -198,7 +219,8 @@ function restore(from: Layout[], to: Layout[]) { } function selectPage(index: number) { pageIndex.value = index; - selectedId.value = undefined; + clearSelection(); + pickingRow.value = false; } function changePages(add: boolean) { remember(); @@ -222,30 +244,49 @@ function updateValue(record: T, key: K, val remember(); record[key] = value; } +const effectiveIconSize = computed(() => ({ + w: clamp(iconSize.value.width, 1, canvas.value.designWidth), + h: clamp(iconSize.value.height, 1, canvas.value.designHeight), +})); +const allIcons = computed(() => layout.value.pages.flatMap(entry => entry.items.filter(item => isIcon(item.type)))); + +function applyIconSize() { + const { w, h } = effectiveIconSize.value; + const updates = allIcons.value.filter(item => item.w !== w || item.h !== h); + if (!updates.length) { + ElMessage.info("所有图标已是指定大小"); + return; + } + remember(); + for (const item of updates) Object.assign(item, resizedIconBounds(item, w, h, canvas.value)); + ElMessage.success("已统一 " + updates.length + " 个图标的大小"); +} + const grid = (n: number) => snap.value ? Math.round(n / 12) * 12 : Math.round(n); function addItem(template: Template, x?: number, y?: number) { const count = page.value.items.length; if (count >= 80) { ElMessage.warning("本页最多 80 个元素"); return; } remember(); - const w = Math.min(template.w, canvas.value.designWidth); - const h = Math.min(template.h, canvas.value.designHeight); + const { w, h } = iconSize.value.enabled && isIcon(template.type) + ? effectiveIconSize.value + : { w: Math.min(template.w, canvas.value.designWidth), h: Math.min(template.h, canvas.value.designHeight) }; let suffix = count + 1; while (page.value.items.some(item => item.id === "e" + suffix)) suffix++; const item = { id: "e" + suffix, type: template.type, w, h, z: 2, payload: { ...template.payload }, - x: clamp(grid(x ?? 108 + count % 4 * 216), 0, canvas.value.designWidth - w), - y: clamp(grid(y ?? 300 + count % 3 * 60), 0, canvas.value.designHeight - h), + x: clamp(grid(x === undefined ? 108 + count % 4 * 216 : x - w / 2), 0, canvas.value.designWidth - w), + y: clamp(grid(y === undefined ? 300 + count % 3 * 60 : y - h / 2), 0, canvas.value.designHeight - h), }; page.value.items.push(item); selectedId.value = item.id; tab.value = "properties"; } function clickBlank(event: MouseEvent) { - if ((event.target as HTMLElement).closest(".layout-item")) return; + if (pickingRow.value || (event.target as HTMLElement).closest(".layout-item")) return; const rect = (event.currentTarget as HTMLElement).getBoundingClientRect(); - addItem(templates[0]!, (event.clientX - rect.left) / designScale.value - 66, - (event.clientY - rect.top) / designScale.value - 84); + addItem(templates[0]!, (event.clientX - rect.left) / designScale.value, + (event.clientY - rect.top) / designScale.value); } function removeItem() { if (!selected.value) return; @@ -260,6 +301,43 @@ function changeLayer(item: LayoutItem, top: boolean) { : Math.max(-2147483648, Math.min(...layers) - 1); updateValue(item, "z", layer); } +function clearSelection() { + selectedId.value = undefined; + rowSelection.value = []; +} + +function toggleRowSelection() { + const item = selected.value; + pickingRow.value = !pickingRow.value; + clearSelection(); + if (pickingRow.value && item?.type === "app_icon") rowSelection.value = [item.id]; +} + +function arrangeRow() { + const icons = page.value.items.filter(item => item.type === "app_icon" && rowSelection.value.includes(item.id)); + const arranged = arrangeIconRow(icons, canvas.value); + if (!arranged) { + ElMessage.warning("画布宽度不足,请减少选中的图标"); + return; + } + if (arranged.some(({ item, x, y }) => page.value.items.some(other => + other.type !== "dock_bg" && !rowSelection.value.includes(other.id) && + x < other.x + other.w - 0.5 && x + item.w > other.x + 0.5 && + y < other.y + other.h - 0.5 && y + item.h > other.y + 0.5))) { + ElMessage.warning("排列后会与其他元素重叠,请选择同一排图标"); + return; + } + if (arranged.some(({ item, x, y }) => item.x !== x || item.y !== y)) { + remember(); + for (const { item, x, y } of arranged) { + item.x = x; + item.y = y; + } + } + pickingRow.value = false; + clearSelection(); + ElMessage.success("已按行排列"); +} function centerHorizontally() { const item = selected.value; if (!item || item.w > canvas.value.designWidth) return; @@ -283,6 +361,14 @@ let drag: { item: LayoutItem; original: LayoutItem; pointer: number; clientX: nu function startDrag(event: PointerEvent, item: LayoutItem, resize: boolean) { if (!event.isPrimary || event.button !== 0 || drag) return; event.stopPropagation(); + if (pickingRow.value) { + if (!resize && item.type === "app_icon") { + rowSelection.value = rowSelection.value.includes(item.id) + ? rowSelection.value.filter(id => id !== item.id) + : [...rowSelection.value, item.id]; + } + return; + } selectedId.value = item.id; const neighbors = resize ? [] : page.value.items.filter(entry => entry.id !== item.id); drag = { item, original: { ...item }, pointer: event.pointerId, clientX: event.clientX, @@ -405,6 +491,9 @@ onUnmounted(() => { 重做 对齐栅格 水平居中 + {{ pickingRow ? '退出多选' : '多选图标' }} + 按行排列 删除元素 校验 导入 @@ -427,6 +516,15 @@ onUnmounted(() => { +
+

图标大小

+ 统一图标大小 + + + 应用全部 +

画布