feat(panels): 常用颜色改为自适应布局,图标选择器分页优化

- 常用颜色网格从固定 4x5 改为根据屏幕宽度自动计算列数
  (与 ShortX 图标列表一致的 adaptive layout)
- 图标浮窗选择器改为翻页模式,按当前可见容量动态分页
- 修复图标选择器关闭后无法再次打开的问题
- 入口返回信息增加中文 msg/syncMsg 及 updatedModules 字段
- 同步更新 README 文档
This commit is contained in:
Hermes
2026-04-20 14:48:01 +08:00
parent fbb8b6e682
commit ffbbcf647f
2 changed files with 57 additions and 8 deletions

View File

@@ -138,7 +138,7 @@ ToolHub/
- 收起后再次点击 **展开图标库** 可正常重新打开 - 收起后再次点击 **展开图标库** 可正常重新打开
当前交互要点: 当前交互要点:
- 常用颜色会按色相自动排序,主题色固定在最前 - 常用颜色会按色相自动排序,主题色固定在最前,并像 ShortX 图标列表一样按当前可用宽度自动排布
1. 切到 `ShortX图标` 时自动展开图标库 1. 切到 `ShortX图标` 时自动展开图标库
2. 列数按当前可用宽度自动计算,屏幕更宽时一页可显示更多图标 2. 列数按当前可用宽度自动计算,屏幕更宽时一页可显示更多图标
3. 每页容量按自动列数 × 当前可见行数实时计算 3. 每页容量按自动列数 × 当前可见行数实时计算

View File

@@ -713,7 +713,11 @@ FloatBallAppWM.prototype.buildButtonEditorPanelView = function() {
blueValueTv: null, blueValueTv: null,
recentGrid: null, recentGrid: null,
recentEmptyTv: null, recentEmptyTv: null,
commonGrid: null commonGrid: null,
commonCols: 0,
commonCellWidthPx: 0,
commonMinCellWidthDp: 72,
commonLastMeasuredWidth: 0
}; };
function getShortXPickerClosedLabel() { function getShortXPickerClosedLabel() {
@@ -1360,12 +1364,13 @@ FloatBallAppWM.prototype.buildButtonEditorPanelView = function() {
applyTintHexValue(buildArgbHex(alphaByte, rgbHex), !!pushRecent); applyTintHexValue(buildArgbHex(alphaByte, rgbHex), !!pushRecent);
} }
function createTintSwatchCell(label, hexValue, isFollowTheme) { function createTintSwatchCell(label, hexValue, isFollowTheme, cellWidthPx) {
var wrap = new android.widget.LinearLayout(context); var wrap = new android.widget.LinearLayout(context);
wrap.setOrientation(android.widget.LinearLayout.VERTICAL); wrap.setOrientation(android.widget.LinearLayout.VERTICAL);
wrap.setGravity(android.view.Gravity.CENTER_HORIZONTAL); wrap.setGravity(android.view.Gravity.CENTER_HORIZONTAL);
wrap.setPadding(self.dp(6), self.dp(6), self.dp(6), self.dp(6)); wrap.setPadding(self.dp(6), self.dp(6), self.dp(6), self.dp(6));
var lp = new android.widget.GridLayout.LayoutParams(); 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)); lp.setMargins(self.dp(4), self.dp(4), self.dp(4), self.dp(4));
wrap.setLayoutParams(lp); wrap.setLayoutParams(lp);
try { wrap.setBackground(self.ui.createRoundDrawable(self.withAlpha(cardColor, 0.96), self.dp(10))); } catch(eTintSwBg0) {} 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) {} try { if (tintPaletteState.recentEmptyTv) tintPaletteState.recentEmptyTv.setVisibility(android.view.View.GONE); } catch(eTintRecent2) {}
for (i = 0; i < list.length && i < 5; i++) { 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); tintPaletteBody.addView(tintCommonTitle);
var tintCommonGrid = new android.widget.GridLayout(context); var tintCommonGrid = new android.widget.GridLayout(context);
try { tintCommonGrid.setColumnCount(4); } catch(eTintCommonCols0) {} try { tintCommonGrid.setColumnCount(1); } catch(eTintCommonCols0) {}
tintPaletteBody.addView(tintCommonGrid); tintPaletteBody.addView(tintCommonGrid);
tintPaletteState.commonGrid = 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) { function getTintSortInfo(hexValue) {
var normalized = normalizeTintColorValue(hexValue, false); var normalized = normalizeTintColorValue(hexValue, false);
if (!normalized) return { hue: 999, sat: -1, val: -1 }; if (!normalized) return { hue: 999, sat: -1, val: -1 };
@@ -1683,12 +1709,22 @@ FloatBallAppWM.prototype.buildButtonEditorPanelView = function() {
{ label: "棕色", hex: "#FF8D6E63" }, { label: "棕色", hex: "#FF8D6E63" },
{ label: "银灰", hex: "#FFCBD5E1" } { label: "银灰", hex: "#FFCBD5E1" }
]); ]);
var tintCi;
for (tintCi = 0; tintCi < tintCommonDefs.length; tintCi++) { function renderTintCommonGrid() {
tintCommonGrid.addView(createTintSwatchCell(tintCommonDefs[tintCi].label, tintCommonDefs[tintCi].hex, !!tintCommonDefs[tintCi].followTheme)); 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(); renderRecentTintGrid();
renderTintCommonGrid();
setTintPaletteExpanded(tintPaletteState.expanded); setTintPaletteExpanded(tintPaletteState.expanded);
syncTintUiFromInput(false); syncTintUiFromInput(false);
@@ -1702,6 +1738,19 @@ FloatBallAppWM.prototype.buildButtonEditorPanelView = function() {
onTextChanged: function(s, st, b, c) {} onTextChanged: function(s, st, b, c) {}
})); }));
} catch(eTwIcon2) {} } 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) { function updateIconInputs(type) {
if (type === "file") { if (type === "file") {