Collapse focus/hover/normal ternaries into Style.controlFill helpers

TextField, NumberField, Dropdown, SearchableDropdown, and Toggle all
painted their background, border color, and border width with the same
three-line ternary ladder (`_focused ? focusFill : _hot ? hoverFill :
normalFill`). Five components × three properties × three branches is a
lot of room for one of them to drift from the others when a new state
ever gets added.

Add controlFill / controlBorder / controlBorderWidth on Style and rewrite
each call site as a single binding. No visual change.
This commit is contained in:
David Heinemeier Hansson
2026-05-20 20:37:04 +02:00
parent 8ed6e302b0
commit b54d8e04ae
6 changed files with 37 additions and 65 deletions
+22
View File
@@ -158,6 +158,28 @@ QtObject {
function selectedBorderFor(foreground, accent, urgent) { return Util.alpha(selectedStateColor(foreground, accent, urgent), selectedBorderAlpha) }
function focusBorderFor(foreground, accent, urgent) { return Util.alpha(focusStateColor(foreground, accent, urgent), focusBorderAlpha) }
// Composite helpers for the focus > hover > normal priority chain used by
// every form control surface (TextField, NumberField, Dropdown, Toggle,
// etc.). Saves callers from re-writing the three-line ternary ladder for
// fill / border / border-width on every Rectangle background.
function controlFill(focused, hot, foreground, accent) {
if (focused) return focusFillFor(foreground, accent)
if (hot) return hoverFillFor(foreground, accent)
return normalFillFor(foreground, accent)
}
function controlBorder(focused, hot, foreground, accent) {
if (focused) return focusBorderFor(foreground, accent)
if (hot) return hoverBorderFor(foreground, accent)
return normalBorderFor(foreground, accent)
}
function controlBorderWidth(focused, hot) {
if (focused) return focusBorderWidth
if (hot) return hoverBorderWidth
return normalBorderWidth
}
// Convenience colors resolved against the foundational palette.
readonly property color normalFill: normalFillFor(Color.foreground, Color.accent, Color.urgent)
readonly property color hoverFill: hoverFillFor(Color.foreground, Color.accent, Color.urgent)