feat(ui): let a widget opt out of the pressed style

A custom node that paints its own key highlight does not want the whole
node marked dirty on every press.
This commit is contained in:
2026-08-03 18:24:51 -04:00
parent 40f7a3e4ca
commit 2255fe214e
2 changed files with 28 additions and 2 deletions
+20
View File
@@ -194,4 +194,24 @@ assert(columns == 3 and side == 93, "width is the binding constraint in portrait
-- Five cards are two rows, so a reserve that eats the height budget shrinks the card.
assert(select(1, ui.cardSide(5, 12, 8, 300)) == 74, "height binds once the reserve is large")
-- A widget painting its own feedback is never given a pressed style, while an ordinary one
-- still is. Which node was hit is geometry, so the test names the target directly.
ui.reset()
local pressedCalls = {}
node.setPressed = function(_, on) pressedCalls[#pressedCalls + 1] = on end
local own = ui.custom{h = 20, press_style = false, on_click = function() end}
local styled = ui.button{h = 20, label = "ok", on_click = function() end}
local board = ui.screen(ui.box{own, styled})
local target
node.hit = function() return target end
target = own
board:down(0, 0)
board:up(0, 0)
assert(#pressedCalls == 0, "a self-painting widget is not styled on press")
target = styled
board:down(0, 0)
assert(pressedCalls[1] == true, "an ordinary widget still gets its pressed style")
print("ok")