2 Commits
Author SHA1 Message Date
Jokul d1b7e083eb fix: 任务栏箭头与数值间距固定 + 数值右侧留边距
整数部分宽度改为动态计算两行最大整数位数,右对齐到此宽度:
箭头与数值间距固定不随位数变化,短的整数补占位,小数点对齐;
数值右侧加 4px 边距避免贴边
2026-08-08 21:47:00 +08:00
Jokul 72c1f1e702 feat: 任务栏双行网速数值小数点垂直对齐
将数值拆为整数部分(右对齐固定宽度)+ 小数+单位部分(左对齐),
整数位数不同时小数点仍垂直对齐,箭头位置保持不变
2026-08-08 21:35:38 +08:00
+59 -4
View File
@@ -77,6 +77,23 @@ AppletItem {
} }
} }
// 拆分速度字符串为整数部分:formatSpeedShort("194.07K") -> "194"
// 用于任务栏双行数值小数点对齐:整数部分右对齐,小数部分左对齐,
// 整数位数不同时小数点仍垂直对齐
function formatSpeedIntPart(bytesPerSec) {
var str = formatSpeedShort(bytesPerSec)
var idx = str.indexOf('.')
return idx < 0 ? str : str.substring(0, idx)
}
// 拆分速度字符串为小数+单位部分:formatSpeedShort("194.07K") -> ".07K"
// 与 formatSpeedIntPart 配合,分别渲染实现小数点对齐
function formatSpeedDecimalPart(bytesPerSec) {
var str = formatSpeedShort(bytesPerSec)
var idx = str.indexOf('.')
return idx < 0 ? "" : str.substring(idx)
}
// 带单位的速度/总量格式化函数(formatSpeed / formatTotal)已移至 NetCommon, // 带单位的速度/总量格式化函数(formatSpeed / formatTotal)已移至 NetCommon,
// 本文件未直接使用;弹窗与图表窗口经 common.formatSpeed / common.formatTotal 调用 // 本文件未直接使用;弹窗与图表窗口经 common.formatSpeed / common.formatTotal 调用
@@ -99,17 +116,31 @@ AppletItem {
// 用户主动选色后覆盖,空串回退到 primaryText 保持自适应 // 用户主动选色后覆盖,空串回退到 primaryText 保持自适应
readonly property color speedTextColor: (applet && applet.textColor.length > 0) ? applet.textColor : primaryText readonly property color speedTextColor: (applet && applet.textColor.length > 0) ? applet.textColor : primaryText
// 任务栏图标区:双行紧凑数值,箭头与数值紧贴、左对齐 // 任务栏图标区:双行紧凑数值,箭头与数值紧贴
// 设计原因:箭头与数值作为一组固定在左侧,数值左对齐紧贴箭头; // 设计原因:箭头与数值作为一组固定在左侧;
// 不给每行固定高度,让 RowLayout 按内容自然高度排列, // 不给每行固定高度,让 RowLayout 按内容自然高度排列,
// 整组垂直居中于 dock 区域,避免两行间出现过大间隙 // 整组垂直居中于 dock 区域,避免两行间出现过大间隙
// 小数点对齐:整数部分右对齐到两行最大整数宽度,小数部分左对齐,
// 整数位数不同时小数点仍垂直对齐;箭头与数值间距固定不随位数变化
Column { Column {
id: horizontalSpeed
visible: !root.isVerticalDock visible: !root.isVerticalDock
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left anchors.left: parent.left
anchors.leftMargin: 4 anchors.leftMargin: 4
anchors.right: parent.right
anchors.rightMargin: 4
spacing: 0 spacing: 0
// 两行整数部分的最大字符数:动态计算,整数短的行补占位到此宽度
property int maxIntDigits: Math.max(
root.formatSpeedIntPart(root.downloadSpeed).length,
root.formatSpeedIntPart(root.uploadSpeed).length
)
// 整数部分固定宽度:按最大字符数 × 单字符宽度估算
// 单字符宽度约为 dockSize * 0.14(数值字号的 ~55%)
property real intPartWidth: maxIntDigits * root.dockSize * 0.14
// 下载速度行 // 下载速度行
RowLayout { RowLayout {
spacing: 2 spacing: 2
@@ -121,8 +152,20 @@ AppletItem {
Layout.alignment: Qt.AlignVCenter Layout.alignment: Qt.AlignVCenter
} }
// 整数部分:右对齐到两行最大整数宽度,短的补占位
Text { Text {
text: root.formatSpeedShort(root.downloadSpeed) text: root.formatSpeedIntPart(root.downloadSpeed)
font.pixelSize: root.dockSize * 0.25
font.weight: Font.Medium
color: root.speedTextColor
Layout.alignment: Qt.AlignVCenter
Layout.preferredWidth: horizontalSpeed.intPartWidth
horizontalAlignment: Text.AlignRight
}
// 小数+单位部分:左对齐,紧跟整数部分
Text {
text: root.formatSpeedDecimalPart(root.downloadSpeed)
font.pixelSize: root.dockSize * 0.25 font.pixelSize: root.dockSize * 0.25
font.weight: Font.Medium font.weight: Font.Medium
color: root.speedTextColor color: root.speedTextColor
@@ -142,8 +185,20 @@ AppletItem {
Layout.alignment: Qt.AlignVCenter Layout.alignment: Qt.AlignVCenter
} }
// 整数部分:右对齐到两行最大整数宽度,短的补占位
Text { Text {
text: root.formatSpeedShort(root.uploadSpeed) text: root.formatSpeedIntPart(root.uploadSpeed)
font.pixelSize: root.dockSize * 0.25
font.weight: Font.Medium
color: root.speedTextColor
Layout.alignment: Qt.AlignVCenter
Layout.preferredWidth: horizontalSpeed.intPartWidth
horizontalAlignment: Text.AlignRight
}
// 小数+单位部分:左对齐,紧跟整数部分
Text {
text: root.formatSpeedDecimalPart(root.uploadSpeed)
font.pixelSize: root.dockSize * 0.25 font.pixelSize: root.dockSize * 0.25
font.weight: Font.Medium font.weight: Font.Medium
color: root.speedTextColor color: root.speedTextColor