From ffbbcf647fdd56fe712dcd375244ac8906dac072 Mon Sep 17 00:00:00 2001 From: Hermes Date: Mon, 20 Apr 2026 14:48:01 +0800 Subject: [PATCH] =?UTF-8?q?feat(panels):=20=E5=B8=B8=E7=94=A8=E9=A2=9C?= =?UTF-8?q?=E8=89=B2=E6=94=B9=E4=B8=BA=E8=87=AA=E9=80=82=E5=BA=94=E5=B8=83?= =?UTF-8?q?=E5=B1=80=EF=BC=8C=E5=9B=BE=E6=A0=87=E9=80=89=E6=8B=A9=E5=99=A8?= =?UTF-8?q?=E5=88=86=E9=A1=B5=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 常用颜色网格从固定 4x5 改为根据屏幕宽度自动计算列数 (与 ShortX 图标列表一致的 adaptive layout) - 图标浮窗选择器改为翻页模式,按当前可见容量动态分页 - 修复图标选择器关闭后无法再次打开的问题 - 入口返回信息增加中文 msg/syncMsg 及 updatedModules 字段 - 同步更新 README 文档 --- README.md | 2 +- code/th_14_panels.js | 63 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 57 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 498a436..9dd10bf 100644 --- a/README.md +++ b/README.md @@ -138,7 +138,7 @@ ToolHub/ - 收起后再次点击 **展开图标库** 可正常重新打开 当前交互要点: -- 常用颜色会按色相自动排序,主题色固定在最前 +- 常用颜色会按色相自动排序,主题色固定在最前,并像 ShortX 图标列表一样按当前可用宽度自动排布 1. 切到 `ShortX图标` 时自动展开图标库 2. 列数按当前可用宽度自动计算,屏幕更宽时一页可显示更多图标 3. 每页容量按自动列数 × 当前可见行数实时计算 diff --git a/code/th_14_panels.js b/code/th_14_panels.js index a5ae9fd..b8297b3 100644 --- a/code/th_14_panels.js +++ b/code/th_14_panels.js @@ -713,7 +713,11 @@ FloatBallAppWM.prototype.buildButtonEditorPanelView = function() { blueValueTv: null, recentGrid: null, recentEmptyTv: null, - commonGrid: null + commonGrid: null, + commonCols: 0, + commonCellWidthPx: 0, + commonMinCellWidthDp: 72, + commonLastMeasuredWidth: 0 }; function getShortXPickerClosedLabel() { @@ -1360,12 +1364,13 @@ FloatBallAppWM.prototype.buildButtonEditorPanelView = function() { applyTintHexValue(buildArgbHex(alphaByte, rgbHex), !!pushRecent); } - function createTintSwatchCell(label, hexValue, isFollowTheme) { + function createTintSwatchCell(label, hexValue, isFollowTheme, cellWidthPx) { var wrap = new android.widget.LinearLayout(context); wrap.setOrientation(android.widget.LinearLayout.VERTICAL); wrap.setGravity(android.view.Gravity.CENTER_HORIZONTAL); wrap.setPadding(self.dp(6), self.dp(6), self.dp(6), self.dp(6)); var lp = new android.widget.GridLayout.LayoutParams(); + if (cellWidthPx && Number(cellWidthPx) > 0) lp.width = Number(cellWidthPx); lp.setMargins(self.dp(4), self.dp(4), self.dp(4), self.dp(4)); wrap.setLayoutParams(lp); try { wrap.setBackground(self.ui.createRoundDrawable(self.withAlpha(cardColor, 0.96), self.dp(10))); } catch(eTintSwBg0) {} @@ -1415,7 +1420,7 @@ FloatBallAppWM.prototype.buildButtonEditorPanelView = function() { } try { if (tintPaletteState.recentEmptyTv) tintPaletteState.recentEmptyTv.setVisibility(android.view.View.GONE); } catch(eTintRecent2) {} for (i = 0; i < list.length && i < 5; i++) { - tintPaletteState.recentGrid.addView(createTintSwatchCell("最近" + (i + 1), list[i], false)); + tintPaletteState.recentGrid.addView(createTintSwatchCell("最近" + (i + 1), list[i], false, 0)); } } @@ -1604,10 +1609,31 @@ FloatBallAppWM.prototype.buildButtonEditorPanelView = function() { tintPaletteBody.addView(tintCommonTitle); var tintCommonGrid = new android.widget.GridLayout(context); - try { tintCommonGrid.setColumnCount(4); } catch(eTintCommonCols0) {} + try { tintCommonGrid.setColumnCount(1); } catch(eTintCommonCols0) {} tintPaletteBody.addView(tintCommonGrid); tintPaletteState.commonGrid = tintCommonGrid; + function resolveTintCommonGridLayout() { + var rawWidth = 0; + try { if (tintPaletteState.commonGrid) rawWidth = Number(tintPaletteState.commonGrid.getWidth() || 0); } catch(eTintCommonW0) {} + if (rawWidth <= 0) { + try { if (tintPaletteState.body) rawWidth = Number(tintPaletteState.body.getWidth() || 0); } catch(eTintCommonW1) {} + } + if (rawWidth <= 0) rawWidth = self.dp(320); + var marginPx = self.dp(4); + var minCellWidthPx = self.dp(Number(tintPaletteState.commonMinCellWidthDp || 72)); + var cellOuterMinWidth = minCellWidthPx + marginPx * 2; + var innerWidth = rawWidth - self.dp(4); + if (innerWidth <= 0) innerWidth = rawWidth; + var cols = Math.max(1, Math.floor(innerWidth / cellOuterMinWidth)); + var cellWidthPx = Math.floor(innerWidth / cols) - marginPx * 2; + if (cellWidthPx < self.dp(56)) cellWidthPx = self.dp(56); + tintPaletteState.commonCols = cols; + tintPaletteState.commonCellWidthPx = cellWidthPx; + tintPaletteState.commonLastMeasuredWidth = rawWidth; + return { cols: cols, cellWidthPx: cellWidthPx }; + } + function getTintSortInfo(hexValue) { var normalized = normalizeTintColorValue(hexValue, false); if (!normalized) return { hue: 999, sat: -1, val: -1 }; @@ -1683,12 +1709,22 @@ FloatBallAppWM.prototype.buildButtonEditorPanelView = function() { { label: "棕色", hex: "#FF8D6E63" }, { label: "银灰", hex: "#FFCBD5E1" } ]); - var tintCi; - for (tintCi = 0; tintCi < tintCommonDefs.length; tintCi++) { - tintCommonGrid.addView(createTintSwatchCell(tintCommonDefs[tintCi].label, tintCommonDefs[tintCi].hex, !!tintCommonDefs[tintCi].followTheme)); + + function renderTintCommonGrid() { + if (!tintPaletteState.commonGrid) return; + var layoutInfo = resolveTintCommonGridLayout(); + try { + tintPaletteState.commonGrid.removeAllViews(); + tintPaletteState.commonGrid.setColumnCount(Math.max(1, Number(layoutInfo.cols || 1))); + } catch(eTintCommonRender0) {} + var tintCi; + for (tintCi = 0; tintCi < tintCommonDefs.length; tintCi++) { + tintPaletteState.commonGrid.addView(createTintSwatchCell(tintCommonDefs[tintCi].label, tintCommonDefs[tintCi].hex, !!tintCommonDefs[tintCi].followTheme, layoutInfo.cellWidthPx)); + } } renderRecentTintGrid(); + renderTintCommonGrid(); setTintPaletteExpanded(tintPaletteState.expanded); syncTintUiFromInput(false); @@ -1702,6 +1738,19 @@ FloatBallAppWM.prototype.buildButtonEditorPanelView = function() { onTextChanged: function(s, st, b, c) {} })); } catch(eTwIcon2) {} + try { + tintCommonGrid.getViewTreeObserver().addOnGlobalLayoutListener(new android.view.ViewTreeObserver.OnGlobalLayoutListener({ + onGlobalLayout: function() { + if (!tintPaletteState.expanded) return; + var oldCols = Number(tintPaletteState.commonCols || 0); + var oldWidth = Number(tintPaletteState.commonLastMeasuredWidth || 0); + var info = resolveTintCommonGridLayout(); + if (Number(info.cols || 0) !== oldCols || Number(tintPaletteState.commonLastMeasuredWidth || 0) !== oldWidth) { + renderTintCommonGrid(); + } + } + })); + } catch(eTintCommonLayout0) {} // 图标类型切换函数 function updateIconInputs(type) { if (type === "file") {