▣
module · drop-in viewer
What it does
game.ui.pointer
What is under the cursor, asked cheaply.
local Pointer = require("game.ui.pointer")
local moved, x, y = Pointer.moved("table")
if moved then
local id, index = Pointer.find(x, y, "^gp%-card%-(%d+)$")
if index then focus(tonumber(index)) end
end
Pointer.moved(key) -> moved, x, y— has the cursor moved since this key last asked. Reads the cursor position out of the input state, cached once a frame and shared between callers. No hit test happens here, so a frame with a resting cursor costs a few hundredths of a millisecond. The first ask for a key answerstrue, so a row already under a resting cursor lights on the frame its screen comes up.Pointer.forget(key)— make the nextmoved(key)answertrueanyway. What sits under a resting cursor changes when the screen under it does: a new hand is dealt, a card is played, a set of rows is rebuilt. The caller says so with this.Pointer.idsAt(x, y) -> { string }— the widget ids under a point, top-most first. This is the expensive half (about 1.3 ms), so it is asked on the framesmovedanswers true for and no others.Pointer.find(x, y, pattern) -> id, capture— the first id under the point that matches a Lua pattern, plus that pattern's first capture.Pointer.at() -> x, y— the cursor, without disturbing any key's mark.
On a touchscreen and on a pad the cursor never moves, so moved answers
false forever and nothing here costs anything — which is right, because
hover means nothing to a finger or a thumbstick. Taps and pad focus reach the
table and the cards by their own routes.
Discussion
Scoped to this part · feeds back into the world's score.
Sign in to post.sign in
No comments yet. Be the first.