natiny.view.get_pointer
Lua
natiny.view.get_pointer(view) -> x, y
Returns where the pointer is, measured from a view's top-left corner.
Parameters
| Name |
Type |
Description |
view |
number |
View handle |
Returns
| Type |
Description |
number |
Distance from the view's left edge to the pointer, in drawing units |
number |
Distance from the view's top edge to the pointer, in drawing units |
Example
Lua
-- a slider that follows the pointer while it is held
local function drag(self)
local px = natiny.view.get_pointer(self)
local _, _, w = natiny.view.get_rect(self)
value = math.max(0, math.min(1, px / w))
end
natiny.view.set_hook(slider, natiny.view.HOOK_MOUSE_DOWN, drag)
natiny.view.set_hook(slider, natiny.view.HOOK_MOUSE_MOVE, drag)