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
+3 -13
View File
@@ -53,19 +53,9 @@ Rectangle {
readonly property bool _hot: hasCursor || mouse.containsMouse
color: activeFocus
? Style.focusFillFor(foreground, accent)
: (_hot
? Style.hoverFillFor(foreground, accent)
: Style.normalFillFor(foreground, accent))
border.color: activeFocus
? Style.focusBorderFor(foreground, accent)
: (_hot
? Style.hoverBorderFor(foreground, accent)
: Style.normalBorderFor(foreground, accent))
border.width: activeFocus
? Style.focusBorderWidth
: (_hot ? Style.hoverBorderWidth : Style.normalBorderWidth)
color: Style.controlFill(activeFocus, _hot, foreground, accent)
border.color: Style.controlBorder(activeFocus, _hot, foreground, accent)
border.width: Style.controlBorderWidth(activeFocus, _hot)
Behavior on color { ColorAnimation { duration: 100 } }