Measure each chip with FontMetrics.advanceWidth

The shared TextMetrics had its text set imperatively inside the width
bindings, which went stale from the third chip on — every container
collapsed to single-char width, so Super/Space/Backspace were illegible
in combos of 3+. FontMetrics.advanceWidth(text) is a stateless method,
so every chip gets its own correct width.
This commit is contained in:
felixzsh
2026-08-11 17:31:36 -05:00
parent 3d42d0e726
commit 21f9f3fb57
+7 -9
View File
@@ -73,11 +73,14 @@ Item {
readonly property int chipGap: Style.space(8)
readonly property int chipPadX: Style.space(9)
readonly property int chipPadY: Style.space(4)
readonly property int chipHeight: Math.ceil(chipTextMetrics.height) + 2 * chipPadY
readonly property int chipHeight: Math.ceil(chipFontMetrics.height) + 2 * chipPadY
// Stateless measurement: FontMetrics.advanceWidth(text) returns the
// width for the given string directly. The previous shared TextMetrics
// (text set imperatively inside the width bindings) went stale from the
// third chip onwards, collapsing every container to single-char width.
function chipWidth(label) {
chipMetrics.text = String(label)
return Math.ceil(chipMetrics.advanceWidth) + 2 * chipPadX
return Math.ceil(chipFontMetrics.advanceWidth(String(label))) + 2 * chipPadX
}
function contentWidth() {
@@ -86,13 +89,8 @@ Item {
return w + Math.max(0, root.keys.length - 1) * chipGap
}
TextMetrics {
id: chipMetrics
font: chipFont
}
FontMetrics {
id: chipTextMetrics
id: chipFontMetrics
font: chipFont
}