From 27a47892e9d23bef6835f700fb079ba5ba1fab46 Mon Sep 17 00:00:00 2001 From: XIGE <710062962@qq.com> Date: Sun, 29 Nov 2026 11:49:02 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A5=BC=E5=9B=BE=E6=A0=87=E7=AD=BE=E9=97=B4?= =?UTF-8?q?=E8=B7=9D=E6=94=B9=E6=8C=89=E5=AD=97=E4=BD=93=E5=BA=A6=E9=87=8F?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=EF=BC=8C=E9=9A=8F=E7=B3=BB=E7=BB=9F=E5=AD=97?= =?UTF-8?q?=E5=8F=B7=E8=87=AA=E9=80=82=E5=BA=94=EF=BC=8C=E6=9D=9C=E7=BB=9D?= =?UTF-8?q?=E5=91=A8=E6=9C=88=E5=B9=B4=E5=A4=9A=E5=88=87=E7=89=87=E9=87=8D?= =?UTF-8?q?=E5=8F=A0=EF=BC=88v0.15=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 4 ++ .../app/ui/settings/SettingsFragment.kt | 2 +- .../com/focusbox/app/widget/LabelDonutView.kt | 47 ++++++++++--------- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4bc496f..5f1c8fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # 变更记录 +## 2026-11-29 · 饼图标签间距改按字体度量计算,随系统字号自适应,杜绝周月年多切片重叠(v0.15) + +- 同步源码更新 2 个文件(新增/修改 2,删除 0)。 + ## 2026-11-29 · 修复饼图标注重叠:周月年切片多时间距自动压缩,不再文字数字重合(v0.14) - LabelDonutView.layoutTags:一侧标签理想间距 29dp 放不下时按可用高度自动压缩(间距 = 可用高度 / 间隔数),替代原先"溢出整体上移 + coerceIn 钳回边界"把多个标签压到同一 y 的旧逻辑,相邻标注保证不重叠;极端小控件场景改为在可视区内均匀铺开 diff --git a/src/main/java/com/focusbox/app/ui/settings/SettingsFragment.kt b/src/main/java/com/focusbox/app/ui/settings/SettingsFragment.kt index 22f80fa..c83b5a1 100644 --- a/src/main/java/com/focusbox/app/ui/settings/SettingsFragment.kt +++ b/src/main/java/com/focusbox/app/ui/settings/SettingsFragment.kt @@ -373,6 +373,6 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) { } companion object { - const val VERSION = "0.14" + const val VERSION = "0.15" } } diff --git a/src/main/java/com/focusbox/app/widget/LabelDonutView.kt b/src/main/java/com/focusbox/app/widget/LabelDonutView.kt index fda6930..7abccc8 100644 --- a/src/main/java/com/focusbox/app/widget/LabelDonutView.kt +++ b/src/main/java/com/focusbox/app/widget/LabelDonutView.kt @@ -197,40 +197,45 @@ class LabelDonutView @JvmOverloads constructor( } } - /** 同侧标签按落点排序后做最小间距夹逼,再整体收回可视区 */ + /** + * 同侧标签按落点排序后做最小间距夹逼。 + * + * 最小间距不能写死:标签占位 = 间隙 + 时间行高 + 间隙 + 任务名行高, + * 随系统字号/字体(鸿蒙 Sans 字面更高)缩放,固定 29dp 在大字号下 + * 会让相邻标签的时间压到上一个标签的任务名上。 + * 这里全部由字体度量实时算出,放不下时压缩间距,任何字号都不重叠。 + */ private fun layoutTags(tags: List) { - val top = context.dpf(15f) - val bottom = height - context.dpf(17f) + val gap = context.dpf(4f) + val vfm = tagValuePaint.fontMetrics + val nfm = tagNamePaint.fontMetrics + // 时间在引线上方占 (gap + valueCell),任务名在下方占 (gap + nameCell) + val valueCell = -vfm.ascent + val nameCell = -nfm.ascent + nfm.descent + val ideal = gap + valueCell + gap + nameCell + context.dpf(2f) + // 上下边界同样按度量算:最顶标签的时间、最底标签的任务名不被裁切 + val top = gap + valueCell + context.dpf(2f) + val bottom = height - (gap + nameCell + context.dpf(2f)) val avail = (bottom - top).coerceAtLeast(0f) - val ideal = context.dpf(29f) + for (side in intArrayOf(-1, 1)) { val group = tags.filter { it.side == side }.sortedBy { it.anchorY } if (group.isEmpty()) continue - // 理想间距 29dp;周/月/年切片多时一侧放不下, - // 按可用高度压缩间距(间距 = 可用高度 / 间隔数), - // 保证相邻标签永不重叠——原先"溢出整体上移+钳回边界" - // 会把多个标签压到同一 y,文字数字叠在一起。 val minGap = if (group.size > 1) { minOf(ideal, avail / (group.size - 1)) } else ideal + // 前向:从上往下推,保证与上一个标签的间距 group.forEachIndexed { i, t -> t.y = if (i == 0) maxOf(t.anchorY, top) else maxOf(t.anchorY, group[i - 1].y + minGap) } - // 少量溢出(间距未压缩仍超界):整体上移,首端不低于 top - val overflow = group.last().y - bottom - if (overflow > 0f) { - group.forEach { it.y -= overflow } - if (group.first().y < top) { - // 上下都顶住仍放不下(极端小控件):在 [top, bottom] 内均匀铺开 - val n = group.size - if (n == 1) { - group[0].y = top - } else { - val step = avail / (n - 1) - group.forEachIndexed { i, t -> t.y = top + i * step } - } + // 末端超出底部:从下往上收(每个标签不超过下一个的 y - 间距,也不出顶界), + // 不会把标签压到同一位置 + if (group.last().y > bottom) { + group[group.size - 1].y = bottom + for (i in group.size - 2 downTo 0) { + group[i].y = minOf(group[i].y, group[i + 1].y - minGap).coerceAtLeast(top) } } }